Sha256: a4c6cc445571778ce65daa6631ea5ffb6535a5c7d98c693bde77a93ee5858a27

Contents?: true

Size: 907 Bytes

Versions: 396

Compression:

Stored size: 907 Bytes

Contents

local beer = {}

local GENERIC_VERSE = 'N bottles of beer on the wall, N bottles of beer.\nTake one down and pass it around, M bottles of beer on the wall.\n'

local VERSE_FOR_0 = 'No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n'

function beer.verse(number)
  if number == 0 then
    return VERSE_FOR_0
  end
  local a_verse = GENERIC_VERSE:gsub('N', number):gsub('M', number - 1)
  if number < 3 then
    a_verse = a_verse:gsub('1 bottles', '1 bottle')
  end
  if number == 1 then
    a_verse= a_verse:gsub('one', 'it'):gsub('0 bottles', 'no more bottles')
  end
  return a_verse
end

function beer.sing(start, finish)
  finish = finish or 0
  local verses = ''
  for i = start, finish, -1 do
    verses = verses .. beer.verse(i)
    if i ~= finish then verses = verses .. '\n' end
  end
  return verses
end

return beer

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.179 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.178 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.177 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.176 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.175 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.174 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.173 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.172 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.171 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.170 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.169 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.167 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.166 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.165 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.164 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.163 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.162 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.161 tracks/lua/exercises/beer-song/example.lua
trackler-2.2.1.160 tracks/lua/exercises/beer-song/example.lua