Skip to content

Commit dad77e0

Browse files
committed
Regenerated samples & exercise descriptions
1 parent 52a11e8 commit dad77e0

File tree

80 files changed

+156
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+156
-201
lines changed

Functional Programming/Building Maps/Examples/src/ImmutableBlendMap.kt renamed to Functional Programming/Building Maps/Examples/src/ReadOnlyBlendMap.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// BuildingMaps/ImmutableBlendMap.kt
1+
// BuildingMaps/ReadOnlyBlendMap.kt
22
@file:OptIn(ExperimentalStdlibApi::class)
33
package buildingmaps
44

Functional Programming/Building Maps/Examples/task-info.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ files:
2424
visible: true
2525
- name: src/ColorBlend.kt
2626
visible: true
27-
- name: src/ImmutableBlendMap.kt
27+
- name: src/ReadOnlyBlendMap.kt
2828
visible: true

Functional Programming/Folding Lists/Exercise 4/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
The starter code provides a `Condition` class and a function
44
`Condition.combine()` that combines two conditions. There's also a skeleton
55
for the `List<Condition>` extension function `combineAll()` that combines all
6-
conditions in the `List`. Complete the implementation using `reduce()`,
6+
the conditions in the `List`. Complete the implementation using `reduce()`,
77
assuming the `List` is non-empty.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Manipulating Lists (#3)
22

3-
Reimplement the `authorBooksMap()` function from the Data Classes atom,
3+
Reimplement the `authorBooksMap()` function from [Data Classes],
44
using operations for manipulating collections. `authorBooksMap()` takes a
55
`List<Book>` as a parameter and builds a `Map` from each `Author` to the
66
`Book`s they have written.

Functional Programming/Manipulating Lists/Exercise 4/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Bob - Charlie
1212
`friendSuggestions()` should return Charlie for Alice, because Charlie is a
1313
friend of Alice's friend Bob and isn't yet a friend of Alice.
1414

15-
The following example produces no friend suggestions for Alice because Bob and
15+
The following example produces no friend suggestions for Alice, because Bob and
1616
Charlie are already her friends:
1717

1818
```text

Functional Programming/Operations on Collections/Exercise 4/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Operations on Collections (#4)
22

33
`all()`, `none()` and `any()` can be used to produce identical results.
4-
Implement `List<Int>` extension functions `allNonZero()` and `hasZero()` using
5-
each of `all()`, `none()` and `any()`.
4+
Implement the `List<Int>` extension functions `allNonZero()` and `hasZero()`
5+
using each of `all()`, `none()` and `any()`.
66

77
- `allNonZero()` checks that all elements in the list are non-zero.
88

Functional Programming/Recursion/Exercise 1/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
Write a tail recursive function called `simulation()` that takes a `String`
44
called `group` and an `Int` called `level`. It displays `"Simulation: $group
5-
Reality: level"`, then recursively calls itself with `level - 1` as long as
6-
`level` is greater than zero.
5+
Reality: level"`, then calls itself with `level - 1` as long as `level` is
6+
greater than zero.

Functional Programming/Recursion/Exercise 4/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
## Recursion (#4)
22

3-
The starter code defines a `City` class. Implement an extension function
3+
The starter code provides a class `City`. Implement an extension function
44
`City.allReachable()` that builds a set of all cities reachable from the
55
current `City`. Implement it in two ways: recursive and iterative.
66

77
The direct connections for each `City` are stored in its `connections`
8-
property. `allReachable()` should return all cities reachable from the given
9-
city via other cities. The city is reachable from itself, so it should be also
10-
present in the resulting set.
8+
property. `allReachable()` should return all the cities reachable from the
9+
given city via other cities. The city is reachable from itself, so it should be
10+
also present in the resulting set.
1111

1212
For example, consider the following connections graph:
1313

Functional Programming/Sequences/Exercise 3/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
Implement the `School` extension function `averageInstructorRating()` that
44
takes `Instructor` as a parameter and calculates the average rating that the
5-
instructor was given by all students that attended his or her classes. If a
5+
instructor was given by all the students that attended his or her classes. If a
66
student attended several lessons by that instructor, the ratings for individual
77
lessons should be treated separately.

Functional Programming/The Importance of Lambdas/Exercise 3/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## The Importance of Lambdas (#3)
22

3-
Implement the function `other(s: String)` so it returns a `String` containing
3+
Implement the function `other(s: String)` that returns a `String` containing
44
every other letter of `s`. For example, for an input of "cement" it returns
55
"cmn".
66

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Constraining Visibility (#2)
22

33
Continue developing the `Robot` class from the exercises in the previous atoms.
4-
Use `private` on all the properties and the `crossBoundary()` function, and
5-
verify that you can't access the `private` members outside the class.
4+
Use `private` on all the properties and `crossBoundary()`, and verify that you
5+
can't access the private members outside of the class.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Constructors (#2)
22

33
Continue developing the `Robot` class from the exercises in the previous atom.
4-
Convert the properties that store the size of the field and the current
4+
Convert the properties storing the size of the field and the current
55
coordinates into `Robot` constructor parameters.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Creating Classes (#1)
22

33
Create a class named `SomeClass` with three member functions: `a()` which
4-
displays `42` on the console, `b()` which calls `a()`, and `c()` which calls
5-
`b()` by qualifying it.
4+
displays `42` on the console when you call it, `b()` which calls `a()`,
5+
and `c()` which calls `b()` by qualifying it.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## Creating Classes (#3)
22

3-
Create a `Robot` class with the following four member functions: `right(steps:
4-
Int)`, `left(steps: Int)`, `down(steps: Int)` and `up(steps: Int)`. Each
5-
function should display one of the following phrases on the console:
3+
Create a `Robot` class with the following four member functions:
4+
`right(steps: Int)`, `left(steps: Int)`, `down(steps: Int)` and
5+
`up(steps: Int)`. Each function should display one of the following
6+
phrases on the console:
67

78
```
89
Right N steps
@@ -11,4 +12,4 @@ Down N steps
1112
Up N steps
1213
```
1314

14-
N is the provided number of steps.
15+
where N is the provided number of steps.

Introduction to Objects/Exceptions/Exercise 1/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Exceptions (#1)
22

3-
Display on the console all the following `String`s that can't be converted to
3+
Display to the console all of the following `String`s that can't be converted to
44
`Double` (that is, those where an attempt to convert it throws an exception):
55

66
```

Introduction to Objects/Lists/Examples/src/OutOfBounds.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ fun main() {
55
val ints = listOf(1, 2, 3)
66
capture {
77
ints[3]
8-
} eq "ArrayIndexOutOfBoundsException: " +
9-
"Index 3 out of bounds for length 3"
8+
} contains
9+
listOf("ArrayIndexOutOfBoundsException")
1010
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
## Lists (#3)
22

3-
Write a function that determines whether two `String`s are anagrams. An anagram
3+
Write a function to determine whether two `String`s are anagrams. An anagram
44
is a word formed by rearranging the letters of a different word, using all the
55
original letters exactly once.
66

77
<div class="hint">
88

9-
Compare two sorted `Lists` of characters obtained from two `String`s. Convert a
10-
`String` to a `List` by calling `toList()`. If the `Lists` are equal, the words
11-
are anagrams. For example, for the two anagrams "terrain" and "trainer", the
12-
sorted character `List` will be `[a, e, i, n, r, r, t]`.
9+
Compare two sorted `Lists` of characters obtained from two `String`s.
10+
Convert a `String` to a `List` by calling `toList()`. If the `Lists` are equal,
11+
the words are anagrams. For example, for two anagrams "terrain" and "trainer"
12+
the sorted character `List` will be `[a, e, i, n, r, r, t]`.
1313

1414
</div>

Introduction to Objects/Maps/Exercise 3/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ constant time. With a `List`, in the worst case you must iterate over every
66
element.
77

88
Change the internal implementation of the `Cage` class to store elements in a
9-
`Map` rather than a `List`. To get an element, use the `getValue()` member
9+
`Map` rather than a `List`. To get an element use the `getValue()` member
1010
function, which throws `NoSuchElementException` if the key is missing.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Properties (#1)
22

3-
Create a class `X` containing three `Int` properties: `a` and `b` are `val`s
3+
Create a class `X` that contains three `Int` properties: `a` and `b` are `val`s
44
and `c` is a `var`. Initialize `a` to 3, `b` to 42, and `c` to zero. Create an
55
`add()` member function that sums `a` and `b` and assigns the result to `c`,
66
then returns `c`. Write a `main()` to test `X`.

Introduction to Objects/Properties/Exercise 2/task.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ is the top-left corner:
1111
```
1212

1313
Moving right increases the `x` coordinate, moving down increases the `y`
14-
coordinate, while moving left and up decrease the `x` and `y` coordinates,
15-
respectively.
14+
coordinate, while moving left and up decrease the `x` and `y` coordinates.
1615

1716
Implement `Robot`'s member functions `right()`, `left()`, `up()` and `down()`,
1817
each of which takes a `steps` parameter. Also implement `getLocation()` which

Introduction to Objects/Property Accessors/Exercise 3/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ Create a class `MessageStorage` with two properties: a `private` one named
44
`_messages` of type `MutableList<String>` and a `public` one named `messages`
55
of type `List<String>`. The custom getter for `messages` returns `_messages`.
66

7-
Since `_messages` is `private`, its contents can be only changed within the
7+
Because `_messages` is `private` its contents can be only changed within the
88
`MessageStorage` class. Define an `addMessage()` member function that takes a
99
`String` parameter and adds it to the `_messages` list.

Introduction to Objects/Summary 2/Exercise 2/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
Create a class named `Boring2` that is just like `Boring` except it has
44
constructor parameters, which are all `val`s. The parameter `a` holds the value
5-
that `a()` produces, `b` holds the value that `b()` produces, and `c` holds the
6-
value produced by `c()`. Test `Boring2` using `atomictest`.
5+
that `a()` produces, the parameter `b` holds the value that `b()` produces, and
6+
`c` holds the value produced by `c()`. Test `Boring2` using `atomictest`.

Introduction to Objects/Summary 2/Exercise 7/task.md

+7-19
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,18 @@
22

33
Convert a natural number into a number in the Roman numeral system.
44

5-
| Roman | Decimal |
6-
|-------|---------|
7-
| I | 1 |
8-
| IV | 4 |
9-
| V | 5 |
10-
| IX | 9 |
11-
| X | 10 |
12-
| XL | 40 |
13-
| L | 50 |
14-
| XC | 90 |
15-
| C | 100 |
16-
| CD | 400 |
17-
| D | 500 |
18-
| CM | 900 |
19-
| M | 1000 |
5+
Roman numerals:
6+
1000 = M, 900 = CM, 500 = D, 400 = CD, 100 = C, 90 = XC,
7+
50 = L, 40 = XL, 10 = X, 9 = IX, 5 = V, 4 = IV, 1 = I.
208

219
For example: 23 = XXIII, 44 = XLIV, 100 = C.
2210

2311
<div class="hint">
2412

25-
Perform the conversion in steps. Use an auxiliary `remainder` variable to store
26-
the remaining part of the converted integer and a `result` variable to store
27-
the resulting Roman numeral representation. For each step, the initial `number`
28-
equals the sum of `remainder` and `result`.
13+
Perform the conversion in steps. Use an auxiliary `remainder`
14+
variable to store the remaining part of the converted integer and the `result`
15+
variable to store the resulting Roman numeral representation. For each step,
16+
the initial `number` equals the sum of the `remainder` and `result`.
2917

3018
Store the Roman numerals in a mapping from `Int` to the associated `String`
3119
representation. For each pair `int = roman` starting from `1000 = M`:

Introduction to Objects/Summary 2/Exercise 8/task.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
## Summary 2 (#8)
22

33
Convert from a Roman number into a natural number. For
4-
example: XXIII is 23, XLIV is 44, and C is 100.
4+
example: XXIII = 23, XLIV = 44, C = 100.
55

66
<div class="hint">
77

8-
Iterate over each digit in the Roman number and calculate the answer. Traverse
9-
a Roman number in reverse order, a single digit at a time (for example, `IV`
10-
contains two digits) and store the maximum value found so far. If the next
11-
Roman digit is greater than or equal to the current maximum value, add it to
12-
the result. If it's less than the maximum, subtract it instead. For example, to
13-
convert XLIV, iterate over `VILX` which is the reverse of `XLIV`. Add `V`(`5`)
14-
and `L`(`50`), but subtract `1`(`I`) because it's less than the current maximum
15-
`V`, and subtract `10`(`X`) because it's less than the updated maximum `X`:
8+
Simply iterate over each digit in the Roman number and calculate the
9+
answer. Traverse a Roman number in reverse order, a single digit at a time (for
10+
example, `IV` contains two digits) and store the maximum value found so far. If
11+
the next Roman digit is greater than or equal to the current maximum value, add
12+
it to the result. If it's less than the maximum, subtract it instead. For
13+
example, to convert `XLIV = 44`, iterate over `VILX` which is the reverse of
14+
`XLIV`. You add `V`(`5`) and `L`(`50`), but subtract `1`(`I`) because it's less
15+
than the current maximum `V`, and subtract `10`(`X`) because it's less than the
16+
updated maximum `X`:
1617

17-
| Numeral | Current Maximum | Action |
18+
| numeral | current maximum | action |
1819
| ------- |-----------------|--------|
1920
| V | 5 | + 5 |
2021
| I | 5 | - 1 |

Introduction to Objects/Variable Argument Lists/Exercise 2/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Write a function `printArgs()` with a `String` as the first parameter, and a
44
`vararg` parameter of `Int` as the second parameter. `printArgs()` displays its
5-
arguments on the console: first the `String`, then the `Int`s, separated by
5+
arguments to the console: first the `String`, then the `Int`s, separated by
66
commas and surrounded by square brackets.
77

88
For example, the output for `printArgs("Numbers: ", 1, 2, 3)` should be:

Object-Oriented Programming/Class Delegation/Exercise 2/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Class Delegation (#2)
22

3-
Exercise 1 from the Inheritance & Extensions atom uses
3+
Exercise 1 in [Inheritance & Extensions] uses
44
composition to adapt `Crocodile` to work with `interactWithDuck()`. This
55
produces an inconsistency when using `IAmHonestlyDuck` with the
66
`interactWithCrocodile()` function---the composed `crocodile` must be
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Complex Constructors (#1)
22

3-
Modify `Alien` to use "verbose" syntax: make `name` a constructor parameter
3+
Modify `Alien` to use the "verbose" syntax: make `name` a constructor parameter
44
rather than a property, add the `val` property `myName` and assign `name` value
55
to the property `myName` inside the `init` section.

Object-Oriented Programming/Complex Constructors/Exercise 3/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Complex Constructors (#3)
22

3-
Show that multiple `init` sections are executed in declaration order. The starter
3+
Show that multiple init sections are executed in declaration order. The starter
44
code contains `MultipleInit` class with a
55
`val initOrder = mutableListOf<String>()` property. Add the `String`s `"one"`,
66
`"two"` and `"three"` to the `initOrder` property in three different `init`

Object-Oriented Programming/Composition/Exercise 1/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
The starter code contains the classes `Shape`, `Circle` and `Rectangle`.
44
`Circle` and `Rectangle` use composition and store an instance of `Shape`.
5-
Modify them to use inheritance instead of composition.
5+
Modify them to use inheritance instead.

Object-Oriented Programming/Composition/Exercise 2/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
The starter code contains implementations of `Stack` and `Queue` classes.
44

5-
`Stack` provides last-in-first-out access to elements. You can add ("push")
6-
new elements, and get ("pop") the last element that was added.
5+
`Stack` provides a last-in-first-out access to elements. You can add ("push")
6+
new elements to it, and get ("pop") the last one that was added.
77

8-
`Queue` provides first-in-first-out access to elements. You can add new
9-
elements to it, and get ("poll") returns the first element that was added.
8+
`Queue` provides a first-in-first-out access to elements. You can add new
9+
elements to it, and get ("poll") returns you the first one that was added.
1010

1111
In the starter code, both `Stack` and `Queue` extend `ArrayList`, which opens
1212
too many methods in the public API (for example, you can get the first element

Object-Oriented Programming/Composition/Exercise 3/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Based on your solution for the previous exercise, modify the implementation of
55
`MutableList`. `ArrayDeque` represents a "double ended queue", so it provides
66
member functions to add last and remove first elements.
77

8-
Note that composition allows you to change the internal implementation of the
8+
Note how with composition you can change the internal implementation of the
99
class without changing the code that uses that class.
1010

1111
`ArrayDeque` is currently experimental in the Kotlin library, so we must add

Object-Oriented Programming/Inheritance & Extensions/Exercise 1/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Inheritance & Extensions (#1)
22

33
The starter code contains `Duck` and `interactWithDuck()` declarations (we
4-
assume they're part of a third-party library). Implement the `mimicDuck()`
4+
assume they're part of the third-party library). Implement the `mimicDuck()`
55
function that dynamically adapts an object, accepting a `Crocodile` and
66
returning an `IAmHonestlyDuck`. `IAmHonestlyDuck` should implement `Duck` and
77
delegate both `Duck` member functions to `crocodile.bite()`. Is it possible to

Object-Oriented Programming/Inheritance/Exercise 1/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ The starter code contains an `open` class `Cleanser` and a class `Detergent`
44
that inherits it. Add to the `Cleanser` class the property
55
`var ops: MutableList<String>` and the functions `dilute()`, `apply()` and
66
`scrub()` that simply add their names to `ops`. In `main`, make sure that
7-
`Detergent` now has the same functions as `Cleanser`.
7+
`Detergent` has now the same functions as `Cleanser`.

Object-Oriented Programming/Inner Classes/Exercise 3/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Define a standalone function `<T> traceAll(select: Selector<T>)` that uses
2222
`select` to append all the values of `current()` to `trace` using `+=`, then
2323
returns `trace`.
2424

25-
Inherit `Container` from `Iterable<T>`, and add a function called
25+
Now make `Container` inherit from `Iterable<T>`, and add a function called
2626
`iterator()` that returns an instance of an anonymous inner class that inherits
2727
from `Iterator<T>`. Add a standalone function `<T> traceAll2(ib: Iterable<T>)`
2828
that produces the same behavior as `traceAll()`.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Sealed Classes (#3)
22

3-
Modify `SealedSubclasses.kt` so that all subclasses of `Top` are nested
3+
Modify `SealedSubclasses.kt` so that all the subclasses of `Top` are nested
44
within `Top`. Create a seeded random-number generator by defining `val rand =
55
Random(17)`. Use this generator to randomly select a subclass of `Top` and
66
display its `simpleName`.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## Secondary Constructors (#3)
22

3-
Replace all constructors in the `GardenItem` class with a single primary
3+
Replace all the constructors in the `GardenItem` class with a single primary
44
constructor using default arguments.

Object-Oriented Programming/Type Checking/Exercise 3/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Modify `Insects.kt` so that `Insect` is a `sealed` class (this may require
44
modifications to other components). Change `basic()` to use a `when`
55
expression.
66

7-
What does this gain you, since the `else` clauses in the `when` expressions
8-
still make sense?
7+
The `else` clauses in the `when` expressions still make sense, so how does this
8+
benefit you?
99

1010
<sub> This task doesn't contain automatic tests,
1111
so it's always marked as "Correct" when you run "Check".

0 commit comments

Comments
 (0)