Skip to content

Instantly share code, notes, and snippets.

@1995hnagamin
1995hnagamin / 証明
Last active August 29, 2015 14:05
対角線論法で自然数の濃度が実数の濃度と等しいことを示せるか?
任意の自然数aに対し、ある自然数bが存在してa < 2^b となることを示す。
このようなbが存在しないと仮定すると、任意のbに対して a ≧ 2^b
したがって、集合A = {2^b | b ∈ N} を考えると、この集合は上に有界であるので、上限u = sup Aが存在する。
いま、u' = u / 2 とおく。
uは明らかに正である(0 < 2 ∈ A)ので、u' < u
したがって、u' = u / 2 < 2^b' をみたすb' ∈ Aが存在する。
これより 2^(b + 1) > u
2^(b + 1) はAの要素なので、sup Aより大きいAの要素が存在することになるが、これは矛盾。
ゆえに任意の自然数aに対し、ある自然数bが存在してa < 2^b. (ア)
@1995hnagamin
1995hnagamin / 2251.cc
Last active August 29, 2015 14:05
2014/08/15の進捗
void init() {
REP(i, VMAX) {
G[i].clear();
}
REP(i, LMAX) {
ptime[i] = req[i] = 0;
}
REP(i, NMAX) {
REP(j, NMAX) {
dist[i][j] = (i == j ? 0 : INF);
@1995hnagamin
1995hnagamin / macro.js
Created September 1, 2014 15:03
Sweet.js上でマクロを定義する動かないマクロ
macro fun {
rule {
$name($param (,) ...) {
$body ...
}
} => {
macro $name {
rule { ($param (,) ...) } => {
$body ...
}
@1995hnagamin
1995hnagamin / RPMCalc.hs
Created September 13, 2014 04:39
すごいH本で取り上げられていた逆ポーランド記法電卓で遊んだ
import Data.List
import Control.Monad
import System.IO
type Result = Either String
readMaybe :: (Read a) => String -> Result a
readMaybe st = case reads st of [(x,"")] -> Right x
_ -> Left ("Parse Error: \"" ++ st ++ "\"")
@1995hnagamin
1995hnagamin / hs-do.scm
Last active August 29, 2015 14:06
すごいH本の13章をSchemeで
(define nothing '())
(define (just x) (list x))
(define (value maybe) (car maybe))
(define nothing? null?)
(define return just)
(define (>> m1 m2)
(>>= m1 (lambda (_) m2)))
@1995hnagamin
1995hnagamin / partial_application.scm
Created September 13, 2014 10:06
部分適用(実装中)
(define plus2
(lambda (a . b)
(if (null? b)
(lambda (b) (+ a b))
(apply (plus2 a) b))))
(define (plus3 a . bc)
(if (null? bc)
(lambda (b . c)
(if (null? c)
@1995hnagamin
1995hnagamin / sos.scm
Created September 18, 2014 13:39
Scheme Object System
(define (Maybe . m)
`(((nothing? . ,(lambda () (null? m)))
(value . ,(lambda () (if (null? m)
(error "Nothing has no value")
(car m))))
(show . ,(lambda () (if (null? m)
'Nothing
`(Just ,(car m))))))))
(define (Just x) (Maybe x))
@1995hnagamin
1995hnagamin / brainfuck.hs
Last active August 29, 2015 14:06
HaskellによるBrainfuck実装
import Data.Char
import Control.Applicative
import Data.Maybe
data BFChar = Lt | Gt | Plus | Minus | Dot | Comma | LPar | RPar
deriving (Eq, Show)
type BFCode = [BFChar]
type State = ([Int], Int)
operateAt :: Int -> (a -> a) -> [a] -> [a]
@1995hnagamin
1995hnagamin / stream.scm
Created September 20, 2014 11:03
SICP 3.5 ストリーム
(define (1+ n)
(+ 1 n))
(define (1- n)
(- n 1))
(define (bfind/l pred lower upper)
(letrec ((M (lambda (low high)
(if (even? (- high low))
(/ (+ high low) 2)
@1995hnagamin
1995hnagamin / a.cc
Last active August 29, 2015 14:06
CODE FESTIVAL 2014 予選A
#include<iostream>
#include<string>
using namespace std;
int main() {
string str;
cin >> str;
cout << str + "2014" << endl;
}