2021-01-19 02:18:49 +01:00
|
|
|
//
|
|
|
|
// Quiz time again! Let's see if you can solve the famous "Fizz Buzz"!
|
|
|
|
//
|
|
|
|
// "Players take turns to count incrementally, replacing
|
|
|
|
// any number divisible by three with the word "fizz",
|
2021-03-14 07:26:52 +01:00
|
|
|
// and any number divisible by five with the word "buzz".
|
2021-01-19 02:18:49 +01:00
|
|
|
// - From https://en.wikipedia.org/wiki/Fizz_buzz
|
|
|
|
//
|
2023-05-27 01:28:30 +02:00
|
|
|
// Let's go from 1 to 16. This has been started for you, but there
|
|
|
|
// are some problems. :-(
|
2021-01-19 02:18:49 +01:00
|
|
|
//
|
2024-05-27 15:21:28 +02:00
|
|
|
const std = @import("std");
|
2021-01-19 02:18:49 +01:00
|
|
|
|
2024-05-27 15:21:28 +02:00
|
|
|
pub fn main() void {
|
2021-01-19 02:18:49 +01:00
|
|
|
var i: u8 = 1;
|
2023-06-22 11:41:41 +02:00
|
|
|
const stop_at: u8 = 16;
|
2021-01-19 02:18:49 +01:00
|
|
|
|
|
|
|
// What kind of loop is this? A 'for' or a 'while'?
|
2024-05-27 15:21:28 +02:00
|
|
|
while (i <= stop_at) : (i += 1) {
|
2021-01-19 02:18:49 +01:00
|
|
|
if (i % 3 == 0) std.debug.print("Fizz", .{});
|
|
|
|
if (i % 5 == 0) std.debug.print("Buzz", .{});
|
2021-02-15 22:55:44 +01:00
|
|
|
if (!(i % 3 == 0) and !(i % 5 == 0)) {
|
2024-05-27 15:21:28 +02:00
|
|
|
std.debug.print("{}", .{i});
|
2021-01-19 02:18:49 +01:00
|
|
|
}
|
|
|
|
std.debug.print(", ", .{});
|
|
|
|
}
|
2021-02-15 22:55:44 +01:00
|
|
|
std.debug.print("\n", .{});
|
2021-01-19 02:18:49 +01:00
|
|
|
}
|