- 三上遼
- 0x20歳
- IoTの会社でスマートロック作ってます
- 数学弱いです
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 Num | |
def initialize(v) | |
@v = v | |
end | |
def combine(target) | |
target | |
end | |
end |
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
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 |
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
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} |
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
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 |
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
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) |
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 Data.Char | |
euler16 = sum . (map digitToInt) . show | |
main = print $ euler16 (2 ^ 1000) |
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
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 |
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
(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))))))))) |
NewerOlder