File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 44
55container :
66 image : " rzuckerm/factor"
7- tag : " 0.99-1 "
7+ tag : " 0.100-2 "
88 cmd : " factor {{ source.name }}{{ source.extension }}"
You can’t perform that action at this time.
0 commit comments