fizzbuzz.nv
· 2.4 KiB · Text
原始檔案
Playground
|| :: fizzbuzz :n: 1 :max: 100
|:: fizzbuzz :n: $n? :max: $m?|
:: as long as $n is not greater than $m :: then
:: $n is a multiple of 3 :: then
:: it's a fizz number
:: $n is a multiple of 5 :: then
:: it's a buzz number
:: end
:: else :: $n is a multiple of 5 :: then
:: it's a buzz number
:: $n is a multiple of 3 :: then
:: it's a buzz number
:: end
:: end
:: show the number's fizzbuzziness
:: next n :: fizzbuzz
:: end
|:: as long as $n is not greater than $m :@math: greater|
:: false
|:: as long as $n is not greater than $m :@math: $not-greater|
|:: as long as $n is not greater than $m?|
:@math: compare $n $m
|:: $n is a multiple of $m :@math: 0|
|:: $n is a multiple of $m :@math: $nope|
:: false
|:: $n is a multiple of $m?|
:@math: modulo $n $m
|:: it's a fizz number| :fizz:
|:: it's a buzz number| :buzz:
|:: show the number's fizzbuzziness|
:: push new line
:: push buzz
:: push fizz
:: show the fizzbuzziness
|:: push new line|
:message: "\n"
|:: push buzz :buzz:|
:message: "buzz"
|:: push buzz|
|:: push fizz :fizz:|
:message: "fizz"
|:: push fizz|
|:: show the fizzbuzziness :n: $n? :message: "\n"|
:: print (formatted)
:message: "{%d}\n"
:arguments: $n :arguments:
|:: show the fizzbuzziness|
:: print (formatted)
|:: next n :@math: $n|
:n: $n
|:: next n? :n: $n|
:@math: add $n 1
|:: print (formatted)? :message: "{%d}" :arguments:|
|:: print (formatted)? :message: "{%d}" :arguments: $n|
:message: "{}"
:: collect digits of $n
|:: collect digits of $n :div: 0 :mod: $mod|
:: add digit to message $mod
|:: collect digits of $n :div: $div :mod: $mod|
:: add digit to message $mod
:: collect digits of $div
|:: collect digits of $n?|
:: divide by 10 :@math: divide $n 10
:: mod by 10 :@math: modulo $n 10
|:: divide by 10 :@math: $div|
:div: $div
|:: mod by 10 :@math: $mod|
:mod: $mod
|:: add digit to message $n :@math: $char|
:message: $char
|:: add digit to message $n?|
:@math: add 48 $n
|:: print (formatted)? :message: "{}" :arguments: |
|:: print (formatted)? :message: "{}"? :arguments: $char|
:@stdio: write $char
|:: print (formatted)? :message: "\n"|
:@stdio: write 10
|:: print (formatted)? :message: $char|
:@stdio: write $char
|:: print (formatted)|
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)| |