Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Omfg, this kata description like puzzle.
Yes, it is for the sake of the inject. If
d1
is the first digit ofid
, after themap.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.It's broken in Ruby. Works fine in other languages
No. There's an easier way of doing this. Think less algorithmically, and more mathematically.
Your function may be called without any given arguments, like
howManyLightsabersDoYouOwn() => 0