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.Bits | |
import Data.List | |
binStr :: Bits a => a -> String | |
binStr n = foldl' f "" $ take (bitSize n) [0..] | |
where | |
f str i | |
| testBit n i = '1' : str | |
| otherwise = '0' : str |
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 Control.Applicative ((<$>)) | |
import Data.List (intersperse, sort, sortBy) | |
import Text.Parsec (char, digit, letter, many1, parse) | |
--| 日付はIntとして持つ | |
-- 1と10の位が日, 100と1000の位が月に相当する | |
-- e.g., 1月 5日 -> 105 | |
-- 12月30日 -> 1230 | |
data Ticket = Ticket { tName :: String | |
, tFrom :: 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 Control.Applicative ((<$>)) | |
import Data.Char (ord) | |
main :: IO () | |
main = do | |
ws <- lines' <$> getContents | |
mapM_ putStrLn $ solve ws | |
solve :: [String] -> [String] | |
solve ws = do |
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 Control.Applicative ((<$>)) | |
import Data.List (nub, delete, subsequences, group, sort) | |
import System.Environment (getArgs) | |
import Test.HUnit | |
type Gem = Char | |
main :: IO () | |
main = do | |
princessPath <- (!! 0) <$> getArgs |
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 Control.Applicative ((<$>)) | |
import Data.List (intercalate) | |
import System.Environment (getArgs) | |
main :: IO () | |
main = do | |
n <- read . (!! 0) <$> getArgs | |
let (h, ts) = splitAt 1 . map show $ take n [1..] | |
decode = foldl (\acc x -> injects x acc) [h] ts | |
mapM_ (putStrLn . intercalate ".") decode |
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 OverloadedStrings #-} | |
import Control.Applicative ((<$>)) | |
import Data.ByteString (ByteString) | |
import Data.ByteString.Char8 (readFile, readInt, split) | |
import Data.Vector.Unboxed.Mutable (null, read, splitAt, length, new, write, IOVector) | |
import qualified Data.Vector.Unboxed as VU | |
import System.Environment (getArgs) | |
import System.Posix.Time (epochTime) |
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
{- | |
> halve [] | |
([],[]) | |
> halve [1] | |
([],[1]) | |
> halve [1,2] | |
([1],[2]) | |
> halve [1,2,3] | |
([1],[2,3]) |
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
-- | |
-- Neapolitan | |
-- | |
-- Build: | |
-- $ ghc -o neapolitan neapolitan.hs | |
-- | |
-- Usage: | |
-- $ ./neapolitan < input.txt | |
-- | |
-- System requirements |
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 Control.Applicative((<$>)) | |
import Data.List (intersperse, foldl') | |
import qualified Data.Map as M | |
import Network.HTTP (getResponseBody, simpleHTTP, getRequest) | |
import System.Posix.Unistd (nanosleep) | |
type Id = String | |
data Star = Star { cost :: Int, stars :: [Id], routes :: [Id] } deriving (Show, Eq) | |
type Galaxy = M.Map Id Star |
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 Control.Applicative ((<$>)) | |
import Data.List (sort, intersect, foldl', nub) | |
import qualified Data.Map as M | |
type Id = Int | |
type IdList = [Id] | |
type Name = String | |
type Tmpids = M.Map Name [[Id]] | |
type Workids = M.Map [Id] [Name] |