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,8 @@
import Data.List (find)
import Data.Ratio (Ratio, (%), denominator)
fractran :: (Integral a) => [Ratio a] -> a -> [a]
fractran fracts n = n :
case find (\f -> n `mod` denominator f == 0) fracts of
Nothing -> []
Just f -> fractran fracts $ truncate (fromIntegral n * f)

View file

@ -0,0 +1 @@
import Data.List.Split (splitOn)

View file

@ -0,0 +1,3 @@
readProgram :: String -> [Ratio Int]
readProgram = map (toFrac . splitOn "/") . splitOn ","
where toFrac [n,d] = read n % read d

View file

@ -0,0 +1,2 @@
import Data.Maybe (mapMaybe)
import Data.List (elemIndex)

View file

@ -0,0 +1,20 @@
primes :: [Int]
primes = mapMaybe log2 $ fractran prog 2
where
prog =
[ 17 % 91
, 78 % 85
, 19 % 51
, 23 % 38
, 29 % 33
, 77 % 29
, 95 % 23
, 77 % 19
, 1 % 17
, 11 % 13
, 13 % 11
, 15 % 14
, 15 % 2
, 55 % 1
]
log2 = fmap succ . elemIndex 2 . takeWhile even . iterate (`div` 2)