Created
February 11, 2021 15:21
-
-
Save DarkWiiPlayer/f01e6ff1d5b60f153aca00b8e72e4a5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local fun = require 'fun' () | |
local function avg(...) | |
local sum, count = 0, 0 | |
for i=1,select('#', ...) do | |
count = count + 1 | |
sum = sum + select(i, ...) | |
end | |
return sum / count | |
end | |
function dice(sides, number) | |
if number > 0 then | |
return math.random(sides), dice(sides, number-1) | |
end | |
end | |
duplicate(20, 20) -- An iterator that yields two values | |
:take(10) | |
:map(dice) -- calls dice(20, 20), returning 20 integers | |
:map(avg) -- averages all 20 integers | |
:each(print) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment