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
-- L = {0^n 1^n | n \in N} | |
match :: String -> Bool | |
match s = case trace s of | |
Just [] -> True | |
_ -> False | |
where trace :: String -> Maybe String | |
trace ('0':xs) = do | |
remainString <- trace xs | |
(case remainString of |
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
-- The CPS-transformed version of match. | |
-- https://gist.github.com/suhorng/5204442 | |
match' :: String -> Bool | |
match' s = trace s null | |
where trace :: String -> (String -> Bool) -> Bool | |
trace ('0':xs) k = trace xs $ \remainString -> | |
case remainString of | |
'1':xs' -> k xs' | |
_ -> False |
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
-- Defunctionalizing match' -- we obtain a 2-state push-down automaton! | |
-- 1) https://gist.github.com/suhorng/5204442 | |
-- 2) https://gist.github.com/suhorng/5204636 | |
data Cont = Cont0 | |
| Cont1 Cont | |
match'' :: String -> Bool | |
match'' s = trace s Cont0 | |
where trace :: String -> Cont -> Bool |
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
{- | |
The original evaluator to be transformed. | |
See A Functional Correspondence between Evaluators and Abstract Machines, by O. Danvy | |
www.brics.dk/RS/03/13/BRICS-RS-03-13.pdf | |
-} | |
data Value = Var String | |
| Lambda String Expr | |
data Expr = Val Value | |
| Ap Expr Expr |
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
{- | |
The abstract machine obtained by transforming | |
the original direct evaluator. | |
Previous codes: https://gist.github.com/suhorng/5355222 | |
-} | |
data Value = Var String | |
| Lambda String Code |
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 <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
char l_exist[10000], r_exist[10000]; | |
int n, m, val[10000], seq[10000]; | |
int main() { | |
int i, j, k, diff, ans = 0; | |
scanf("%d", &n); |
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 pygame | |
import sys # exit | |
import random # randint | |
from collections import deque | |
def new_food(snake, surface): | |
newfood = (random.randint(0, 80)*10, random.randint(0, 60)*10) | |
# the food shouldn't appear inside the body of the snake or at where we show the score | |
while newfood in snake or newfood[1] >= 550: | |
newfood = (random.randint(0, 80)*10, random.randint(0, 60)*10) |
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 Y | |
(lambda (f) | |
(let [(A (lambda (x) (f (lambda (y) ((x x) y)))))] | |
(A A)))) | |
(define (factF self) | |
(lambda (n) | |
(if (= n 0) | |
1 | |
(* n (self (- n 1)))))) |
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
Essentials of Programming Langauges 1e | |
Daniel P. Friedman, Mitchell Wand, and Christopher T. Haynes | |
Chapter 1 Tools for Symbolic Programming | |
1.1 Simple Expressions | |
1.2 Data Types | |
1.3 Procedures | |
1.4 Summary | |
Chapter 2 Induction, Recursion, and Scope |
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
Essentials of Programming Langauges 3e | |
Daniel P. Friedman and Mitchell Wand | |
Chapter 1 Inductive Sets of Data | |
1.1 Recursively Specified Data | |
1.2 Deriving Recursive Programs | |
1.3 Auxiliary Procedures and Context Arguments | |
1.4 Exercises | |
Chapter 2 Data Abstraction |
OlderNewer