This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <time.h> | |
| #include <stdlib.h> | |
| #define ARR_LEN 100 | |
| void swap(int *a, int *b) | |
| { | |
| int temp = *a; | |
| *a = *b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class InfiniteListEmptyError(Exception): | |
| pass | |
| class InfiniteList(list): | |
| """ | |
| Pretty much a regular list, but when iterated over, it does not stop in the end. | |
| Instead, it iterates indefinitely. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from random import SystemRandom | |
| r=SystemRandom() | |
| """ | |
| TASK. | |
| An array A of integers is given. Find all the combinations of indexes i,j,k, so A[i]+A[j]+A[k]==0. Preferably in O(N^2). | |
| It's a variant of 3SUM puzzle. | |
| """ | |
| def bad_algorithm(INPUT): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sys import argv | |
| IN = float(argv[1]) | |
| PRECISION = 0.000000001 | |
| if IN == 1: | |
| i = 1 | |
| elif IN > 1: | |
| i = IN/2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdbool.h> | |
| #include <string.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int findPatternRight(char* s, char* pat){ | |
| bool flag = true; | |
| int i, j, k, left; | |
| int len_s = strlen(s); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <ctype.h> | |
| #include <stdio.h> | |
| #include <math.h> | |
| double atod(char * s) | |
| { | |
| int i; | |
| for(i=0;isspace(s[i]);i++); | |
| int sign = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from itertools import groupby | |
| def split_list(alist,max_size=1): | |
| """Yield successive n-sized chunks from l.""" | |
| for i in range(0, len(alist), max_size): | |
| yield alist[i:i+max_size] | |
| def toAscii85(data): | |
| result = [] | |
| for chunk in split_list(data, max_size=4): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| number_pattern = r"(([1-9]?[0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))" | |
| IP_validator = re.compile(r'^{0}(\.{0}){1}$'.format(number_pattern, "{3}")) | |
| def is_valid_IP(strng): | |
| return bool(IP_validator.match(strng)) | |
| is_valid_IP("12.34.56.708") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| A function that takes a list and a number. Returns the maximum number that is no larger than def_max. | |
| """ | |
| def bad_definedMax(in_array, def_max): | |
| """ | |
| O(N) (not counting the sorting) | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // reverses a string of space-separated words terminated by newline | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| void swap(char* arr, int i, int j){ | |
| char t = arr[j]; | |
| arr[j] = arr[i]; | |
| arr[i] = t; | |
| } |