Two minute challenge

Notices and updates
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Two minute challenge

Post by cormullion »

OK, here's a trivial challenge to solve in 2 minutes or less.
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”.
When you've written your newLISP script, read this blog entry to find out more.

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Re: Two minute challenge

Post by DrDave »

Thanks for posting that, Mr. C. I resorted to using COND, plus for ease of reading, defined three other functions that are predicates for the testing for being a factor of 15, 5, or 3. I accessed the numbers by using DOTIMES, forgeting that it starts at 0. So I guess I get points off for covering 0-99 instead of 1-100, LOL

After I read through the blog, I noticed that most entries did the test for being a factor of both 3 and 5 by ANDing. I was a bit surprised that checking to be a factor of 15 wasn't the norm for doing that.

It was certainly easy enough to define a function in under 2 minutes by plugging in those predicates, but then it took another minute or so to actually define the three predicates.

I think that is doing well, considering I am just a "casual" programmer having taken only two formal computer science courses at the university. (Well, actually, I have CREDIT for two but only took one. They wouldn't let me in the first course, so I petitioned to get credit for it because they thought my knowledge was too advanced to actually sit in the first class.)
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: Two minute challenge

Post by xytroxon »

Code: Select all

(for (i 1 100)
	(print i " ")
	(if (= (% i 3) 0)(print "Fizz"))
	(if (= (% i 5) 0)(print "Buzz"))
	(println)
)
(exit)
-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: Two minute challenge

Post by xytroxon »

Code: Select all

(for (i 1 100)
	(print i " ")
	(when (zero? (% i 3))(print "Fizz"))
	(when (zero? (% i 5))(print "Buzz"))
	(println)
)
(exit)
-- xytroxon

Update: Self documenting "natural language" reading style...

Code: Select all

(for (number 1 100)
	(print number " ")
	(when (zero? (% number 3))(print "Fizz"))
	(when (zero? (% number 5))(print "Buzz"))
	(println)
)
(exit)
P.S.

Q.E.D. ;)
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Re: Two minute challenge

Post by DrDave »

xytroxon
I like your solution because it takes care of the "FizzBuzz" case without needing a separate test for it! And it is readable, understandable code.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

I was surprised that the author said:
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.
It does seem a very trivial problem... At least, in newLISP.

The response numbered 404 must have taken a few minutes!

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

But its not correct yet!
print “Fizz” instead of the number
emphasis on instead. I believe, it should look like this:

Code: Select all

...
Fizz
88
89
FizzBuzz
91
...

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Post by DrDave »

I read quite a few of the replies on that blog as well as replies on another blog. A couple of comments essentially said that the universities typically are not turning out people that know how to go about solving problems. From my experinece, I have to say that I think in general, most universities at both undergraduate and graduate level do not train students to solve problems, but rather expect nothing more than the students learn how to pass their classroom tests with high scores. When you graduate, it's all about your academic scores and nothing about what you have learned (I suspect this is because you have learned next to nothing LOL). I have seen many students with top academic scores that cannot function at any meaningful level on any problems outside the classroom. And it is no wonder, because from personal experience, thinking outside the box or outside the professor's field of dogma are not only frowned upon, but typically result in academic penalites. I could usually get away with out of the box thinking if I also included the expected dogmatic response, just so the professor could be sure I understood "his" way of thinking.

I've found the same problem in industry. So many incompetent people are in high paying positions without a clue about what their staff are actually doing. I haven't figured out how they get those positions with thier qualifications, but if I do, I'll be sure to emulate it.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post by xytroxon »

Picky, picky... ;)

Code: Select all

(define (fizz-buzz max-count, fizz buzz)
	(println "Fizz-Buzz:")
	(for (number 1 max-count)
		(setq fizz (% number 3) buzz (% number 5))
		(unless (or (zero? fizz) (zero? buzz))(print number))
		(when (zero? fizz)(print "Fizz"))
		(when (and (zero? fizz) (zero? buzz))(print "-"))
		(when (zero? buzz)(print "Buzz"))
		(if (< number max-count)(print ", ")(print "!"))
	)
	(println)
)
(fizz-buzz 100)
(exit)
Fizz-Buzz:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz-Buzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz-Buzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, Fizz-Buzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, Fizz-Buzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, Fizz-Buzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, Fizz-Buzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz!

According to Wikipedia, the name of the game is "Bizz Buzz"...
http://en.wikipedia.org/wiki/Bizz_buzz

Code: Select all

(define (bizz-buzz max-count, bizz buzz)
	(println "Bizz-Buzz:")
	(for (number 1 max-count)
		(setq bizz (% number 3) buzz (% number 5))
		(unless (or (zero? bizz) (zero? buzz))(print number))
		(when (zero? bizz)(print "Bizz"))
		(when (and (zero? bizz) (zero? buzz))(print "-"))
		(when (zero? buzz)(print "Buzz"))
		(if (< number max-count)(print ", ")(print "!"))
	)
	(println)
)
(bizz-buzz 100)
(exit)
Bizz-Buzz:
1, 2, Bizz, 4, Buzz, Bizz, 7, 8, Bizz, Buzz, 11, Bizz, 13, 14, Bizz-Buzz, 16, 17, Bizz, 19, Buzz, Bizz, 22, 23, Bizz, Buzz, 26, Bizz, 28, 29, Bizz-Buzz, 31, 32, Bizz, 34, Buzz, Bizz, 37, 38, Bizz, Buzz, 41, Bizz, 43, 44, Bizz-Buzz, 46, 47, Bizz, 49, Buzz, Bizz, 52, 53, Bizz, Buzz, 56, Bizz, 58, 59, Bizz-Buzz, 61, 62, Bizz, 64, Buzz, Bizz, 67, 68, Bizz, Buzz, 71, Bizz, 73, 74, Bizz-Buzz, 76, 77, Bizz, 79, Buzz, Bizz, 82, 83, Bizz, Buzz, 86, Bizz, 88, 89, Bizz-Buzz, 91, 92, Bizz, 94, Buzz, Bizz, 97, 98, Bizz, Buzz!

Which sounds much harder to play, with "Bizz Buzz" being a better tongue twister than "Fizz Buzz"...

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Re: Two minute challenge

Post by DrDave »

Because I liked xytroxon's elimination of explicit testing for factor of 15, I looked for a solution that eliminates this test but also gives only the requested output, but without resorting to OR and still being reasonably simple (for us simple-minded folk).

Code: Select all

(define (reset-vars)
         (setf FIZZ ""  BUZZ "")
)

(define (FIZZER? n)
         (zero? (% n 3))
)

(define (BUZZER? n)
         (zero? (% n 5))
)

(for (number 1 100)
         (setf NUM number)
         (if (FIZZER? number) (setf FIZZ "Fizz" NUM "")
         )
         (if (BUZZER? number) (setf BUZZ "Buzz" NUM "")
         )
         (println (string NUM FIZZ BUZZ))
         (reset-vars)
)
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

unixtechie
Posts: 65
Joined: Sat Sep 06, 2008 6:30 am

LMHO

Post by unixtechie »

Cormullion - thanks, laughed my head off

However I did not see immediately how to do it in a roundabout and convoluted way while using some intricate functional programming techniques (that's what this challenge was about, right?)

Because otherwise, in procedural and straightforward stle it looks almost indecently naked:

Code: Select all

(for (x 1 100 1)

 (set 'three (= 0 (% x 3)))
 (set 'five (= 0 (% x 5)))

 (or
  (and three (not five)(println  "Fizz"))
  (and  five (not three) (println "Buzz"))
  (and three five (println "FizzBuzz"))
  (println x)
 )
)
(exit)
So I'm waiting eagerly (not lazily) for improvements of this solution.
Actually, I could write an interesting one if a non-lazy OR (i.e. the one that evaluates ALL its parts in any case) was constructed

unixtechie
Posts: 65
Joined: Sat Sep 06, 2008 6:30 am

marginally more convoluted

Post by unixtechie »

1. you know what? I have just made it marginally more convoluted, like this:

Code: Select all

(for (x 1 100 1)

  (or
   (and (set 'three (= 0 (% x 3))) (println "Fizz"))
   (and (= 0 (% x 5)) (or
      (and three (println "FizzBuzz"))
      (println "Buzz")  ))
   (println x)
  )

)
(exit)
Piece'o'cake ;)))))))))


2. .. but the true corporate solution would be this:

Code: Select all

(println 1)
(println 2)
(println "Fizz")
(println 4)
(println "Buzz")
(println "Fizz")
(println 7)
Note to the team leader: "please forward this code to the junior member of the team to complete typing"

Note to the manager: "I have submited perfectly working code which should meet all deadlines. The team will be working on the next version as time permits to improve satisfaction in case of customer requests for number of items other than one hundred"


3. But by the time work on the second version started, it was mandated that all code followed the Object Oriented Paradigm.
So, in accordance with the principle that objects reflect real life entities, the program now generates 100 "Child_player" objects, which are passed request_messages from the Game_Master object (the supervisor pattern?). Each of the objects' reply to the Fizz-Buzz question is then collected and formatted centrally for dispatch to the expernal requesting entity.

..mmm working on it.


4. Just got an e-mail from the management. Version 3 is supposed to be a network distributed solution. Each of the 100 children objects will be converted to a freely-flying persistent network agent, which maintain their internal state and are able to change their chairs so to say, while still engaged in the game. Results are to be sent to a company overseas branch and support integrity checking and strong encryption

Help!

unixtechie
Posts: 65
Joined: Sat Sep 06, 2008 6:30 am

A truly functional solution. Anyone?

Post by unixtechie »

.. but there was in this company in the farthest corner of the room where all programmers sat a tiny office, and it was occupied by an old grumpy unix geek, who was actually the company system administrator.
As his servers buzzed on for the third year without a single reboot and his monitoring scripts notified him of the problems about 15 minutes before they happened, he had all the time on his hands to play with his favourite geeky toys. And one of such toys was functional programming.

So in half the time it took the company testing department to discover that typo in the customer report which turned an innocuous phrase into a grossly indecent one (slashing the company revenues and resulting in a couple of lawsuits by enraged budgerigar owners, all luckily settled out of court), he produced his own truly functional solution to the Fizz-Buzz problem.

It ran like this:
The input stream (potentially infinite, but reduced to the first 100 numbers for the sake of testing) is processed lazily, i.e. one item at a time.
The program runs 2 lazy generators in two coroutines, one spits numbers which are consequtive multiples of 3, the other one bakes multiples of 5 (or any other given numbers). So, once the generator is kicked, a new member of the virtual "list" is generated, the next multiple to check against.

The main program therefore checks each input value from that (infinite) input stream for _equivalence_ with the current 3-list and 5-list members by ping-ponging to the coroutine.
Once the equivalence is found, the 3-list or 5-list generator(s) lazily produce a next number for comparison.

But, to speed things up and save on the coroutine invocation, the numbers from those lazy generators are of course memoized, thus cutting up the needed time and improving performance
Everyone marvelled at the sight of the sysadmin prog crunching Fizz-Buzzer player numbers in the gazillions and the generality of the solution allowing it not to slow down even if 312345912358 and 512309482093481209358340 were the needed as multiples, but no one understood a thing, and management turned it down as totally unmantainable.

The geek then sligtly changed some output parameters of his script and posted it on the Internet, where it became popular as a computer game called "Squash the Bill".

Has anyone seen it recently? Could you post the source code here?

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

:) Sounds like the voice of experience there...!


I didn't think the two-minute challenge was a major one - I was more intrigued with the idea of people considering themselves to be programmers yet finding it difficult...

I also like watching people produce a seemingly unlimited amount of solutions in every language under the sun.

With newLISP you can't really play code golf ("59 bytes - beat that" kind of thing). Better perhaps is to search for elegance, simplicity, and also for speed (if your first solution is particularly lumbering...).

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Post by DrDave »

cormullion wrote:I also like watching people produce a seemingly unlimited amount of solutions in every language under the sun.
And I am particularly interested in seeing just how horribly undreadable code is in some of the languages. (Unreadable because of the syntax and symbols of the language, not becasue of purposeful obfuscation or because of some dolt of a coder.)

cormullion wrote:With newLISP you can't really play code golf ("59 bytes - beat that" kind of thing). Better perhaps is to search for elegance, simplicity, and also for speed (if your first solution is particularly lumbering...).
But with newLISP, we also have the "FUN" factor, so sometimes we get to see some fun solutions that are of no practical value.

In addition, being a functional language that is heavily into list processing, we get to see solutions that are not even considered by coders of imperative languages.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

didi
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

Post by didi »

Code: Select all

 ( for ( x 1 100 ) 
  ( set 'y "" )
  ( if ( = 0 ( mod x 5 ))  ( push "Buzz" y))
  ( if ( = 0 ( mod x 3 ))  ( push "Bizz" y))
  ( if ( = y "" ) ( push ( string x ) y ))
  ( print y " " ) 
 )
result:
1 2 Bizz 4 Buzz Bizz 7 8 Bizz Buzz 11 Bizz 13 14 BizzBuzz 16 17 Bizz 19 Buzz Bizz 22 23 Bizz Buzz 26 Bizz 28 29 BizzBuzz 31 32 Bizz 34 Buzz Bizz 37 38 Bizz Buzz 41 Bizz 43 44 BizzBuzz 46 47 Bizz 49 Buzz Bizz 52 53 Bizz Buzz 56 Bizz 58 59 BizzBuzz 61 62 Bizz 64 Buzz Bizz 67 68 Bizz Buzz 71 Bizz 73 74 BizzBuzz 76 77 Bizz 79 Buzz Bizz 82 83 Bizz Buzz 86 Bizz 88 89 BizzBuzz 91 92 Bizz 94 Buzz Bizz 97 98 Bizz Buzz

unixtechie
Posts: 65
Joined: Sat Sep 06, 2008 6:30 am

perl is - sixfold - to twice - as fast in this test

Post by unixtechie »

Yours looks nice because of the minimalism you got through using an output accumulator instead of direct logic.
..a slightly modified version with "lazy generators" instead of modulo division

Code: Select all

(set 'step3 3)
(set 'step5 5)
(set 'lgen3 step3)
(set 'lgen5 step5)

( for ( x 1 100 )
 ( set 'acc "" )
 ( and ( = x lgen3 )  ( push "Bizz" acc) (inc lgen3 step3))
 ( and ( = x lgen5 )  ( push "Buzz" acc) (inc lgen5 step5))
 ( and ( = acc "" ) ( push ( string x ) acc ))
 ( println acc )
)
(exit)
Versions in which logic is used (rather than string operations) cut appr. 1-2 second(s) per 1 million iteration loops:
your version runs at 14.28 sec
yours modified at 13.75
and the one with logic plus "lazy accs" in place of modulo division is at 12.6 seconds on my machine

The unpleasant thing however is that perl does this script verbatim (i.e. the same 1 million iterations) in 1.7 seconds (!!)

If I switch off output buffering in it ($| = 1;), the time increases to 6 seconds.

Newlisp does it approx twice as slow. -- Why?
Last edited by unixtechie on Wed Dec 24, 2008 1:29 pm, edited 3 times in total.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Struggling to make a more functional version:

Code: Select all

(define (/? a b) (= 0 (% a b)))

(define (action i)
    (cond ((= 0 (% i 15)) "fizzbuzz")
          ((= 0 (% i 3))  "fizz")
          ((= 0 (% i 5))  "buzz")
          (true           i)))
   
(map println (map action (sequence 1 100)))

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: perl is - sixfold - to twice - as fast in this test

Post by cormullion »

unixtechie wrote:Newlisp does it approx twice as slow. -- Why?
That's another aspect of a challenge: any given algorithm will probably suit either Perl or newLISP better, and is unlikely to be completely language-agnostic. Typically, Perl runs "Perl code" better and faster than any other language can. But newLISP can run "newLISP code" better than it runs "Perl code". (I wrote a bit about this once http://unbalanced-parentheses.nfshost.com/andcounting.)

Don't know about "unpleasant". I'd trade quite a bit of performance to not have to look at Perl... :)

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: perl is - sixfold - to twice - as fast in this test

Post by xytroxon »

Day two (or is it three?) of the "two minute" challenge...

Examinaton of the curious effect of the product of mods...

Code: Select all

;for number :0000000001111111111222222222233333333334
;-----------:123456789o123456789o123456789o123456789o
;(% fizz 3) :1201201201201201201201201201201201201201
;(% buzz 5) :1234012340123401234012340123401234012340
;(*(%3)(%5)):nn0n00nn00n0nn0nn0n00nn00n0nn0nn0n00nn00
;X->fizzbuzz:--f-bf--fb-f--X--f-bf--fb-f--X--f-bf--fb

(for (number 1 100)
   (setq fizz (% number 3) buzz (% number 5) fizzbuzz (* fizz buzz))
   (when (zero? fizz)(print "Fizz"))
   (when (zero? buzz)(print "Buzz"))
   (when (not (zero? fizzbuzz))(print number))
   (print ", ")
)
(exit) 
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz,

Inline version:

Code: Select all

(for (number 1 100)
   (when (zero? (% number 3))(print "Fizz"))
   (when (zero? (% number 5))(print "Buzz"))
   (when (not (zero? (* (% number 3)(% number 5))))(print number))
   (print ", ")
)
(exit) 
Area proposed for major research grant funding:
The effects of (% number 15) aka "Factoring In The Overlooked And True Modulus of FizzBuzz" ;O

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: perl is - sixfold - to twice - as fast in this test

Post by xytroxon »

xytroxon wrote:Day two (or is it three?) of the "two minute" challenge...

Area proposed for major research grant funding:
The effects of (% number 15) aka "Factoring In The Overlooked And True Modulus of FizzBuzz" ;O
Damm!

Code: Select all

(cond ((= 0 (% i 15)) "fizzbuzz") 
Looks like cormullion beat me too it!!!

Have to start refreshing this thread more often... and eating... and (sniff) taking a bath... ;)

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

unixtechie
Posts: 65
Joined: Sat Sep 06, 2008 6:30 am

Buggy thinking ;)))))

Post by unixtechie »

Damm!

Code: Select all

(cond ((= 0 (% i 15)) "fizzbuzz") 
Looks like cormullion beat me too it!!!
It's very wrong to use and hardcode "3*5" into this solution.

Supposing the numbers you were given were something like 6 and 15. Your program would think it should check for multiples of 90, while in fact it's multiples of 30.

To correctly solve this you'd have to decompose the given numbers into their (don't know proper terms in English) the prime numbers and find the smallest common ???

Unless you want to do it, use a clean reasoning scheme which generalizes without introducing bugs

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

My 3 cents:

Code: Select all

(for (i 1 100)
  (cond 
    ((zero? (% i 15)) (println "FizzBuzz"))
    ((zero? (% i 5)) (println "Buzz"))
    ((zero? (% i 3)) (println "Fizz"))
    (true (println i))))

(for (i 1 100)
  (let (buff " ")
    (if (zero? (% i 3)) (setf (last buff) "Fizz "))
    (if (zero? (% i 5)) (setf (last buff) "Buzz"))
    (if (= buff " ") (println i) (println buff))))

(for (i 1 100)
  (let (buff (string (if (zero? (% i 3)) "Fizz" "") 
          (if (zero? (% i 5)) "Buzz" "")))
    (println (if (empty? buff) i buff))))
all of them variations of previously shown solutions, more or less.

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post by xytroxon »

Code: Select all

;for number :0000000001111111111222222222233333333334
;-----------:123456789o123456789o123456789o123456789o
;(% fizz 3) :1201201201201201201201201201201201201201
;(% buzz 5) :1234012340123401234012340123401234012340
;(*(%3)(%5)):nn0n00nn00n0nn0nn0n00nn00n0nn0nn0n00nn00
;(+(%3)(%5)):nnnnnnnnnnnnnn0nnnnnnnnnnnnnn0nnnnnnnnnn
;X->fizzbuzz:--f-bf--fb-f--X--f-bf--fb-f--X--f-bf--fb

; "if-not" version with product and sum of mods
(for (number 1 100)
   (setq fizz (% number 3) buzz (% number 5))
   (if-not (zero? (* fizz buzz))
      (print number ", ")
      (if-not (zero? (+ fizz buzz))
         (if-not (zero? buzz)
            (print "fizz, ")
            (print "buzz, ")
         )
         (print "FIZZ-BUZZ, ")
      )
   )
)
(exit)
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

That's what I like to see - dedication to newlisp, on Xmas day! nice job...

Locked