Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from itertools import combinations
n,m=map(int,input().split())
strings=[]
for i in range(n):
strings.append(input())
combos=list(combinations(strings,2))
or_res=[]
for i in combos:
from itertools import combinations
n,m=map(int,input().split())
strings=[]
for i in range(n):
strings.append(input())
combos=list(combinations(strings,2))
or_res=[]
for i in combos:
or_res.append(bin(int('0b' + i[0], 2) | int('0b' + i[1], 2)).count('1'))
362 changes: 181 additions & 181 deletions Algorithms/Algorithms for Competitive Programming/Deletion.c
Original file line number Diff line number Diff line change
@@ -1,181 +1,181 @@
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int item;
void insert_end();
void delete_by_location();
void delete_by_item();
void display(void);
struct node
{
int data;
struct node *next;
};
struct node *start;
struct node *tail = NULL;
void main()
{
int choice;
printf("PUSH ELEMENTS ONE BY ONE BEFORE DELETING INTO THE LINKED LIST:");
int will;
while(will)
{
insert_end();
printf("ENTER 1 TO CONTINUE INSERTING AND 0 TO STOP:");
scanf("%d",&will);
}
while (1)
{
printf("\n LINKED LIST: \n 1. DELETE BY LOCATION\n 2. DELETE BY VALUE\n 3. DISPLAY\n 4. EXIT\n\n");
printf("\nENTER YOUR CHOICE:\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
delete_by_location();
break;
case 2:
delete_by_item();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\n YOU HAVE ENTERED A WRONG CHOICE\n");
}
}
}
void insert_end()
{
struct node *p = start, *temp;
temp = (struct node *)malloc(sizeof(struct node));
printf("\n ENTER ITEM:\n");
scanf("%d", &item);
temp->data = item;
if (start == NULL)
{
start = temp;
temp->next = NULL;
}
else
{
while (p->next != NULL)
{
p = p->next;
}
p->next = temp;
temp->next = NULL;
}
}
void delete_by_location()
{
struct node *p = start, *old = start, *temp;
int loc, i;
if (start==NULL)
{
printf("NOTHING TO DELETE");
return;
}
printf("\nENTER LOCATION:\n");
scanf("%d", &loc);
for (i = 1; i < loc; i++)
{
p = p->next;
}
if (p == NULL)
{
printf("LOCATION NOT FOUND\n");
free(p);
return;
}
if (p == start)
{
start = start->next;
free(p);
}
else if (p->next == NULL)
{
for (i = 1; i < loc - 1; i++)
{
old = old->next;
}
old->next = NULL;
free(p);
}
else
{
for (i = 1; i < loc - 1; i++)
{
old = old->next;
}
old->next = p->next;
free(p);
}
}
void delete_by_item()
{
int value;
struct node *p = start, *old = start, *temp;
if (start == NULL)
{
printf("NOTHING TO DELETE\n");
return;
}
printf("\nENTER DATA OF A NODE WHICH YOU WISH TO DELETE:\n");
scanf("%d", &value);
while (p->data != value)
{
p = p->next;
if (p==NULL)
{
printf("VALUE ENTERED IS NOT FOUND");
free(p);
return;
}
}
if (p == start)
{
start = start->next;
free(p);
}
else if (p->next == NULL)
{
while (old->next->data != value)
{
old = old->next;
}
old->next = NULL;
free(p);
}
else
{
while (old->next->data != value)
{
old = old->next;
}
old->next = p->next;
free(p);
}
}
void display()
{
struct node *p = start;
printf("\n YOUR LINKED LIST LOOKS LIKE :\n\n");
printf("\n|_START");
while (p != NULL)
{
printf(" |_%d_|_|->", p->data);
p = p->next;
}
printf("[NULL]\n");
}
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int item;
void insert_end();
void delete_by_location();
void delete_by_item();
void display(void);
struct node
{
int data;
struct node *next;
};
struct node *start;
struct node *tail = NULL;
void main()
{
int choice;
printf("PUSH ELEMENTS ONE BY ONE BEFORE DELETING INTO THE LINKED LIST:");
int will;
while(will)
{
insert_end();
printf("ENTER 1 TO CONTINUE INSERTING AND 0 TO STOP:");
scanf("%d",&will);
}
while (1)
{
printf("\n LINKED LIST: \n 1. DELETE BY LOCATION\n 2. DELETE BY VALUE\n 3. DISPLAY\n 4. EXIT\n\n");
printf("\nENTER YOUR CHOICE:\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
delete_by_location();
break;
case 2:
delete_by_item();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\n YOU HAVE ENTERED A WRONG CHOICE\n");
}
}

}
void insert_end()
{
struct node *p = start, *temp;

temp = (struct node *)malloc(sizeof(struct node));
printf("\n ENTER ITEM:\n");
scanf("%d", &item);
temp->data = item;
if (start == NULL)
{
start = temp;
temp->next = NULL;
}
else
{
while (p->next != NULL)
{
p = p->next;
}
p->next = temp;
temp->next = NULL;
}
}
void delete_by_location()
{
struct node *p = start, *old = start, *temp;
int loc, i;
if (start==NULL)
{
printf("NOTHING TO DELETE");
return;
}
printf("\nENTER LOCATION:\n");
scanf("%d", &loc);
for (i = 1; i < loc; i++)
{
p = p->next;
}

if (p == NULL)
{
printf("LOCATION NOT FOUND\n");
free(p);
return;
}
if (p == start)
{
start = start->next;
free(p);
}
else if (p->next == NULL)
{
for (i = 1; i < loc - 1; i++)
{
old = old->next;
}
old->next = NULL;
free(p);
}

else
{
for (i = 1; i < loc - 1; i++)
{
old = old->next;
}
old->next = p->next;
free(p);
}
}
void delete_by_item()
{
int value;
struct node *p = start, *old = start, *temp;
if (start == NULL)
{
printf("NOTHING TO DELETE\n");
return;
}
printf("\nENTER DATA OF A NODE WHICH YOU WISH TO DELETE:\n");
scanf("%d", &value);
while (p->data != value)
{
p = p->next;
if (p==NULL)
{
printf("VALUE ENTERED IS NOT FOUND");
free(p);
return;
}
}

if (p == start)
{
start = start->next;
free(p);
}
else if (p->next == NULL)
{
while (old->next->data != value)
{
old = old->next;
}
old->next = NULL;
free(p);
}


else
{
while (old->next->data != value)
{
old = old->next;
}
old->next = p->next;
free(p);
}
}
void display()
{
struct node *p = start;
printf("\n YOUR LINKED LIST LOOKS LIKE :\n\n");
printf("\n|_START");
while (p != NULL)
{
printf(" |_%d_|_|->", p->data);
p = p->next;
}
printf("[NULL]\n");
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
l=[1,2,3,4,5,5]
print(any(i==j for i,j in zip(l,l[1:])))
l=[1,2,3,4,5,5]
print(any(i==j for i,j in zip(l,l[1:])))
Loading