Skip to content

Instantly share code, notes, and snippets.

@nobsun
nobsun / F03.hs
Created March 23, 2017 01:12
「トリオミノの分類」問題 ref: http://qiita.com/nobsun/items/2b9b15bcaa50b32e4fbb
module F03 where
import Data.Ix (range)
import Data.List (sort)
import Data.Maybe (mapMaybe)
import Data.Tuple (swap)
type Index = (Int,Int)
type Omino = [Index]
type Moves = [Index]
@nobsun
nobsun / E13.hs
Created April 23, 2017 12:11
「六角形のテトロミノ」問題 ref: http://qiita.com/nobsun/items/4099ee005e300b3dbb0c
module E13 where
import Data.List
import Data.Maybe
type CubeCoord = (Int, Int, Int)
cubecoord :: Char -> Maybe CubeCoord
cubecoord 'a' = Just (0,0,0)
cubecoord 'b' = Just (1,-1,0)
@nobsun
nobsun / F04.hs
Created April 23, 2017 12:19
「正八角形の分割」問題 ref: http://qiita.com/nobsun/items/2c227bab1156eddeb3df
module F04 where
import Data.Bool (bool)
import Data.List (sort,unfoldr)
import Text.Printf (printf)
readDiag :: String -> Word
readDiag = read
toBin :: Word -> String
@nobsun
nobsun / lazyIO.hs
Created May 22, 2017 07:27
lazy IO と imperative programming とが相性がわるい例
module Main where
import System.IO.Unsafe
lazy :: IO a -> IO a
lazy = unsafeInterleaveIO
main :: IO ()
main = do
{ input1 <- getLine
@nobsun
nobsun / F05.hs
Last active May 25, 2017 10:10
「ブロックを回す」問題 ref: http://qiita.com/nobsun/items/a48a372dcb1b95199e84
module F05 where
import Control.Arrow (first, (&&&))
import Data.Bool
import Data.List (sortBy,transpose,intercalate,isPrefixOf)
import Data.List.Split (splitOn)
import Data.Ord (comparing)
import Data.Tuple (swap)
rot :: ([String] -> [String], [String] -> [String]) -> [String] -> [String]
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
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
@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
@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 / 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 []]]