Coding challenge: FizzBuzz

Miscellaneous Forums/General Discussion/Coding challenge: FizzBuzz

I've just been reading an interesting article which claims a very large percentage of candidates who apply for a programing position simply can't program.

As an example the candidates were asked to write a FizzBuzz program. Rules as follows:

________________________________________
Write a program that prints the numbers from 1 to 100
But, for multiples of 3 print "Fizz" instead of the number
For the multiples of 5 print "Buzz" instead of the number
For numbers which are multiples of both 3 and 5 print "FizzBuzz".
________________________________________

I've knocked up a BlitzMax variant which I'll post later.
I'll post a link to the article too.



For now though, your turn. Post your code samples!

SuperStrict

For Local i:Int = 1 To 100
	Local s:String = ""
	If i Mod 3 = 0
		s:+"Fizz"
	EndIf
	If i Mod 5 = 0
		s:+"Buzz"
	EndIf
	If s=""
		s:+i
	EndIf
	Print s
Next
I've just been reading an interesting article which claims a very large percentage of candidates who apply for a programing position simply can't program.
Got a link? Because that sounds completely absurd!

@FD, take a look at www.Microsoft.com.

Perfect example of the above :)

Or simply:
For Local i:Int = 1 To 100
	If i Mod 15 = 0 Then
		Print "FizzBuzz"
	ElseIf i Mod 3 = 0 Then
		Print "Fizz"
	ElseIf i Mod 5 = 0 Then
		Print "Buzz"
	Else
		Print i
	EndIf
Next
I'm also interested in a link. The claim seems a bit exagerated. I'd replace "can't program" with "can't program properly". Then the percentage is certainly large.

This then starts the whole "do it in fewer instructions, do it using less RAM" debacle.

You should see the amount of code samples on the site I read the article from:

http://www.codinghorror.com/blog/archives/000781.html

Talk about more than one way to skin a cat.

Here's my method (pretty much identical to FlameDucks):

' FizzBuzz
Framework BRL.StandardIO

For Local x% = 1 To 100
	Local t$=""
	If (x Mod 3 = 0) t$:+"Fizz"
	If (x Mod 5 =0) t$:+"Buzz"
	If t$="" t$=String(x)
	Print t$
Next


If I employ a programmer, I don't really care how efficient their code is. Obviously I want it to be readable and modular - but it's more important that they actually understand the end user and their needs, than how to write code. Software wouldn't exist without an end purpose. I have seen very expensive software systems, developed by highly paid consultants, costing hundreds of thousands of £ (SAP being a particular bugbear) flop on delivery because basic stuff like a decent GUI isn't thought of.

And sadly I often find that the better programmers are less likely to be able to communicate effectively with the end user.

I couldn't complete this task-is that a bad thing for a begginer?

Not for a beginner, it is however for someone applying for a code-job :P

my entry:
For i=1 To 100
	Select True
	Case i Mod 3=0
		Print "fizz"
	Case i Mod 5=0
		Print "buzz"
	Default
		Print i
	End Select
Next


hahahaha @ Skid,

For numbers which are multiples of both 3 and 5 print "FizzBuzz".
No wonder you dont work for Mark anymore ;)

Yup, pretty much why I haven't been able to find a job since:)

How does the Mod command work?

Mod returns the remainder so 5 mod 3 is return the remainder of 5/3 ---- 2

So if i Mod 3 = 0 then i is divisable by 3

Here's my entry:
For Local i:Int = 1 To 100
	Local div35:Int = 0
	If isInt(i / 3.0) Then div35 :+ 1
	If isInt(i / 5.0) Then div35 :+ 2
	Select div35
		Case 1 
			Print "Fizz"
		Case 2
			Print "Buzz"
		Case 3
			Print "FizzBuzz"
		Default
			Print i
	End Select
Next

Function isInt:Int(num:Float)
	If num = Int(num) Return True Else Return False
End Function


I can't believe how unbelievably crap some of these solutions are. I mean really, redundant variables? String concatenations? Function calls? Floating point conversion? Give me a break!
If I was your prospective employer, I'd show all of you the door!

"Er, don't call us, we'll call you.."
(but don't hold your breath)

Ok, since you press me, here's the correct answer...

For Local i: Int = 1 To 100
  If i Mod 3
    If i Mod 5
      WriteLine StandardIOStream, i
    Else
      WriteLine StandardIOStream, "Buzz"
    End If
  Else
    If i Mod 5
      WriteLine StandardIOStream, "Fizz" 
    Else
      WriteLine StandardIOStream, "FizzBuzz"
    End If
  End If
Next


Agent Smith Wins followed by Koriolis. Wonder who got the booby prize?

Gi'us a job...
For i=1 To 100
  If i = 3 Then Print "Fizz" ; Goto skip
  If i = 5 Then Print "Buzz" ; Goto skip
  If i = 6 Then Print "Fizz" ; Goto skip
  If i = 9 Then Print "Fizz" ; Goto skip
  If i = 10 Then Print "Buzz" ; Goto skip
  If i = 12 Then Print "Fizz" ; Goto skip
  If i = 15 Then Print "FizzBuzz" ; Goto skip
  If i = 18 Then Print "Fizz" ; Goto skip
  If i = 20 Then Print "Buzz" ; Goto skip
  If i = 21 Then Print "Fizz" ; Goto skip
  If i = 24 Then Print "Fizz" ; Goto skip
  If i = 25 Then Print "Buzz" ; Goto skip
  If i = 27 Then Print "Fizz" ; Goto skip
  If i = 30 Then Print "FizzBuzz" ; Goto skip
  If i = 33 Then Print "Fizz" ; Goto skip
  If i = 35 Then Print "Buzz" ; Goto skip
  If i = 36 Then Print "Fizz" ; Goto skip
  If i = 39 Then Print "Fizz" ; Goto skip
  If i = 40 Then Print "Buzz" ; Goto skip
  If i = 42 Then Print "Fizz" ; Goto skip
  If i = 45 Then Print "FizzBuzz" ; Goto skip
  If i = 48 Then Print "Fizz" ; Goto skip
  If i = 50 Then Print "Buzz" ; Goto skip
  If i = 51 Then Print "Fizz" ; Goto skip
  If i = 54 Then Print "Fizz" ; Goto skip
  If i = 55 Then Print "Buzz" ; Goto skip
  If i = 57 Then Print "Fizz" ; Goto skip
  If i = 60 Then Print "FizzBuzz" ; Goto skip
  If i = 63 Then Print "Fizz" ; Goto skip
  If i = 65 Then Print "Buzz" ; Goto skip
  If i = 66 Then Print "Fizz" ; Goto skip
  If i = 69 Then Print "Fizz" ; Goto skip
  If i = 70 Then Print "Buzz" ; Goto skip
  If i = 72 Then Print "Fizz" ; Goto skip
  If i = 75 Then Print "FizzBuzz" ; Goto skip
  If i = 78 Then Print "Fizz" ; Goto skip
  If i = 80 Then Print "Buzz" ; Goto skip
  If i = 81 Then Print "Fizz" ; Goto skip
  If i = 84 Then Print "Fizz" ; Goto skip
  If i = 85 Then Print "Buzz" ; Goto skip
  If i = 87 Then Print "Fizz" ; Goto skip
  If i = 90 Then Print "FizzBuzz" ; Goto skip
  If i = 93 Then Print "Fizz" ; Goto skip
  If i = 95 Then Print "Buzz" ; Goto skip
  If i = 96 Then Print "Fizz" ; Goto skip
  If i = 99 Then Print "Fizz" ; Goto skip
  If i = 100 Then Print "Buzz" ; Goto skip
  Print i
  #skip
Next

End


Yan,
Did you happen to write any Vista code?
Maybe thats why the install is 8Gb .. ha!

@Yan, hehehehehe..I like it dirtyyy coooolllllll... :))

Agent Smith Wins followed by Koriolis. Wonder who got the booby prize?

No way. I'd hire Koriolis and fire everyone else. Yuck.

Although if Yan wrote that code by hand and it's bug free I'm impressed...

Koriolis' code evaluates the expression i Mod 15 = 0 every single iteration of the loop, but this condition is satisfied only 6 times out of 100.

Also, calling WriteLine directly is faster than calling Print, because Print calls WriteLine.

So you give that much importance to speed in such a case. Fair enough.
But the call to print shouldn't be part of the evaluation then or else I could even bypass writeline to be even faster but what's the point.
OK, so if speed matters, I will only change the order:
For Local i:Int = 1 To 100
	If i Mod 3 = 0 Then
		Print_ "Fizz"
	ElseIf i Mod 5 = 0 Then
		Print_ "Buzz"
	ElseIf i Mod 15 = 0 Then
		Print_ "FizzBuzz"
	Else
		Print_ i
	EndIf
Next

I just tested it, my version is slightly faster. I've used a dummy print_ function that just does nothing, because printing is what takes the most time, of a long shot, and it makes timing the code worthless.

Last but not least, I wouldn't appreciate your version in a real world case. It was never said that the code should be the fastest one, and you've provided a least redable and maintainable version in an attempt to go faster. That's certainly not a plus point for a potential employer, except in very specific cases (or if he's up to discuss technic with you and can ensure you'd do such a thig only if speed really matters).
My version is both shorter that FD's version (and yours), and faster.

Now, I guess you wouldn't have really provided this solution in a real test, would you? You just like brain stimulation and jumped in right :) ?

Now I'm awaiting to see who will post and ASM version ;)
Speed, me want speeeed.

Oh and BTW, if speed really matters, I have a much faster version:
Print "1~n2~nFizz~n4~nBuzz... :p"


EDIT: and still on the "speed, speed now" side of things, another one, a bit less dummy. And yet faster.
Const COUNT% = 100
Local cycle% = 1
Local i%
For i: Int = 0 Until COUNT-15 Step 15
	Print_ cycle
	Print_ cycle + 1		
	Print_ "Fizz"
	Print_ cycle + 3
	Print_ "Buzz"
	Print_ "Fizz"
	Print_ cycle + 6
	Print_ cycle + 7
	Print_ "Fizz"
	Print_ "Buzz"
	Print_ cycle + 10
	Print_ "Fizz"
	Print_ cycle + 12
	Print_ cycle + 13
	Print_ "FizzBuzz"
	cycle :+ 15
Next
i :+ 1
While i <= COUNT
	If i Mod 3 = 0 Then
		Print_ "Fizz"
	ElseIf i Mod 5 = 0 Then
		Print_ "Buzz"
	ElseIf i Mod 15 = 0 Then
		Print_ "FizzBuzz"
	Else
		Print_ i
	EndIf
	i :+ 1
Wend


Choose your poison. Who want speed after seing that :)

+1. Premature optimisation over code readability is ridiculous.

The fact that Next can't be on the same line as For in BMax prevents me from doing a oneliner..

For Local i:Int=1 To 100; If ((Not(i Mod 3))+(Not(i Mod 5)*2)) Print Mid( "Fizz    Buzz    FizzBuzz",1+(((Not(i Mod 3))+(Not(i Mod 5)*2))-1)*8,8) Else Print i
Next; End


Am I hired? :P

People trying to optimize a FizzBuzz program for speed have too much free time on their hands.

Maybe you should have quit while you were ahead, Koriolis..
This code will not produce the correct output!

For Local i:Int = 1 To 100
	If i Mod 3 = 0 Then
		Print_ "Fizz"
	ElseIf i Mod 5 = 0 Then
		Print_ "Buzz"
	ElseIf i Mod 15 = 0 Then
		Print_ "FizzBuzz"
	Else
		Print_ i
	EndIf
Next


more geeky!

For Local i:Int=1 To 100;i:|(((Not(i Mod 3))+(Not(i Mod 5)*2)) Shl 16);If (i&$ff0000) Shr 16 Print Mid( "Fizz    Buzz    FizzBuzz",1+(((i&$ff0000) Shr 16)-1)*8,8) Else Print i&$ff
i:&$ff;Next


Got rid of the extra state calculation at the cost of geeky usage of the counter for storage :-)
(the counter, which is still the only variable btw!)

No, it doesn't, but at least it's easy to spot the error! That's exactly what he's saying. Koriolis is an insanely good programmer - he made a Blitz compatable VM just to see if he could do it - and yet silly mistakes can and will happen. If your code is nicely structured, optimised for readability, mistakes often jump out the page at you.

This code will not produce the correct output!

Eh eh your're right :)
Nice example of why optimization is often pessimization don't you think ?

People trying to optimize a FizzBuzz program for speed have too much free time on their hands.
Precisely what I'm saying.
Mind you, it's my last day of vacations, so I have free time. I just finished the last but one biggie thing of my current project, and have not enough time to start the last one. With friends currently working, I'm definitely left with way too much time on my hands :)

Mmm, maybe I'd better use my time cleaning up and sending the project I promissed to pass to you Michael.

You can't use Function...End Function either. Annoying:

Function n(n) ; Print ([ String( n ), "Fizz", "Buzz", "FizzBuzz" ][ 3 - ( 0 <> ( n Mod 3 ) ) - ( 0 <> ( n Mod 5 ) ) * 2 ]) ; If n < 100 Then .n( n + 1 )
End Function ; n( 1 )

what the.. oO
:D

:)

what's the deal with those square brackets then?

It creates an auto array and indexes it.

Print [ "Cheese", "Bread", "Milk" ][ 1 ]

Another coding issue: over-analysis of a simple problem :)

Oh sure! Agent Smith comes along and sees all our entries and then combines/tweaks them because he can't come up with his own solution! Boo on you sir. As Donald Trump would say...YOU'RE FIRED!

Beat this:-

for loop = 1 to 100

Select loop
Case 1:Print "1"
Case 2:Print "2"
Case 3:Print "Fizz"
Case 4:Print "4"
Case 5:Print "Buzz"
Case 6:Print "Fizz"
Case 7:Print "7"
Case 8:Print "8"
Case 9:Print "Fizz"
Case 10:Print "Buzz"
Case 11:Print "11"
Case 12:Print "Fizz"
Case 13:Print "13"
Case 14:Print "14"
Case 15:Print "FizzBuzz"
Case 16:Print "16"
Case 17:Print "17"
Case 18:Print "Fizz"
Case 19:Print "19"
Case 20:Print "Buzz"
Case 21:Print "Fizz"
Case 22:Print "22"
Case 23:Print "23"
Case 24:Print "Fizz"
Case 25:Print "Buzz"
Case 26:Print "26"
Case 27:Print "Fizz"
Case 28:Print "28"
Case 29:Print "29"
Case 30:Print "FizzBuzz"
Case 31:Print "31"
Case 32:Print "32"
Case 33:Print "Fizz"
Case 34:Print "34"
Case 35:Print "Buzz"
Case 36:Print "Fizz"
Case 37:Print "37"
Case 38:Print "38"
Case 39:Print "Fizz"
Case 40:Print "Buzz"
Case 41:Print "41"
Case 42:Print "Fizz"
Case 43:Print "43"
Case 44:Print "44"
Case 45:Print "Fizz"
Case 46:Print "46"
Case 47:Print "47"
Case 48:Print "Fizz"
Case 49:Print "49"
Case 50:Print "Buzz"
Case 51:Print "Fizz"
Case 52:Print "52"
Case 53:Print "53"
Case 54:Print "Fizz"
Case 55:Print "Buzz"
Case 56:Print "56"
Case 57:Print "Fizz"
Case 58:Print "58"
Case 59:Print "59"
Case 60:Print "FizzBuzz"
Case 61:Print "61"
Case 62:Print "62"
Case 63:Print "Fizz"
Case 64:Print "64"
Case 65:Print "Buzz"
Case 66:Print "Fizz"
Case 67:Print "67"
Case 68:Print "68"
Case 69:Print "Fizz"
Case 70:Print "Buzz"
Case 71:Print "71"
Case 72:Print "Fizz"
Case 73:Print "73"
Case 74:Print "74"
Case 75:Print "FizzBuzz"
Case 76:Print "76"
Case 77:Print "77"
Case 78:Print "Fizz"
Case 79:Print "79"
Case 80:Print "Buzz"
Case 81:Print "Fizz"
Case 82:Print "82"
Case 83:Print "83"
Case 84:Print "Fizz"
Case 85:Print "Buzz"
Case 86:Print "86"
Case 87:Print "Fizz"
Case 88:Print "88"
Case 89:Print "89"
Case 90:Print "FizzBuzz"
Case 91:Print "91"
Case 92:Print "92"
Case 93:Print "Fizz"
Case 94:Print "94"
Case 95:Print "Buzz"
Case 96:Print "Fizz"
Case 97:Print "97"
Case 98:Print "98"
Case 99:Print "Fizz"
case 100:Print "Buzz"
End Select

Next


LOL... this is COOL ENAY ;)

Beat this:-

OK :P

Print "1"
Print "2"
Print "Fizz"
Print "4"
Print "Buzz"
Print "Fizz"
Print "7"
Print "8"
Print "Fizz"
Print "Buzz"
Print "11"
Print "Fizz"
Print "13"
Print "14"
Print "FizzBuzz"
Print "16"
Print "17"
Print "Fizz"
Print "19"
Print "Buzz"
Print "Fizz"
Print "22"
Print "23"
Print "Fizz"
Print "Buzz"
Print "26"
Print "Fizz"
Print "28"
Print "29"
Print "FizzBuzz"
Print "31"
Print "32"
Print "Fizz"
Print "34"
Print "Buzz"
Print "Fizz"
Print "37"
Print "38"
Print "Fizz"
Print "Buzz"
Print "41"
Print "Fizz"
Print "43"
Print "44"
Print "Fizz"
Print "46"
Print "47"
Print "Fizz"
Print "49"
Print "Buzz"
Print "Fizz"
Print "52"
Print "53"
Print "Fizz"
Print "Buzz"
Print "56"
Print "Fizz"
Print "58"
Print "59"
Print "FizzBuzz"
Print "61"
Print "62"
Print "Fizz"
Print "64"
Print "Buzz"
Print "Fizz"
Print "67"
Print "68"
Print "Fizz"
Print "Buzz"
Print "71"
Print "Fizz"
Print "73"
Print "74"
Print "FizzBuzz"
Print "76"
Print "77"
Print "Fizz"
Print "79"
Print "Buzz"
Print "Fizz"
Print "82"
Print "83"
Print "Fizz"
Print "Buzz"
Print "86"
Print "Fizz"
Print "88"
Print "89"
Print "FizzBuzz"
Print "91"
Print "92"
Print "Fizz"
Print "94"
Print "Buzz"
Print "Fizz"
Print "97"
Print "98"
Print "Fizz"
Print "Buzz"


'===================================================================================================
'
'				FizzBuzz
'				________
'		------------------------------------------------------------------------------------
SuperStrict
'		------------------------------------------------------------------------------------
'	Brief.
'	Write a program that prints the numbers from 1 To 100
'	But, For multiples of 3 Print "Fizz" instead of the number
'	For the multiples of 5 Print "Buzz" instead of the number
'	For numbers which are multiples of both 3 And 5 Print "FizzBuzz".

'		-------------------------------------------------------------------------------------
'===================================================================================================

TConditReponse.RF_Create (3,"Fizz")  'First Condition
TConditReponse.RF_Create (5,"Buzz")  'Second Condition


For Local Iterater:Int = 1 To 100
	Print TConditReponse.Result(Iterater)
Next

'===================================================================================================



Delay 1000
End



'===================================================================================================
'Conditions must be added in the order you wish them to be printed
'===================================================================================================
Type TConditReponse				'Type to handle the conditions and responses           
'				--------------------------------------------------------------------
	Field F_Divisaleby:Int 					'The Divisable Condition
	Field F_Responce:String 				'The String to be printed
	Global GF_List:TList = New TList		'A List of the conditions
'				--------------------------------------------------------------------
	Method RM_Set:TConditReponse(P_DivisableBy:Int,P_Responce:String)
		
		Self.F_Divisaleby = P_DivisableBy
		Self.F_Responce = P_Responce
		Self.GF_List.AddLast (Self)
		Return Self
		
	End Method
'				----------------------------------------------------------------------
	Function RF_Create:TConditReponse(P_DivisableBy:Int,P_Responce:String)
	
		Return New TConditReponse.RM_Set(P_DivisableBy,P_Responce)
		
	EndFunction
'				----------------------------------------------------------------------	
	Method NumberIsDivisableBy:Int(P_Number:Int) 	'Does the Number meet a condition
		
		If P_Number Mod Self.F_Divisaleby
			Return False
		Else
			Return True
		EndIf
		
	End Method
'				----------------------------------------------------------------------
	Function result:String(P_Number:Int)			'Make the respose string
		
		Local Result:String = ""
		For Local Condition:TConditReponse = EachIn Self.GF_List
			If Condition.NumberIsDivisableBy (P_Number)
				Result:+Condition.F_Responce
			End If
		Next
		If Result = "" Then result = P_number
		Return Result
	End Function
End Type
'===================================================================================================


Enay & big10p - neither of you are hired. Why? Not because of your ridiculous approach to the programs, nope - it was because 45 should have printed "FizzBuzz" (and I think it's obvious that big10p copied!)

:P

LMAO!!

Enay & big10p - neither of you are hired. Why? Not because of your ridiculous approach to the programs, nope - it was because 45 should have printed "FizzBuzz" (and I think it's obvious that big10p copied!)
Damn - busted for writing crap, erroneous, plagiarized code. I'll get my coat... :P

@big10p

I think it's OK to release a "FizzBuzz v 1.01" or a hotfix...

Mmm, looks like we may have a thread full of bed-wetters here.

Let's be honest - the task was hardly challenging.

Continue bed-wetting.

Wait a sec. I WIN!!

For Local i:Int = 1 To 100
	Select False
		Case i Mod 15
			WriteLine StandardIOStream,"FizzBuzz"
		Case i Mod 3 
			WriteLine StandardIOStream,"Fizz"
		Case i Mod 5
			WriteLine StandardIOStream,"Buzz"
		Default
			WriteLine StandardIOStream,i
	End Select
Next


EDIT: Ok..I win x2!

For Local i:Int = 1 To 100
	If Not (i Mod 15)
		WriteLine StandardIOStream,"FizzBuzz"
	ElseIf Not (i Mod 3)
		WriteLine StandardIOStream,"Fizz"
	ElseIf Not (i Mod 5)
		WriteLine StandardIOStream,"Buzz"
	Else
		WriteLine StandardIOStream,i
	EndIf
Next


lol this thread is great. I chose Agent Smith as it was clearly faster than Koriolis's inefficient if mod testing.

Lol @ Big10p's entry btw.

Oh and H&K's :-)

Perhaps I should wrap one of the solutions in my framework for ultra bloat ;-)

There should be more code challenges like this one.. :P

H&K wins... you can't beat coding standards for re-usability ... LMAO (;->

Nasty:

Global AllFuncs:TList = New TList

Type Func
	
	Global out$	
	Field name$
	Field myargs$[]
	Field body$
	
	Method Execute$( args$[] )
		
		Assert( Len( args ) = Len( myargs ) )
		
		Local newbody$ = body
		
		For Local c = 0 Until Len( myargs )
			
			newbody = newbody.replace( myargs[ c ], eval( args[ c ] ) )
			
		Next
		
		Return Eval( newbody )
		
	End Method
	
End Type

Type DefunFunc Extends Func
	
	Method New( )
		
		name = "defun"
		
		AllFuncs.AddLast( Self )
		
	End Method
	
	Method Execute$( args$[] )
		
		Local meth$[] = pParse( args[ 0 ] )
		Local body$ = args[ 1 ]
			
		Local f:Func = New Func

		f.Name = meth[ 0 ]
		f.myargs = meth[1..]
		f.body = body
		
		AllFuncs.AddLast( f )
		
	End Method
	
End Type

Type IfFunc Extends Func
	
	Method New( )
		
		name = "if"
		
		AllFuncs.AddLast( Self )
		
	End Method
	
	Method Execute$( args$[] )
		
		If Eval( args[ 0 ] ) = "nil"
			
			Return Eval( args[ 2 ] )
			
		Else
			
			Return Eval( args[ 1 ] )
			
		EndIf
				
	End Method
	
End Type

Type EqFunc Extends Func
	
	Method New( )
		
		name = "="
		AllFuncs.Addlast( Self )
		
	End Method
	
	Method Execute$( args$[] ) 
		
		If ( Double( Eval( args[ 0 ] ) ) = Double( Eval( args[ 1 ] ) ) )
			
			Return "1"
			
		Else
		
			Return "nil"
			
		EndIf
		
	End Method
	
End Type


Type LTFunc Extends Func
	
	Method New( )
		
		name = "<"
		AllFuncs.Addlast( Self )
		
	End Method
	
	Method Execute$( args$[] ) 
		
		If ( Double( Eval( args[ 0 ] ) ) < Double( Eval( args[ 1 ] ) ) )
			
			Return "1"
			
		Else
		
			Return "nil"
			
		EndIf
		
	End Method
	
End Type

Type Pr Extends Func
	
	Method New( )
	
		name = "pr"
		AllFuncs.AddLast( Self )
	
	End Method
	
	Method Execute$( Args$[] )

		Local n[] = [ $46, $69, $7A, $42, $75 ]
		
		
		If Int( Eval( Args[ 0 ] ) ) > 100
			
			Print Func.Out
			End
		
		Else
		
			Func.Out:+[ String( Int( Eval( Args[ 0 ] ) ) ), Pr( n, [ 0, 1, 2, 2 ] ), Pr( n, [ 3, 4, 2, 2 ] ), Pr( n, [ 0, 1, 2, 2 ] ) + Pr( n, [ 3, 4, 2, 2 ] ) ][ Int( Eval( Args[ 1 ] ) ) ] + "~n"
				
		EndIf

	End Method
	
	
	Method Pr$( ca[], n[] )
		
		Local o$
		
		For Local c = EachIn n
		
			o:+Chr(ca[c])
		
		Next
		
		Return o
		
	End Method
	
	
End Type

Type SubFunc Extends Func
	
	Method New( )
		
		name = "-"
		AllFuncs.Addlast( Self )
		
	End Method
	
	Method Execute$( args$[] ) 
	
		Return Double( Eval( args[ 0 ] ) ) - Double( Eval( args[ 1 ] ) )

	End Method
	
End Type


Type PlusFunc Extends Func
	
	Method New( )
		
		name = "+"
		AllFuncs.Addlast( Self )
		
	End Method
	
	Method Execute$( args$[] ) 
	
		Return Double( Eval( args[ 0 ] ) ) + Double( Eval( args[ 1 ] ) )

	End Method
	
End Type

Type TimesFunc Extends Func
	
	Method New( )
		
		name = "*"
		AllFuncs.Addlast( Self )
		
	End Method
	
	Method Execute$( args$[] ) 
		
		Return Double( Eval( args[ 0 ] ) ) * Double( Eval( args[ 1 ] ) )

	End Method
	
End Type

Local d:DefunFunc = New DefunFunc
Local f:IfFunc = New IfFunc
Local eq:EqFunc = New EqFunc
Local sub:SubFunc = New SubFunc
Local plus:PlusFunc = New PlusFunc
Local times:TimesFunc = New TimesFunc
Local lt:LTFunc = New LTFunc
Local p:PR = New PR

For Local str$ = EachIn [ "(defun (i n p) (if (< n p) (= n 0) (i (- n p) (- p 0))))", "(defun (pp t) (if (pr t (+ (i t 3) (+ (i t 5) (i t 5) ) ) ) ) )", "(defun (it a) (if (pp a) (it (+ a 1)) (it (+ a 1)) ) )", "(it 1)" ]
	
	Eval( str )
	
Next

Function Eval$( str$ )
		
	Local funcs$[] = pParse( str )

	For Local f:Func = EachIn AllFuncs
		
		If ( f.Name = funcs[ 0 ] )
			
			Local n$ = f.Execute( funcs[1..] )
			
			Return n
			
		EndIf
	
	Next
	
	Return str
		
End Function

Function pParse$[]( str$ )
	
	Local ret$[256]
	Local level = 0
	Local slot = 0
	
	For n = 1 To Len( str )
		
		
		If level > 1 Or ( ( Level = 1 ) And ( Mid( str, n, 1 ) = "(" ) )
			
			ret[ slot ]:+Mid( str, n, 1 )
			
		EndIf
		
		
		Select Mid( str, n, 1 )
		
			Case "("
				
				level:+1
				
			Case ")"
				
				level:-1
				
			Case " "
				
				If ( level <= 1 )
				
					If ret[ slot ] <> ""
						
						slot:+1
						
					EndIf
					
				EndIf
			
			Default
				
				If level <= 1
					
					ret[ slot ]:+Mid( str, n, 1 )
					
				EndIf
				
				
		End Select
		
		
	Next
	
	Return ret[..slot+1]

End Function


Hard-coded 'Fizz' and 'Buzz' conditions, the lot of you.

Pathetic. ;o)

Errr, mine is only semi Hardcoded

Well my conditions were in a string if that makes you feel any better:

(defun (pp t) (if (pr t (+ (i t 3) (+ (i t 5) (i t 5) ) ) ) ) )

This way should be faster than mod:
For num = 1 To 100
	
	If num/3*3 = num Then
		WriteString StandardIOStream,"Fizz"
		did=1
	EndIf
	
	If num/5*5 = num Then
		WriteString StandardIOStream,"Buzz"
		did=1
	EndIf
	
	If did=0 Then
		WriteString StandardIOStream,num
	Else
		did=0
	EndIf
	
	Print
Next


Michael Reitzenstein: You need comments too I'm afraid.

It also relies on the languages treatment of integers (autopromotion to double would break it, as would a rounding on integer divide), is hard to follow, would break if there's a global variable called 'did', and is slower because you're calling the bottleneck functions - WriteString and Print, at least twice per line.

It's coders throwing in cute tricks like this into a production system that creates nightmares down the track. It's worse than useless to try to optimise problems like this - it's dangerous. And if you profiled it you'd see that your version is actually slower than most of the others.

Michael Reitzenstein: You need comments too I'm afraid.

I don't comment my own code, because nobody else will ever touch it. I also strip out comments when I'm working with other peoples code, because invariably the comments are useless, out of date, unclear and just reading the code - if its well written - will give you a better understanding more quickly, if you've got the domain knowledge. If it's not written well, then you're screwed either way.

This way should be faster than mod:
It's not. Doing a division and a multiplication is much slower than doing a modulus.

As far as I understand it, under x86 the modulus is calculated on each integer divide, so yes it's slower. But I don't think its relevent anyway - because even if it WAS faster, changing the code like that is dumb, dumb, dumb.

> Why? Not because of your ridiculous
> approach to the programs, nope - it
> was because 45 should have printed
> "FizzBuzz" (and I think it's obvious
> that big10p copied!)

As a matter of fact I put that mistake in there on purpose so I could poke fun at the really sad loser who bothered to proof read my code. But then big10p went a step further by plagarising my work and passing it off as his own, complete with the mistake! If that's not really sad, I don't know what is :)

Yes my approach was a bit ridiculous wasn't it. Sorry about that, I've had another go, do I qualify this time?

Global dataparam1 = ""
Global dataparam2 = ""
Global dataparam3 = ""
Global dataparam4 = ""
Global dataparam5 = ""
Global dataparam6 = ""
Global dataparam7 = ""
Global dataparam8 = ""
Global dataparam9 = ""
Global dataparam10 = ""
Global dataparam11 = ""
Global dataparam12 = ""
Global dataparam13 = ""
Global dataparam14 = ""
Global dataparam15 = ""
Global dataparam16 = ""
Global dataparam17 = ""
Global dataparam18 = ""
Global dataparam19 = ""
Global dataparam20 = ""
Global dataparam21 = ""
Global dataparam22 = ""
Global dataparam23 = ""
Global dataparam24 = ""
Global dataparam25 = ""
Global dataparam26 = ""
Global dataparam27 = ""
Global dataparam28 = ""
Global dataparam29 = ""
Global dataparam30 = ""
Global dataparam31 = ""
Global dataparam32 = ""
Global dataparam33 = ""
Global dataparam34 = ""
Global dataparam35 = ""
Global dataparam36 = ""
Global dataparam37 = ""
Global dataparam38 = ""
Global dataparam39 = ""
Global dataparam40 = ""
Global dataparam41 = ""
Global dataparam42 = ""
Global dataparam43 = ""
Global dataparam44 = ""
Global dataparam45 = ""
Global dataparam46 = ""
Global dataparam47 = ""
Global dataparam48 = ""
Global dataparam49 = ""
Global dataparam50 = ""
Global dataparam51 = ""
Global dataparam52 = ""
Global dataparam53 = ""
Global dataparam54 = ""
Global dataparam55 = ""
Global dataparam56 = ""
Global dataparam57 = ""
Global dataparam58 = ""
Global dataparam59 = ""
Global dataparam60 = ""
Global dataparam61 = ""
Global dataparam62 = ""
Global dataparam63 = ""
Global dataparam64 = ""
Global dataparam65 = ""
Global dataparam66 = ""
Global dataparam67 = ""
Global dataparam68 = ""
Global dataparam69 = ""
Global dataparam70 = ""
Global dataparam71 = ""
Global dataparam72 = ""
Global dataparam73 = ""
Global dataparam74 = ""
Global dataparam75 = ""
Global dataparam76 = ""
Global dataparam77 = ""
Global dataparam78 = ""
Global dataparam79 = ""
Global dataparam80 = ""
Global dataparam81 = ""
Global dataparam82 = ""
Global dataparam83 = ""
Global dataparam84 = ""
Global dataparam85 = ""
Global dataparam86 = ""
Global dataparam87 = ""
Global dataparam88 = ""
Global dataparam89 = ""
Global dataparam90 = ""
Global dataparam91 = ""
Global dataparam92 = ""
Global dataparam93 = ""
Global dataparam94 = ""
Global dataparam95 = ""
Global dataparam96 = ""
Global dataparam97 = ""
Global dataparam98 = ""
Global dataparam99 = ""
Global dataparam100 = ""

Restore FizzBuzzData

Read dataparam1
Read dataparam2
Read dataparam3
Read dataparam4
Read dataparam5
Read dataparam6
Read dataparam7
Read dataparam8
Read dataparam9
Read dataparam10
Read dataparam11
Read dataparam12
Read dataparam13
Read dataparam14
Read dataparam15
Read dataparam16
Read dataparam17
Read dataparam18
Read dataparam19
Read dataparam20
Read dataparam21
Read dataparam22
Read dataparam23
Read dataparam24
Read dataparam25
Read dataparam26
Read dataparam27
Read dataparam28
Read dataparam29
Read dataparam30
Read dataparam31
Read dataparam32
Read dataparam33
Read dataparam34
Read dataparam35
Read dataparam36
Read dataparam37
Read dataparam38
Read dataparam39
Read dataparam40
Read dataparam41
Read dataparam42
Read dataparam43
Read dataparam44
Read dataparam45
Read dataparam46
Read dataparam47
Read dataparam48
Read dataparam49
Read dataparam50
Read dataparam51
Read dataparam52
Read dataparam53
Read dataparam54
Read dataparam55
Read dataparam56
Read dataparam57
Read dataparam58
Read dataparam59
Read dataparam60
Read dataparam61
Read dataparam62
Read dataparam63
Read dataparam64
Read dataparam65
Read dataparam66
Read dataparam67
Read dataparam68
Read dataparam69
Read dataparam70
Read dataparam71
Read dataparam72
Read dataparam73
Read dataparam74
Read dataparam75
Read dataparam76
Read dataparam77
Read dataparam78
Read dataparam79
Read dataparam80
Read dataparam81
Read dataparam82
Read dataparam83
Read dataparam84
Read dataparam85
Read dataparam86
Read dataparam87
Read dataparam88
Read dataparam89
Read dataparam90
Read dataparam91
Read dataparam92
Read dataparam93
Read dataparam94
Read dataparam95
Read dataparam96
Read dataparam97
Read dataparam98
Read dataparam99
Read dataparam100

.FizzBuzzData

Data "1"
Data "2"
Data "Fizz"
Data "4"
Data "Buzz"
Data "Fizz"
Data "7"
Data "8"
Data "Fizz"
Data "Buzz"
Data "11"
Data "Fizz"
Data "13"
Data "14"
Data "FizzBuzz"
Data "16"
Data "17"
Data "Fizz"
Data "19"
Data "Buzz"
Data "Fizz"
Data "22"
Data "23"
Data "Fizz"
Data "Buzz"
Data "26"
Data "Fizz"
Data "28"
Data "29"
Data "FizzBuzz"
Data "31"
Data "32"
Data "Fizz"
Data "34"
Data "Buzz"
Data "Fizz"
Data "37"
Data "38"
Data "Fizz"
Data "Buzz"
Data "41"
Data "Fizz"
Data "43"
Data "44"
Data "FizzBuzz"
Data "46"
Data "47"
Data "Fizz"
Data "49"
Data "Buzz"
Data "Fizz"
Data "52"
Data "53"
Data "Fizz"
Data "Buzz"
Data "56"
Data "Fizz"
Data "58"
Data "59"
Data "FizzBuzz"
Data "61"
Data "62"
Data "Fizz"
Data "64"
Data "Buzz"
Data "Fizz"
Data "67"
Data "68"
Data "Fizz"
Data "Buzz"
Data "71"
Data "Fizz"
Data "73"
Data "74"
Data "FizzBuzz"
Data "76"
Data "77"
Data "Fizz"
Data "79"
Data "Buzz"
Data "Fizz"
Data "82"
Data "83"
Data "Fizz"
Data "Buzz"
Data "86"
Data "Fizz"
Data "88"
Data "89"
Data "FizzBuzz"
Data "91"
Data "92"
Data "Fizz"
Data "94"
Data "Buzz"
Data "Fizz"
Data "97"
Data "98"
Data "Fizz"
Data "Buzz"


for loop = 1 to 100

Select loop

Case 1: Print dataparam1
Case 2: Print dataparam2
Case 3: Print dataparam3
Case 4: Print dataparam4
Case 5: Print dataparam5
Case 6: Print dataparam6
Case 7: Print dataparam7
Case 8: Print dataparam8
Case 9: Print dataparam9
Case 0: Print dataparam10
Case 11: Print dataparam11
Case 12: Print dataparam12
Case 13: Print dataparam13
Case 14: Print dataparam14
Case 15: Print dataparam15
Case 16: Print dataparam16
Case 17: Print dataparam17
Case 18: Print dataparam18
Case 19: Print dataparam19
Case 20: Print dataparam20
Case 21: Print dataparam21
Case 22: Print dataparam22
Case 23: Print dataparam23
Case 24: Print dataparam24
Case 25: Print dataparam25
Case 26: Print dataparam26
Case 27: Print dataparam27
Case 28: Print dataparam28
Case 29: Print dataparam29
Case 30: Print dataparam30
Case 31: Print dataparam31
Case 32: Print dataparam32
Case 33: Print dataparam33
Case 34: Print dataparam34
Case 35: Print dataparam35
Case 36: Print dataparam36
Case 37: Print dataparam37
Case 38: Print dataparam38
Case 39: Print dataparam39
Case 40: Print dataparam40
Case 41: Print dataparam41
Case 42: Print dataparam42
Case 43: Print dataparam43
Case 44: Print dataparam44
Case 45: Print dataparam45
Case 46: Print dataparam46
Case 47: Print dataparam47
Case 48: Print dataparam48
Case 49: Print dataparam49
Case 50: Print dataparam50
Case 51: Print dataparam51
Case 52: Print dataparam52
Case 53: Print dataparam53
Case 54: Print dataparam54
Case 55: Print dataparam55
Case 56: Print dataparam56
Case 57: Print dataparam57
Case 58: Print dataparam58
Case 59: Print dataparam59
Case 60: Print dataparam60
Case 61: Print dataparam61
Case 62: Print dataparam62
Case 63: Print dataparam63
Case 64: Print dataparam64
Case 65: Print dataparam65
Case 66: Print dataparam66
Case 67: Print dataparam67
Case 68: Print dataparam68
Case 69: Print dataparam69
Case 70: Print dataparam70
Case 71: Print dataparam71
Case 72: Print dataparam72
Case 73: Print dataparam73
Case 74: Print dataparam74
Case 75: Print dataparam75
Case 76: Print dataparam76
Case 77: Print dataparam77
Case 78: Print dataparam78
Case 79: Print dataparam79
Case 80: Print dataparam80
Case 81: Print dataparam81
Case 82: Print dataparam82
Case 83: Print dataparam83
Case 84: Print dataparam84
Case 85: Print dataparam85
Case 86: Print dataparam86
Case 87: Print dataparam87
Case 88: Print dataparam88
Case 89: Print dataparam89
Case 90: Print dataparam90
Case 91: Print dataparam91
Case 92: Print dataparam92
Case 93: Print dataparam93
Case 94: Print dataparam94
Case 95: Print dataparam95
Case 96: Print dataparam96
Case 97: Print dataparam97
Case 98: Print dataparam98
Case 99: Print dataparam99
Case 100: Print dataparam100

End select

Next


Hard-coded 'Fizz' and 'Buzz' conditions, the lot of you.
Excuse me! My awesome 'reworking' of ENAY's code doesnt have ANY conditions. -_-

As a matter of fact I put that mistake in there on purpose so I could poke fun at the really sad loser who bothered to proof read my code. But then big10p went a step further by plagarising my work and passing it off as his own, complete with the mistake! If that's not really sad, I don't know what is :)
lol :D

ENAY, your code sucks, it uses Globals, and Globals are evil.. :D