Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello, world!\n");
return 0;
}
#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'
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"
@314maro
314maro / iterateN.hs
Created August 22, 2013 15:55
フィボナッチ数列を一般化したみたいなもの作れます
{-# 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
@314maro
314maro / fib.hs
Last active December 21, 2015 12:59
よくよく考えればこれだけでよかったんだ 無駄なことした気がするぜ ただ、sumを置き換えれるように引数取るようにするとエラー なんでだろ と思ってたら、再帰の部分をfoo xsと書いてたからだった あるある
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
@314maro
314maro / Lsystem.hs
Last active December 23, 2015 02:48
L-system 手抜きなので気が向けば直したい
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
@314maro
314maro / type_L_system.hs
Created September 26, 2013 15:48
型レベルでのL-systemのようなもの
{-# 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]
@314maro
314maro / a.hs
Created November 25, 2013 15:43
抽象
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
{-# 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" ++)
@314maro
314maro / janken.c
Created January 23, 2014 11:51
クソコードかきました
#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) {