This file contains hidden or 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
+++++ +++++ initialize counter (cell #0) to 10 | |
[ use loop to set the next four cells to 70/100/30/10 | |
> +++++ ++ add 7 to cell #1 | |
> +++++ +++++ add 10 to cell #2 | |
> +++ add 3 to cell #3 | |
> + add 1 to cell #4 | |
<<<< - decrement counter (cell #0) | |
] | |
> ++ . print 'H' |
This file contains hidden or 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 Control.Applicative | |
import Control.Arrow | |
game = scanl1 (+) . getFrameScores . getFrames | |
where | |
getFrames xs = if length scores == 10 then scores | |
else (take 9 scores) ++ [concat $ drop 9 scores] | |
where | |
scores = parseScores xs | |
parseScores [] = [] |
This file contains hidden or 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
data Fraction = Frac Integer Integer deriving Show -- Numerator Denominator | |
sqrtTwo = (map rep [0..] !!) | |
where | |
rep 0 = Frac 1 2 | |
rep x = (Frac 1 1) |/| ( (Frac 2 1) |+| (sqrtTwo $ pred x)) | |
answer = length . filter moreInDenom . roots | |
where | |
roots = map (\x -> simplify $ Frac 1 1 |+| sqrtTwo x) . enumFromTo 0 |
This file contains hidden or 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 System.Environment | |
f=concat.r | |
r []=[[]] | |
r s=(scanr(:)[]s):(r$init s) | |
g [a,b]=snd.maximum.map(\x->(length x,x))$intersect(f a)(f b) | |
main=getArgs>>= \z-> print.g$z |
This file contains hidden or 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 -- gets us the function "intersect" | |
import System.Environment -- gets us the function "getArgs" | |
f=concat.r -- calls "r" on some input and flattens the results (concat) | |
{- The function "r" takes a list of elements and produces all of it's possible sublists. | |
Base case: If the input list is empty, return an empty list containing a single empty list. -} | |
r []=[[]] -- base case for "r" | |
r s= (scanr(:)[]s) {- recursively build substrings from the list "s" |
This file contains hidden or 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
data Fraction = Frac Integer Integer -- Numerator Denominator | |
instance Show Fraction where | |
show (Frac a b) = (show a) ++ " / " ++ (show b) |
This file contains hidden or 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
num :: Fraction -> Integer | |
num (Frac a _) = a | |
denom :: Fraction -> Integer | |
denom (Frac _ b) = b |
This file contains hidden or 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
simplify :: Fraction -> Fraction | |
simplify (Frac a b) = Frac (a `quot` factor) (b `quot` factor) | |
where factor = gcd a b |
This file contains hidden or 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
instance Num Fraction where | |
(-) f f' = f + (negate f') | |
(+) (Frac a b) (Frac c d) = Frac num denom | |
where denom = lcm b d | |
num = a * (denom `quot` b) + c * (denom `quot` d) | |
(*) (Frac a b) (Frac c d) = Frac (a*c) (b*d) | |
negate (Frac a b) = Frac (-a) b | |
abs f = fmapF abs f | |
where fmapF f (Frac a b) = Frac (f a) (f b) | |
fromInteger x = Frac x 1 |
This file contains hidden or 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
instance Fractional Fraction where | |
(/) f = (*) f . recip | |
recip (Frac a b) = Frac b a | |
fromRational r = Frac (numerator r) (denominator r) |