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.
a one liner that is actually easy to understand, good one.
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.Is it for getting a negative sum, so that inject subtracts it based on that instead of writing it seperately?
In the ternary operator's else condition, what is the purpose of -d.to_i?
I understand the to_i part, its the -d that is throwing me off.
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.
Yes. Think less algorithmically and more mathematically. It's possilbe to solve this with only one semicolon. My advice is to think carefully about relations between the length of a set and its power-set counterpart.
This comment is hidden because it contains spoiler information about the solution
Any help on what ruby feature I should use to automatically call the next name and also will Argument error suffice for calling an error??
Correct me if I am wrong, but that is not said anywhere in the description.
Your function may be called without any given arguments, like
howManyLightsabersDoYouOwn() => 0
This comment is hidden because it contains spoiler information about the solution
Where a and b are strings is the expession if a > b same as if a.length > b.length