Skip to content

Instantly share code, notes, and snippets.

@jiamo
jiamo / adventofcode_2021_day8.py
Last active December 10, 2021 01:40
adventofcode-2021-day8
import os
"""
0: 1: 2: 3: 4:
aaaa .... aaaa aaaa ....
b c . c . c . c b c
b c . c . c . c b c
.... .... dddd dddd dddd
e f . f e . . f . f
@jiamo
jiamo / SimpleEval.hs
Created January 30, 2021 13:39
Try to make a same type definition for mutually eval add expr
module SimpleEval where
import Prelude hiding (odd, even)
import Data.Dynamic
data Expr = Val Int | Add Expr Expr
data Cont = HALT | EVAL Expr Cont | ADD Int Cont
eval :: Expr -> Int
#lang lazy
(define g
(lambda (f)
(lambda (n)
(if (= n 0)
1
(* n (f (- n 1)))))))
(define f
@jiamo
jiamo / lazy-ycombinator.rkt
Created October 21, 2019 10:24
ycombinator from fix point of function
#lang lazy
(define g
(lambda (f)
(lambda (n)
(if (= n 0)
1
(* n (f (- n 1)))))))
(define f
@jiamo
jiamo / can.agda
Last active September 12, 2019 10:17
plfa exercise in relation.
module Can where
import Relation.Binary.PropositionalEquality as Eq
import Data.Nat.Properties as Pro
open Pro using (+-assoc; +-identityʳ; +-suc; +-comm)
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _^_)
@jiamo
jiamo / Ycombinator4.rkt
Created January 8, 2019 14:18
Ycombinator4.rkt
#lang racket
;;(define Y
;; (lambda (f)
;; ((lambda (x) (f (x x))) (lambda (x) (f (x x)))) ))
;;(define almost-Y
;; (lambda (f)
;; ((lambda (x) (f (x x))) (lambda (x) (f (x x)))) ))
@jiamo
jiamo / Ycombinator3.rkt
Created September 20, 2018 12:28
Ycombinator3
#lang racket
(define identity (lambda (x) x))
(define (part-factorial0 self n)
(if (= n 0)
1
(* n (self self (- n 1))))) ;; note the extra "self" here the same as below
(part-factorial0 part-factorial0 5)
@jiamo
jiamo / Ycombinator2.rkt
Created September 20, 2018 10:54
Ycombinator2
#lang racket
;(Y f) = fixpoint-of-f
;(f fixpoint-of-f) = fixpoint-of-f
;(Y f) = fixpoint-of-f = (f fixpoint-of-f)
;(Y f) = (f (Y f))
(define (Y f) (f (Y f)))
(define Y-lambda
@jiamo
jiamo / Ycombinator1.rkt
Last active September 20, 2018 10:43
Ycombinator1
#lang racket
(define (factorial n)
(if (= n 0)
1
(* n (factorial (- n 1)))))
(define factorial_lambda
(lambda (n)
@jiamo
jiamo / Cartesian_product3.hs
Last active May 29, 2018 01:58
Cartesian_product3.hs
{-# LANGUAGE RebindableSyntax #-}
module Cartesian_product3 where
import Prelude hiding((>>=), return, Monad, fail)
-- begin help -----
class Applicative m => Monad m where
return :: a -> m a