Skip to content

Instantly share code, notes, and snippets.

@nathan818fr
Last active August 29, 2015 14:24
Show Gist options
  • Save nathan818fr/b60d02531d39ae8ad065 to your computer and use it in GitHub Desktop.
Save nathan818fr/b60d02531d39ae8ad065 to your computer and use it in GitHub Desktop.
A WTF epitech my_aff_comb.c - only 8 lines of code in 2 functions (for lucas <3)
int my_aff_combr(int i)
{
if (i % 4 == 3)
my_putchar(',');
my_putchar((i % 4 == 3) ? ' ' : '0' + ((i / 4) / (i % 4 == 0 ? 100 :
(i % 4 == 1) ? 10 : 1) + i % 4) % 10);
if (i < 3111)
my_aff_combr(i + (i % 400 == 311 ? 44 * (3 + i / 400) + 1 :
(i % 40 == 31 ? (4 * (3 + i / 40) + 1) - (i / 400) * 40 : 1)));
}
int my_aff_comb()
{
my_aff_combr(0);
}
// Result:
// 012, 013, 014, 015, 016, 017, 018, 019, 023, 024, 025, 026, 027, 028, 029, 034,
// 035, 036, 037, 038, 039, 045, 046, 047, 048, 049, 056, 057, 058, 059, 067, 068,
// 069, 078, 079, 089, 123, 124, 125, 126, 127, 128, 129, 134, 135, 136, 137, 138,
// 139, 145, 146, 147, 148, 149, 156, 157, 158, 159, 167, 168, 169, 178, 179, 189,
// 234, 235, 236, 237, 238, 239, 245, 246, 247, 248, 249, 256, 257, 258, 259, 267,
// 268, 269, 278, 279, 289, 345, 346, 347, 348, 349, 356, 357, 358, 359, 367, 368,
// 369, 378, 379, 389, 456, 457, 458, 459, 467, 468, 469, 478, 479, 489, 567, 568,
// 569, 578, 579, 589, 678, 679, 689, 789
// Function my_putchar is included by the 'moulinette':
// void my_putchar(char c)
// {
// write(1, &c, 1);
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment