Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

bytelandianExchange

By: a guest on Mar 11th, 2013  |  syntax: Lua  |  size: 0.48 KB  |  views: 32  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. --Bytelandian Exchange 1
  2. --Initialize
  3. coinValue = 0
  4. --Get positive integer
  5. while( coinValue < 1 ) do
  6.         print( "Insert coin:")
  7.         coinValue = math.floor( tonumber( io.read() ) )
  8. end
  9. --Exchange coin recursively
  10. function exchange( coin )
  11.         if( coin == 0 ) then
  12.                 return 1
  13.         else
  14.                 return exchange( math.floor( coin/2 ) ) + exchange( math.floor( coin/3 ) ) + exchange( math.floor( coin/4 ) )
  15.         end
  16. end
  17. --Output
  18. print( "You get back " .. exchange( coinValue ) .. " 0-value coins." )