Skip to content

Instantly share code, notes, and snippets.

@mika-f
Last active September 21, 2023 12:32
Show Gist options
  • Save mika-f/64eed752c2d68b3e50160205729e51d4 to your computer and use it in GitHub Desktop.
Save mika-f/64eed752c2d68b3e50160205729e51d4 to your computer and use it in GitHub Desktop.
// Compiled on CentOS 7 x64
// $ gcc --version
// gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
// Copyright (C) 2015 Free Software Foundation, Inc.
// This is free software; see the source for copying conditions. There is NO
// warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// $ rm pure.out
// $ gcc pure.c -o pure.out
// $ ./pure.out
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void entry();
int fb(int n);
void _print(char* s);
void plain(int n, char* str);
void fizz(int n, char* str);
void buzz(int n, char* str);
void fizzbuzz(int n, char* str);
void init_B();
void init_F();
void init_i();
void init_u();
void init_z();
void init_n();
// 64byte (16 * 4)
struct b_t {
long double _a;
long double _b;
long double _c;
long double _d;
};
// 32byte
struct i_t {
long double _b;
long double _c;
};
char b, f, i, u, z, _;
int _1 = sizeof(char);
int _2 = sizeof(short);
int _4 = sizeof(int);
int _8 = sizeof(long);
int _16 = sizeof(long long);
int _32 = sizeof(struct i_t);
int _64 = sizeof(struct b_t);
// N % 15 == 0 : 15
//
// fizzbuzz 本体
void (*fire[])(int, char*) = {
fizzbuzz, // 15
plain, // 14
plain, // 13
fizz, // 12
plain, // 11
buzz, // 10
fizz, // 9
plain, // 8
plain, // 7
fizz, // 6
buzz, // 5
plain, // 4
fizz, // 3
plain, // 2
plain, // 1
};
int main() {
entry();
return;
}
// FizzBuzz
void entry() {
init_B();
init_F();
init_i();
init_u();
init_z();
init_n();
fb(_1);
}
int fb(int n) {
char* str = (char*)malloc(sizeof(char) * _16);
fire[n % (_8 + _4 + _2 + _1)](n, str);
_print(str);
free(str);
return n == (_64 + _32 + _4) ? _1 : fb(n + _1);
}
void _print(char* c) {
printf(c);
}
// "0" = 48
void plain(int n, char* str) {
char v = (n >= (_8 + _2)) ? (n / (_8 + _2) % (_8 + _2) + (_32 + _16 + _8)) : (_1 - _1);
strncat(str, &v, _1);
// 1桁目
char w = (n % (_8 + _2) + (_32 + _16 + _8));
strncat(str, &w, _1);
strncat(str, &_, _1);
}
void fizz(int n /*BLANK*/, char* str) {
strncat(str, &f, _1);
strncat(str, &i, _1);
strncat(str, &z, _1);
strncat(str, &z, _1);
strncat(str, &_, _1);
}
void buzz(int n /*BLANK*/, char* str) {
strncat(str, &b, _1);
strncat(str, &u, _1);
strncat(str, &z, _1);
strncat(str, &z, _1);
strncat(str, &_, _1);
}
void fizzbuzz(int n /*BLANK*/, char* str) {
strncat(str, &f, _1);
strncat(str, &i, _1);
strncat(str, &z, _1);
strncat(str, &z, _1);
strncat(str, &b, _1);
strncat(str, &u, _1);
strncat(str, &z, _1);
strncat(str, &z, _1);
strncat(str, &_, _1);
}
// B = 66
void init_B() {
b = _64 + _2;
}
// F = 70
void init_F() {
f = b + _4;
}
// i = 105
void init_i() {
i = f + _32 + _2 + _1;
}
// u = 117
void init_u() {
u = i + _8 + _4;
}
// z = 122
void init_z() {
z = u + _4 + _1;
}
// \n = 10
void init_n() {
_ = _8 + _2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment