Skip to content

Instantly share code, notes, and snippets.

始代数とcatamorphism


自己紹介

  • 三上遼
  • 0x20歳
  • IoTの会社でスマートロック作ってます
  • 数学弱いです
@mikamix
mikamix / fizzbuzz.rb
Last active September 15, 2015 15:49
class Num
def initialize(v)
@v = v
end
def combine(target)
target
end
end
module Monad where
import Prelude hiding (fmap, Functor, Monad)
class Functor f where
fmap :: (a -> b) -> f a -> f b
class Functor m => Applicative m where
declare
fun {Fact N}
if N == 0 then 1 else N * {Fact N - 1} end
end
declare
fun {AddList L1 L2}
case L1 of H1 | T1 then
case L2 of H2 | T2 then
H1 + H2 | {AddList T1 T2}
module Main
data FizzBuzz : (n: Nat) -> Type where
Zero : FizzBuzz n
Fizz : FizzBuzz n
Buzz : FizzBuzz n
Woof : FizzBuzz n
Comb : FizzBuzz n -> FizzBuzz n -> FizzBuzz n
instance Semigroup (FizzBuzz n) where
def pascal1(c: Int, r: Int): Int = {
if (c == 0 || c == r) 1
else pascal1(c - 1, r - 1) + pascal1(c, r - 1)
}
def pascal2(c: Int, r: Int): Int = {
@tailrec
def pascal(n: Int, prev: List[Int]): Int = {
val row = (0 :: prev).zipAll(prev, 0, 0).map(t => t._1 + t._2)

!SLIDE

YCombinator

!SLIDE

YCombinatorとは何か

!SLIDE

ベンチャーキャピタル

YコンビネータLLC(Y Combinator LLC)は、カリフォルニア州マウンテンビューのベンチャーキャピタルである。

import Data.Char
euler16 = sum . (map digitToInt) . show
main = print $ euler16 (2 ^ 1000)
combination n r = factorial n `div` (factorial (n - r) * factorial r)
where factorial 1 = 1
factorial n = n * factorial (n - 1)
main = print $ combination 40 20
(define (union-set set1 set2)
(cond ((null? set1) set2)
((null? set2) set1)
(else (let ((x1 (car set1)) (x2 (car set2)))
(cond ((< x1 x2) (cons x1 (union-set (cdr set1) set2)))
((> x1 x2) (cons x2 (union-set set1 (cdr set2))))
(else (cons x1 (union-set (cdr set1) (cdr set2)))))))))