Skip to content

Instantly share code, notes, and snippets.

@e-parkinson
e-parkinson / timerBadge.html
Created November 15, 2016 12:18
Google Play badge for Tabata Timer app
<a href='https://play.google.com/store/apps/details?id=esme.parkinson.tabatatimer&utm_source=global_co&utm_medium=prtnr&utm_content=Mar2515&utm_campaign=PartBadge&pcampaignid=MKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1'><img alt='Get it on Google Play' src='https://play.google.com/intl/en_gb/badges/images/generic/en_badge_web_generic.eps'/></a>
@e-parkinson
e-parkinson / simpleCaesarBothDirections.py
Last active September 13, 2015 13:47
Caesar Cipher - known key
'''
Caesar Cipher - encrypt and decrypt
Takes as input: 'e'/'d', key, plaintext/ciphertext
Outputs: ciphertext/plaintext
'''
import os
def encrypt(plaintext, key):
plaintext = plaintext.lower()
shiftBy = key - 32
@e-parkinson
e-parkinson / filter.hs
Last active September 6, 2015 06:49
Filter list, return elements less than n.
import Data.List
f :: Int -> [Int] -> [Int]
f n arr = filter (<n) arr
import Data.List
f :: Int -> [Int] -> [Int]
f n arr = filter (<n) arr
-- The Input/Output section. You do not need to change or modify this part
main = do
n <- readLn :: IO Int
inputdata <- getContents
let
numbers = map read (lines inputdata) :: [Int]
#15 minutes
'''
Input: 2 sets ascending order sorted, separated by semi-colon.
Comma delimited values.
Output: Print out the ascending order sorted intersection of the two lists, one per line.
If no intersection, print empty.
'''
file = open('testValues.txt', 'r')
'''
Input: user enters string consisting of words without spaces
Output: each word is printed on a different line.
In case of overlap, favours shorter words on left hand side.
words.txt is file containing all valid words to check against
'''
def checkIfReal(word):
real = False
file = open('words.txt', 'r')
f :: Int -> [Int] -> [Int]
f n arr = concatMap (replicate n) arr
main :: IO ()
main = getContents >>=
mapM_ print. (\(n:arr) -> f n arr). map read. words
@e-parkinson
e-parkinson / naturalsGaussTrick.py
Created August 24, 2015 19:26
Snippet: find sum of natural numbers to n inclusive using Gauss' trick
n = int(input())
if n % 2 == 0:
total = (n^2 + n)/2
else:
total = (n + 1)*math.floor(n/2) + math.ceiling(n/2)
@e-parkinson
e-parkinson / naturalsRecursion.py
Last active August 29, 2015 14:28
Snippet: find the sum of natural numbers to n inclusive using recursion
i = 0
n = int(input())
running_total = 0
def make_answer(i, n, running_total):
if i > n:
print(running_total)
else:
make_answer(i+1,n,running_total+i)
make_answer(i, n, running_total)
@e-parkinson
e-parkinson / naturalsIteration.py
Last active August 29, 2015 14:28
Snippet: find sum of natural numbers to n inclusive using iteration
n = int(input())
running_total = 0
for i in range(0,n+1):
running_total += i
print(running_total)