Skip to content

Instantly share code, notes, and snippets.

from sys import argv
IN = float(argv[1])
PRECISION = 0.000000001
if IN == 1:
i = 1
elif IN > 1:
i = IN/2
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):
@Highstaker
Highstaker / InfiniteList.py
Created October 13, 2016 15:44
Pretty much a regular list, but when iterated over, it does not stop in the end. Instead, it iterates indefinitely.
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.
"""
@Highstaker
Highstaker / bubblesort.c
Last active October 28, 2016 06:27
Sorting algorithms in different languages
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define ARR_LEN 100
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
@Highstaker
Highstaker / telegram_bot_webhook_example.py
Created August 25, 2016 04:45
A simple bot working on webhooks.
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',
@Highstaker
Highstaker / password_breaker.py
Last active June 27, 2016 11:22
A function that generates a set of variations of a string based on replacers. Good for coming up with passwords with popular replacers (1 for i, 0 for o, etc.)
INPUT = "terminator"
REPLACERS = {
"o" : {"0", "Q"},
"i" : {"1",},
"a" : {"@",},
"e" : {"3",},
}
# Add capitals
#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;
# 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 = ""
@Highstaker
Highstaker / array_operations.py
Last active June 11, 2016 10:12
Studies of numpy library
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]
@Highstaker
Highstaker / argparse_example.py
Created May 31, 2016 13:31
An example of how to use argparse module for Python
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