Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
2 answers
2k views

Pascal's triangle in mit-scheme

As suggested by the name of source file (ex1.12.scm), I just started learning mit-scheme by reading SICP. In Exercise 1.12, I'm asked to "compute elements of Pascal'...
nalzok's user avatar
  • 503
2 votes
1 answer
454 views

SICP - exercise 1.11 - tree recursion

From SICP Exercise 1.11: A function \$f\$ is defined by the rule that: \$f(n) = n\$ if \$n < 3\$, and \$f(n) = f(n-1)+2f(n-2)+3f(n-3)\$ if \$n >= 3\$. Write a procedure ...
lightning_missile's user avatar
4 votes
4 answers
2k views

Generic sequence splitter in Common Lisp

I wrote a function split-seq-by-n which accepts a sequence and a number and splits the sequence into subsequences of length n (the last subsequence getting the ...
Wojciech Gac's user avatar
2 votes
1 answer
168 views

Rewrite apply function to use recursion instead

Probably the hardest part of learning lisp has been to think in the "lisp way" which is elegant and impressive, but not always easy. I know that recursion is used to solve a lot of problems, and I am ...
johnbakers's user avatar
1 vote
1 answer
442 views

Square-tree using maps and recursion

Define a procedure square-tree analogous to the square-list procedure of exercise 2.21. That is, square-list should behave as follows: ...
jaresty's user avatar
  • 2,283
2 votes
2 answers
10k views

Design a procedure to reverse a list

SICP exercise 2.18 asks the following: Exercise 2.18. Define a procedure reverse that takes a list as argument and returns a list of the same elements in reverse order: ...
jaresty's user avatar
  • 2,283
0 votes
1 answer
2k views

Iterative sum using recursion

Given the following recursive definition of sum: (define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) next b)))) And ...
jaresty's user avatar
  • 2,283
1 vote
1 answer
1k views

Both an Iterative and a Recursive f(x)

A function f is defined by the rule that f(n) = n if n < 3 and f(n) = f(n-1) + 2f(n-2) + 3f(n-3) if n>=3. Write a recursive and an iterative process for computing f(n). I wrote the ...
jaresty's user avatar
  • 2,283