Rich Mellor wrote, on 02/11/2010 19:53:
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.
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
My inelegant machine code program (untested) is:
Sorry - made an error when typing the 68000 assembly language in - I
hit a key which submitted the form!
<m/c snipped>
I am sure plenty can write this in SuperBASIC, but is there a simpler
solution in machine code?
Well the first sb attempt:
10 FOR j = 1 TO 100
15 sp$ = " ";
20 PRINT j;
20 if j/3 == int(j/3)
25 sp$="";
30 PRINT " FIZZ";
40 END IF
30 IF j/5 == int(j/5)
40 PRINT sp$&"BUZZ";
50 END IF
60 PRINT
70 END FOR
2.5 mins
Now my sB is *very* rusty and I spend my life in Perl and Python, so
their syntax may have crept in.
I forget whether "==" is needed - I think not.It is in Perl.
Tony
--
QBBS (QL fido BBS 2:257/67) +44(0)1442-828255
[email protected] http://firshman.co.uk
Voice: +44(0)1442-828254 Fax: +44(0)1442-828255 Skype: tonyfirshman
TF Services, 29 Longfield Road, TRING, Herts, HP23 4DG
_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm