123 lines
3.3 KiB
C
123 lines
3.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* the_array.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/06/15 16:37:33 by whaffman #+# #+# */
|
|
/* Updated: 2024/06/16 13:53:41 by whaffman ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
/*
|
|
“Vogon poetry is of course, the third worst in the universe.
|
|
The second worst is that of the Azgoths of Kria. During a recitation by their
|
|
poet master Grunthos the Flatulent of his poem "Ode to a Small Lump of Green
|
|
Putty I Found in My Armpit One Midsummer Morning" four of his audience died
|
|
of internal haemorrhaging and the president of the Mid-Galactic Arts Nobbling
|
|
Council survived by gnawing one of his own legs off. Grunthos was reported
|
|
to have been "disappointed" by the poem's reception, and was about to embark
|
|
on a reading of his 12-book epic entitled "My Favourite Bathtime Gurgles"
|
|
when his own major intestine, in a desperate attempt to save humanity, leapt
|
|
straight up through his neck and throttled his brain.
|
|
The very worst poetry of all perished along with its creator,
|
|
Paul Neil Milne Johnstone of Redbridge, in the destruction of the planet Earth.
|
|
Vogon poetry is mild by comparison.”
|
|
|
|
*/
|
|
#include <stdlib.h>
|
|
|
|
int **allocate_array(int r, int c)
|
|
{
|
|
int **arr;
|
|
int i;
|
|
|
|
i = 0;
|
|
arr = (int **) malloc(r * sizeof(int *));
|
|
while (i < r)
|
|
{
|
|
arr[i] = (int *) malloc(c * sizeof(int));
|
|
i++;
|
|
}
|
|
return (arr);
|
|
}
|
|
|
|
int **make_the_array(void)
|
|
{
|
|
int **the_array;
|
|
int i;
|
|
int j;
|
|
const int the_ugly_one[144] = {4, 1, 1, 2, 3, 4, 3, 1, 2, 1, 3, 4, 2, 1, \
|
|
3, 1, 2, 4, 3, 1, 1, 3, 2, 4, 3, 1, 2, 3, 1, 4, 2, 1, 3, 2, 1, 4, 2, 2, 3, \
|
|
2, 4, 1, 3, 2, 2, 3, 4, 1, 1, 4, 4, 3, 2, 1, 2, 3, 3, 4, 2, 1, 2, 3, 2, 4, \
|
|
3, 1, 1, 3, 4, 2, 3, 1, 1, 3, 4, 1, 3, 2, 2, 3, 1, 4, 3, 2, 2, 2, 3, 4, 1, \
|
|
2, 1, 3, 4, 3, 1, 2, 3, 2, 1, 3, 4, 2, 2, 2, 3, 1, 4, 2, 2, 2, 2, 1, 4, 3, \
|
|
3, 2, 1, 2, 4, 3, 1, 2, 4, 2, 1, 3, 2, 2, 2, 4, 1, 3, 2, 2, 1, 4, 2, 3, 1, \
|
|
2, 4, 1, 2, 3};
|
|
|
|
the_array = allocate_array(24, 6);
|
|
i = 0;
|
|
while (i < 24)
|
|
{
|
|
j = 0;
|
|
while (j < 6)
|
|
{
|
|
the_array[i][j] = the_ugly_one[6 * i + j];
|
|
j++;
|
|
}
|
|
i++;
|
|
}
|
|
return (the_array);
|
|
}
|
|
|
|
int find_candidate(int front_view, int reverse_view, int index)
|
|
{
|
|
int i;
|
|
int **the_array;
|
|
|
|
i = 0;
|
|
the_array = make_the_array();
|
|
while (i < 24)
|
|
{
|
|
if (the_array[i][0] == front_view && the_array[i][1] == reverse_view)
|
|
{
|
|
if (index == 0)
|
|
{
|
|
free(the_array);
|
|
return (i);
|
|
}
|
|
index--;
|
|
}
|
|
i++;
|
|
}
|
|
free(the_array);
|
|
return (-1);
|
|
}
|
|
|
|
int exists_in_array(int *row)
|
|
{
|
|
int y;
|
|
int x;
|
|
int **the_array;
|
|
|
|
the_array = make_the_array();
|
|
y = 0;
|
|
while (y < 24)
|
|
{
|
|
x = 0;
|
|
while (the_array[y][x] == row[x] && x < 6)
|
|
{
|
|
if (x == 5)
|
|
{
|
|
free(the_array);
|
|
return (1);
|
|
}
|
|
x++;
|
|
}
|
|
y++;
|
|
}
|
|
free(the_array);
|
|
return (0);
|
|
}
|