class MyClass;
in the beggining or include guards etcclass CGameClient : public IGameClient
{
public:
// all components
CKillMessages m_KillMessages;
CCamera m_Camera;
...
KeHub m_KeHub;
...
}
m_vpAll.insert
call in CGameClient::OnConsoleInit()
and add your kehub instance in the same manner m_vpAll.insert(m_vpAll.end(), {&m_Skins,
&m_CountryFlags,
&m_MapImages,
...
&m_KeHub,
...
&m_GameConsole,
&m_MenuBackground});
(edited)class CGameClient : public IGameClient
{
public:
// all components
CKillMessages m_KillMessages;
CCamera m_Camera;
...
KeHub m_KeHub;
...
}
m_vpAll.insert
call in CGameClient::OnConsoleInit()
and add your kehub instance in the same manner m_vpAll.insert(m_vpAll.end(), {&m_Skins,
&m_CountryFlags,
&m_MapImages,
...
&m_KeHub,
...
&m_GameConsole,
&m_MenuBackground});
(edited)C++
[build] In file included from D:/Projects/KeHub/src/game/client/components/kehub/test.cpp:7:
[build] D:/Projects/KeHub/src/game/client/components/kehub/test.h:4:7: error: redefinition of 'class KeHub'
[build] 4 | class KeHub : public CComponent{
[build] | ^~~~~
[build] In file included from D:/Projects/KeHub/src/game/client/gameclient.h:56,
[build] from D:/Projects/KeHub/src/game/client/components/kehub/test.cpp:5:
[build] D:/Projects/KeHub/src/game/client/components/kehub/test.h:4:7: note: previous definition of 'class KeHub'
[build] 4 | class KeHub : public CComponent{
[build] | ^~~~~
[build] cc1plus.exe: note: unrecognized command-line option '-Wno-nullability-completeness' may have been intended to silence earlier diagnostics
#pragma once
#pragma once
should worktfdata
to residue. I could avoid the cell array by using the 'v' flag, but then I need to do it 4 times for each member in this matrixcellfun
with two arguments worked very well1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz...
(edited)#include <stdio.h>
int
main(int argc, char *argv[])
{
int i, p;
for (i = 1; i <= 100; i++) {
// printf("(i:%d) ", i);
p = 0;
if (i % 3 == 0)
p = 1, printf("fizz");
if (i % 5 == 0)
p = 1, printf("buzz");
if (!p)
printf("%d", i);
printf("\n");
}
}
i hope this gets spoiler proofedvoid main(int argc, char **argv)
thenvoid main(int argc, char **argv)
then void main(int argc, char **argv)
then int test
#include <stdio.h>
int
main()
{
int n, i;
for (n = 1; n < 101; n++) {
if (n % 3 == 0) {
i = 1;
printf("fizz");
}
if (n % 5 == 0) {
i = 1;
printf("buzz");
}
if (i == 1)
printf("\n");
else
printf("%d\n", n);
i = 0;
}
}
#include <stdio.h>
int
main(int argc, char *argv[])
{
int i, p;
for (i = 1; i <= 100; i++) {
// printf("(i:%d) ", i);
p = 0;
if (i % 3 == 0)
p = 1, printf("fizz");
if (i % 5 == 0)
p = 1, printf("buzz");
if (!p)
printf("%d", i);
printf("\n");
}
}
i hope this gets spoiler proofed #include <stdio.h>
int main(void)
{
for(int i = 1; i <= 100; i++) {
if(i % 3 && i % 5)
printf("%d", i);
else
printf("%s%s", i % 3 ? "" : "fizz", i % 5 ? "" : "buzz");
putchar('\n');
}
return 0;
}
#include <stdio.h>
int
main()
{
int n, i;
for (n = 1; n < 101; n++) {
if (n % 3 == 0) {
i = 1;
printf("fizz");
}
if (n % 5 == 0) {
i = 1;
printf("buzz");
}
if (i == 1)
printf("\n");
else
printf("%d\n", n);
i = 0;
}
}
#include <stdio.h>
int main(void)
{
for(int i = 1; i <= 100; i++) {
if !(i % 3 && i % 5)
printf("%s%s", i % 3 ? "" : "fizz", i % 5 ? "" : "buzz");
return
printf("%d", i);
putchar('\n');
}
return 0;
}
#include <stdio.h>
int main(void){for(int i=1;i<101;puts(i++%5?"":"buzz"))printf(i%3?i%5?"%d":"":"fizz",i);}
#include <stdio.h>
int main(void)
{
for(int i = 1; i <= 100; i++) {
if !(i % 3 && i % 5)
printf("%s%s", i % 3 ? "" : "fizz", i % 5 ? "" : "buzz");
return
printf("%d", i);
putchar('\n');
}
return 0;
}
#include <stdio.h>
int main(void) {
int i, d3, d5;
for (i = 1; i <= 100; i++) {
if ((d3 = i % 3) && (d5 = i % 5))
printf("%d", i);
else
printf("%s%s",
d3 ? "" : "fizz",
d5 ? "" : "buzz");
putchar('\n');
}
return 0;
}
#include <stdio.h>
int main(void) {
int i, d3, d5;
for (i = 1; i <= 100; i++) {
if ((d3 = i % 3) && (d5 = i % 5))
printf("%d", i);
else
printf("%s%s",
d3 ? "" : "fizz",
d5 ? "" : "buzz");
putchar('\n');
}
return 0;
}
import fizzbuzz
fizzbuzz.fizzbuzz()
#include <stdio.h>
int main(void)
{
for(int i = 1; i <= 100; i++) {
if(i % 3 && i % 5)
printf("%d", i);
else
printf("%s%s", i % 3 ? "" : "fizz", i % 5 ? "" : "buzz");
putchar('\n');
}
return 0;
}
#include <stdio.h>
int main(void)
{
for(int i = 1; i <= 100; i++) {
if(i % 3 && i % 5)
printf("%d", i);
else
printf("%s%s", i % 3 ? "" : "fizz", i % 5 ? "" : "buzz");
putchar('\n');
makeMeABurger();
}
return 0;
}
warning: implicit declaration of function 'makeMeABurger'
undefined reference to 'makeMeABurger
collect: error: ld returned 1 exit status
#include <stdio.h>
int main(void){for(int i=1;i<101;puts(i++%5?"":"buzz"))printf(i%3?i%5?"%d":"":"fizz",i);}
#include <stdio.h>
int main(void)
{
for(int i = 1; i <= 100; i++) {
if(i % 3 && i % 5)
printf("%d", i);
else
printf("%s%s", i % 3 ? "" : "fizz", i % 5 ? "" : "buzz");
putchar('\n');
makeMeABurger();
}
return 0;
}
#include <stdio.h>
int main(void){for(int i=1;i<101;puts(i++%5?"":"buzz"))printf(i%3?i%5?"%d":"":"fizz",i);}
main(){for(;i<101;puts(i++%5?"":"buzz"))printf(i%3?i%5?"%d":"":"fizz",i);}
In Ansi C it can get shorter I guessmain(){for(;i<101;puts(i++%5?"":"buzz"))printf(i%3?i%5?"%d":"":"fizz",i);}
In Ansi C it can get shorter I guess main(i){for(;i<101;puts(i++%5?"":"buzz"))printf(i%3?i%5?"%d":"":"fizz",i);}
(edited)main(){for(;i<101;puts(i++%5?"":"buzz"))printf(i%3?i%5?"%d":"":"fizz",i);}
In Ansi C it can get shorter I guess fn main()
{
(1..=100).for_each(|this_is_the_current_number| {
let mut is_divisible_by_3 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 -= 3;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 == 0 {
is_divisible_by_3 = true;
}
let mut is_divisible_by_5 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 -= 5;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 == 0 {
is_divisible_by_5 = true;
}
if is_divisible_by_3 | is_divisible_by_5 {
if is_divisible_by_3 {
print!("Fizz")
}
if is_divisible_by_5 {
print!("Buzz")
}
}
else {
print!("{}", this_is_the_current_number)
}
print!("\n")
});
}
(edited)fn main()
{
(1..=100).for_each(|this_is_the_current_number| {
let mut is_divisible_by_3 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 -= 3;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 == 0 {
is_divisible_by_3 = true;
}
let mut is_divisible_by_5 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 -= 5;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 == 0 {
is_divisible_by_5 = true;
}
if is_divisible_by_3 | is_divisible_by_5 {
if is_divisible_by_3 {
print!("Fizz")
}
if is_divisible_by_5 {
print!("Buzz")
}
}
else {
print!("{}", this_is_the_current_number)
}
print!("\n")
});
}
(edited)fn main()
{
(1..=100).for_each(|this_is_the_current_number| {
let mut is_divisible_by_3 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 -= 3;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 == 0 {
is_divisible_by_3 = true;
}
let mut is_divisible_by_5 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 -= 5;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 == 0 {
is_divisible_by_5 = true;
}
if is_divisible_by_3 | is_divisible_by_5 {
if is_divisible_by_3 {
print!("Fizz")
}
if is_divisible_by_5 {
print!("Buzz")
}
}
else {
print!("{}", this_is_the_current_number)
}
print!("\n")
});
}
(edited)fn main()
{
(1..=100).for_each(|this_is_the_current_number| {
let mut is_divisible_by_3 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 -= 3;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 == 0 {
is_divisible_by_3 = true;
}
let mut is_divisible_by_5 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 -= 5;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 == 0 {
is_divisible_by_5 = true;
}
if is_divisible_by_3 | is_divisible_by_5 {
if is_divisible_by_3 {
print!("Fizz")
}
if is_divisible_by_5 {
print!("Buzz")
}
}
else {
print!("{}", this_is_the_current_number)
}
print!("\n")
});
}
(edited)fn main()
{
(1..=100).for_each(|this_is_the_current_number| {
let mut is_divisible_by_3 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 -= 3;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 == 0 {
is_divisible_by_3 = true;
}
let mut is_divisible_by_5 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 -= 5;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 == 0 {
is_divisible_by_5 = true;
}
if is_divisible_by_3 | is_divisible_by_5 {
if is_divisible_by_3 {
print!("Fizz")
}
if is_divisible_by_5 {
print!("Buzz")
}
}
else {
print!("{}", this_is_the_current_number)
}
print!("\n")
});
}
(edited)use divisibility::{by_3, by_4};
fn main()
{
(1..=100).for_each(|this_is_the_current_number| {
let mut is_divisible_by_3 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 -= 3;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 == 0 {
is_divisible_by_3 = true;
}
let mut is_divisible_by_5 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 -= 5;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 == 0 {
is_divisible_by_5 = true;
}
if is_divisible_by_3 | is_divisible_by_5 {
if is_divisible_by_3 {
print!("Fizz")
}
if is_divisible_by_5 {
print!("Buzz")
}
}
else {
print!("{}", this_is_the_current_number)
}
print!("\n")
});
}
(edited)fn main()
{
(1..=100).for_each(|this_is_the_current_number| {
let mut is_divisible_by_3 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 -= 3;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_3 == 0 {
is_divisible_by_3 = true;
}
let mut is_divisible_by_5 = false;
let mut this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 = this_is_the_current_number;
while this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 > 0 {
this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 -= 5;
}
if this_number_will_decrease_to_check_if_the_current_number_is_in_the_zero_modulo_class_of_5 == 0 {
is_divisible_by_5 = true;
}
if is_divisible_by_3 | is_divisible_by_5 {
if is_divisible_by_3 {
print!("Fizz")
}
if is_divisible_by_5 {
print!("Buzz")
}
}
else {
print!("{}", this_is_the_current_number)
}
print!("\n")
});
}
(edited)#![forbid(unsafe_code)]
#![deny(warnings)]
#![deny(clippy::nursery)]
#![deny(clippy::pedantic)]
#![deny(clippy::all)]
use std::{fmt::Display, println, write};
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
struct FizzBuzzGenerator(usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum FizzBuzzPutput {
Fizz,
Buzz,
FizzBuzz,
Number(usize),
}
impl Display for FizzBuzzPutput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Fizz => write!(f, "Fizz"),
Self::Buzz => write!(f, "Buzz"),
Self::FizzBuzz => write!(f, "FizzBuzz"),
Self::Number(x) => write!(f, "{x}"),
}
}
}
impl Iterator for FizzBuzzGenerator {
type Item = FizzBuzzPutput;
fn next(&mut self) -> Option<Self::Item> {
self.0 += 1;
let n5 = self.0 % 5 == 0;
let n3 = self.0 % 3 == 0;
if n5 && n3 {
Some(FizzBuzzPutput::FizzBuzz)
} else if n3 {
Some(FizzBuzzPutput::Fizz)
} else if n5 {
Some(FizzBuzzPutput::Buzz)
} else {
Some(FizzBuzzPutput::Number(self.0))
}
}
}
fn main() {
let epic_fizz_buzz = FizzBuzzGenerator::default();
epic_fizz_buzz.take(20).for_each(|x| println!("{x}"));
}
#![forbid(unsafe_code)]
#![deny(warnings)]
#![deny(clippy::nursery)]
#![deny(clippy::pedantic)]
#![deny(clippy::all)]
use std::{fmt::Display, println, write};
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
struct FizzBuzzGenerator(usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum FizzBuzzPutput {
Fizz,
Buzz,
FizzBuzz,
Number(usize),
}
impl Display for FizzBuzzPutput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Fizz => write!(f, "Fizz"),
Self::Buzz => write!(f, "Buzz"),
Self::FizzBuzz => write!(f, "FizzBuzz"),
Self::Number(x) => write!(f, "{x}"),
}
}
}
impl Iterator for FizzBuzzGenerator {
type Item = FizzBuzzPutput;
fn next(&mut self) -> Option<Self::Item> {
self.0 += 1;
let n5 = self.0 % 5 == 0;
let n3 = self.0 % 3 == 0;
if n5 && n3 {
Some(FizzBuzzPutput::FizzBuzz)
} else if n3 {
Some(FizzBuzzPutput::Fizz)
} else if n5 {
Some(FizzBuzzPutput::Buzz)
} else {
Some(FizzBuzzPutput::Number(self.0))
}
}
}
fn main() {
let epic_fizz_buzz = FizzBuzzGenerator::default();
epic_fizz_buzz.take(20).for_each(|x| println!("{x}"));
}
#![forbid(unsafe_code)]
#![deny(warnings)]
#![deny(clippy::nursery)]
#![deny(clippy::pedantic)]
#![deny(clippy::all)]
use std::{fmt::Display, println, write};
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
struct FizzBuzzGenerator(usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum FizzBuzzPutput {
Fizz,
Buzz,
FizzBuzz,
Number(usize),
}
impl Display for FizzBuzzPutput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Fizz => write!(f, "Fizz"),
Self::Buzz => write!(f, "Buzz"),
Self::FizzBuzz => write!(f, "FizzBuzz"),
Self::Number(x) => write!(f, "{x}"),
}
}
}
impl Iterator for FizzBuzzGenerator {
type Item = FizzBuzzPutput;
fn next(&mut self) -> Option<Self::Item> {
self.0 += 1;
let n5 = self.0 % 5 == 0;
let n3 = self.0 % 3 == 0;
if n5 && n3 {
Some(FizzBuzzPutput::FizzBuzz)
} else if n3 {
Some(FizzBuzzPutput::Fizz)
} else if n5 {
Some(FizzBuzzPutput::Buzz)
} else {
Some(FizzBuzzPutput::Number(self.0))
}
}
}
fn main() {
let epic_fizz_buzz = FizzBuzzGenerator::default();
epic_fizz_buzz.take(20).for_each(|x| println!("{x}"));
}
Option
type. See the module level documentation for more.boost::make_game<teeworlds>
5_i32
by zero
|
= note: #[deny(unconditional_panic)]
on by default5_i32
by zero
|
= note: #[deny(unconditional_panic)]
on by default use macroquad::prelude::*;
#[macroquad::main("BasicShapes")]
async fn main() {
loop {
clear_background(RED);
draw_line(40.0, 40.0, 100.0, 200.0, 15.0, BLUE);
draw_rectangle(screen_width() / 2.0 - 60.0, 100.0, 120.0, 60.0, GREEN);
draw_circle(screen_width() - 30.0, screen_height() - 30.0, 15.0, YELLOW);
draw_text("HELLO", 20.0, 20.0, 20.0, DARKGRAY);
next_frame().await
}
}
use macroquad::prelude::*;
#[macroquad::main("BasicShapes")]
async fn main() {
loop {
clear_background(RED);
draw_line(40.0, 40.0, 100.0, 200.0, 15.0, BLUE);
draw_rectangle(screen_width() / 2.0 - 60.0, 100.0, 120.0, 60.0, GREEN);
draw_circle(screen_width() - 30.0, screen_height() - 30.0, 15.0, YELLOW);
draw_text("HELLO", 20.0, 20.0, 20.0, DARKGRAY);
next_frame().await
}
}
for i in range(1, 101): print(i if (i % 3 and i % 5) else ("Fizz" if not i % 3 else "") + ("Buzz" if not i % 5 else ""))
for i in range(1, 101): print(i if (i % 3 and i % 5) else ("Fizz" if not i % 3 else "") + ("Buzz" if not i % 5 else ""))
#![forbid(unsafe_code)]
#![deny(warnings)]
#![deny(clippy::nursery)]
#![deny(clippy::pedantic)]
#![deny(clippy::all)]
use std::{fmt::Display, println, write};
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
struct FizzBuzzGenerator(usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum FizzBuzzPutput {
Fizz,
Buzz,
FizzBuzz,
Number(usize),
}
impl Display for FizzBuzzPutput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Fizz => write!(f, "Fizz"),
Self::Buzz => write!(f, "Buzz"),
Self::FizzBuzz => write!(f, "FizzBuzz"),
Self::Number(x) => write!(f, "{x}"),
}
}
}
impl Iterator for FizzBuzzGenerator {
type Item = FizzBuzzPutput;
fn next(&mut self) -> Option<Self::Item> {
self.0 += 1;
let n5 = self.0 % 5 == 0;
let n3 = self.0 % 3 == 0;
if n5 && n3 {
Some(FizzBuzzPutput::FizzBuzz)
} else if n3 {
Some(FizzBuzzPutput::Fizz)
} else if n5 {
Some(FizzBuzzPutput::Buzz)
} else {
Some(FizzBuzzPutput::Number(self.0))
}
}
}
fn main() {
let epic_fizz_buzz = FizzBuzzGenerator::default();
epic_fizz_buzz.take(20).for_each(|x| println!("{x}"));
}
i32
instead#![forbid(unsafe_code)]
#![deny(warnings)]
#![deny(clippy::nursery)]
#![deny(clippy::pedantic)]
#![deny(clippy::all)]
use std::{fmt::Display, println, write};
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
struct FizzBuzzGenerator(usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum FizzBuzzPutput {
Fizz,
Buzz,
FizzBuzz,
Number(usize),
}
impl Display for FizzBuzzPutput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Fizz => write!(f, "Fizz"),
Self::Buzz => write!(f, "Buzz"),
Self::FizzBuzz => write!(f, "FizzBuzz"),
Self::Number(x) => write!(f, "{x}"),
}
}
}
impl Iterator for FizzBuzzGenerator {
type Item = FizzBuzzPutput;
fn next(&mut self) -> Option<Self::Item> {
self.0 += 1;
let n5 = self.0 % 5 == 0;
let n3 = self.0 % 3 == 0;
if n5 && n3 {
Some(FizzBuzzPutput::FizzBuzz)
} else if n3 {
Some(FizzBuzzPutput::Fizz)
} else if n5 {
Some(FizzBuzzPutput::Buzz)
} else {
Some(FizzBuzzPutput::Number(self.0))
}
}
}
fn main() {
let epic_fizz_buzz = FizzBuzzGenerator::default();
epic_fizz_buzz.take(20).for_each(|x| println!("{x}"));
}