[Jprogramming] FizzBuzz
Roger Hui
rhui000 at shaw.ca
Wed Mar 7 05:11:00 HKT 2007
If you were doing this in a real interview you'd
better be more careful. Strictly speaking your
programs fail because they print "fizz" instead
of "Fizz", etc.
----- Original Message -----
From: June Kim <juneaftn at gmail.com>
Date: Tuesday, March 6, 2007 12:33 pm
Subject: [Jprogramming] FizzBuzz
> FizzBuzz is a very simple toy problem for screening programming
> applicants at interviews.
>
> The problem is:
>
> Write a program that prints the numbers from 1 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".
>
> see some solutions in various languages at:
> * http://mult.ifario.us/articles/2007/01/25/laziness-and-fizzbuzz-
> in-haskell
> * http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-
> find-developers-who-grok-coding/
> * http://programming.reddit.com/info/10d7w/comments
> * http://www.ittutor.net/forums/index.php?showtopic=31262
> * http://tkyte.blogspot.com/2007/02/what-is-your-fizzbuzz-factor.html
>
> How short and simple solution in J can you write for this problem?
>
>
> Following are my trials:
>
> f=:0=3&|
> b=:0=5&|
> pr=:[: ; (('';'fizz') {~ f) , ('';'buzz') {~ b
> fb=:":`pr at .(f+.b)"0
>
> s=:(('';'fizz') {~ f ) , each ('';'buzz') {~ b
> ll=:,:~ s&>
> fb2=:[: ":&> (a: = {.@])}@ll@:(<"0)
>
> assert (fb -: fb2) >:i.100
More information about the Programming
mailing list