- Exercism
Completed Phase 1 week 3 exercises on exercism:
- hello-world
- two-fer
- raindrops
- bob
- hamming
- pangram
- isogram
- difference-of-squares

- Played with function composition in scala - implemented simple banner generator (see header of this and previous entry).
Also, learned about external process calling
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
object Colors {
abstract class ColorSource {
//generate colors from string once
lazy val into: List[Color] = {
val hx = hexes()
println(hx)
hx.map(Color.decode)
}
def hexes(): List[String]
def random: Color = into(r.nextInt(into.length))
}
class Pastel extends ColorSource {
def hexes(): List[String] = {
import scala.sys.process._
val result = (Seq("pastel", "random","-s", "vivid") #| Seq("pastel", "format", "hex")).!!
result.split("\n").toList
}
}
class Gradient(from: String="ffffcc", to: String="fd8d3c", n: Int = 5) extends ColorSource {
def hexes(): List[String] = {
import scala.sys.process._
val cmd = Seq("pastel", "gradient", "--colorspace", "HSL", from, to, "-n", n.toString) #| Seq("pastel", "format", "hex")
println(cmd)
val result = cmd.!!
result.split("\n").toList
}
}
class Fixed(cols: List[String]) extends ColorSource {
def hexes(): List[String] = cols
}
def pastel: ColorSource = new Pastel
def gradient(from: String, to: String, n: Int) = new Gradient(from, to, n)
def fixed(cols: List[String]) = new Fixed(cols)
/** ... */
}
|
- Setting up rustlings failed. I probably messed up the configuration (or had old version of
rustlings tool). Worked after removal of whole repo (minus execrises done so far),tool reinstall (cargo install rustlings), rustlings init and copying over my exercises.

- Learned about traits from https://doc.rust-lang.org/book/ch10-02-traits.html