2024-12-21 17:58:39 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2024-12-21 18:20:33 +03:00
|
|
|
#define YELLOW "\033[1;33m#"
|
|
|
|
#define RED "\033[1;31m#"
|
|
|
|
#define BLUE "\033[1;34m#"
|
|
|
|
#define GREEN "\033[1;32m#"
|
2024-12-21 17:58:39 +03:00
|
|
|
#define RESET "\033[0m"
|
|
|
|
|
2024-12-21 18:20:33 +03:00
|
|
|
static char* lightbulbs[] = {RED, YELLOW, BLUE, GREEN};
|
|
|
|
|
2024-12-21 17:58:39 +03:00
|
|
|
typedef struct Garland {
|
2024-12-21 18:20:33 +03:00
|
|
|
char* lightbulbs;
|
2024-12-21 17:58:39 +03:00
|
|
|
unsigned int length;
|
|
|
|
} Garland;
|
|
|
|
|
|
|
|
Garland generate_garland(unsigned int length);
|
|
|
|
void print_garland(Garland* g);
|
|
|
|
|
|
|
|
int main () {
|
|
|
|
Garland g = generate_garland(100);
|
|
|
|
print_garland(&g);
|
|
|
|
}
|
|
|
|
|
|
|
|
Garland generate_garland(unsigned int length) {
|
|
|
|
Garland g;
|
|
|
|
g.lightbulbs = malloc(length * sizeof(char*));
|
|
|
|
g.length = length;
|
|
|
|
for (unsigned int i = 0; i < length; i ++) {
|
2024-12-21 18:20:33 +03:00
|
|
|
g.lightbulbs[i] = rand() % 4;
|
2024-12-21 17:58:39 +03:00
|
|
|
}
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_garland(Garland* g) {
|
|
|
|
for (unsigned int i = 0; i < g->length; i ++) {
|
2024-12-21 18:20:33 +03:00
|
|
|
printf("%s", lightbulbs[g->lightbulbs[i]]);
|
2024-12-21 17:58:39 +03:00
|
|
|
}
|
|
|
|
printf(RESET);
|
|
|
|
printf("\n");
|
|
|
|
}
|