Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Problem: Imagine a game where a player starts at level 1 and gains
- -- a level when they gain 10 times their current level in experience.
- -- Given a player's total experience, calculate what level they are.
- -- Hard mode: do this without using a while-do or repeat-until block.
- -- Input
- total_xp = 270
- level = 1
- -- Calculation
- while total_xp >= level * 10 do
- total_xp = total_xp - level * 10
- level = level + 1
- end
- -- Output
- print("Level:", level)
- -- Alternate solution using a repeat-until
- total_xp = 270
- level = 0
- repeat
- level = level + 1
- total_xp = total_xp - level * 10
- until total_xp < 0
- print("Level:", level)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement