Skip to content

Commit 99bd843

Browse files
authored
Add Baklava in Factor (#4188)
1 parent e1c594e commit 99bd843

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

archive/f/factor/baklava.factor

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
USING: io kernel math prettyprint ranges sequences ;
2+
IN: baklava
3+
4+
! Based on https://rosettacode.org/wiki/Repeat_a_string#Factor
5+
! but reversed arguments for fewer operations
6+
: repeat-string ( n str -- str' ) <repetition> concat ;
7+
8+
: baklava-line ( n -- str )
9+
10 - abs ! stack: num-spaces = abs(n - 10)
10+
dup ! stack: num-spaces, num-spaces
11+
" " ! stack: num-spaces, num-spaces, " "
12+
repeat-string ! stack: num-spaces, spaces = " " num-spaces times
13+
swap ! stack: spaces, num-spaces
14+
-2 * 21 + ! stack: spaces, num-stars = 21 - 2 * num-spaces
15+
"*" ! stack: spaces, num-stars, "*"
16+
repeat-string ! stack: spaces, stars = "*" num-stars times
17+
append ! stack: spaces + stars
18+
;
19+
20+
! For n = 0 to 20, output Baklava line n
21+
20 [0..b] [ baklava-line print ] each

archive/f/factor/testinfo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ folder:
44

55
container:
66
image: "rzuckerm/factor"
7-
tag: "0.99-1"
7+
tag: "0.100-2"
88
cmd: "factor {{ source.name }}{{ source.extension }}"

0 commit comments

Comments
 (0)