Skip to content

Instantly share code, notes, and snippets.

@nobsun
nobsun / Main.hs
Created June 2, 2021 01:36
Advent of Code 2020 day08
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
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]
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NPlusKPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveFunctor #-}
module FullBinaryTree where
import Control.Arrow ((&&&))
import Control.Comonad.Cofree (Cofree (..))
@nobsun
nobsun / SLang.hs
Last active November 3, 2018 12:32
Eagerな(おもちゃ)言語
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module SLang where
import Control.Monad.State
import Data.Bool
import Data.Maybe
-- Abstract Syntax
@nobsun
nobsun / Lang.hs
Last active November 7, 2018 12:59
Lazyな(おもちゃ)言語
{-# 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
@nobsun
nobsun / file0.txt
Last active January 21, 2018 08:30
Tree: 親子関係の付け替え ref: https://qiita.com/nobsun/items/27fe53516cbb90ba02e2
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 []]]
@nobsun
nobsun / FizzBuzz.hs
Last active September 26, 2017 21:00
「FizzBuzzクイズ」クイズ - Haskell版? ref: http://qiita.com/nobsun/items/285f208a17285953f2ab
{-# LANGUAGE TupleSections #-}
module FizzBuzz where
import Data.Bool
{- |
>>> gFB (fizz.buzz) 1
"1"
>>> gFB (fizz.buzz) 3
"Fizz"
@nobsun
nobsun / F06.hs
Last active September 21, 2017 11:48
「ツリーの中の数」の問題 ref: http://qiita.com/nobsun/items/495b0cc478521dd6b60a
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
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
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