Skip to content

Commit 0485079

Browse files
committed
sample: Add sample programs from advent blog posts
1 parent 3c9412f commit 0485079

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

sample/100-doors.ys

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
!yamlscript/v0
2+
3+
defn main():
4+
say:
5+
"Open doors after 100 passes:
6+
$(apply str interpose(\", \" open-doors()))"
7+
8+
defn open-doors():
9+
for: .[[d n] map(vector doors() iterate(inc 1)) :when d] n
10+
11+
defn doors():
12+
reduce:
13+
fn [doors idx]: assoc(doors idx true)
14+
into []: repeat(100 false)
15+
map \(dec (% * %)): 1..10

sample/factorial.ys

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env ys-0
2+
3+
defn main(n):
4+
say: factorial(n)
5+
6+
defn factorial(x):
7+
apply *: 2..x

sample/hello-world.ys

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!yamlscript/v0
2+
say: "Hello, world!"

sample/pipeline.ys

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
!yamlscript/v0
2+
->> (1..10):
3+
www: "before map"
4+
map: inc
5+
www: "after map"
6+
filter: \(= 0 (mod % 2)) # odd?
7+
www: "after filter"
8+
reduce: +
9+
www: "after reduce"
10+
=>: say
11+
=>: www

sample/twas-a-bit

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env ys-0
2-
# a-bit-before -- Generate a winter-holiday poem in the Mad Libs style
3-
4-
declare: poem
2+
# twas-a-bit -- Generate a winter-holiday poem in the Mad Libs style
53

64
defn main():
7-
->: poem() say
5+
say: poem()
86

97
data =: load("a-bit-of-data.ys")
108

0 commit comments

Comments
 (0)