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
import System.Environment (getArgs) | |
import System.IO (IOMode(..),withFile,hGetContents) | |
import qualified Data.Fixed as FP | |
import NonIntegral | |
data E34 | |
instance FP.HasResolution E34 where | |
resolution _ = 10^(34::Int) |
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
import qualified Data.Fixed as FP | |
import Test.QuickCheck | |
data E34 | |
instance FP.HasResolution E34 where | |
resolution _ = 10^34 | |
type FixedPoint = FP.Fixed E34 |
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
-- [Sheldon's (Conjecture) Theorem](https://www.math.dartmouth.edu/~carlp/sheldonresub011119.pdf) | |
import Test.QuickCheck | |
import Data.Tuple | |
import Data.List | |
unDigits base = foldl (\a b -> a * base + b) 0 | |
digitsRev base = unfoldr step | |
where | |
step 0 = Nothing |
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
import Data.List | |
import qualified Data.List.Key as K | |
import Data.Map ((!), fromList, fromListWith, adjust, keys, Map) | |
import Data.Monoid.Inf (Inf(..),Pos,posInfty) -- cabal install monoid-extras | |
type T = Inf Pos Integer | |
type G a = Map a [(a,T)] | |
buildGraph :: Ord a => [(a,a,T)] -> G a | |
buildGraph g = fromListWith (++) (g >>= f) where |
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
import RegExp | |
import Data.List | |
-- Kanji numerals | |
oneOf = foldr (:|) Phi . map Single | |
kanji = o (u :. Single 'T') | |
:. o (a :. Single 'M') | |
:. o (a :. Single 'C') |
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
import Data.List | |
-- https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Figure-Figure_sequences | |
-- Hofstadter Figure-Figure sequences [R](https://oeis.org/A005228) and [S](https://oeis.org/A030124) | |
-- R(0) = 1; S(0) = 2; {S(n)} = increasing series of positive integers not present in {R(n)} | |
-- R(n+1) = R(n) + S(n) | |
r = 1:zipWith (+) r s | |
s = 2:4:drop 2 (concat $ zipWith ss r (tail r)) where ss x y = [x+1..y-1] | |
main = print (take 22 r) -- [1,3,7,12,18,26,35,45,56,69,83,98,114,131,150,170,191,213,236,260,285,312] |