From 2daf276cc0df14bc5fc672c6f3546162f513fa92 Mon Sep 17 00:00:00 2001 From: lovezyou Date: Sun, 6 Oct 2024 16:21:04 +0530 Subject: [PATCH 1/2] added two new challenge programs to the repo --- c/food_line.c | 36 +++++++++++++++++++++ c/snowflak.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 c/food_line.c create mode 100644 c/snowflak.c diff --git a/c/food_line.c b/c/food_line.c new file mode 100644 index 0000000..e18dc4b --- /dev/null +++ b/c/food_line.c @@ -0,0 +1,36 @@ +// this is a small program solution for food line programing challenge + +#include +#include +#include + +#define MAX_LINES 100 + +//finds shortest line for new people +int shortest_line_index(int lines[], int n) { + int j, shortest = 0; + for (j = 1;j < n; j++) + if (lines[j] < lines[shortest]) + shortest = j; + return shortest; +} + +void solve(int lines[], int n, int m) { + int i, shortest; + for (i = 0;i < m; i++) { + shortest = shortest_line_index(lines, n); + printf("in line %d : no of people %d\n", shortest + 1, lines[shortest]); + lines[shortest]++; + } +} + +int main(void) { + int lines[MAX_LINES]; + int n, m, i; + printf("enter number of \"lines\" \"new people\" : "); + scanf("%d%d", &n, &m); + for (i = 0;i < n; i++) + scanf("%d", &lines[i]); + solve(lines, n, m); + return 0; +} diff --git a/c/snowflak.c b/c/snowflak.c new file mode 100644 index 0000000..ee3613d --- /dev/null +++ b/c/snowflak.c @@ -0,0 +1,86 @@ +//this program i for to find identical pair of snowflak in given input max of 100000 + + +#include +#include +#include +#define MAXSIZE 100000 + +//this function check tow flaks are identical from the starting position to the right +int identical_right (int flak1[], int flak2[], int start) +{ + int offset; + for (offset = 0; offset < 6; offset++) + { + if (flak1[offset] != flak2[(start + offset) % 6]) + return 0; + } + return 1; +} + +//checks flaks are identical from start to left +int identical_left (int flak1[], int flak2[], int start) +{ + int offset; + for (offset = 0; offset < 6; offset++) + { + if ((start - offset) < 0) + if (flak1[offset] != flak2[(start - offset) + 6]) + return 0; + if (flak1[offset] != flak2[(start - offset) + 6]) + return 0; + + } + return 1; +} + +//returns true if flaks identical in start to left or right else false +int isIdentical (int flak1[], int flak2[]) +{ + int start; + for (start = 0; start < 6; start++) + { + if (identical_right(flak1, flak2, start)) + return 1; + if (identical_left(flak1, flak2, start)) + return 1; + } + return 0; +} + +//taks array of snowflakes and checks for identiacl +int identify_identical(int snowflaks[][6], int n) +{ + int i, j; + for ( i=0; i Date: Sun, 6 Oct 2024 10:57:28 +0000 Subject: [PATCH 2/2] Rename snowflak.c to snowflake.c --- c/{snowflak.c => snowflake.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename c/{snowflak.c => snowflake.c} (100%) diff --git a/c/snowflak.c b/c/snowflake.c similarity index 100% rename from c/snowflak.c rename to c/snowflake.c