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
module Main where | |
import Data.Char ( toUpper ) | |
main :: IO () | |
main = print . finalAcc . run . load . map toUpper . filter ('+' /=) =<< readFile "day08.txt" | |
finalAcc :: [VMState] -> Acc | |
finalAcc states = case last states of | |
vm -> _acc vm |
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
module Multiplication4 where | |
import Data.List | |
import Data.Ord | |
multi :: Int -> Int -> [Int] -> Int | |
multi n k as = case sg of | |
1 -> product' xs | |
0 -> 0 | |
_ -> maxprod n k [ss,xs,ys,nxs,pxs,nys,pys] |
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
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE NPlusKPatterns #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE DeriveFunctor #-} | |
module FullBinaryTree where | |
import Control.Arrow ((&&&)) | |
import Control.Comonad.Cofree (Cofree (..)) |
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
{-# LANGUAGE BangPatterns #-} | |
{-# LANGUAGE TupleSections #-} | |
module SLang where | |
import Control.Monad.State | |
import Data.Bool | |
import Data.Maybe | |
-- Abstract Syntax |
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
{-# LANGUAGE TupleSections #-} | |
module Lang where | |
import Control.Arrow | |
import Control.Monad.State | |
import Data.Bool | |
import Data.Either | |
import Data.List | |
import Data.Maybe | |
import Control.Monad.Trans.Iter |
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.Tree | |
data Lab = A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | |
deriving (Eq,Ord,Enum,Bounded,Show,Read) | |
sample :: Tree Lab | |
sample = Node A [Node B [Node C [Node D [] | |
,Node E []] | |
,Node F [Node G [] | |
,Node H []]] |
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
{-# LANGUAGE TupleSections #-} | |
module FizzBuzz where | |
import Data.Bool | |
{- | | |
>>> gFB (fizz.buzz) 1 | |
"1" | |
>>> gFB (fizz.buzz) 3 | |
"Fizz" |
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
module F06 where | |
import Data.Map | |
import Data.Function (fix) | |
import Data.Function.YaMemo (Memo, memo) | |
ordering :: b -> b -> b -> Ordering -> b | |
ordering x _ _ LT = x | |
ordering _ y _ EQ = y | |
ordering _ _ z GT = z |
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
type Score = Int | |
data Grade = A | B | C | D | |
instance Show Grade where | |
show A = "優" | |
show B = "良" | |
show C = "可" | |
show D = "不可" | |
grade :: Score -> Maybe Grade |
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
poly00 :: Maybe a -> Maybe a | |
poly00 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just x -> Nothing | |
poly01 :: Maybe a -> Maybe a | |
poly01 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just !x -> Nothing |