-
Notifications
You must be signed in to change notification settings - Fork 17
/
arrow.kt
55 lines (43 loc) · 1.07 KB
/
arrow.kt
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//for compile
// alias arrow="kotlinc arrow.kt -include-runtime -d arrow.jar && java -jar arrow.jar"
// arrow <size>
package dojo.katafleche
import kotlin.system.exitProcess
import kotlin.*
fun main(args: Array<String>) {
if (args.size == 0) {
println("Please provide the size of the arrow (2-20)")
return
}
val size: Int? = try { args[0].toInt() } catch (e: NumberFormatException) { null }
if (size == null)
bye("${args[0]} is not a number dumbass")
size!!
println("Drawing a $size sized arrow!")
spike(size)
arrow(size)
base(size)
tail(size)
}
fun bye (msg: String) {
println(msg)
exitProcess(1)
}
fun errorHandling(size: Int) {
if (size !in 2..20)
bye("Between 2 and 20... What don't you understand ?")
}
fun spike(size: Int) {
println(" ".repeat(size) + '*')
}
fun arrow(size: Int) {
for (a in 1..size-1)
println(" ".repeat(size-a) + '*' + " ".repeat(2*a-1) + '*')
}
fun base(size: Int) {
println("*".repeat(size*2+1))
}
fun tail(size: Int) {
for (a in 1..size)
println(" ".repeat(size) + '*')
}