Author Topic: Fizz Buzz Plus  (Read 3248 times)

B+

  • Guest
Fizz Buzz Plus
« on: May 07, 2019, 01:25:40 PM »
http://wiki.c2.com/?FizzBuzzTest

Code: [Select]
check$ = "0203050711": say$ = "BizzFizzBuzzFuzzWow"
FOR i = 1 TO 100
    Flag = 1
    FOR j = 0 TO 4
        IF i MOD VAL(MID$(check$, j * 2 + 1, 2)) = 0 THEN PRINT MID$(say$, j * 4 + 1, 4);: Flag = 0
    NEXT
    IF Flag THEN PRINT i ELSE PRINT
NEXT
« Last Edit: May 07, 2019, 01:36:25 PM by B+ »

jj2007

  • Guest
Re: Fizz Buzz Plus
« Reply #1 on: May 08, 2019, 02:40:24 PM »

Tomaaz

  • Guest
Re: Fizz Buzz Plus
« Reply #2 on: May 09, 2019, 11:29:05 PM »
Newlisp (a single line version):

Code: [Select]
(print (map (fn (x) (if (zero? (% x 15)) "FizzBuzz" (zero? (% x 3)) "Fizz" (zero? (% x 5)) "Buzz" x)) (sequence 1 100)))

B+

  • Guest
Re: Fizz Buzz Plus
« Reply #3 on: May 10, 2019, 01:28:50 PM »
Nice one liner!  :)

but no plus?  :-[

Tomaaz

  • Guest
Re: Fizz Buzz Plus
« Reply #4 on: May 10, 2019, 05:01:16 PM »
Code: [Select]
(define (sprawdz x)
    (set 'slowa '(2 bizz 3 fizz 5 buzz 7 fuzz 11 wow))
    (set 'k 0)
    (dolist (y (filter integer? slowa))
        (if (zero? (% x y)) (begin (print (slowa (+ (* $idx 2) 1))) (inc k))))
        (if (zero? k) (println x) (print "\n")))
(map sprawdz (sequence 1 100))

Aurel

  • Guest
Re: Fizz Buzz Plus
« Reply #5 on: May 10, 2019, 05:56:24 PM »
..just for translation

slowa = slova = letters
 :D

Tomaaz

  • Guest
Re: Fizz Buzz Plus
« Reply #6 on: May 10, 2019, 06:01:45 PM »
slowa = slova = letters
 :D

Wrong. Slowa == words.  ;D

Aurel

  • Guest
Re: Fizz Buzz Plus
« Reply #7 on: May 10, 2019, 10:29:03 PM »
interesting ..same word but different meaning  ::)

B+

  • Guest
Re: Fizz Buzz Plus
« Reply #8 on: May 13, 2019, 01:24:27 PM »
Using JB's WORD$():
Code: [Select]
FOR i = 1 TO 100
    b$ = ""
    FOR w = 1 TO 5
        IF i mod val(word$("2 3 5 7 11", w)) = 0 THEN b$ = b$ + word$("Bizz Fizz Buzz Fuzz Wow", w)
    NEXT
    IF b$ = "" THEN PRINT i ELSE PRINT b$
NEXT

Output:
Code: [Select]
1
Bizz
Fizz
Bizz
Buzz
BizzFizz
Fuzz
Bizz
Fizz
BizzBuzz
Wow
BizzFizz
13
BizzFuzz
FizzBuzz
Bizz
17
BizzFizz
19
BizzBuzz
FizzFuzz
BizzWow
23
BizzFizz
Buzz
Bizz
Fizz
BizzFuzz
29
BizzFizzBuzz
31
Bizz
FizzWow
Bizz
BuzzFuzz
BizzFizz
37
Bizz
Fizz
BizzBuzz
41
BizzFizzFuzz
43
BizzWow
FizzBuzz
Bizz
47
BizzFizz
Fuzz
BizzBuzz
Fizz
Bizz
53
BizzFizz
BuzzWow
BizzFuzz
Fizz
Bizz
59
BizzFizzBuzz
61
Bizz
FizzFuzz
Bizz
Buzz
BizzFizzWow
67
Bizz
Fizz
BizzBuzzFuzz
71
BizzFizz
73
Bizz
FizzBuzz
Bizz
FuzzWow
BizzFizz
79
BizzBuzz
Fizz
Bizz
83
BizzFizzFuzz
Buzz
Bizz
Fizz
BizzWow
89
BizzFizzBuzz
Fuzz
Bizz
Fizz
Bizz
Buzz
BizzFizz
97
BizzFuzz
FizzWow
BizzBuzz

jbk

  • Guest
Re: Fizz Buzz Plus
« Reply #9 on: May 13, 2019, 05:17:21 PM »
hi B+
how did you come up with the algorithm?
your last program also runs in LB5

B+

  • Guest
Re: Fizz Buzz Plus
« Reply #10 on: May 13, 2019, 09:28:21 PM »
Hi jbk,

I imagine one would be hard pressed to find a Basic that the first program wouldn't work, specially if line numbers were added.

The algo came from trying to generalize the case of 3 and 5 to more numbers and more fun words to say for each divisor of i.