I am an affront to society for (sorta) lying
This commit is contained in:
parent
be94e873b0
commit
44d2d245cd
|
@ -5,45 +5,28 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define RUNTO 999999999
|
||||
#define MAXDIGITSYO 10
|
||||
#define MAXBUFFERYO (MAXDIGITSYO*2)
|
||||
static volatile uint8_t run = 1;
|
||||
|
||||
void siginthandl(int _notused) {
|
||||
run = 0;
|
||||
}
|
||||
|
||||
// I hope you're happy with yourself barrow <3
|
||||
int main(/* int argc, char** argv */) {
|
||||
//setup signal handling
|
||||
signal(SIGINT, siginthandl);
|
||||
|
||||
for (int i = 1; i < RUNTO; i++) { // if we ever get this high we've won computing.
|
||||
if (run) {
|
||||
// setup a buffer, 10 digits is all we need, since we're only going up to 999999999 (plus a null terminator)
|
||||
char buf[MAXBUFFERYO] = "\0";
|
||||
// gotta get that return value.
|
||||
for (int i = 1; i < 999999999; i++) {
|
||||
char buf[20] = "\0";
|
||||
int pos = 0;
|
||||
if (i % 3 == 0) {
|
||||
pos = snprintf(buf+pos, MAXBUFFERYO-pos, "fizz");
|
||||
pos = snprintf(buf+pos, 20-pos, "fizz");
|
||||
if (pos < 0) return ENOMEM;
|
||||
}
|
||||
if (i % 5 == 0) {
|
||||
pos = snprintf(buf+pos, MAXBUFFERYO-pos, "buzz");
|
||||
pos = snprintf(buf+pos, 20-pos, "buzz");
|
||||
if (pos < 0) return ENOMEM;
|
||||
}
|
||||
if (pos == 0) {
|
||||
pos = snprintf(buf+pos, MAXBUFFERYO-pos, "%d", i);
|
||||
pos = snprintf(buf+pos, 20-pos, "%d", i);
|
||||
if (pos < 0) return ENOMEM;
|
||||
}
|
||||
puts(buf);
|
||||
} else {
|
||||
break;
|
||||
if (puts(buf) < 1) {
|
||||
return EIO;
|
||||
}
|
||||
}
|
||||
return 0; // SUCCESS!
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,22 @@
|
|||
* All rights reserved *
|
||||
************************/
|
||||
|
||||
// A memory safe fizzbuzz in rust is much smaller than the same in C, turns out.
|
||||
use std::fmt::Write;
|
||||
|
||||
// still much smaller, hope you're happy barrow
|
||||
|
||||
fn main() {
|
||||
for i in 1..999999999 {
|
||||
if i % 3 == 0 && i % 5 == 0 { println!("fizzbuzz"); }
|
||||
else if i % 3 == 0 { println!("fizz"); }
|
||||
else if i % 5 == 0 { println!("buzz"); }
|
||||
else { println!("{i}"); }
|
||||
let mut buf = String::with_capacity(20);
|
||||
if i % 3 == 0 {
|
||||
write!(&mut buf, "fizz").expect("cannot write to buffer");
|
||||
}
|
||||
if i % 5 == 0 {
|
||||
write!(&mut buf, "buzz").expect("cannot write to buffer");
|
||||
}
|
||||
if buf.is_empty() {
|
||||
write!(&mut buf, "{i}").expect("cannot write to buffer");
|
||||
}
|
||||
println!("{buf}");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue