Skip to content

Commit a7e8da2

Browse files
authored
Add Baklava in Hobbes (#4163)
1 parent eb1ccca commit a7e8da2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

archive/h/hobbes/baklava.hob

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repeatString :: (string, int) -> string
2+
repeatString s n = if (n > 0) then s ++ repeatString(s, n - 1) else ""
3+
4+
iabs :: int -> int
5+
iabs n = if (n < 0) then -n else n
6+
7+
baklavaLine :: int -> string
8+
baklavaLine n =
9+
let
10+
numSpaces = iabs(n);
11+
numStars = 21 - 2 * numSpaces
12+
in
13+
repeatString(" ", numSpaces) ++ repeatString("*", numStars)
14+
15+
baklava :: (int, int) -> ()
16+
baklava n ne = if (n <= ne) then do {
17+
putStrLn(baklavaLine(n));
18+
baklava(n + 1, ne);
19+
} else ()
20+
21+
baklava(-10, 10)

0 commit comments

Comments
 (0)