Cody

# Problem 43650. Church Encoding

Solution 1571595

Submitted on 29 Jun 2018 by David Verrelli
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
incr = @(a)a+1 c = church(0) assert(isequal(c(incr,100),100))

incr = function_handle with value: @(a)a+1 ans = function_handle with value: @(f,x)applyFun(f,x) c = function_handle with value: @(f,x)applyFun(f,x) result = 100

2   Pass
incr = @(a)a+1 c = church(3) assert(isequal(c(incr,0),3))

incr = function_handle with value: @(a)a+1 ans = function_handle with value: @(f,x)applyFun(f,x) c = function_handle with value: @(f,x)applyFun(f,x) result = 0 result = 1 result = 2 result = 3

3   Pass
twice = @(a)a*2 c = church(5) assert(isequal(c(twice,1),32))

twice = function_handle with value: @(a)a*2 ans = function_handle with value: @(f,x)applyFun(f,x) c = function_handle with value: @(f,x)applyFun(f,x) result = 1 result = 2 result = 4 result = 8 result = 16 result = 32

4   Pass
incr = @(a)a+1 c = church(10) assert(isequal(c(incr,10),20))

incr = function_handle with value: @(a)a+1 ans = function_handle with value: @(f,x)applyFun(f,x) c = function_handle with value: @(f,x)applyFun(f,x) result = 10 result = 11 result = 12 result = 13 result = 14 result = 15 result = 16 result = 17 result = 18 result = 19 result = 20

5   Pass
twice = @(a)a*2 c = church(10) assert(isequal(c(twice,3),3072))

twice = function_handle with value: @(a)a*2 ans = function_handle with value: @(f,x)applyFun(f,x) c = function_handle with value: @(f,x)applyFun(f,x) result = 3 result = 6 result = 12 result = 24 result = 48 result = 96 result = 192 result = 384 result = 768 result = 1536 result = 3072