1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-05-31 18:41:30 +00:00
millfork/examples/crossplatform/fizzbuzz2.mfk

42 lines
766 B
Plaintext
Raw Permalink Normal View History

2019-07-26 22:58:10 +00:00
import stdio
bool divisible3(byte x) = x %% 3 == 0
bool divisible5(byte x) = x %% 5 == 0
struct stage {
function.byte.to.bool predicate
pointer text
}
2020-07-31 14:07:39 +00:00
#if ENCODING_NOLOWER
array(stage) stages = [
stage(divisible3.pointer, "FIZZ"z),
stage(divisible5.pointer, "BUZZ"z)
]
#else
2019-07-26 22:58:10 +00:00
array(stage) stages = [
2019-07-26 23:38:06 +00:00
stage(divisible3.pointer, "fizz"z),
stage(divisible5.pointer, "buzz"z)
2019-07-26 22:58:10 +00:00
]
2020-07-31 14:07:39 +00:00
#endif
2019-07-26 22:58:10 +00:00
void main() {
byte i, s
bool printed
for i,1,to,100 {
printed = false
for s,0,until,stages.length {
if call(stages[s].predicate, i) {
printed = true
2019-07-26 23:11:46 +00:00
putstrz(stages[s].text)
2019-07-26 22:58:10 +00:00
}
}
if not(printed) {
putword(i)
}
putchar(' ')
}
}