Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Fractran/Haskell/fractran-1.hs
Normal file
8
Task/Fractran/Haskell/fractran-1.hs
Normal 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)
|
||||
1
Task/Fractran/Haskell/fractran-2.hs
Normal file
1
Task/Fractran/Haskell/fractran-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
import Data.List.Split (splitOn)
|
||||
3
Task/Fractran/Haskell/fractran-3.hs
Normal file
3
Task/Fractran/Haskell/fractran-3.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
readProgram :: String -> [Ratio Int]
|
||||
readProgram = map (toFrac . splitOn "/") . splitOn ","
|
||||
where toFrac [n,d] = read n % read d
|
||||
2
Task/Fractran/Haskell/fractran-4.hs
Normal file
2
Task/Fractran/Haskell/fractran-4.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import Data.Maybe (mapMaybe)
|
||||
import Data.List (elemIndex)
|
||||
20
Task/Fractran/Haskell/fractran-5.hs
Normal file
20
Task/Fractran/Haskell/fractran-5.hs
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue