Skip to content

Commit a7a4cfd

Browse files
committed
Problem#5
1 parent bc74922 commit a7a4cfd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

DailyCodingProblem/Problem5.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Asked by Jane Street.
2+
3+
# cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4.
4+
5+
# author @Nishant
6+
7+
8+
def cons(a, b):
9+
def pair(f):
10+
return f(a, b)
11+
return pair
12+
13+
14+
def car(cons):
15+
return cons(lambda a, b: a)
16+
17+
18+
def cdr(cons):
19+
return cons(lambda a, b: b)
20+
21+
22+
print(car(cons(3, 4)))
23+
print(cdr(cons(3, 4)))

0 commit comments

Comments
 (0)