Skip to content

DSA algorythm chalenge #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions c/food_line.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// this is a small program solution for food line programing challenge

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#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;
}
86 changes: 86 additions & 0 deletions c/snowflake.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//this program i for to find identical pair of snowflak in given input max of 100000


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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<n; i++)
{
for (j=i+1; j<n; j++)
{
if (isIdentical(snowflaks[i], snowflaks[j]))
{
printf("\nfound identical!\n");
return 1;
}
}
}
printf("\nno identical found!\n");
return 0;
}

int main()
{
int n, i, j;
static int snowflaks[MAXSIZE][6];
printf("Enter number of flaks: ");
scanf("%d", &n);
for ( i=0; i<n; i++)
{
printf("Enter flake patern values: ");
for ( j=0; j<6; j++)
{
scanf("%d", &snowflaks[i][j]);
}
}
identify_identical(snowflaks, n);
return 0;
}