最後活躍 1748901835

修訂 e312caba5b0111738d1e8ae1702b9da5f9c9b6e6

fizzbuzz.nv 原始檔案 Playground
1|| :: fizzbuzz :n: 1 :max: 100
2
3|:: fizzbuzz :n: $n? :max: $m?|
4 :: as long as $n is not greater than $m :: then
5 :: $n is a multiple of 3 :: then
6 :: it's a fizz number
7 :: $n is a multiple of 5 :: then
8 :: it's a buzz number
9 :: end
10 :: else :: $n is a multiple of 5 :: then
11 :: it's a buzz number
12 :: $n is a multiple of 3 :: then
13 :: it's a buzz number
14 :: end
15 :: end
16 :: show the number's fizzbuzziness
17 :: next n :: fizzbuzz
18 :: end
19
20|:: as long as $n is not greater than $m :@math: greater|
21 :: false
22|:: as long as $n is not greater than $m :@math: $not-greater|
23|:: as long as $n is not greater than $m?|
24 :@math: compare $n $m
25
26|:: $n is a multiple of $m :@math: 0|
27|:: $n is a multiple of $m :@math: $nope|
28 :: false
29|:: $n is a multiple of $m?|
30 :@math: modulo $n $m
31
32|:: it's a fizz number| :fizz:
33|:: it's a buzz number| :buzz:
34
35
36|:: show the number's fizzbuzziness|
37 :: push new line
38 :: push buzz
39 :: push fizz
40 :: show the fizzbuzziness
41
42|:: push new line|
43 :message: "\n"
44
45|:: push buzz :buzz:|
46 :message: "buzz"
47|:: push buzz|
48
49|:: push fizz :fizz:|
50 :message: "fizz"
51|:: push fizz|
52
53|:: show the fizzbuzziness :n: $n? :message: "\n"|
54 :: print (formatted)
55 :message: "{%d}\n"
56 :arguments: $n :arguments:
57
58|:: show the fizzbuzziness|
59 :: print (formatted)
60
61|:: next n :@math: $n|
62 :n: $n
63|:: next n? :n: $n|
64 :@math: add $n 1
65
66|:: print (formatted)? :message: "{%d}" :arguments:|
67|:: print (formatted)? :message: "{%d}" :arguments: $n|
68 :message: "{}"
69 :: collect digits of $n
70
71|:: collect digits of $n :div: 0 :mod: $mod|
72 :: add digit to message $mod
73|:: collect digits of $n :div: $div :mod: $mod|
74 :: add digit to message $mod
75 :: collect digits of $div
76|:: collect digits of $n?|
77 :: divide by 10 :@math: divide $n 10
78 :: mod by 10 :@math: modulo $n 10
79
80|:: divide by 10 :@math: $div|
81 :div: $div
82|:: mod by 10 :@math: $mod|
83 :mod: $mod
84
85|:: add digit to message $n :@math: $char|
86 :message: $char
87|:: add digit to message $n?|
88 :@math: add 48 $n
89
90|:: print (formatted)? :message: "{}" :arguments: |
91|:: print (formatted)? :message: "{}"? :arguments: $char|
92 :@stdio: write $char
93|:: print (formatted)? :message: "\n"|
94 :@stdio: write 10
95|:: print (formatted)? :message: $char|
96 :@stdio: write $char
97|:: print (formatted)|