Fizz=: 'Fizz' #~ 0 = 3&|
Buzz=: 'Buzz' #~ 0 = 5&|
FB  =: (": [^:(0&[EMAIL PROTECTED]@]) Fizz,Buzz)"0

FB >: i.100



----- Original Message -----
From: June Kim <[EMAIL PROTECTED]>
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=:":[EMAIL PROTECTED](f+.b)"0
> 
> s=:(('';'fizz') {~ f ) , each ('';'buzz') {~ b
> ll=:,:~ s&>
> fb2=:[: ":&> (a: = [EMAIL PROTECTED])[EMAIL PROTECTED]@:(<"0)
> 
> assert   (fb -: fb2) >:i.100
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to