6 kyu

Fizz Buzz Reloaded

129 of 358the_Hamster
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • saudiGuy Avatar
  • Mitsunee Avatar

    Next time I would prefer that instead of relying on implementation details such as ordered dicts/Maps you simply provide an array of tuplies (i.e. the result of functions.entries() in JS). the V8 engine happens to also have ordered Maps and Sets, but that is not guranteed to happen in other JS engines.

    • trashy_incel Avatar

      what about this ?

      The entries() method of Map instances returns a new map iterator object that contains the [key, value] pairs for each element in this map in insertion order.

  • tmxk Avatar

    If multiple functions are true for any given x, return them in same order found in the intial dictionary. (for example, in the case above 15 is "fizzbuzz" not "buzzfizz" because "fizz" appears first)

    But a "dictionary" should have no "order"..?

    • FArekkusu Avatar

      But dictionaries in Python 3.6 are ordered, no?

      Question marked resolved by FArekkusu 7 years ago
    • tmxk Avatar

      Oh really? I really don't know new properties in py3.6.

      May I firstly clarify a bit, do you really mean that when I input {1:2,3:4} and {3:4,1:2} they are actually different, or just I just simply use the dict as a list and need not to care about the order?

    • Blind4Basics Avatar

      yes, see the note at the end of the description.

    • Blind4Basics Avatar

      crossed messages. To be more precise: dict for py3.6 and above retains the order in which the items have been pushed in. So it's "ordered", but not "sorted".

    • Unnamed Avatar

      As far as I remember, they are still not officially ordered, it's just an implementation detail.

    • tmxk Avatar

      This kata is designed with Python3.6 in mind. In this version of Python dictionary's are ordered.

      Well, I am still not understanding.. Does that mean that we should have

      funcs3 = {"fizz" : lambda x: x % 3 == 0,
                "buzz" : lambda x: x % 5 == 0}
      fizz_buzz_reloaded(1, 19, 1, funcs3)
      # returns '1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz 16 17 fizz 19'
      

      while

      funcs3 = {"buzz" : lambda x: x % 5 == 0,
                "fizz" : lambda x: x % 3 == 0}
      fizz_buzz_reloaded(1, 19, 1, funcs3)
      # should return '1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 buzzfizz 16 17 fizz 19' ?
      

      ?

    • the_Hamster Avatar

      ^ for this kata you shouldn't have to do anything with the functions other than iterate through them (e.g "for func in functions: do X")

      As for ordered dicts being a 3.6 implementation detail yes that is the case. However I've seen in mentioned in a tweet[1] that they plan on keeping it since ordered dicts have turned out to be suprisingly useful.

      [1] https://twitter.com/raymondh/status/850102884972675072?lang=en

    • FArekkusu Avatar

      True, I've done a little research today to check this and it was stated that Python 3.7 will have ordered dicts as a language feature.

    • tmxk Avatar

      Thanks for all explanations above. Now I know that "dict is ordered" is a new implementation feature in py3.6, which means (I think) that when I do list(a dict), I actually get a sorted list, while it may not be sorted before 3.6.

      However, in this kata, what I see is that the order I use should be the order I type. I mean when I type {a:b,c:d} and {c:d,a:b}, they should cause different results, or simply I should at least bool({1:2,3:4}=={3:4,1:2})==False. I think this shouldn't be, so I asked to check whether I'm misunderstanding.

      If multiple functions are true for any given x, return them in same order found in the intial dictionary. 
      (for example, in the case above 15 is "fizzbuzz" not "buzzfizz" because "fizz" appears first) 
      

      I think it means that the only reason that "fizz" comes before "buzz" is "fizz" is firstly mensioned when I type the parameter of the function.

    • Blind4Basics Avatar

      To be more precise: dict for py3.6 and above retains the order in which the items have been pushed in. So it's "ordered", but not "sorted".

      ;)

      meaning:

      d = {'b':1, 'z':2, 'a':3, 'c':4}
       
       with that, you are guranteed that whatever you do with the dict, you'll get the items/keys/values in this order:
       
       list(d.items()) == [('b',1), ('z',2), ('a',3), ('c',4)]
       
       and furthermore:
       
       d['b'] = 486
       list(d.items()) == [('b',486), ('z',2), ('a',3), ('c',4)]
       
       d['x'] = -12
       list(d.items()) == [('b',486), ('z',2), ('a',3), ('c',4), ('x',-12)]
      

      So it's definitely NOT sorted. But it is definitely ordered. In the same manner than a list is.

    • tmxk Avatar

      OK, now I totally understand. (I wonder why I didn't notice when I did some tests before..)

      Simply give an example for those confused:

      print(list({1:2,3:4}))
      # returns [1, 3]
      print(list({3:4,1:2}))
      # returns [3, 1]
      
  • nmelhado Avatar

    I can't seem to call the map function within fizzBuzzReloaded. Can someone give me a hint?

    • FArekkusu Avatar

      Do you mean new Map(...) in JavaScript version or the .map() method? Because the first one is an associative array, not a function.

  • ChaosD Avatar

    Is it appropriate to ask for hints here? I've been struggling to understand why one test (with expected numbers only) seems to be off by 4. I guessed the parameters of the test and it seems to produce the desired results. If its okay, i will also post code.

    • Voile Avatar

      Have you accounted for the fact that both ends are inclusive? So you need to include both 1001 and 105 when generating the sequence.

    • ChaosD Avatar

      This comment has been hidden.

    • the_Hamster Avatar

      ChaosD there is a problem with your code snippet. I could tell you the awnser but you won't learn from it.

      but heres a helpful hint: write a function that counts 1 to 10 and 10 to 1 (make sure to use the same format as my function, eg 1, 10, 1 ... 10, 1, -1) . Your code will fail do that....How?...why?

    • ChaosD Avatar

      This comment has been hidden.

      Question marked resolved by ChaosD 7 years ago
    • Voile Avatar

      InconsequentialHumiliatingArray

      I found the randomly generated link name somewhat relevant and hilarious ;-)

    • ChaosD Avatar

      sometimes, when all the stars align, RNGesus rewards you with blatant irony :D

    • Voile Avatar

      Let's say you're counting down from 10 to 1: You want to say "go from 10 to 0 not including 0", but what your code does at the moment is "go from 11 to 1 not including 1" ;-)

    • ChaosD Avatar

      Thanks again... counting is hard when I'm tired.

  • FArekkusu Avatar

    JavaScript translation available! Please review and approve it ;)

    I know the tests are barely readable, but don't worry, I fully copied your original fixture.

  • Blind4Basics Avatar

    If multiple functions are true for any given x, return them in same order found in the intial dictionary. (for example in the case above 15 is "fizzbuzz" not "buzzfizz" because "fizz" appears first in the dictionary)

    That applies ONLY for py 3.6 and above. So either you have to provide a list of tuples, or you have to be explicit about that. Dictionaries were unordered before py3.6.

    • Voile Avatar

      As far as I can see only Python 3.6 is available, so that's already dealt with.

      Issue marked resolved by Voile 7 years ago
    • Blind4Basics Avatar

      Ah, I missed that they were dark grayed...

      Though, a note should be added for those who do not know about this feature.

    • lechevalier Avatar

      B4B is right. A kata like this musn't be version-dependent: CW allows to exclude languages, but not versions. Unless a note is added to only use Python 3.6 and translation is restricted to this version, this issue isn't resolved.

    • the_Hamster Avatar

      If I change to lists of functions now I potentically invalidate a bunch of solutions (plus...its work, lol).

      So I'll just make a note of this behaviour in the description.

    • Blind4Basics Avatar

      No, what we are telling is that you should update the description, not the code. ;)

    • the_Hamster Avatar

      Yeah, its done.

  • tachyonlabs Avatar

    In your sample tests, you've got a test4/text4 typo here:

    test4_expected = '19 fizz 17 16 fizzbuzz 14 13 fizz 11 buzz fizz 8 7 fizz buzz 4 fizz 2 1'
    Test.assert_equals(text4_expected, test4_actual)
    

    and you've also got expected and actual reversed, so error messages claim that the desired result should equal the incorrect result instead of the other way around.