Skip to content

Instantly share code, notes, and snippets.

View md2perpe's full-sized avatar

Per Persson md2perpe

View GitHub Profile
@md2perpe
md2perpe / primes.py
Created February 11, 2021 22:07
Prime number generator in Python
import itertools
def primes():
def sieve(numbers):
try:
n = next(numbers)
yield n
yield from sieve(filter(lambda m: m%n!=0, numbers))
except StopIteration:
@md2perpe
md2perpe / prepare-commit-msg
Created January 31, 2021 14:06
Prepare commit message for merge
#!/usr/bin/env python3
import sys
import fileinput
import re
if sys.argv[2] == "merge":
with fileinput.input(sys.argv[1], inplace=True) as f:
for line in f:
if line.startswith("Merge branch"):
@md2perpe
md2perpe / fizzbuzz.py
Created December 28, 2020 18:38
FizzBuzz
from itertools import count, cycle
for (n, d3, d5) in zip(count(0), cycle([True, False, False]), cycle([True, False, False, False, False])):
print(("Fizz" if d3 else "")+("Buzz" if d5 else "") or str(n))
@md2perpe
md2perpe / solve.py
Created December 25, 2020 16:32
Solve a specific character addition
# Solve:
# LETA
# +TALL
# =====
# CACHE
for a in range(10):
for e in range(10):
for l in range(10):
for t in range(10):
@md2perpe
md2perpe / .gitignore
Last active December 23, 2020 16:40
Hello world in x86-64 assembly
*.o
@md2perpe
md2perpe / solution.py
Created December 10, 2020 01:11
Simple coding challenge found on Facebook
# https://www.facebook.com/groups/270834543757117/?creative_provider_id=admin_can_post_branded_content&notif_id=1607539332809717&notif_t=qp_notifs_pups_notification_to_mall_dogfood_1730789509&ref=notif
N = 10
for i in range(N):
print("He" * i)
print("Ha" * i)
print("Hi" * i)
@md2perpe
md2perpe / permutations.js
Created January 1, 2014 18:54
Function for generating permutations of a list.
function permutations(list)
{
// Empty list has one permutation
if (list.length == 0)
return [[]];
var result = [];
for (var i=0; i<list.length; i++)
# Maximum unattacked squares
def attacked_from_square(r, c):
attacked = set([])
for i in range(5):
attacked.add((r,i))
attacked.add((i,c))
if 0<=r+i<5 and 0<=c+i<5:
attacked.add((r+i,c+i))
if 0<=r+i<5 and 0<=c-i<5:
################
known_domains = {
"hotmail.com": [],
"gmail.com": [],
"yahoo.com": [],
"mail.ru": [],
}
notfound = []
################
We couldn’t find that file to show.