Skip to content

Instantly share code, notes, and snippets.

View thomasgassmann's full-sized avatar

Thomas Gassmann thomasgassmann

View GitHub Profile
def fib(n):
if n <= 2:
return 1
a = [1, 1, 1]
for i in range(3, n + 1):
a[i % 3] = a[(i - 1) % 3] + a[(i - 2) % 3]
return a[n % 3]

Keybase proof

I hereby claim:

  • I am thomasgassmann on github.
  • I am thomasgassmann (https://keybase.io/thomasgassmann) on keybase.
  • I have a public key ASDd0aQwdCYhnTTZ9o6_WdLpgU6FtYMapZ640BkzR--LNQo

To claim this, I am signing this object:

@thomasgassmann
thomasgassmann / commit-msg.sh
Last active October 23, 2018 10:21 — forked from pgilad/Instructions.md
Git commit-msg hook to validate for jira issue or the word merge
#!/usr/bin/env bash
error_msg="Aborting commit. Your commit message does not match the regex. Please provide a format like: '#666 foo bar'"
msg="`cat $1`"
if [[ ! $msg =~ ^#[0-9]{3,9}(.|\n)* ]]; then
echo "$error_msg" >&2
exit 1
fi
x = ['print("x =", x)', 'for m in x: print(m)']
print("x =", x)
for m in x: print(m)
@thomasgassmann
thomasgassmann / missing_values.py
Created June 10, 2018 18:45
Find the missing value in a sequence of numbers by using XOR
from functools import reduce
from operator import xor
def missing_value(numbers):
return reduce(xor, numbers + list(range(len(numbers) + 1)))
if __name__ == '__main__':
# 4
print(missing_value([0, 1, 2, 3, 5, 6, 7]))
@thomasgassmann
thomasgassmann / sum_numbers.py
Created June 10, 2018 18:29
Summing up two numbers in Python without using the + or - operators.
def sum(x, y):
if y == 0:
return x
sum_without_carry = x ^ y
carry = (x & y) << 1
return sum(sum_without_carry, carry)
import winreg
def get_registry_roots(hkey):
results = []
try:
i = 0
while True:
key = winreg.EnumKey(hkey, i)
i += 1
@thomasgassmann
thomasgassmann / fizzbuzz.py
Last active June 23, 2018 22:02
FizzBuzz in Python
rules = {
3: 'Fizz',
5: 'Buzz'
}
for i in range(1, 1000):
output = [rules[key] if i % key == 0 else '' for key in rules]
output = ''.join(output)
print(output if output != '' else i)