Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,12 @@
main :: IO ()
main =
mapM_ print $
[2, 4, 6] >>=
\x ->
[1 .. 7] >>=
\y ->
[12 - (x + y)] >>=
\z ->
case y /= z && 1 <= z && z <= 7 of
True -> [(x, y, z)]
_ -> []

View file

@ -0,0 +1,9 @@
main :: IO ()
main =
mapM_
print
[ (x, y, z)
| x <- [2, 4, 6]
, y <- [1 .. 7]
, z <- [12 - (x + y)]
, y /= z && 1 <= z && z <= 7 ]

View file

@ -0,0 +1,9 @@
main :: IO ()
main =
mapM_ print $
do x <- [2, 4, 6]
y <- [1 .. 7]
z <- [12 - (x + y)]
if y /= z && 1 <= z && z <= 7
then [(x, y, z)]
else []

View file

@ -0,0 +1,14 @@
import Data.List (nub)
main :: IO ()
main =
let xs = [1 .. 7]
in mapM_ print $
xs >>=
\x ->
xs >>=
\y ->
xs >>=
\z ->
[ (x, y, z)
| even x && 3 == length (nub [x, y, z]) && 12 == sum [x, y, z] ]

View file

@ -0,0 +1,28 @@
-------------------- DEPARTMENT NUMBERS ------------------
options :: Int -> Int -> Int -> [(Int, Int, Int)]
options lo hi total =
( \ds ->
filter even ds
>>= \x ->
filter (/= x) ds
>>= \y ->
[total - (x + y)]
>>= \z ->
[ (x, y, z)
| y /= z && lo <= z && z <= hi
]
)
[lo .. hi]
--------------------------- TEST -------------------------
main :: IO ()
main =
let xs = options 1 7 12
in putStrLn "(Police, Sanitation, Fire)\n"
>> mapM_ print xs
>> mapM_
putStrLn
[ "\nNumber of options: ",
show (length xs)
]

View file

@ -0,0 +1,8 @@
options :: Int -> Int -> Int -> [(Int, Int, Int)]
options lo hi total =
let ds = [lo .. hi]
in [ (x, y, z)
| x <- filter even ds
, y <- filter (/= x) ds
, let z = total - (x + y)
, y /= z && lo <= z && z <= hi ]

View file

@ -0,0 +1,10 @@
import Control.Monad (guard)
options :: Int -> Int -> Int -> [(Int, Int, Int)]
options lo hi total =
let ds = [lo .. hi]
in do x <- filter even ds
y <- filter (/= x) ds
let z = total - (x + y)
guard $ y /= z && lo <= z && z <= hi
return (x, y, z)