on master help sign in
trivial
2d95a11Galen Wolfe-Pauly
docs/programming/hoon/exercises/data-structures.mdnew file+22
@@ -0,0 +1,22 @@
1+---
2+sort: 4
3+comments: true
4+---
5+
6+# Sets, Maps, and Queues
7+
8+Sets are constructed with `++silt`. A set is a non-ordered
9+collection of unique elements.
10+
11+```
12+(silt `(list @t)`['urbit' 'arvo' 'hoon' 'arvo' ~])
13+```
14+
15+We'll refer to this particular set as `s` in the exercises. It
16+is of type `(set @t)` since each element is a `@t`.
17+
18+The `++in` core contains library functions for dealing with sets.
19+For example, `++has:in` checks whether an element is in the set.
20+Thus, `(~(has in s) 'arvo')` returns yes.
21+
22+
docs/programming/hoon/exercises/life.md+26−23
@@ -1,5 +1,5 @@
1---
1---
2−sort: 3
2+sort: 5
3comments: true
3comments: true
4---
4---
5
5
@@ -25,23 +25,23 @@ space.
25 ##.
25 ##.
26
26
27
27
28−1. Write a function that takes nine loobean inputs, `nw`, `nc`,
28+1. Write a function `next-generation` that takes nine loobean
29− `ne`, `cw`, `cc`, `ce`, `sw`, `sc`, and `se`. Produce 'yes'
29+ inputs, `nw`, `nc`, `ne`, `cw`, `cc`, `ce`, `sw`, `sc`, and
30− if the center space will be alive in the next generation and
30+ `se`. Produce 'yes' if the center space will be alive in the
31− 'no' if it will be dead.
31+ next generation and 'no' if it will be dead.
32
32
33−1. Write a function that takes an integer `n` and produces an
33+1. Write a function `create-board` that takes an integer `n` and
34− `n` by `n` grid of loobeans, (hereafter, "board"),
34+ produces an `n` by `n` grid of loobeans, (hereafter,
35− initialized to 'no'. This grid should be represented as a
35+ "board"), initialized to 'no'. This grid should be
36− list of `n` lists of length `n`.
36+ represented as a list of `n` lists of length `n`.
37
37
38−1. Write a function that takes a board, a row index, and a
38+1. Write a function `toggle-space` that takes a board, a row
39− column index, and produces a new board, identical to the old
39+ index, and a column index, and produces a new board,
40− except that the state of the space referred to by the row and
40+ identical to the old except that the state of the space
41− column indices has been toggled.
41+ referred to by the row and column indices has been toggled.
42
42
43−1. Use the following function to pretty-print the board. For
43+1. Use the following function `print-board` to pretty-print the
44− bonus points, try to follow what it's doing.
44+ board. For bonus points, try to follow what it's doing.
45
45
46 ```
46 ```
47 :: XX test
47 :: XX test
@@ -85,8 +85,8 @@ space.
85 . . . . . . . . . .
85 . . . . . . . . . .
86 ```
86 ```
87
87
88−1. Write a function that iterates every space on the board.
88+1. Write a function `step` that iterates every space on the
89− Print out the new board. It should look like this:
89+ board. Print out the new board. It should look like this:
90
90
91 ```
91 ```
92 . . . . . . . . . .
92 . . . . . . . . . .
@@ -104,14 +104,17 @@ space.
104 > Note that the spaces on the edge don't have the full nine
104 > Note that the spaces on the edge don't have the full nine
105 > neighbors. For now, assume that they're always dead.
105 > neighbors. For now, assume that they're always dead.
106
106
107−1. Write a function that runs the above function `n` times on
107+1. Write a function `life` that runs the above function `n`
108− the board. Observe the board as the game progresses.
108+ times on the board. Observe the board as the game
109− Congratulations, you've written Conway's Game of Life in
109+ progresses. Congratulations, you've written Conway's Game of
110− Hoon!
110+ Life in Hoon!
111
111
1121. One common way to handle the edge of the board is to pretend
1121. One common way to handle the edge of the board is to pretend
113 that it "wraps around", forming a torus. In other words, say
113 that it "wraps around", forming a torus. In other words, say
114 that the spaces on the left edge of the map are adjacent to
114 that the spaces on the left edge of the map are adjacent to
115 the ones on the right edge, and the spaces on the top edge
115 the ones on the right edge, and the spaces on the top edge
116− are adjacent to the spaces on the bottom edge. Pay special
116+ are adjacent to the spaces on the bottom edge. Modify `step`
117− attention to the corners.
117+ to act this way. Pay special attention to the corners.
118+
119+1. Modify `create-board` to use `++og` to randomly initialize
120+ the board with live or dead spaces.
docs/programming/hoon/exercises/lists.mdnew file+39
@@ -0,0 +1,39 @@
1+---
2+sort: 3
3+comments: true
4+---
5+
6+# Lists
7+
8+In the following exercises, let `l` be `` `(list @t)`['u' 'r' 'b'
9+'i' 't' ~]``
10+
11+1. A list is a null-terminated tuple of values. For example,
12+ `[1 2 3 ~]` is a list of three integers, and
13+ `['a' 'b' 'c' ~]` is a list of three cords. Try casting
14+ `['a' 'b' 'c' ~]` to `(list @t)` and to `(list @)`. Lists
15+ are parameterized with the type of the values.
16+
17+1. `++flop` takes a list and produces its reverse. Use it to
18+ reverse `l`.
19+
20+1. Repeat the above exercise without using `++flop`.
21+
22+1. `++sort` takes a list and a comparison function to sort a
23+ list. The function must take two elements of the list and
24+ produce true if the first element is "less than" the other.
25+ Sort `l` alphabetically. Sort it reverse alphabetically.
26+
27+1. `++turn` takes a list and a function and applies the function
28+ to each element in the list, forming a new list of the
29+ results. This is called "map" in many functional languages.
30+ The function must accept an element of the list. Use the
31+ fact that subtracting 32 from a lowercase letter gives the
32+ equivalent uppercase letter (i.e. `(sub 'a' 'A')` is 32) to
33+ change every character in `l` to uppercase.
34+
35+1. `++welp` concatentates two lists. Concatenate `l` with the
36+ reverse of `l`.
37+
38+1. `++snag` takes a number `n` and a list and produces the
39+ element at index `n`. Pull out the `'i'` in `l`.
docs/programming/hoon/exercises/math.md+11
@@ -13,3 +13,14 @@ comments: true
13 function that produces the first `n` tetrahedral numbers.
13 function that produces the first `n` tetrahedral numbers.
14 The `n`th tetrahedral number is the sum of the first `n`
14 The `n`th tetrahedral number is the sum of the first `n`
15 triangular numbers.
15 triangular numbers.
16+
17+1. The Fibonacci numbers are defined on the natural numbers as
18+ follows:
19+
20+ ```
21+ fib(0) = 0
22+ fib(1) = 1
23+ fib(n) = fib(n-1) + fib(n-2)
24+ ```
25+
26+ Write a function that computes the `nth` Fibonacci number.