Skip to content

Instantly share code, notes, and snippets.

View msysyamamoto's full-sized avatar
🦀

Masayasu Yamamoto msysyamamoto

🦀
View GitHub Profile
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
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 (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 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
@msysyamamoto
msysyamamoto / DoukakuOnline.hs
Created August 4, 2012 13:09
LL Decade 君ならどう書く Online
import Numeric
import Data.Char
import Control.Monad
import Control.Applicative hiding (many, (<|>))
import Text.Parsec
import Text.Parsec.String
data LLVal = IPv4 | IPv6 | MAC | Etc
deriving (Show, Eq)
@msysyamamoto
msysyamamoto / check_liveness.php
Created September 13, 2012 14:15
Interval to check liveness.
<?php
$hostname = '192.168.0.100';
$port = 80;
$timeout = 10;
$sock = fsockopen($hostname, $port, $errono, $errstr, $timeout);
if ($sock === false) {
exit("{$errstr} ({$errono})\n");
}
echo "connect {$hostname}:{$port}\n";
@msysyamamoto
msysyamamoto / intelligent.hs
Created October 18, 2012 13:55
会話できる人工知能のプログラム (Haskell)
import System.Random
import System.Time
import Control.Monad.State
main :: IO ()
main = do
seed <- mkSeed
talk $ iSaid seed
mkSeed :: IO Int
@msysyamamoto
msysyamamoto / bubblesort.hs
Created October 21, 2012 04:58
bubble sort
import Data.List
import Test.QuickCheck
bubbleSort :: Ord a => [a] -> [a]
bubbleSort [] = []
bubbleSort [x] = [x]
bubbleSort xs = bubbleSort zs ++ z
where
(zs, z) = splitAt (length xs - 1) $ bubble xs
bubble (y0:y1:ys)
@msysyamamoto
msysyamamoto / combsort.hs
Created October 21, 2012 04:59
comb sort
import Data.List
import Test.QuickCheck
combSort :: Ord a => [a] -> [a]
combSort xs = comb (gap (length xs)) xs
comb :: Ord a => Int -> [a] -> [a]
comb h xs
| h <= 0 = xs
| h == 1 = let sorted = comb' in
@msysyamamoto
msysyamamoto / mergesort.hs
Created October 21, 2012 04:59
merge sort
import Data.List
import Test.QuickCheck
mergeSort :: (Ord a) => [a] -> [a]
mergeSort [] = []
mergeSort [x] = [x]
mergeSort items = merge l' r'
where
(l, r) = halve items
l' = mergeSort l