Haskell - FizzBuzz P97301


Statement
 

pdf   zip

html

En el cèlebre article Using FizzBuzz to Find Developers who Grok Coding (el podeu trobar a l’enllaç http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/), Imran Ghory explica que la majoria dels programadors que entrevista com a candidats a una feina no poden escriure ni un programa senzill:

On occasion you meet a developer who seems like a solid programmer. They know their theory, they know their language. They can have a reasonable conversation about programming. But once it comes down to actually producing code they just don’t seem to be able to do it well.

After a fair bit of trial and error I’ve discovered that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems. So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK. An example of a Fizz-Buzz question is the following:

Write a program that prints the numbers from 0 to 100, but: For multiples of three print ‘Fizz’ instead of the number, and for the multiples of five print ‘Buzz’. For numbers which are multiples of both three and five print ‘FizzBuzz’.

Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes. Want to know something scary? The majority of comp sci graduates can’t. I’ve also seen self- proclaimed senior programmers take more than 10-15 minutes to write a solution.

Demostreu que vosaltres sí que podeu escriure un programa així en Haskell, i amb estíl! (Però no trigueu gaire...)

Especificació

Definiu la funció

fizzBuzz :: [Either Int String]

que retorni la llista infinita de “FizzBuzz” per a cada enter de 0 en endavant.

Public test cases
  • Input

    take 8 fizzBuzz
    

    Output

    [Right "FizzBuzz",Left 1,Left 2,Right "Fizz",Left 4,Right "Buzz",Right "Fizz",Left 7]
    
  • Information
    Author
    Jordi Petit
    Language
    Catalan
    Other languages
    English
    Official solutions
    Haskell
    User solutions
    Haskell