This file contains hidden or 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<math.h> | |
#include<stdio.h> | |
#include<stdlib.h> | |
int prime_bound(int n) | |
{ | |
return n / log(n) + (n / log(n) / log(n)); | |
} | |
int powmod(int b, int e, int m) |
This file contains hidden or 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 qualified Data.Map as Map | |
import qualified Data.Set as Set | |
import Data.List (partition) | |
import Control.Arrow (first, second) | |
import Control.Applicative | |
infixr 9 :-> | |
infixl 8 >$ | |
type Name = String | |
data Type = Var Name | Type :-> Type | Rigid Name | Any deriving (Show, Eq, Ord, Read) |
This file contains hidden or 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
class MemoizedIterator: | |
def __init__(self, iterable): | |
self.iterator = iterable | |
self.elements = [] | |
def __iter__(self): | |
for i in self.elements: | |
yield i | |
for i in self.iterator: | |
self.elements.append(i) | |
yield i |
This file contains hidden or 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
{ | |
https://twitter.com/its_out_of_tune/status/221500817616805890 (´・ω・`)すんません。広義の意味で「オブジェクト」と言ったでつ。関数はファーストクラスオブジェクトでしょうか? | |
https://twitter.com/kuina_tesso/status/221503452851871744 @its_out_of_tune ほぼ、そうであるといえますね。 | |
ならば、これが動くはずだ。 | |
} | |
func fix(f) | |
{the simplest implementation of fixed point combinator} | |
func g(arg) | |
return f(fix(f))(arg) {戻り値の返し方が不明} |
This file contains hidden or 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
-- $は右結合、$$は左結合 | |
main = proc -- proc [args]…argsを引数に取るブロックを表す | |
oddprimes <- [] -- ミュータブルな変数への代入 | |
for [3,5..] proc n | |
it := forelse(takeWhile ((<n) . (**2)) oddprimes) -- :=は式に別名をつける | |
$$ proc m (if n % m == 0 then break it) | |
$$ proc (oddprimes <- append oddprimes n) | |
for (2 : oddprimes) proc n | |
print n -- 遅延評価のため、oddprimesに値が追加されるとすぐに出力する |
This file contains hidden or 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 Control.Monad.Trans.Loop | |
import Control.Applicative | |
import Control.Monad.Base | |
import System.Time | |
import System.Posix.Unistd | |
fizzbuzz n = case (mod n 3, mod n 5) of | |
(0, 0) -> "FizzBuzz" | |
(_, 0) -> "Fizz" | |
(0, _) -> "Buzz" |
This file contains hidden or 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
from Prelude import cons | |
from Prelude import pattern | |
fact = pattern.build(("0", lambda: 1), | |
("n", lambda n: n * fact(n - 1))) | |
map_ = pattern.build(("_ []", lambda: []), | |
("f (x:xs)", lambda f x xs: cons(f(x), map_(f, xs)))) |
This file contains hidden or 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
公理X: ((a -> b -> a) -> ((c -> d -> e) -> (c -> d) -> c -> e) -> (f -> g -> f) -> h) -> hとおく。 | |
定理P: α -> β -> γ -> β | |
a' -> b' -> a' : (a -> b -> a) -> ((c -> d -> e) -> (c -> d) -> c -> e) -> (f -> g -> f) -> h | |
a' : a -> b -> a | |
b' : (c -> d -> e) -> (c -> d) -> c -> e | |
a' : (f -> g -> f) -> h | |
→ b' -> a' | |
→ b' -> a -> b -> a | |
→ α -> β -> γ -> β |
This file contains hidden or 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
`k``````s``s`k`s`k``sii``s``s`ks``s`k`s`ks``s`k`s`kk``s``s`ks``s`k`s`ks``s`k`s`k | |
`s`ks``s`k`s`k`s`k`s`ks``s`k`s`k`s`k`s`k`s`ks``s`k`s`k`s`k`s``s`k``s`ksk``s`k``s | |
`ksk``si`k``s`k`sik``s`k`s`k`s`k`s`k`s`k`s`kk``s``s`ks``s`k`s`ks``s`k`s`k`s`ks`` | |
s`k`s`k`s`k`s`ks``s`k`s`k`s`k`s`k`s`ks``s``s`ks``s`k`s`ks``s`k`s`k`s`ks``s`k`s`k | |
`s`k`s`ks``s`k`s`k`s`k`s`k`s`ks``s``s`ks``s`k`s`ks``s`k`s`k`s`ks``s`k`s`k`s`k`s` | |
ks``s`k`s`k`s`k`s`k`s`k``s`ksk``s``s`k``s`ksk``s`ks``s`k`s`ks``s`k`s`k`s`k``s`ks | |
k``s``s`k``s`ksk``s`ks``s``s`k``s`ksk``s`ks``s`k`s`ks``s`k`s`k`s`ks``s`k`s`k`s`k | |
`s`k``s`ksk``s`k`s`k`s`k`s`k``s`ksk``s`k`s`k`s``s`ks``ss`k`k`ki``s`k`s`k``s`kkk` | |
`s``s`k``s`ksk``s`k`s```s``si`k``s``s`ksk``s``s`ksk``s`k```sii``s``s`kski``s``s` | |
ksk```s``siii``s``s`kski`k``s``si`k``s``s`ksk``s`k```sii``s``s`kski``s``s`ksk``` |
This file contains hidden or 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
showInteger n str = divmod10 n \d r -> (ifnonzero d (showInteger d) id) ((:) ((+) 48 r) str); | |
divmod10 n = n (\f a b -> ifgt 9 b (f a (succ b)) (f (succ a) 0) ) (:) 0 0; | |
fizzbuzz n a b = ifgt n 100 endofoutput | |
((\s p q a' b' -> if (and p q) | |
((++) "FizzBuzz\n" (s 0 0)) | |
(if p ((++) "Fizz\n" (s 0 b')) | |
(if q ((++) "Buzz\n" (s a' 0)) | |
(showInteger n (cons '\n' (s a' b')))))) | |
(fizzbuzz (succ n)) ((==) 2 a) ((==) 4 b) (succ a) (succ b)); |