Let’s pick lottery numbers. That is to pick 6 numbers from 1 to 45. The Lotto (korean lottery)
>>> range(1, 46) | choice(size=6) | sort
[2, 8, 22, 24, 37, 39]
# This is one game. People usually buy five games at once.
>>> [ range(1, 46) | choice(size=6) | sort for _ in range(5) ]
[[4, 6, 11, 38, 41, 45],
[5, 8, 23, 25, 26, 40],
[13, 18, 23, 25, 37, 44],
[17, 21, 24, 32, 41, 43],
[5, 9, 13, 25, 30, 38]]
# Or equivalently,
# Feel Unix pipelines
>>> replicate(5, range(1, 46)) | map(choice(size=6)) | map(sort) | unpack
# Feel Haskell-like mathematical symbol
>>> (unpack . map(sort . fx(choice(size=6))))(replicate(5, range(1, 46)))
I recently wrote a post with foc
on r/haskell
, and I got some good ideas from there. If you’re interested, take a look. Any opinions are welcome.
You must log in or register to comment.