#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 26 20:46:03 2018

@author: daniel

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.

Given this implementation of cons:

def cons(a, b):
    def pair(f):
        return f(a, b)
    return pair

Implement car and cdr.

"""


def cons(a, b):
    def pair(f):
        return f(a, b)
    return pair


def car(pair):
    def f(a, b):
        return a
    return pair(f)


def cdr(pair):
    def f(a, b):
        return b
    return pair(f)


assert car(cons(3, 4)) == 3
assert cdr(cons(3, 4)) == 4

print('all fine')
