Advertisement
Guest User

bytelandianExchange

a guest
Mar 11th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.48 KB | None | 0 0
  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." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement