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
// Run with target-cpu="native" | |
// Commit history at https://git.plobos.xyz/Playground/1brc/src/branch/main/src/main/rust | |
use std::{ | |
fs::File, | |
io::BufReader, | |
thread, | |
}; | |
use std::collections::HashMap; | |
use std::fmt::Display; |
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 <stdlib.h> | |
#include <string.h> | |
#include <time.h> | |
int is_equal(char guess, char sol[]){ | |
int j = 0; | |
for(; j <= strlen(sol); j++){ | |
if(guess == sol[j]){ | |
return 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
TARGET = 200 | |
coins = (1, 2, 5, 10, 20, 50, 100, 200) | |
def coin_search(coins): | |
if min(coins) == TARGET: | |
return 1 | |
elif min(coins) > TARGET: | |
return 0 | |
else: | |
return coin_search(TARGET-min(coins), coins) + coin_search(TARGET, coins[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
SIZE = 20 | |
cache = { (SIZE, SIZE): 0,} | |
def search(x, y): | |
if (x, y) not in cache: | |
if x == SIZE or y == SIZE: | |
return 1 | |
else: | |
cache[x+1, y] = search(x+1, y) | |
cache[x, y+1] = search(x, y+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
height = input("How high should it be?") | |
levels = input("How many levels should it have?") | |
import turtle | |
t = turtle.Turtle() | |
t.speed(0) | |
t.hideturtle() | |
t.penup() | |
t.left(90) | |
t.backward(height*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
def suffix_sequences(suffix, seq): | |
result = [] | |
for l in seq: | |
result.append(l+[suffix]) | |
return result | |
from math import log | |
def power_list(seq, 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
def binary_search(seq, x): | |
def recurs(low, high): | |
if low <= high: | |
mid = low + (high - low) / 2 | |
if x < seq[mid]: | |
return recurs(low, mid-1) | |
elif x > seq[mid]: | |
return recurs(mid+1, high) | |
else: | |
return mid |
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
VALID_LENGTHS = dict() | |
for s in open("is_valid_iban_data.txt").read().split("\n"): | |
VALID_LENGTHS[s[:2]] = int(s[3:]) | |
def is_valid_iban(string): | |
iban = string.replace(" ", "").replace("-", "").upper() | |
if len(iban) == VALID_LENGTHS[iban[:2]]: | |
inverted_iban = iban[4:] + iban[:4] | |
number = "" |
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
DATA = { | |
"A": {"unlimited": 70, "package": 50, "extra_mile": 1}, | |
"B": {"unlimited": 140, "package": 100, "extra_mile": 1.5}, | |
} | |
DAILY_MILEAGE_LIMIT = 200 | |
mileage = input("Mileage? ") | |
duration = input("Duration (days)? ") | |
category = raw_input("Category (A or B)? ").upper() |
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
def unique_elements(l): | |
set_1 = set() | |
set_2 = set() | |
for i in l: | |
if i not in set_1: | |
set_1.add(i) | |
else: | |
set_2.add(i) | |
return set_1.difference(set_2) |
NewerOlder