Skip to content

Instantly share code, notes, and snippets.

Avatar

Per Persson md2perpe

View GitHub Profile
View a_not_so_magic_square.c
#include <stdio.h>
typedef int square;
typedef int row;
typedef int col;
int is_valid_row(row n)
{
return (
n == 0b0011 ||
View pi_sequence.hs
t :: Integer -> Float
t 0 = 0
t n = sqrt(2 + t(n-1))
p :: Integer -> Float
p n = 2**(n+1) * sqrt(2 - t(n))
View monads.ts
interface Thenable<a> {
then<b>(cont: (_: a) => Thenable<b>): Thenable<b>;
}
/*
run_slow_task.then((result) => {
do_something(result).then((new_result) => {
do_something_else(new_result)
})
})
@md2perpe
md2perpe / primes.py
Created Feb 11, 2021
Prime number generator in Python
View primes.py
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 Jan 31, 2021
Prepare commit message for merge
View prepare-commit-msg
#!/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 / .gitignore
Last active Aug 21, 2021
StackOverflow 64497615
View .gitignore
venv/
*.pyc
View fizzbuzz.py
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 Dec 25, 2020
Solve a specific character addition
View solve.py
# 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 Dec 23, 2020
Hello world in x86-64 assembly
@md2perpe
md2perpe / solution.py
Created Dec 10, 2020
Simple coding challenge found on Facebook
View solution.py
# 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)