/prog/ - Programming General
-
Thricegreat
- Posts: 171
- Joined: Tue Jun 09, 2026 9:30 am
- Has thanked: 163 times
- Been thanked: 210 times
- Contact:
-
Thricegreat
- Posts: 171
- Joined: Tue Jun 09, 2026 9:30 am
- Has thanked: 163 times
- Been thanked: 210 times
- Contact:
Re: /prog/ - Programming General
I 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 perceiving it as using Z15 instead of Z3 + Z5. Because those are isomorphic.
`````````````````````````````````````````````````````````````````````````````
`````````````````````````````````````````````````````````````````````````````
P.S. It seems I can't show multiple spaces or tabs.
-- Thank you satoridepon. :)
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 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. :)
Last edited by Thricegreat on Sat Jun 20, 2026 3:58 pm, edited 6 times in total.
-
satoridepon
- Posts: 29
- Joined: Fri May 29, 2026 11:09 pm
- Has thanked: 79 times
- Been thanked: 60 times
-
drummyfish
- Posts: 103
- Joined: Wed May 27, 2026 1:10 pm
- Location: Moravia (Czech Republic)
- Has thanked: 167 times
- Been thanked: 170 times
- Contact:
Re: /prog/ - Programming General
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.![]()
I tried writing FizzBuzz in different ways for my wiki. Here's what I came up with.
This is like the "normal", basic solution:
Spoiler
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;
}
Spoiler
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;
}
Spoiler
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)Spoiler
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;
}
Spoiler
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)Spoiler
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));}
Last edited by drummyfish on Mon Jun 22, 2026 12:00 pm, edited 1 time in total.
love everyone, help selflessly
-
drummyfish
- Posts: 103
- Joined: Wed May 27, 2026 1:10 pm
- Location: Moravia (Czech Republic)
- Has thanked: 167 times
- Been thanked: 170 times
- Contact:
Re: /prog/ - Programming General
Thricegreat 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;
}
love everyone, help selflessly
-
Thricegreat
- Posts: 171
- Joined: Tue Jun 09, 2026 9:30 am
- Has thanked: 163 times
- Been thanked: 210 times
- Contact:
Re: /prog/ - Programming General
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; }
To 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.
But that is just my autistic screeching. And I don't think this thread is the place to talk about matters like this. So feel free about that. Your version is better than mine anyway.
-
drummyfish
- Posts: 103
- Joined: Wed May 27, 2026 1:10 pm
- Location: Moravia (Czech Republic)
- Has thanked: 167 times
- Been thanked: 170 times
- Contact:
Re: /prog/ - Programming General
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.
love everyone, help selflessly