6 kyu

Number Sequence Rabbit Hole

62 of 84amir650
Description
Loading description...
Puzzles
Mathematics
  • Please sign in or sign up to leave a comment.
  • ahmet_popaj Avatar

    Mathy challenge in fact.

  • nisen25 Avatar

    for each generator call, it must produce one number from the sequence?????

  • user7391375 Avatar

    is there a solution in python? I think there is a time limit (12 secs) when you attempt. my code pass the small and medium sized smoke test but no luck with large dataset. I just wanna check if there is a solution, I don't ask for the soultion itself.

  • JohanWiltink Avatar

    LC translation

    this translation modifies the description ( LC needs some more information than other languages )

  • JohanWiltink Avatar
  • JohanWiltink Avatar
  • anter69 Avatar

    You are currently running only one huge test (length 500k...1M). You should have a few fixed tests of smaller length (10, 20, 50, ...) so people can debug their code without a huge error message.

    Oh, and a hardcoded solution fits easily into 1000 bytes... even 300 :-)

  • anter69 Avatar

    Approved + cleaned up description

  • anter69 Avatar

    Seemed interesting at first, but turned out to be just another one of those katas where you calculate the first few elements, search for it, then copy-paste a magic formula...

  • mauro-1 Avatar

    Tests can compare specific ranges, no need to compare the sequence from beginning every time.

    Random tests should compare the entire range in a single assert to avoid long sequences of 1 should equal 2, 2 should equal 1, ...

    For example:

    for _ in num_tests:
        start = randrange(100_000)
        length = randrange(10, 100)
        expected = ...
        actual = [*itertools.islice(special_sequence(), start, start+length)]
        tests.assert_equals(actual, expected)
    
  • mauro-1 Avatar

    Make it clearer that when a number is both square and triangular (36, 1225, 41616, ...), squares always precede tringles ((28,'t'), (36,'s'), (36,'t'), (45,'t') and not (28,'t'), (36,'t'), (36,'s'), (45,'t')).

    You can put a limit on code size to avoid precoded sequences.

  • benjaminzwhite Avatar

    Nice kata @amir650 !

    Just 2 small things: you have 3 different spellings of Hofstadter in Discourse - the correct one is Hofstadter (it's not an easy name to spell that's for sure)

    Also, I'd make it clearer that the "magic derived sequence" mentioned in the Task that you want people to produce for the kata is in fact the "2,1,2..." one rather than the "squares + triangle numbers in order".

    I know it's clear from the tests, but just adding something like "...for the magic derived sequence 2, 1, 2...." or something.

  • Voile Avatar

    Sample test is broken:

    File "/workspace/default/tests.py", line 29
        def test_case():
    IndentationError: unexpected unindent
    
    Traceback (most recent call last):
      File "/workspace/default/tests.py", line 2, in <module>
        from solution import s2
    ImportError: cannot import name 's2' from 'solution' (/workspace/default/solution.py)
    

    Initial code also seems to be incorrect:

    Traceback (most recent call last):
      File "/workspace/default/.venv/lib/python3.10/site-packages/codewars_test/test_framework.py", line 112, in wrapper
        func()
      File "/workspace/default/tests.py", line 39, in test_second_oldest_first
        g2 = special_sequence()
    TypeError: special_sequence() missing 1 required positional argument: 'ages'
    

    Also, test_second_oldest_first? There are many things left over from kata sample template that should be cleaned up.