/prog/ - Programming General
Posted: Fri Jun 19, 2026 5:05 pm
Discuss about what to program and how to program.
Welcome to the official forum of PANTSU PROPHET:
https://forums.pantsuprophet.xyz/
Code: Select all
#include <stdio.h>
const char *ARRAY[15] = {
"FizzBuzz", "", "", "Fizz", "",
"Buzz", "Fizz", "", "", "Fizz",
"Buzz", "", "Fizz", "", ""
};
int main(void) {
int num, i;
printf("Num? ");
scanf("%d", Num);
for (i=1; i<=num; ++i) {
if (ARRAY[i%15] == "")
printf("%d\n", i);
else
printf("%s\n", ARRAY[i%15]);
}
return 0;
}
You need to surround it with [c0de][/code]
Nice, a mathematician's approach. I think instead of 'if (ARRAY[i%15] = "")' you maybe want 'if (ARRAY[i%15][0] == 0)'?Thricegreat wrote: Sat Jun 20, 2026 8:05 amI would start with a lightweight topic everyone knows: FizzBuzz.
This is my version of it I once posted on my webpage. Which was the only programming post of mine. I think you can find this answer pretty much anywhere too, but the point is that perceiving it as using Z15 instead of Z3 + Z5. Because those are isomorphic.
``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````Code: Select all
#include <stdio.h> const char *ARRAY[15] = { "FizzBuzz", "", "", "Fizz", "", "Buzz", "Fizz", "", "", "Fizz", "Buzz", "", "Fizz", "", "" }; int main(void) { int num, i; printf("Num? "); scanf("%d", Num); for (i=1; i<=num; ++i) { if (ARRAY[i%15] = "") printf("%d\n", i); else printf("%s\n", ARRAY[i%15]); } return 0; }
P.S. It seems I can't show multiple spaces or tabs.
-- Thank you satoridepon.![]()
Code: Select all
#include <stdio.h>
int main(void)
{
for (int i = 1; i <= 100; ++i)
{
if (i != 1)
printf(", ");
if (i % 3 == 0 && i % 5 == 0)
printf("FizzBuzz");
else if (i % 3 == 0) // checking divisibility by 3 again :/
printf("Fizz");
else if (i % 5 == 0) // checking divisibility by 5 again :/
printf("Buzz");
else
printf("%d",i);
}
putchar('\n');
return 0;
}
Code: Select all
#include <stdio.h>
int main(void)
{
for (int i = 1; i <= 100; ++i)
{
if (i != 1)
printf(", ");
int printNum = 1;
if (i % 3 == 0)
{
printf("Fizz");
printNum = 0;
}
if (i % 5 == 0)
{
printf("Buzz");
printNum = 0;
}
if (printNum)
printf("%d",i);
}
putchar('\n');
return 0;
}
Code: Select all
#include <stdio.h>
int main(void)
{
for (int i = 1; i <= 100; ++i)
{
if (i != 1)
printf(", ");
switch ((i % 3 == 0) + ((i % 5 == 0) << 1))
{
case 1: printf("Fizz"); break;
case 2: printf("Buzz"); break;
case 3: printf("FizzBuzz"); break;
default: printf("%d",i); break;
}
}
putchar('\n');
return 0;
}
(edited to a better version now)Code: Select all
#include <stdio.h>
int main(void)
{
int next3Mult = 3, next5Mult = 5;
for (int i = 1; i <= 100; ++i)
{
int printNum = 1;
if (i > 1)
printf(", ");
if (i == next3Mult)
{
printf("Fizz");
next3Mult += 3;
printNum = 0;
}
if (i == next5Mult)
{
printf("Buzz");
next5Mult += 5;
printNum = 0;
}
if (printNum)
printf("%d",i);
}
return 0;
}
Code: Select all
#include <stdio.h>
char str[] = "\0\0\0\0\0\0\0\0Fizz\0\0\0\0Buzz\0\0\0\0FizzBuzz";
char *comma = ", ";
int main(void)
{
for (int i = 1; i <= 100; ++i)
{
// look mom, no branches!
char *s = str;
printf(comma + 2 * (i == 1));
*s = '1'; // convert number to string
s += i >= 100;
*s = '0' + (i / 10) % 10;
s += (*s != '0') | (i >= 100);
*s = '0' + i % 10;
int offset = ((i % 3 == 0) + ((i % 5 == 0) << 1)) << 3;
printf(str + offset);
}
putchar('\n');
return 0;
}
(EDIT: minimized a little more)Code: Select all
#include <stdio.h>
int i;main(){for(;i++<100;printf(", "+2*(i<2))&printf("%d\0FizzBuzz\0Fizz"+!(i%3)*12+!(i%5)*7%16,i));}
Code: Select all
#include <stdio.h>
#define F "Fizz"
#define B "Buzz"
#define FB "FizzBuzz"
#define N "%d"
static const char *pattern[15] = {N,N,F,N,B,F,N,N,F,B,N,F,N,N,FB};
int main(void)
{
int p = 0;
for (int i = 1; i <= 100; ++i)
{
if (i > 1)
printf(", ");
printf(pattern[p],i);
p = p < 14 ? p + 1 : 0;
}
return 0;
}
That is great. A nice job.drummyfish wrote: Sun Jun 21, 2026 8:23 amThricegreat I've taken inspiration in your approach and wrote my own version of it to add to my fizzbuzz collection, thank you for the idea. It uses no division, I think it's a very cool solution overall.
Code: Select all
#include <stdio.h> #define F "Fizz" #define B "Buzz" #define FB "FizzBuzz" #define N "%d" static const char *pattern[15] = {N,N,F,N,B,F,N,N,F,B,N,F,N,N,FB}; int main(void) { int p = 0; for (int i = 1; i <= 100; ++i) { if (i > 1) printf(", "); printf(pattern[p],i); p = p < 14 ? p + 1 : 0; } return 0; }
It's a great topic for discussion in math general or even philosophy general maybe, feel free to bring it up. In this thread it's just an identifier name I guess, I chose it without thinking. "Structure" in this context tends to invoke "data structure" or something that could be confusing. But if you ask me to take off my engineer hat and put on a philosopher hat, I'll agree with you, I choose to think of mathematical structures as perfectly real, just abstract. A starting point I found on Wikipedia can perhaps be this.Thricegreat wrote: Sun Jun 21, 2026 1:23 pmTo note anything, in my mind it was a structure rather than a pattern. Since I think natural numbers are as real as my hands, I regard Z15 as an independently existing structure in the real world. So when I read "pattern" it felt so weird.