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
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
printf("Hello, world!\n"); | |
return 0; | |
} |
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 <Foundation/Foundation.h> | |
int intFromChar(char aChar, int notation) { | |
// error | |
if (!isalnum(aChar)) | |
return INT_MAX; | |
int result = 0; | |
if (isdigit(aChar)) // '0'-'9' |
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.Char | |
import Foreign.C.String | |
foreign import ccall "unistd.h crypt" c_crypt :: CString -> CString -> CString | |
trip ('#':str) = crypt str salt >>= return . ('◆':) . reverse . take 10 . reverse | |
where | |
substr x y = take y . drop x | |
salt0 = substr 1 2 $ str ++ "H." | |
salt1 = map (\x -> if ord x < ord '.' || ord x > ord 'z' then '.' else x) salt0 | |
table = zip ":;<=>?@[\\]^_`" "ABCDEFGabcdef" |
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 GADTs, TypeFamilies, ScopedTypeVariables, FlexibleInstances, FlexibleContexts #-} | |
import Data.List (tails) | |
-- 関数の名前わかりづらいのは見逃して | |
hoge :: (FromList (ListN (S a)), Num x) => ListN (S a) x -> [x] | |
hoge = iterateN sumN | |
fib = hoge $ 0 ::: 1 ::: N | |
lucas = hoge $ 2 ::: 1 ::: N | |
tri = hoge $ 0 ::: 0 ::: 1 ::: N |
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.List (transpose,tails) | |
hoge = foo sum | |
fib = hoge [0,1] | |
lucas = hoge [2,1] | |
tri = hoge [0,0,1] | |
tetra = hoge [0,0,0,1] | |
foo f xs = xs ++ map f a | |
where a = transpose $ take (length xs) $ tails $ foo f xs |
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.Maybe (fromMaybe) | |
data Turtle = Turtle { turtleX :: Double | |
, turtleY :: Double | |
, turtleD :: Double | |
, turtleLine :: [(Double,Double,Double,Double)] | |
} deriving Show | |
moveTurtle a c t | |
| c == '+' = turn a t |
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 DataKinds, UndecidableInstances, FlexibleInstances #-} | |
{-# LANGUAGE TypeFamilies, TypeOperators, ScopedTypeVariables #-} | |
{-# LANGUAGE PolyKinds #-} | |
data V = A | B deriving Show | |
type Omega = '[A] | |
type family P (v :: V) :: [V] | |
type instance P A = '[B] |
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
infixl 5 :* | |
data C = S | K | I | V Char | C :* C | |
elemC c (x :* y) = elemC c x || elemC c y | |
elemC c (V c') = c == c' | |
elemC _ _ = False | |
s (v, V c) | |
| v == c = I | |
| v /= c = K :* V c |
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 FlexibleInstances #-} | |
import Control.Arrow | |
data Atom = S | K | I | V Char deriving Eq | |
infixl 5 :$ | |
data Tree a = Leaf a | Tree a :$ Tree a | |
instance Show (Tree Atom) where | |
showsPrec _ (Leaf S) = ("S" ++) | |
showsPrec _ (Leaf K) = ("K" ++) |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int main(void) { | |
srand(time(NULL)); | |
for (;;) { | |
int c = getchar(); | |
int enemy = rand()%3, player; | |
switch (c) { |
OlderNewer