Skip to content

Instantly share code, notes, and snippets.

View msysyamamoto's full-sized avatar
🦀

Masayasu Yamamoto msysyamamoto

🦀
View GitHub Profile
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
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
import Control.Applicative ((<$>))
import Data.Char (ord)
main :: IO ()
main = do
ws <- lines' <$> getContents
mapM_ putStrLn $ solve ws
solve :: [String] -> [String]
solve ws = do
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
@msysyamamoto
msysyamamoto / numdot.hs
Last active December 23, 2015 22:59
ナムドット問題。自力では解けなかったので、解説をもとに実装してみた。 https://codeiq.jp/ace/yuki_hiroshi/q468
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
{-# 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)
{-
> halve []
([],[])
> halve [1]
([],[1])
> halve [1,2]
([1],[2])
> halve [1,2,3]
([1],[2,3])
--
-- Neapolitan
--
-- Build:
-- $ ghc -o neapolitan neapolitan.hs
--
-- Usage:
-- $ ./neapolitan < input.txt
--
-- System requirements
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
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]