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

Pages: 1-

FizzBuzz

Name: Anonymous 2011-08-31 2:15

(defun fizz-buzz (start end)
  (loop for x from start to end do
       (let ((3? (= (mod x 3) 0))
         (5? (= (mod x 5) 0)))
     (when 3?             (format t "Fizz"))
     (when 5?          (format t "Buzz"))
     (unless (or 3? 5?) (format t "~a" x))
     (terpri))))


What does /b/ think?

Name: Anonymous 2011-08-31 2:40

Ask /b/?

Name: Anonymous 2011-08-31 3:41

What kind of horrible whitespace is that?

(defun fizz-buzz (start end)
  (loop for x from start to end do
        (let ((3? (= (mod x 3) 0))
              (5? (= (mod x 5) 0)))
          (when 3? (format t "Fizz"))
          (when 5? (format t "Buzz"))
          (unless (or 3? 5?) (format t "~a" x))
          (terpri))))

Name: Anonymous 2011-08-31 4:12

        (let ((3? (= (mod x 3) 0))
              (5? (= (mod x 5) 0)))
          (when 3? (format t "Fizz"))
          (when 5? (format t "Buzz"))
          (unless (or 3? 5?) (format t "~a" x))
Why not to use cond?

Name: Anonymous 2011-08-31 4:16

        (let ((3? (= (mod x 3) 0))
              (5? (= (mod x 5) 0)))
          (when 3? (format t "Fizz"))
          (when 5? (format t "Buzz"))
          (unless (or 3? 5?) (format t "~a" x))

Fucking BBCode.

Name: Anonymous 2011-08-31 5:24

>>4
As you wish!

(defun fizz-buzz (start end)
  (loop for x from start to end do
        (let ((3? (= (mod x 3) 0))
              (5? (= (mod x 5) 0))
              (15? (= (mod x 15) 0)))
          (cond (15? (format t "FizzBuzz"))
                (5? (format t "Buzz"))
                (3? (format t "Fizz"))
                (t (format t "~a" x)))
          (terpri))))

Name: Anonymous 2011-08-31 5:38

#include <stdio.h>
#include <stdlib.h>

main(int argc, char** argv)
{
    printf(argc % 3 == 0 ? argc % 5 == 0 ? "FizzBuzz\n" : "Fizz\n" : argc % 5 == 0 ? "Buzz\n" : "%d\n", argc);
    if(argc < 100) main(argc + 1, 0); else return 0;
    getchar();
}

Name: Anonymous 2011-08-31 5:40

#include <stdio.h>
#include <stdlib.h>

main(int argc, char** argv)
{
    printf(argc % 3 == 0 ? argc % 5 == 0 ? "FizzBuzz\n" : "Fizz\n" : argc % 5 == 0 ? "Buzz\n" : "%d\n", argc);
    if(argc < 100) main(argc + 1, 0); else return 0;
}

Name: Anonymous 2011-08-31 7:31

>>7
unrichable coed. Ura faget.

Name: Anonymous 2011-08-31 12:52

>>9
That's what happens when you let LISPPER use C.

Name: Anonymous 2011-08-31 14:05

i thinks its gay

Name: Anonymous 2011-08-31 14:10

#include <ooc/io/io.h>
#include <ooc/util/FizzBuzz.h>

int main(void) {
  var fb = new(FizzBuzzGenerator(),
               100);

  foreach (var elem, fb) {
    println(elem);
  } foreach_end;

  del(fb);

  return 0;
}

Name: Anonymous 2011-08-31 15:36


(define fizzbuzz
  (lambda (n p)
    (if (> n p)
        '()       
        (cons
         (cond ((= (remainder n 15) 0) 'fizzbuzz) 
               ((= (remainder n 3) 0) 'fizz)
               ((= (remainder n 5) 0) 'buzz)
               (else n))
         (fizzbuzz (+ n 1) p)))))
(fizzbuzz 1 100)

Name: Anonymous 2011-08-31 23:15

(labels ((fizz-buzz (start end)
                    (cond ((= 0 (mod start 15)) (format t "FizzBuzz"))
                          ((= 0 (mod start 5)) (format t "Buzz"))
                          ((= 0 (mod start 3)) (format t "Fizz"))
                          (t (format t "~A" start)))
                    (terpri)
                    (if (< start end)
                      (fizz-buzz (1+ start) end))))
  (fizz-buzz 1 100))

Name: Anonymous 2011-08-31 23:34

>>1

[x] A horrible programmer
[x] Will be butthurt when he reads this
[x] Comes from /b/
[x] Sucks cock


Polecat kebabs!

Name: Anonymous 2011-08-31 23:52

>>15
FUCK YOU FAGGOT

Name: Anonymous 2011-08-31 23:53

>>15

If you think /prob/ isn't our /b/oard you can suck my cock

Name: Anonymous 2011-09-01 0:57

>>17
The butthurt flows through this one.

Name: Anonymous 2011-09-01 2:51

>>18
fuck you faggot storm eat shit and die you fucking lithpfag

Name: Anonymous 2011-09-01 4:05

>>19
so mad cuz

Name: Anonymous 2011-09-01 5:52

>>20
fuck you fucking fagnigger

Name: Anonymous 2011-09-01 9:52

>>21
f u

Name: Anonymous 2011-09-01 11:49

Symta:

for I=1..100 say ([@(I%3==0 |> {Fizz}) @(I%5==0 |> {Buzz})]||I)


Ruby:

1.upto(100) { |i| puts i % 3 == 0 ? i % 5 == 0 ? "FizzBuzz" : "Buzz" : i % 5 == 0 ? "Fizz" : i }


Python:

for i in range(1, 101):
  x = ""
  if i % 3 == 0:
    x = x + "Fizz"
  if i % 5 == 0:
    x = x + "Buzz"
  if x == "":
    x = str(i)
  print x



Visual Basic:

Dim i
For i = 1 to 100
  If (i Mod 3 = 0) And (i Mod 5 = 0) Then
    WScript.Echo "FizzBuzz"
  ElseIf (i Mod 3 = 0) Then
    WScript.Echo "Fizz"
  ElseIf (i Mod 5 = 0) Then
    WScript.Echo "Buzz"
  Else
    Wscript.Echo i
  End If
Next




C/C++

#include stdio.h

int main(void) {
  int i,j;
  for(i=j=0; i!=100; j=0, i++) {
     if(i%3==0) printf("Fizz"), j=1;
     if(i%5==0) printf("Buzz"), j=1;
     if(!j) printf("%d",i);
     printf("\n");
  }
}

Name: Anonymous 2011-09-01 11:54

>>23
Concatenating Python strings in a loop is considered an anti-pattern, and should be done using lists and "".join(...) instead.

Name: Anonymous 2011-09-01 11:54

>>24
anti-pattern
I hate you!

Name: Anonymous 2011-09-01 11:56

>>25
Why? You read list of AP on c2 and recognized each of them in your code?

Name: Anonymous 2011-09-01 12:02

>>26
Patterns and anti-patterns are merely the terrain of a language, what you have to work around to get things done.  They are signs of deficiencies inherent in the language.  In Python, concatenating strings in a loop is considered an anti-pattern merely because the popular implementation is incapable of producing good code in such a case.  The intractability or impossibility of static analysis in Python makes such optimizations difficult or impossible.

Name: Anonymous 2011-09-01 12:08

>>27
In Python, concatenating strings in a loop is considered an anti-pattern merely because the popular implementation is incapable of producing good code in such a case.

You still have no future as a computer programmer. Now go run along and clean another toilet you mental midget.

Name: Anonymous 2011-09-01 12:12

>>27
The intractability or impossibility of static analysis in Python makes such optimizations difficult or impossible.
This is why we should use Common Lisp.

Name: Anonymous 2011-09-01 12:29

>>28,29 I like your style, gentlemen.

By the way, concatenating strings in a loop is perfectly OK in CPython at least, because it implements a peculiar ad hoc version of uniqueness typing for strings in particular.

Name: Anonymous 2011-09-01 12:34

>>30
Is this your little jewish way of trying to say that strings are immutable?

Name: Anonymous 2011-09-01 13:21

>>27
Now, look at C++. Does your compiler optimize string concatenation to use a single buffer? Does your Java compiler? Does your .NET compiler? No? You're full of shit.

Name: Anonymous 2011-09-01 13:47

>>31
Is your syphilis spreading to your brain, finally?

Name: Anonymous 2011-09-01 20:01

EXPERT SCHEME SOLUTION

(define-syntax cons~
  (syntax-rules ()
    ((cons~ a b)
     (cons a (delay b)))))
(define car~ car)
(define cdr~ (lambda (l) (force (cdr l))))

(define take~
  (lambda (n l~)
    (if (= n 0)
        '
()
        (cons (car~ l~) (take~ (- n 1) (cdr~ l~))))))

(define fizz-buzz
  ((lambda ()
     (define aux
       (lambda (n)
         (let ((f (lambda (x)
                    (cond ((= (modulo x 15) 0) "FizzBuzz")
                          ((= (modulo x 3) 0) "Fizz")
                          ((= (modulo x 5) 0) "Buzz")
                          (else x)))))
           (cons~ (f n) (aux (+ n 1))))))
     (aux 0))))

(take~ 100 fizz-buzz)

Name: Anonymous 2011-09-01 20:23

>>12
wuts dat?

Name: Anonymous 2011-09-01 21:58

>>35
Depending on your level of autism it is C to GNU-C to ``Well, atleast GCC compiles it'' where the level of autism ranges from mild to severe respectively.

Name: Anonymous 2011-09-01 23:03

>>35
OOC

Name: Haxus the QBasic Master 2011-09-03 21:09

If it ain't a speech impediment, it's bogus.

QBASIC
FOR i% = 1 TO 100
    IF i% MOD 15 = 0 THEN
        PRINT "FizzBuzz"
    ELSEIF i% MOD 5 = 0 THEN
        PRINT "Buzz"
    ELSEIF i% MOD 3 = 0 THEN
        PRINT "Fizz"
    ELSE
        PRINT i%
    END IF
NEXT i%

Name: Anonymous 2011-09-04 4:20

Symta:
for I=1..100 say ([@(I%3==0 |> {Fizz}) @(I%5==0 |> {Buzz})]||I)

J:
(([:#.0=5 3|]){;&(;:'Fizz Buzz FizzBuzz'))"0>:i.100

Now shut up.

Name: Anonymous 2011-09-05 23:52

the pleasure of being denied the relief of farting while receiving analingus

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