Touch the firehose of ds106, the most recent flow of content from all of the blogs syndicated into ds106. As of right now, there have been 92634 posts brought in here going back to December 2010. If you want to be part of the flow, first learn more about ds106. Then, if you are truly ready and up to the task of creating web art, sign up and start doing it.

Sample Problems

Posted by

1) Lazy Sequencing problem:
Write a function in Clojure that outputs a list of numbers 1 through 10. Hint: there is an iterate function, and a take function in Clojure. This demonstrates lazy sequencing in Clojure as the iterate function is an infinite sequence but it uses a small, finite amount of memory.
Example output:
(1 2 3 4 5 6 7 8 9 10)
The `iterate’ function: (iterate f x) – generates an infinite sequence x, f(x), f(f(x)), f(f(f(x))), and so on.
Actually, there is nothing infinite about this sequence. We have a simple two element sequence in memory. The first element is the ‘x’ and the next element is a function that will compute the succeeding elements of the sequence, when required. When we request the second element of the sequence, this function computes the second element plus yet another function which will yield the remaining elements of the sequence and so on.
2) Write a function in Clojure that calculates the cube of a parameter
3) Define a function less so that (less [e,L]) is a list if all the integers L that are less than e.
4) Write a Clojure function that computes the nth permutation of a list parameter. The function header should read (defn permute [n mylist] (;code)) where n is the desired nth permutation, and mylist is the list to be permuted. By nth, we mean to say in lexicographical order, the nth item.
General algorithm:
• Next character is at mylist[(n/(size(mylist) – 1)!]
• Remove the character at this index and recur with [(n-1)!/(mod n), updated mylist].
5) Using the permutation function from before, write a set of functions to solve the Traveling Salesman problem in (O(n!)) time.
Use the Permute function to generate a list of all possible routes to follow between the 5 points.
Here is a listing of the distances between 5 points:
You should also define the following helper functions
(distance [route]) to compute the distance along a route. Route is a list of locations between the 5 points.

Add a comment

ds106 in[SPIRE]