Ad
  • Custom User Avatar

    Omfg, this kata description like puzzle.

  • Default User Avatar

    Yes, it is for the sake of the inject. If d1 is the first digit of id, after the map.with_index step it looks like:

    [d1 * 7, -d2, d3 * 7, -d4, d5 * 7, -d6, d7 * 7, -d8]

    Add it all up and factor out the 7 and it looks like:

    (d1 + d3 + d5 + d7) * 7 - d2 - d4 - d6 - d8.

    This takes care of the instruction to "Take the sum of 1st, 3rd, 5th, 7th and 9th digit and multiply it by 7. Then subtract the sum of 2nd, 4th, 6th and 8th digits from this value." It would probably read more clearly if id was first partitioned into even/odd indices and both were manipulated separately, but the end result is the same.

  • Custom User Avatar

    It's broken in Ruby. Works fine in other languages

  • Custom User Avatar

    No. There's an easier way of doing this. Think less algorithmically, and more mathematically.

  • Custom User Avatar

    Your function may be called without any given arguments, like howManyLightsabersDoYouOwn() => 0