Page 1 of 3 123>
Topic Options
#212979 - 2017-11-26 06:00 PM Kixgolf - 99 Bottles Of Beer - Public Round
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Gentlemen, post your code



Edited by Jochen (2017-12-03 06:03 PM)
_________________________



Top
#212981 - 2017-11-26 06:03 PM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Jochen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
 Code:
; 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! \:D

Top
#212982 - 2017-11-26 06:13 PM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Glenn Barnas]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Nice one. Finally we see the use of Replace() in a golf code (iirc it wasn't there yet)
_________________________



Top
#212983 - 2017-11-26 06:35 PM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Jochen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
559
 Code:
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
#212984 - 2017-11-26 06:47 PM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Wow Glenn... Completely different approach. Nice. I can see some meat on your bones though. :).
Top
#212985 - 2017-11-26 06:50 PM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I found this too late... but 557 on mine.

 Code:
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 Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Mix of codes... 553

 Code:
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 Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
551

 Code:
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 Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
534
 Code:
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 Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
527
 Code:
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 Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
516
 Code:
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 Administrator Offline
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
#212992 - 2017-11-27 07:14 AM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
well,
couldn't open the topic on my iPhone yesterday evening and was too tired to fire up the Notebook. (Strange, only this topic refused to let me in and logged me out)

Will look at the codes this evening more closely. From a first glance, very well combined. Still I spot an IIF() which in Jooels world are bad, mkay?
_________________________



Top
#212993 - 2017-11-27 07:36 AM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Jochen]
Allen Administrator Offline
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
#212994 - 2017-11-27 07:45 AM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I'm going to bed... it's time for someone else to take the reigns.

Good fun Jochen.

Top
#212995 - 2017-11-27 10:33 AM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
much appreciated, thanx ;\)

btw. got rid of the IIF() but no improvement of score there

edit: HAH!!!! got a 515. Now riddle this! *Jooel's right as most of the time


Edited by Jochen (2017-11-27 11:10 AM)
_________________________



Top
#212996 - 2017-11-27 10:39 AM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
 Code:
$a = chr(asc($a)-32) + Right($a, ~) + $b + ', ' + $a + '.'


??? Have no clue yet what this does and why ..
recursive function, yeah, clever basta.

Edit: Ah yeah, mimicking a ucase() on the first char .. neat


Edited by Jochen (2017-11-27 03:18 PM)
_________________________



Top
#212997 - 2017-11-27 11:08 AM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Glenn Barnas]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
 Originally Posted By: Glenn Barnas
 Code:
; 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
#212998 - 2017-11-27 11:31 AM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Dunno if you guys get mad at me for this.. but 511 :p
_________________________



Top
#213003 - 2017-11-27 02:37 PM Re: Kixgolf - 99 Bottles Of Beer - Public Round [Re: Jochen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
515
 Code:
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
Page 1 of 3 123>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 512 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.079 seconds in which 0.03 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org