FIZZBUZZ

Discussion about ZX80 / ZX81 Software
RWAP
Posts: 1348
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

FIZZBUZZ

Post by RWAP »

I was just reading that 99/100 job applicants for programming jobs apparently cannot write a short "fizzbuzz" program when given 10 minutes to do so in an interview.

I was wondering what the best solution (shortest, least memory or most elegant are all acceptable) would be on a ZX81

The rules are simple -
write out the values 1 to 100 on screen
If the value is divisble by 3 write 'FIZZ' after the number
If the value is divisble by 5 write 'BUZZ' after the number
If the value is divisble by 3 and 5 write 'FIZZBUZZ' after the number
User avatar
zx81jens
Posts: 202
Joined: Sat May 10, 2008 8:26 am
Location: a Basement in Nienburg / Germany

Re: FIZZBUZZ

Post by zx81jens »

Hi!

I think it´s a good drinking game as well :-)

Greetz
Jens
eyerything will be okay in the end.
if it´s not okay, it´s not the end.

and: uıɐbɐ ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ɹǝʌǝ ɹǝʌǝu ןןıʍ ı
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: FIZZBUZZ

Post by siggi »

Here it is:
fizzbuzz.p
(1.01 KiB) Downloaded 307 times
Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
Math123
Posts: 44
Joined: Sun May 11, 2008 11:14 pm
Location: Germany Wuppertal
Contact:

Re: FIZZBUZZ

Post by Math123 »

Another one. Pure BASIC, more complex, but much faster!
fizzbuzz-2.p
fizzbuzz2.p
(1.29 KiB) Downloaded 318 times
Math
User avatar
kmurta
Posts: 305
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: FIZZBUZZ

Post by kmurta »

Another one, this time in pure forth ;)
Load the program and type FIZZBUZZ to run it.

Code: Select all

: FIZZBUZZ
   101 1
   DO
     CR I DUP DUP .
     3 MOD 0=
     IF ." FIZZ" THEN
     5 MOD 0=
     IF ." BUZZ " THEN
   LOOP
;
Attachments
fizzbuzz-3.p
(8.16 KiB) Downloaded 250 times
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
User avatar
zx81jens
Posts: 202
Joined: Sat May 10, 2008 8:26 am
Location: a Basement in Nienburg / Germany

Re: FIZZBUZZ

Post by zx81jens »

hi kmurta!

can you tell me something about this forth-version? it´s spanish?

salu2
jens
eyerything will be okay in the end.
if it´s not okay, it´s not the end.

and: uıɐbɐ ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ɹǝʌǝ ɹǝʌǝu ןןıʍ ı
User avatar
kmurta
Posts: 305
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: FIZZBUZZ

Post by kmurta »

This small forth was published in the brazilian magazine "Micro Sistemas" and can be downloaded from http://zx81.eu5.org/files/soft/ms/Forth.zip.

It was also incorporated in the emulator VB81 Xur. See more information here http://forth-retro.pagesperso-orange.fr/index-en.htm.
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
User avatar
gus
Posts: 177
Joined: Fri May 16, 2008 10:18 pm
Location: Buenos Aires. Argentina
Contact:

Re: FIZZBUZZ

Post by gus »

Hi :)

Wow, we have a complete rainbow of solutions here !!!

A very good Sinclair Basic version by Siggi
A very good Speed Optimized version by Math
and a very good Forth Version By Kmurta

This is my asm version. I need almost 10 minutes to write and debug it, reusing an routine to write numbers in decimal form ;)

Image

BTW: I think that the Scroll is not necessary, may be you can think the result is not so nice, but I think that the Rules say print on the screen and my version does just it ;)
In one way this is my Think Out of The Box solution dedicated to the Mensa members (Sir Clive included)

Gus
Attachments
fizzbuzz-4.rar
FizzBuzz By Guzz
(312 Bytes) Downloaded 237 times
RWAP
Posts: 1348
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

Re: FIZZBUZZ

Post by RWAP »

Hi Gus,

You are correct in that there is no rule about having one line per unit, but then surely points are awarded for artistic merit also as programmers need to not only understand the parameters of their remit, but what works well in the hands of a client.

However, your machine code program does break one rule - ie. if a number is divisible by 3 AND 5, then it should display FIZZBUZZ, not FIZZ BUZZ

:lol:
User avatar
gus
Posts: 177
Joined: Fri May 16, 2008 10:18 pm
Location: Buenos Aires. Argentina
Contact:

Re: FIZZBUZZ

Post by gus »

RWAP wrote:Hi Gus,

You are correct in that there is no rule about having one line per unit, but then surely points are awarded for artistic merit also as programmers need to not only understand the parameters of their remit, but what works well in the hands of a client.
Hi Rich,

mmm in the artistic side of my solution you are missing some fact: I don't say it before, but if you look at the screen very carefully, in the same way that you must look the Magic Eye 3D books you will see some secret part of the Ferranti ULA's :lol:
RWAP wrote:
However, your machine code program does break one rule - ie. if a number is divisible by 3 AND 5, then it should display FIZZBUZZ, not FIZZ BUZZ

:lol:
I must admit that you are right here, and now my insolent asm version completes the rainbow...

Gus
Post Reply