Skip to content

Commit 7c98606

Browse files
authored
replace readFloat exercise with rem exercise (#266)
1 parent ef4320b commit 7c98606

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

exercises/chapter2/test/Main.purs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ Note to reader: Delete this line to expand comment block -}
2929
Assert.equal 3.141592653589793 (circleArea 1.0)
3030
test "radius 3" do
3131
Assert.equal 28.274333882308138 (circleArea 3.0)
32-
suite "addE" do
33-
test "1.23" do
34-
Assert.equal 3.948281828459045 (addE "1.23")
35-
test "4.56" do
36-
Assert.equal 7.278281828459045 (addE "4.56")
32+
suite "leftoverCents" do
33+
test "23" do
34+
Assert.equal 23 (leftoverCents 23)
35+
test "456" do
36+
Assert.equal 56 (leftoverCents 456)
37+
test "-789" do
38+
Assert.equal (-89) (leftoverCents (-789))
3739

3840
{- Note to reader: Delete this line to expand comment block
3941
-}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module Test.NoPeeking.Solutions where
22

33
import Prelude
4-
import Global (readFloat)
4+
import Data.Int (rem)
55
import Math (e, pi, sqrt)
66

77
diagonal w h = sqrt (w * w + h * h)
88

99
circleArea r = pi * r * r
1010

11-
addE s = readFloat s + e
11+
leftoverCents n = rem n 100

text/chapter2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Success! Now you're ready to try these next exercises on your own.
109109
## Exercises
110110
111111
1. (Easy) Write a function `circleArea` which computes the area of a circle with a given radius. Use the `pi` constant, which is defined in the `Math` module. _Hint_: don't forget to import `pi` by modifying the `import Math` statement.
112-
1. (Medium) The `readFloat` function converts a String to a floating-point Number. Calling `readFloat "1.23"` produces `1.23`. Write a function `addE` which takes a `String`, converts it to a `Number` with `readFloat`, and then adds the mathematical constant `e` to it. _Hint_: You should first search [Pursuit](https://pursuit.purescript.org/) to find the module that contains the `readFloat` function and import that module.
112+
1. (Medium) Write a function `leftoverCents` which takes an `Integer` and returns what's leftover after dividing by `100`. Use the `rem` function. Search [Pursuit](https://pursuit.purescript.org/) for this function to learn about usage and which module to import it from. _Note:_ Your IDE may support auto-importing of this function if you accept the auto-completion suggestion.
113113
114114
## Conclusion
115115

0 commit comments

Comments
 (0)