#212981 - 2017-11-26 06:03 PM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Jochen]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
; begin BOB
;
;!
function a($)
Dim $W
$ = 1 * $
$W = ' on the wall'
; build the string
; Get the "x bottles of beer" phrase
$a = W($)
; build it, and capitalize the first letter
$a = UCase(Left($a, 1)) + Right($a, ~) + $W + ', ' + $a + '.'
; If $ isn't zero, take one down, otherwise go buy some more!
If $
$a = $a + ' Take one down and pass it around, ' + W($ - 1) + $W + '.'
Else
$a = $a + ' Go to the store and buy some more, ' + W(99) + $W + '.'
endfunction
Function W($)
Dim $S
; array of number terms
$S = Split('no more,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir!,#!,fif!,#!,#!,eigh!,#!,,twen,thir,for,fif,,,eigh,', ',')
If $ < 20
$W = Replace(Replace($S[$], !, teen), #, $S[$ Mod 10]) ; use regular or special number and optional "teen"
Else
$W = $S[19 + $/10] ; Get special tens value
$W = $W + IIf($W, '',$S[$/10]) + ty ; normalize and add "ty"
If $ Mod 10 $W = $W + '-' + $S[$ Mod 10] EndIf ; add optional hyphen and ONEs digit
EndIf
$W = $W + ' bottle' + IIf($ = 1, '', s) + ' of beer'
EndFunction
;!
;!
; end BOB for 568.
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#212983 - 2017-11-26 06:35 PM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Jochen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
559
function a($)
dim $w,$b
if $+0>$
$=0+$
if $
$a="Take one down and pass it around, " + a($-1)
else
$a="Go to the store and buy some more, " + a(99)
endif
$b=" bottle"
$a=$a + $b + chr(115*($<>2))
if $<>1
$b=$b + s
endif
;$b=$b + chr(115*($<>1))
$w=" of beer on the wall"
$a=ucase(left(a($),1)) + right(a($),~) + $b + $w + ", " + a($) + $b + " of beer. " + $a + $w + "."
else
$b="no more",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety
if $<20
$a=$b[$]
else
$a= $b[18+ $/10]
if $ mod 10
$a=$a + "-" + $b[$ mod 10]
;endif
;endif
;endif
endfunction
|
Top
|
|
|
|
#212985 - 2017-11-26 06:50 PM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
I found this too late... but 557 on mine.
function a($)
dim $w,$b
if $+0>$
$=0+$
$b=" bottle"
if $
$a="Take one down and pass it around, " + a($-1) + $b
else
$a="Go to the store and buy some more, " + a(99) + $b
endif
if $<>2
$a=$a + s
endif
if $<>1
$b=$b + s
endif
$w=" of beer on the wall"
$a=chr(asc(a($))-32) + right(a($),~) + $b + $w + ", " + a($) + $b + " of beer. " + $a + $w + "."
else
$b="no more",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety
if $<20
$a=$b[$]
else
$a= $b[18+ $/10]
if $ mod 10
$a=$a + "-" + $b[$ mod 10]
;endif
;endif
;endif
endfunction
|
Top
|
|
|
|
#212986 - 2017-11-26 10:20 PM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
Mix of codes... 553
function a($)
Dim $W
$ = 1 * $
$W = ' on the wall'
; build the string
; Get the "x bottles of beer" phrase
$a = W($)
; build it, and capitalize the first letter
$a = UCase(Left($a, 1)) + Right($a, ~) + $W + ', ' + $a + '.'
; If $ isn't zero, take one down, otherwise go buy some more!
If $
$a = $a + ' Take one down and pass it around, ' + W($ - 1) + $W + '.'
Else
$a = $a + ' Go to the store and buy some more, ' + W(99) + $W + '.'
endfunction
Function W($)
dim $b
$b="no more",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety
if $<20
$w=$b[$]
else
$w= $b[18+ $/10]
if $ mod 10
$w=$w + "-" + $b[$ mod 10]
endif
endif
$W = $W + ' bottle' + IIf($ = 1, @, s) + ' of beer'
EndFunction
|
Top
|
|
|
|
#212987 - 2017-11-26 10:56 PM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
551
function a($)
Dim $W
$ = 1 * $
$W = ' on the wall'
$a = W($)
$a = chr(asc($a)-32) + Right($a, ~) + $W + ', ' + $a + '.'
If $
$a = $a + ' Take one down and pass it around, ' + W($ - 1) + $W + '.'
Else
$a = $a + ' Go to the store and buy some more, ' + W(99) + $W + '.'
endfunction
Function W($)
dim $b
$b="no more",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety
if $<20
$w=$b[$]
else
$w= $b[18+ $/10]
if $ mod 10
$w=$w + "-" + $b[$ mod 10]
endif
endif
$W = $W + ' bottle' + IIf($ = 1, @, s) + ' of beer'
EndFunction
|
Top
|
|
|
|
#212988 - 2017-11-26 11:34 PM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
534
function a($)
Dim $b
if $+0=$
$b="no more",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety
if $<20
$a=$b[$]
else
$a= $b[18+ $/10]
if $ mod 10
$a=$a + "-" + $b[$ mod 10]
endif
endif
$a = $a + ' bottle' + IIf($ = 1, @, s) + ' of beer'
else
$ = 1 * $
$b = ' on the wall'
$a = a($)
$a = chr(asc($a)-32) + Right($a, ~) + $b + ', ' + $a + '.'
If $
$a = $a + ' Take one down and pass it around, ' + a($ - 1) + $b + '.'
Else
$a = $a + ' Go to the store and buy some more, ' + a(99) + $b + '.'
endfunction
|
Top
|
|
|
|
#212989 - 2017-11-27 06:17 AM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
527
function a($)
Dim $b
if $+0=$
$b="no more",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir,four,fif,six,seven,eigh,nine,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety
if $<20
$a=$b[$]
if $ > 12
$a=$a+teen
endif
else
$a= $b[18+ $/10]
if $ mod 10
$a=$a + "-" + $b[$ mod 10]
endif
endif
$a = $a + ' bottle' + IIf($ = 1, @, s) + ' of beer'
else
$ = 1 * $
$b = ' on the wall'
$a = a($)
$a = chr(asc($a)-32) + Right($a, ~) + $b + ', ' + $a + '.'
If $
$a = $a + ' Take one down and pass it around, ' + a($ - 1) + $b + '.'
Else
$a = $a + ' Go to the store and buy some more, ' + a(99) + $b + '.'
endfunction
|
Top
|
|
|
|
#212990 - 2017-11-27 06:26 AM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
516
function a($)
Dim $b
if $+0=$
$b="no more",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir,four,fif,six,seven,eigh,nine,twen,thir,"for",fif,six,seven,eigh,nine
if $<20
$a=$b[$]
if $ > 12
$a=$a+teen
endif
else
$a= $b[18+ $/10] + ty
if $ mod 10
$a=$a + "-" + $b[$ mod 10]
endif
endif
$a = $a + ' bottle' + IIf($ = 1, @, s) + ' of beer'
else
$ = 1 * $
$b = ' on the wall'
$a = a($)
$a = chr(asc($a)-32) + Right($a, ~) + $b + ', ' + $a + '.'
If $
$a = $a + ' Take one down and pass it around, ' + a($ - 1) + $b + '.'
Else
$a = $a + ' Go to the store and buy some more, ' + a(99) + $b + '.'
endfunction
|
Top
|
|
|
|
#212991 - 2017-11-27 06:38 AM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
Glenn... you might prove me wrong, but I think you had the winning code if you had not gone down the road with using replace(). Still, how you were doing the replacement was pretty slick. I had to tear your code apart line by line to figure out how you were getting the numbers like sixty, seventy and ninety. Well done.
I can't tell you how many times I looked at teen and ty and tried to make it work. It seems so simple now, but for the life of me I couldn't see it for the trees.
|
Top
|
|
|
|
#212993 - 2017-11-27 07:36 AM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Jochen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
I remember Jooel's disdain for iif... but but but... i can't see a way around it.
|
Top
|
|
|
|
#212995 - 2017-11-27 10:33 AM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Allen]
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
Top
|
|
|
|
#212997 - 2017-11-27 11:08 AM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Glenn Barnas]
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
; begin BOB
;
;!
function a($)
Dim $W
$ = 1 * $
$W = ' on the wall'
; build the string
; Get the "x bottles of beer" phrase
$a = W($)
; build it, and capitalize the first letter
$a = UCase(Left($a, 1)) + Right($a, ~) + $W + ', ' + $a + '.'
; If $ isn't zero, take one down, otherwise go buy some more!
If $
$a = $a + ' Take one down and pass it around, ' + W($ - 1) + $W + '.'
Else
$a = $a + ' Go to the store and buy some more, ' + W(99) + $W + '.'
endfunction
Function W($)
Dim $S
; array of number terms
$S = Split('no more,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir!,#!,fif!,#!,#!,eigh!,#!,,twen,thir,for,fif,,,eigh,', ',')
If $ < 20
$W = Replace(Replace($S[$], !, teen), #, $S[$ Mod 10]) ; use regular or special number and optional "teen"
Else
$W = $S[19 + $/10] ; Get special tens value
$W = $W + IIf($W, '',$S[$/10]) + ty ; normalize and add "ty"
If $ Mod 10 $W = $W + '-' + $S[$ Mod 10] EndIf ; add optional hyphen and ONEs digit
EndIf
$W = $W + ' bottle' + IIf($ = 1, '', s) + ' of beer'
EndFunction
;!
;!
; end BOB for 568.
Hey Glenn, your code passed the test but the Score says 571
_________________________
|
Top
|
|
|
|
#213003 - 2017-11-27 02:37 PM
Re: Kixgolf - 99 Bottles Of Beer - Public Round
[Re: Jochen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
515
function a($)
Dim $b
if $+0=$
$b="no more",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir,four,fif,six,seven,eigh,nine,twen,thir,"for",fif,six,seven,eigh,nine
if $<20
$a=$b[$]
if $ > 12
$a=$a+teen
endif
else
$a= $b[18+ $/10] + ty
if $ mod 10
$a=$a + "-" + $b[$ mod 10]
endif
endif
$a = $a + ' bottle' + IIf($ = 1, @, s) + ' of beer'
else
$ = 1 * $
$b = ' on the wall'
$a = chr(asc(a($))-32) + Right(a($), ~) + $b + ', ' + a($) + '.'
If $
$a = $a + ' Take one down and pass it around, ' + a($ - 1) + $b + '.'
Else
$a = $a + ' Go to the store and buy some more, ' + a(99) + $b + '.'
endfunction
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 512 anonymous users online.
|
|
|