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]
    
  • Default User Avatar

    I'm sorry but what is this even supposed to mean (Attempt tests)?

    l0 = List.iterate(inc,0), l1 = [0,1,2,3,4,5,6,7,8,9], l2 = l0.take(10)
    l1 === l2
    l1 === l2
    expected [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] to deeply equal [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]

    Where does [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ] come from? I do console.log(List.iterate(inc, 0).take(10).toList()); and it prints [
    0, 1, 2, 3, 4,
    5, 6, 7, 8, 9
    ]

    Same question to the following:

    l = List.iterate(inc,0)

    l.head()
    l.tail().head()
    l.tail().take(3)
    expected [ 2, 3, 4 ] to deeply equal [ 1, 2, 3 ].

  • 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.

  • Default User Avatar

    The following info:

    The interesting thing about polydivisiblity is that it relates to the underlying number, but not the base it is written in, so if aliens came to Earth and used base 23 (11 fingers on one hand and 12 on the other), no matter what squiggles they use to write numbers, they would find the same numbers polydivisible!

    As well as this:

    ...(and a polydivisible base 10 number when converted to 11100 in base 10).

    seems to be misleading. For example, number 3 (base 10) is polydivisble in base 10, but the same "underlying number" in base 2 (11) is not polydivisble.
    And 11100 is not polydivisble in base 10...