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.
Thanks for the example case, I think I misread the if/else logic the first time round. Much appreciated!
This comment is hidden because it contains spoiler information about the solution
hi, could someone help explain the line:
c = n.to_s.split('').each.with_index.inject(0){ |s, (v, i)|
s + v.to_i ** (p + i)
}
I understand that this sums the series as required in the problem description, but am unsure how the behaviour of .with_index works with .inject(0) {|s,(v,i)| ... } to create the sum. From my searches on stackoverflow, my guess is that with_index creates a key-value hash that corresponds with (v, i), and interacts with the inject enumerator? Appreciate if someone could clarify on this please.