Learn Lua · Basics · Lesson 4 of 4
Working with numbers
Lua has whole numbers (3) and numbers with a fraction (2.5). +, - and * work
as you'd expect. / always gives a fraction, // divides and rounds down, and % gives
what's left over:
10 / 4 --> 2.5
10 // 4 --> 2
10 % 4 --> 2The math library rounds: math.ceil rounds up, math.floor rounds down and
math.round rounds to the nearest whole number:
math.ceil(2.5) --> 3
math.floor(2.5) --> 2
math.round(2.4) --> 2What your code receives
Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.
input = { pages = 10, pagesPerSheet = 4, copies = 50 }Steps
- Return
sheets: how many sheets one copy needs,input.pagesdivided byinput.pagesPerSheet, rounded up. - Add
total: the sheets needed for allinput.copies. - Add
blank: how many page spaces are left empty on the sheets of one copy.
Show a hint
A copy of 10 pages at 4 pages per sheet needs 3 sheets. Those 3 sheets have room for 12 pages, so 2 are blank.