Skip to content

Instantly share code, notes, and snippets.

@fabian57
fabian57 / onebrc.rs
Last active July 31, 2024 19:01
My implementation of the 1brc challenge in rust
// 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;
#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;
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:])
@fabian57
fabian57 / lattice_paths_0.py
Created May 5, 2015 17:39
OH MON DIEU JE PENSAIS NE JAMAIS LE TROUVER!!!!
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)
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)
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=[[]]):
@fabian57
fabian57 / search_binary_recurs.py
Last active August 29, 2015 14:17
On dirait que ça marche avec les tests
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
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 = ""
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()
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)