Ad
  • Custom User Avatar

    Thanks for the example case, I think I misread the if/else logic the first time round. Much appreciated!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    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.