Ad
  • Custom User Avatar
  • Custom User Avatar

    Don't even try to simulate everything that happens. That's nice to see patterns and validate your solution against smaller inputs ( because it means you can generate tests yourself ), but it's never going to work for bigger inputs.

    There's a reason this kata has a performance tag and a specified upper bound. O(n²) won't cut it; you'll need O(n) or very close to it.

    If it makes you feel better, my first solutions ( yes, plural ) turned out not to be able to handle a million ants either ( though I could handle a hundred thousand; I skipped simulating entirely ).

  • Default User Avatar

    Difficult to decide whether you'd use the ternary for the smallest code or use an if statement to make it more readable for someone else. I guess you'd go with the ternary because a dev should be able to recognise it.

  • Default User Avatar
  • Custom User Avatar

    Yes, you can use z to hold the resulting array, you can also delete it and write your code inside the function too if you want.