-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaguenaudier.c
46 lines (42 loc) · 1001 Bytes
/
Baguenaudier.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void operer(int NC, int C[NC], int Act, int operation)
{
int A = operation;
// vider = 0, remplir = 1
if (Act == 1 && C[Act] == 1 - A && C[0] == 1)
{
C[Act] = A;
printf("%d\n", Act + 1);
}
else if (Act == 0 && C[Act] == 1 - A)
{
C[Act] = A;
printf("%d\n", Act + 1);
}
else
{
if (C[Act - 1] == 0 && Act != 0)
operer(NC, C, Act - 1, 1);
for (int verifier = Act - 2; verifier >= 0; verifier--)
if (C[verifier] == 1)
operer(NC, C, verifier, 0);
C[Act] = A;
printf("%d\n", Act + 1);
}
}
int main()
{
int Nombre_Cases;
scanf(" %d", &Nombre_Cases);
int Cases[Nombre_Cases];
for (int Act = 0; Act < Nombre_Cases; Act++)
Cases[Act] = 1;
int Actuel = Nombre_Cases - 1;
while (Actuel >= 0)
{
operer(Nombre_Cases, Cases, Actuel, 0);
Actuel--;
}
}