Ad
  • Custom User Avatar

    I could edit the Python version. Both tests have been added.

  • Custom User Avatar

    I've added those tests.

    I'll see if I can edit the Python version. It might be some permissions thing, and I might have a permission you don't.

    ( After this translation is approved, that is. That'll make me a contributor - right now I can't edit at all. )

  • Custom User Avatar
    comfortableWord word = and $ zipWith (/=) <*> tail $ (`elem` "yuiophjklnm") <$> word
    
    confortableWord word = and (zipWith (/=) wordMap (tail wordMap))
      where wordMap = map ( \ letter -> letter `elem` "yuiophjklnm" ) word
    

    It maps word to a list of booleans that indicate if its letters are under the right hand ( true if so, false if not ), it then builds a list of comparisons of every letter with the previous letter for inequality, then it takes the logical and of that list.

    So your crude understanding is correct! :] and [booleans] reduces a list to a single boolean, and elem for "element", given a single element and a list, returns a boolean. <*> is the S combinator, <$> is infix for map, both of which help conciseness and completely kill readability if you don't know Haskell ( most people that do should be able to read this though ). $ is another combinator that obviates the need for parentheses around everything to its right ( same story about concise and unreadable unless you know Haskell ).

    No, the random tests do not do what you think they do. The actual word generator is resize 8 $ listOf $ elements (['a'..'z']), which generates words of up to 8 characters ( a word is a list of characters, the possible elements are 'a'..'z', and the length of the list, thus the word, is resized to a maximum of 8 ); forAll by default runs 100 tests.

    You're right to be careful and I can't fault you for not being able to read Haskell. :] I promise the translation is OK; I've done quite a few.

    Two thing to note: the random generator also generates empty words, for which the reference solution expects True. There should really be a fixed tests for that, and True is the correct value mathematically ( and [] == True and or [] == False the same way sum [] == 0 and product [] == 1 ). There should also really be a fixed test with every letter on the keyboard, to test for spelling errors and such in user solutions. It wouldn't hurt to add those to the example tests as well.

  • Default User Avatar

    not really, but C is faster than other languages, so it probably takes as much time as 100 random tests in JavaScript or so x) but ok, reducing it to 100