Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

fizzbuzz

Name: Anonymous 2011-01-28 20:49

(define (main num)
  (if (= num 100) (exit))
  (set! tmp (modulo num 15))
  (if (or (= tmp 1) (= tmp 2) (= tmp 4) (= tmp 7) (= tmp 8) (= tmp 11) (= tmp 13) (= tmp 14))
      (display num)
      (begin
        (if (or (= tmp 3) (= tmp 6) (= tmp 9) (= tmp 0) (= tmp 12)) (display "Fizz"))
        (if (or (= tmp 5) (= tmp 10) (= tmp 0)) (display "Buzz"))))
  (newline)
  (main (+ num 1)))
(define tmp 0)
(main 1)

can you do better?

Name: Anonymous 2011-01-29 9:00

(define fizzbuzz
  (λ (from to)
    (map (λ (x)
           (if3/zero? (remainder x 5)
                      (remainder x 3)
                      'fizzbuzz 'buzz 'fizz x))
         (range from to))))

(display (fizzbuzz 1 20))


(if3/zero? p1 p2 tt tf ft ff) is a macro that expands to (if3 (zero? p1) (zero? p2) tt tf ft ff)
if3 is a shorthand to three-way-if, that is another macro that evaluates tt is p1 and p2 are true, tf if p1 is true, ft if p2 is true or ff if both are false.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List