Author Topic: Fizz Buzz Plus  (Read 552 times)

B+

  • Hero Member
  • *****
  • Posts: 846
    • View Profile
Fizz Buzz Plus
« on: 07. May 2019, 15:25:40 »
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: 07. May 2019, 15:36:25 by B+ »

jj2007

  • Full Member
  • ***
  • Posts: 168
  • MasmBasic rocks
    • View Profile
    • MasmBasic - faster than C
Re: Fizz Buzz Plus
« Reply #1 on: 08. May 2019, 16:40:24 »

Tomaaz

  • Guest
Re: Fizz Buzz Plus
« Reply #2 on: 10. May 2019, 01:29:05 »
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+

  • Hero Member
  • *****
  • Posts: 846
    • View Profile
Re: Fizz Buzz Plus
« Reply #3 on: 10. May 2019, 15:28:50 »
Nice one liner!  :)

but no plus?  :-[

Tomaaz

  • Guest
Re: Fizz Buzz Plus
« Reply #4 on: 10. May 2019, 19:01:16 »
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

  • Regular Member
  • Hero Member
  • *
  • Posts: 596
    • View Profile
Re: Fizz Buzz Plus
« Reply #5 on: 10. May 2019, 19:56:24 »
..just for translation

slowa = slova = letters
 :D
** NOT RESPOND - HIGH RISK **************
http://basicpro.mipropia.com/smf/index.php
**************************************
USE:
http://basicpro.spacefor.site/smf/index.php

Tomaaz

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

Wrong. Slowa == words.  ;D

Aurel

  • Regular Member
  • Hero Member
  • *
  • Posts: 596
    • View Profile
Re: Fizz Buzz Plus
« Reply #7 on: 11. May 2019, 00:29:03 »
interesting ..same word but different meaning  ::)
** NOT RESPOND - HIGH RISK **************
http://basicpro.mipropia.com/smf/index.php
**************************************
USE:
http://basicpro.spacefor.site/smf/index.php

B+

  • Hero Member
  • *****
  • Posts: 846
    • View Profile
Re: Fizz Buzz Plus
« Reply #8 on: 13. May 2019, 15:24:27 »
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

  • Newcomer
  • *
  • Posts: 36
    • View Profile
Re: Fizz Buzz Plus
« Reply #9 on: 13. May 2019, 19:17:21 »
hi B+
how did you come up with the algorithm?
your last program also runs in LB5

B+

  • Hero Member
  • *****
  • Posts: 846
    • View Profile
Re: Fizz Buzz Plus
« Reply #10 on: 13. May 2019, 23:28:21 »
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.