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

Pages: 1-

FizzBuzz

Name: Anonymous 2012-10-05 7:23

for i in range(110):
    pr = ""
    pr += "Fizz" * (i%3 == 0)
    pr += "Buzz" * (i%5 == 0)
    pr += "Bazz" * (i%7 == 0)
    print (pr if pr else i)


Beat this, faghets.

Name: Anonymous 2012-10-05 8:15

>>1
Not enterprise enough.

(defun divp (d a)
  (zerop (rem a d)))

(defun fizzbuzzbazz (n)
  (labels ((divisibility->string (divisors n)
             (let ((assoc (assoc-if #'(lambda (divisor) (divp divisor n)) divisors)))
               (when assoc
                 (concatenate 'string (cdr assoc) (divisibility->string (remove assoc divisors) n))))))
    (dotimes (i (1- n))
      (write-line (or (divisibility->string '((3 . "Fizz") (5 . "Buzz") (7 . "Bazz")) (1+ i)) (prin1-to-string (1+ i)))))))

Name: Anonymous 2012-10-05 8:34

I am stupid


fizzbuzzbazz :: [Integer] -> [String]
fizzbuzzbazz = map (finish . bazz . buzz . fizz . start)
 where
  start n         = (n, "")
  finish (n, "")  = show n
  finish (_, s)   = s

  appendIfDivides q s (n, r)
                  | n `rem` q == 0  = (n, r ++ s)
                  | otherwise       = (n, r)

  fizz            = appendIfDivides 3 "Fizz"
  buzz            = appendIfDivides 5 "Buzz"
  bazz            = appendIfDivides 7 "Bazz"

main = mapM_ putStrLn $ fizzbuzzbazz [0..109]

Name: 2 2012-10-05 9:19

Changelog for FIZZBUZZBAZZ version 2.0:
— New top-level definitions: DIVISIBILITY->STRING.
— General performance improvements.
— FIZZBUZZBAZZ now takes as an optional parameter an alist of divisors and the string they match. The same divisor can be specified multiple times.

(declaim (inline divp))
(defun divp (d a)
  (zerop (rem a d)))

(defun divisibility->string (divisors n)
  (let ((strings (loop :for (divisor . string) :in divisors
                       :when (divp divisor n) :collect string)))
    (and strings (apply #'concatenate 'string strings))))

(defun fizzbuzzbazz (n &optional (divisors '((3 . "Fizz") (5 . "Buzz") (7 . "Bazz"))))
  (dotimes (i (1- n))
    (write-line (or (divisibility->string divisors (1+ i))
                    (prin1-to-string (1+ i))))))

Name: Anonymous 2012-10-05 9:38

Sing with me /prog/!

(fizzbuzzbazz 100 '((2 . "Then ") (5 . "… ") (1 . "she ") (3 . "came ")  (6 . "in love with ") (7 . "little ") (11 . "bucket ") (9 . "girl ") (2 . "buffalo") (1 . "… ") (4 . "Tender! ") (8 . "Soften up the meat!")))
she …
Then she buffalo…
she came …
Then she buffalo… Tender!
… she …
Then she came in love with buffalo…
she little …
Then she buffalo… Tender! Soften up the meat!
she came girl …
Then … she buffalo…
she bucket …
Then she came in love with buffalo… Tender!
she …
Then she little buffalo…
… she came …
Then she buffalo… Tender! Soften up the meat!
she …
Then she came in love with girl buffalo…
she …
Then … she buffalo… Tender!
she came little …
Then she bucket buffalo…
she …
Then she came in love with buffalo… Tender! Soften up the meat!
… she …
Then she buffalo…
she came girl …
Then she little buffalo… Tender!
she …
Then … she came in love with buffalo…
she …
Then she buffalo… Tender! Soften up the meat!
she came bucket …
Then she buffalo…
… she little …
Then she came in love with girl buffalo… Tender!
she …
Then she buffalo…
she came …
Then … she buffalo… Tender! Soften up the meat!
she …
Then she came in love with little buffalo…
she …
Then she bucket buffalo… Tender!
… she came girl …
Then she buffalo…
she …
Then she came in love with buffalo… Tender! Soften up the meat!
she little …
Then … she buffalo…
she came …
Then she buffalo… Tender!
she …
Then she came in love with girl buffalo…
… she bucket …
Then she little buffalo… Tender! Soften up the meat!
she came …
Then she buffalo…
she …
Then … she came in love with buffalo… Tender!
she …
Then she buffalo…
she came little girl …
Then she buffalo… Tender! Soften up the meat!
… she …
Then she came in love with bucket buffalo…
she …
Then she buffalo… Tender!
she came …
Then … she little buffalo…
she …
Then she came in love with girl buffalo… Tender! Soften up the meat!
she …
Then she buffalo…
… she came …
Then she buffalo… Tender!
she little bucket …
Then she came in love with buffalo…
she …
Then … she buffalo… Tender! Soften up the meat!
she came girl …
Then she buffalo…
she …
Then she came in love with little buffalo… Tender!
… she …
Then she buffalo…
she came …
Then she bucket buffalo… Tender! Soften up the meat!
she …
Then … she came in love with girl buffalo…
she little …
Then she buffalo… Tender!
she came …
Then she buffalo…
… she …
Then she came in love with buffalo… Tender! Soften up the meat!
she …
Then she little buffalo…
she came bucket girl …

Name: Anonymous 2012-10-05 12:20

>>3
I am stupid
You are.


Lisp                           | Haskell
-------------------------------|------------------------------------
map - '(1 2 3 4 5)             | map (-) [1,2,3,4,5,6]
(-1 -2 -3 -4 -5)               | No instance for (Show (a -> a))
                               |   arising from a use of `print'
                               |
map -                          | map negate
invalid number of arguments: 1 | No instance for (Show ([a] -> [a]))
Backtrace:                     |   arising from a use of `print'
  0: (map #<function>)         |
  1: (eval '(map -))           |

Name: Anonymous 2012-10-05 12:22

>>6
Learn about currying a.k.a. automatic function decomposition. Also, Lisp's unary - isn't Haskell's -.

Name: Anonymous 2012-10-05 12:28

>>6
I'm writing a brand new shitty lisp, should non-variadic functions curry whenever possible (so people don't have to explicitly write (curry f ...))?

Name: Anonymous 2012-10-05 12:30

>>8
You should instead have no variadic functions and curry all of them. Variadic macros are OK.

Name: Anonymous 2012-10-05 12:37

>>9
Yes. You're stupid.

>>1

rng 110 |e <I = Pr:ø
              = mod I 3 | <0 = "$(!Pr)Fizz">
              = mod I 5 | <0 = "$(!Pr)Buzz">
              = mod I 7 | <0 = "$(!Pr)Bazz">
              = Pr |v I | say
              >

Name: Anonymous 2012-10-05 12:39

>>10
Fixed for less clutter.


rng 110 |e <I = Pr:ø
              = mod I 3 |c:0 "$(!Pr)Fizz"
              = mod I 5 |c:0 "$(!Pr)Buzz"
              = mod I 7 |c:0 "$(!Pr)Bazz"
              = Pr |v I | say
              >

Name: Anonymous 2012-10-05 12:43

>>9
no variadic functions
That sounds insanely restrictive; optional keyword parameters are pretty damn important.

Name: Anonymous 2012-10-05 12:45

>>12
Say this Haskell putzim.

Name: Anonymous 2012-10-05 13:04

>>13
I strongly dislike Haskell.

Name: Anonymous 2012-10-05 14:02

>>14
I strongly dislike you.

Name: Anonymous 2012-10-05 14:02

>>6
map (0-) [1,2,3,4,5,6]

Name: Anonymous 2012-10-05 14:07

>>15
Likewise.

Name: Anonymous 2012-10-05 14:14

>>16
ugly as a kike.

Name: Anonymous 2012-10-05 14:15

>>18
Dumb as a goy.

Name: Anonymous 2012-10-05 14:28


(0...110).each do |i|
  s = ''
  i % 3 == 0 && s << 'Fizz'
  i % 5 == 0 && s << 'Buzz'
  i % 7 == 0 && s << 'Bazz'
  puts s[0] ? s : i
end

Name: Anonymous 2012-10-05 14:32

Name: Anonymous 2012-10-05 17:39

(function fizzbuzz(n, cases) {
      for (var i = 0; i < n; i++) {
        console.log(cases.reduce(function (prev, c) {
          return i % c[0] ? prev : (prev || '') + c[1];
        }, null) || i);
      }
    }(100, [[3, 'Fizz'], [5, 'Buzz'], [7, 'Bazz'], [11, 'Boo'], [13, 'Blip']]));

>hardcoding if statements
>2011

Name: Anonymous 2012-10-05 17:51

>>22
wow, that looks like an incredibly powerful language. what is it?

Name: Anonymous 2012-10-05 17:58

>>22
Stop concatenating strings inside a loop. Also, back to /g/, ``please''!!

>>23
JavaScript is powerful but it has the elegance and the performance of a prehistoric chainsaw.

Name: Anonymous 2012-10-05 18:06

>>24
Sure, it's powerful, but is it Abelson powerful?

Name: Anonymous 2012-10-05 18:09

>>24
Sure, it's prehistoric, but is it Abelson prehistoric?

Name: Anonymous 2012-10-05 18:17

>>25-27
Sure, it's Abelson, but is it Abelson Abelson?

Name: Anonymous 2012-10-05 18:18

fizzbuzz cs = map (flip fizzbuzz_ cs) . enumFromTo 1
    where fizzbuzz_ n = fromMaybe (show n) . find ((0<) . length) . (:[]) . concatMap snd . filter ((0==) . mod n . fst)

main = mapM_ putStrLn $ fizzbuzz [(3, "Fizz"), (5, "Buzz"), (7, "Bazz")] 100

Name: Anonymous 2012-10-05 18:33

>>28
yuck

Name: Anonymous 2012-10-05 18:45

FOR i TO 110 DO
    STRING pr;
    OP / = (STRING s, INT j)STRING: s * ABS(i %* j = 0);
    pr +:= "Fizz" / 3;
    pr +:= "Buzz" / 5;
    pr +:= "Bazz" / 7;
    print((IF pr /= "" THEN pr ELSE i FI, new line))
OD

Name: Anonymous 2012-10-05 18:52

IDENTIFICATION DIVISION.
       PROGRAM-ID. FIZZ-BUZZ.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CT PIC 999 VALUE 1.
       01 FZ PIC 999 VALUE 1.
       01 BZ PIC 999 VALUE 1.

       PROCEDURE DIVISION.
       FIZZ-BUZZ-MAIN SECTION.
           PERFORM 100 TIMES
                   IF FZ = 3
                        THEN IF BZ = 5
                           THEN DISPLAY "FizzBuzz"
                           COMPUTE BZ = 0
                           ELSE DISPLAY "Fizz"
                           END-IF
                           COMPUTE FZ = 0
                        ELSE IF BZ = 5
                        THEN DISPLAY "Buzz"
                                COMPUTE BZ = 0
                        ELSE
                                DISPLAY CT
                        END-IF
                END-IF
                ADD 1 TO CT
                ADD 1 TO FZ
                ADD 1 TO BZ
           END-PERFORM
           STOP RUN.

Name: Anonymous 2012-10-05 20:01

>>30
FOR i TO 110 DO print((
    IF STRING pr;
    OP / = (STRING s, INT j)STRING: s * ABS(i %* j = 0);
    pr +:= "Fizz" / 3;
    pr +:= "Buzz" / 5;
    pr +:= "Bazz" / 7;
    pr /= "" THEN pr ELSE i FI, new line))
OD

Name: Anonymous 2012-10-06 2:05

>>22
better solution:

function range(n) { return n > 0 ? [].concat.call(range(n-1), n) : [] }
function fizzbuzz(n,factors) { return range(n).map(match.bind(factors)) }
function match(n) { return Object.keys(this).reduce(red.bind(this, n), '') || n }
function red(n, a, b) { return n % b ? a : a + this[b] }

>>24
is this not elegant?

Name: Anonymous 2012-10-06 2:22

>>33

range = (n) -> if n > 0 then [].concat.call(range(n - 1), n) else []
fizzbuzz = (n, factors) -> range(n).map match.bind(factors)
match = (n) -> Object.keys(this).reduce(red.bind(this, n), "") or n
red = (n, a, b) -> (if n % b then a else a + this[b])

Name: Anonymous 2012-10-06 3:22

k = (n, a, b) -> if n % b then a else a+this[b]
fizzbuzz = (n, factors) ->
  (Object.keys(factors).reduce(k.bind(factors,i),'') or i for i in [1..n])


I'm going to cum

Name: Anonymous 2012-10-06 3:22

NO SHOULD BE


k = (n, a, b) -> if n % b then a else a+this[b]
fizzbuzz = (n, factors) ->(Object.keys(factors).reduce(k.bind(factors,i),'') or i for i in [1..n])

Name: Anonymous 2012-10-06 3:23

k = (n, a, b) -> if n % b then a else a+this[b]
fizzbuzz = (n, factors) -> (Object.keys(factors).reduce(k.bind(factors,i),'') or i for i in [1..n])

Name: Anonymous 2012-10-06 3:25

OH BABY THATS BEAUTIFUL

Name: Anonymous 2012-10-06 5:31

coffeescript confirmed for god language.

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