Ad
  • Custom User Avatar

    Looks like your code is mutating the list, which is not allowed by the kata and the reason for the weird side effect you are seeing.
    Trying running this on your code, which will give the wrong answer, just like in the test you posted:

    const l0 = List.iterate(a => a + 1, 0)
    l0.take(10).toList()
    console.log(l0.take(10).toList()) // prints [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
    
  • Custom User Avatar

    I'm not sure what you are getting at here, but what I can say is:

    1. Polydivisible numbers are by definition polydivisibile upto n-1 in base n, using the digits that form base n (0, 1, ..., n-2, n-1).
    2. The claim is that a polydivisible number of a lower base is polydivisible in a higher base, but not vice versa.

    So in your example, I see two issues:

    1. You can't divide by 2 in base 2, as there isn't a single digit in base 2 for the numeral 2b2, you have to use the next order of magnitude: 10b2, so the second check below is invalid:
      • 3b10 = 11b2 -> 11b2 / 1b2 = 11b2 -> 11b2 == floor(11b2)
      • 3b10 = 11b2 -> 11b2 / 10b2 = 1.1b2 -> 1.1b2 != floor(1.1b2)
    2. Moving from base 10 to base 2 and expecting the property to hold is invalid.

    Please let me know if I have missed your point.