7 kyu

Simple eviternity numbers

312 of 1,087KenKamau
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • ohjelmoija Avatar

    Passing all tests but timing out due to long runtime heh, interesting kata.

    def solve(a, b): isEviternity = 0

    for i in range(a, b):
        if all(char in "358" for char in str(i)):
            count3 = str(i).count("3")
            count5 = str(i).count("5")
            count8 = str(i).count("8")
    
            if count8 >= count5 >= count3:
                isEviternity += 1
    
    return isEviternity
    
  • ejini战神 Avatar

    All languages should have such sample and fixed tests to prevent solutions with wrong inclusive-upper-bound checking. (<= b instead of < b)

    • a = 8, b = 888 --> 13
  • ejini战神 Avatar

    C#: method name should be PascalCase (Please refer to implementation of backward compatibility here )

  • stellartux Avatar
  • Infuzibil Avatar

    The code passed on the upper bound (500000) but times out on random tests? How is this possible? Or am I supposed to pass all 45 random tests in 12 seconds?

    def solve(a,b):
        evtn = 0
        for n in range(a, b):
            n = str(n)
            srt = n.translate(n.maketrans('358', '   ')).strip() == ''
            if not srt:
                continue
            a, b, c = n.count('8'), n.count('5'), n.count('3')
            if a>=b>=c:
                evtn += 1
        return evtn
    
  • Fuzzi Avatar

    Any tips how to optimize the performance?

    I already tried to, but still too slow. My code is in the reply so other people can see this question.

  • Hamburgler Avatar

    You could derive the 3 numbers dynamically instead of hardcoading them to 3, 5, and 8. This could avoid the trivial solution of pasting in a series of numbers and instead force the use of an algorithmic solution.

    If solved algorithmatically, there is no way this should be ranked as 7 kyu.

  • vellivid Avatar

    This comment has been hidden.

  • scanning Avatar

    There are a lot of tests in 'Attempt' so you run out of time with viable solution. Since this is low level kata maybe :

    1. Give some warning in description.
    2. Add performace tag.
    3. Lower test count.
    4. Add one out of bounds test in 'test' section that give time orentation how fast the code should be.
  • antonkorolev02135 Avatar

    I'm confused.. How come number 35 is not the eviternity number? It contains 3 and 5 and the number of didgits is equal.. What am I missing ?

  • Ashotovich1990 Avatar

    This comment has been hidden.

  • fenring76 Avatar

    Tests are wrong or description is inaccurate.

    There must be at least one 8 in the number according to the tests, but the description includes situations like this: 7 --> 0 >= 0 >= 0.

  • anter69 Avatar
    • There seems to be a problem with the python random tests, e.g.:

      input: 90 139701
      result: 99
      [358, 385, 538, 583, 588, 835, 853, 858, 885, 888, 3588, 3858, 3885, 5388, 5588, 5838, 5858, 5883, 5885, 5888, 8358, 8385, 8538, 8558, 8583, 8585, 8588, 8835, 8853, 8855, 8858, 8885, 8888, 35588, 35858, 35885, 35888, 38558, 38585, 38588, 38855, 38858, 38885, 53588, 53858, 53885, 53888, 55388, 55838, 55883, 55888, 58358, 58385, 58388, 58538, 58583, 58588, 58835, 58838, 58853, 58858, 58883, 58885, 58888, 83558, 83585, 83588, 83855, 83858, 83885, 85358, 85385, 85388, 85538, 85583, 85588, 85835, 85838, 85853, 85858, 85883, 85885, 85888, 88355, 88358, 88385, 88535, 88538, 88553, 88558, 88583, 88585, 88588, 88835, 88853, 88855, 88858, 88885, 88888]
      

      That's basically all 3, 4 and 5 digit numbers, which is 103 - 4 = 99, confirmed by the sample tests

    • The description doesn't say that these numbers can only have the digits 3, 5, 8

    • suggestion: remove "simple" from the title ;-)

  • kontic Avatar

    JS version Are you sure about random tests? Most of them expect Expected: 2496. I can only pass fixed tests :(