Tagged Questions
5
votes
1answer
125 views
Write a procedure stream-limit that finds
From SICP:
Exercise 3.64. Write a procedure
stream-limit that takes as arguments a
stream and a number (the tolerance).
It should examine the stream until it
finds two successive elements ...
5
votes
4answers
633 views
(Scheme) [SICP ex. 2.41] Find all distinct triples less than N that sum to S
Exercise 2.41. Write a procedure to
find all ordered triples of distinct
positive integers i, j, and k less
than or equal to a given integer n
that sum to a given integer s.
(define ...
1
vote
1answer
362 views
Huffman encoding successive-merge function [SICP ex. 2.69]
From SICP:
Exercise 2.69. The following
procedure takes as its argument a list
of symbol-frequency pairs (where no
symbol appears in more than one pair)
and generates a Huffman encoding ...
1
vote
0answers
123 views
Write a definition of a semaphore in terms of mutexes
From SICP:
Exercise 3.47. A semaphore (of size
n) is a generalization of a mutex.
Like a mutex, a semaphore supports
acquire and release operations, but it
is more general in that up to n
...
1
vote
0answers
157 views
[SICP ex. 3.17] correctly count the number of pairs in an irregular list structure
From SICP:
For background, here is exercise 3.16:
Exercise 3.16. Ben Bitdiddle decides
to write a procedure to count the
number of pairs in any list structure.
It's easy,'' he reasons.The
...
2
votes
0answers
621 views
Union-set intersection-set for a binary-tree implementation of sets [SICP ex. 2.65]
From SICP:
Exercise 2.65. Use the results of
exercises 2.63 and 2.64 to give (n)
implementations of union-set and
intersection-set for sets implemented
as (balanced) binary trees.41
I ...
1
vote
0answers
128 views
Write a definition of a semaphore in terms of test-and-set! operations
From SICP:
Exercise 3.47. A semaphore (of size
n) is a generalization of a mutex.
Like a mutex, a semaphore supports
acquire and release operations, but it
is more general in that up to n
...
2
votes
1answer
202 views
Lookup (search) on a binary tree [SICP ex. 2.66]
From SICP:
Exercise 2.66. Implement the lookup
procedure for the case where the set
of records is structured as a binary
tree, ordered by the numerical values
of the keys.
I wrote the ...
2
votes
0answers
93 views
[SICP ex. 3.22] represent a queue as a procedure with local state
From SICP:
Exercise 3.22. Instead of
representing a queue as a pair of
pointers, we can build a queue as a
procedure with local state. The local
state will consist of pointers to the
...
3
votes
1answer
144 views
SICP ex. 3.18 - Write a program to examine a list for cycles
From SICP:
Exercise 3.18. Write a procedure that
examines a list and determines whether
it contains a cycle, that is, whether
a program that tried to find the end
of the list by taking ...
1
vote
1answer
320 views
(Encode-symbol …) for Huffman tree [SICP ex. 2.68]
From the text:
Exercise 2.68. The encode procedure
takes as arguments a message and a
tree and produces the list of bits
that gives the encoded message.
(define (encode message tree)
...
1
vote
0answers
213 views
Standard Algebraic Derivative Calculator [SICP ex. 2.58 part b]
I had some difficulty with this problem, so I'm sure there is a better way. Here is the question from SICP:
Exercise 2.58. Suppose we want to
modify the differentiation program so
that it ...
3
votes
4answers
421 views
(Scheme) [SICP ex. 2.42] eight-queens puzzle - help me fix my popsicle-stick-bridge solution!
Figure 2.8: A solution to the
eight-queens puzzle. The
``eight-queens puzzle'' asks how to
place eight queens on a chessboard so
that no queen is in check from any
other (i.e., no two ...
1
vote
1answer
149 views
[SICP ex. 3.8] order of evaluation of function arguments
From SICP:
Exercise 3.8. When we defined the
evaluation model in section 1.1.3, we
said that the first step in evaluating
an expression is to evaluate its
subexpressions. But we never ...
0
votes
1answer
382 views
[SICP ex. 1.30] Iterative Sum
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 the task:
Exercise 1.30. The ...