Skip to content

Instantly share code, notes, and snippets.

View msysyamamoto's full-sized avatar
🦀

Masayasu Yamamoto msysyamamoto

🦀
View GitHub Profile
@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
@msysyamamoto
msysyamamoto / insertionsort.hs
Created October 21, 2012 05:00
insertion sort
import Data.List
import Test.QuickCheck
insertionSort :: Ord a => [a] -> [a]
insertionSort = foldr isort []
where
isort x [] = [x]
isort x (y:ys)
| x > y = y : isort x ys
| otherwise = x : y : ys
@msysyamamoto
msysyamamoto / selectionsort.hs
Created October 22, 2012 23:30
selection sort
import Data.List
import Test.QuickCheck
selectionSort :: Ord a => [a] -> [a]
selectionSort [] = []
selectionSort xs = v : (selectionSort (extract i xs))
where
(v, i) = findMin xs
findMin :: Ord a => [a] -> (a, Int)
module JSON where
import Control.Applicative hiding (many, (<|>))
import Numeric
import Text.Parsec
import Text.Parsec.String
-- http://www.ietf.org/rfc/rfc4627.txt
data JValue = JBool Bool
@msysyamamoto
msysyamamoto / fizzbuzz.php
Created November 30, 2012 23:34
剰余を使わないFizzBuzz
<?php
function fizzbuzz($fs, $bs, $i = 1)
{
if ($i <= 100) {
$fs[] = $f = array_shift($fs);
$bs[] = $b = array_shift($bs);
printf('%s', $f . $b) || print $i;
echo PHP_EOL;
fizzbuzz($fs, $bs, $i + 1);
}