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
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
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
#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
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | |
def msg_process(bot, update): | |
bot.sendMessage(131711493,update.message.text + " hello") | |
updater = Updater("176032236:AAF6h2YjwtUfsLP5K5O5wD8xV2dg3VadL5k") | |
disp = updater.dispatcher | |
updater.start_webhook(listen='0.0.0.0', |
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
INPUT = "terminator" | |
REPLACERS = { | |
"o" : {"0", "Q"}, | |
"i" : {"1",}, | |
"a" : {"@",}, | |
"e" : {"3",}, | |
} | |
# Add capitals |
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 <string.h> | |
int main(int argc, char const *argv[]) | |
{ | |
int ndigits[10] = {0}; | |
memset(ndigits, 0, 10 * sizeof(int));//init with zeroes | |
int n_spaces = 0; | |
int n_others = 0; |
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
# https://www.reddit.com/r/dailyprogrammer/comments/4m3ddb/20160601_challenge_269_intermediate_mirror/ | |
import numpy as np | |
def decrypt(inp): | |
mirrors = np.array(list(map(list ,MIRRORS.split('\n')))) | |
TOP = [chr(i) for i in range(97,110)] | |
RIGHT = [chr(i) for i in range(110,123)] | |
LEFT = [chr(i) for i in range(65,78)] | |
BOTTOM = [chr(i) for i in range(78,91)] | |
result = "" |
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 numpy as np | |
a = np.array([20, 30, 40, 50]) | |
b = np.arange(4) | |
# mathematical operationscan be done with arrays. Arrays should be of same size and dimensions | |
print(a+b) # [20 31 42 53] | |
print(a-b) # [20 29 38 47] | |
print(a*b) # [0 30 80 150] | |
print(a/b) # [inf 30 20 16.6666667] |
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 argparse | |
parser = argparse.ArgumentParser() | |
# add a positional argument. THey are treated as strings by default | |
parser.add_argument("echo", help="echo the string you use here") | |
# tell it to treat the argument as an integer | |
parser.add_argument("square", help="display a square of a given number", | |
type=int |