Skip to content

Instantly share code, notes, and snippets.

@globby
globby / DP138.scala
Last active December 26, 2015 14:28
DailyProgrammer #138 Scala
import math._
val g = () => Console.readLine("Params: ").split(' ') map ((x) => x.toFloat)
val a = g()
val b = g()
println(pow(a(0), 2)/(pow(a(1)-b(1), 2) + pow(a(2)-b(2), 2)))
This file has been truncated, but you can view the full file.
==============================
Methionylthreonylthreonylglutaminylarginyltyrosylglutamylserylleucylphenylalanylalanylglutaminylleuc yllysylglutamylarginyllysylglutamylglycylalanylphenylalanylvalylprolylphenylalanylvalylthreonylleucylgl ycylaspartylprolylglycylisoleucylglutamylglutaminylserylleucyllysylisoleucylaspartylthreonylleucylisoleu cylglutamylalanylglycylalanylaspartylalanylleucylglutamylleucylglycylisoleucylprolylphenylalanylseryla spartylprolylleucylalanylaspartylglycylprolylthreonylisoleucylglutaminylasparaginylalanylthreonylleucyl arginylalanylphenylalanylalanylalanylglycylvalylthreonylprolylalanylglutaminylcysteinylphenylalanylglu tamylmethionylleucylalanylleucylisoleucylarginylglutaminyllysylhistidylprolylthreonylisoleucylprolylisol eucylglycylleucylleucylmethionyltyrosylalanylasparaginylleucylvalylphenylalanylasparaginyllysylglycyli soleucylaspartylglutamylphenylalanyltyrosylalanylglutaminylcysteinylglutamyllysylvalylglycylvalylaspa rtylserylvalylleucylvalylalanylaspartylvalylprolylvalylglut
@globby
globby / adler32.py
Last active August 29, 2015 13:56
Adler32 Checksum Algorithm
def adler32(string):
a = map(ord,string)
b = [sum(a[:i])+1%65521 for i in range(len(a)+1)]
return (sum(b) << 16) | max(b)
@globby
globby / postfix.py
Last active August 29, 2015 13:56
Just a random mockup of a postfix evaluator
from operator import *
def isInt(x):
try:
a = float(x)
b = int(a)
except ValueError:
return False
else:
return a == b
def Postfix(exp):
@globby
globby / InsertionSort.py
Created March 3, 2014 23:41
The Insertion Sort algorithm
def insertion(a):
if len(a) < 2: return
for i in range(len(a)):
k = i
while k > 1 and a[k] < a[k-1]:
a[k], a[k-1] = a[k-1], a[k]
k -= 1
@globby
globby / SelectionSort.py
Created March 3, 2014 23:42
The Selection Sort algorithm
def selection(a):
if len(a) < 2: return
for i in range(0,len(a)):
k = i
for j in range(i+1,len(a)):
if a[j] < a[k]: k = j
a[i], a[k] = a[k], a[i]
@globby
globby / BubbleSort.py
Created March 3, 2014 23:43
The Bubble Sort algorithm
def bubble(a):
if len(a) < 2: return
for i in range(0,len(a)):
swapped = False
for j in range(len(a)-1,i+1,-1):
if a[j] < a[j-1]:
a[j], a[j-1], swapped = a[j-1], a[j], True
if not swapped: break
@globby
globby / Quicksort.py
Created March 3, 2014 23:44
The Quicksort algorithm
def quicksort(a):
if len(a) <= 1: return a
pivot = a.pop(len(a)/2)
less, greater = [], []
for x in a:
if x <= pivot:
less.append(x)
else:
greater.append(x)
return quicksort(less) + [pivot] + quicksort(greater)
@globby
globby / Fletcher.py
Created March 4, 2014 00:35
The Fletcher16, Fletcher32 and Fletcher64 algorithms
def Fletcher16(string):
a = map(ord,string)
b = [sum(a[:i])%255 for i in range(len(a)+1)]
return (sum(b) << 8) | max(b)
def Fletcher32(string):
a = map(ord,string)
b = [sum(a[:i])%65535 for i in range(len(a)+1)]
return (sum(b) << 16) | max(b)
def Fletcher64(string):
a = map(ord,string)
@globby
globby / Verhoeff.py
Created March 4, 2014 01:19
A slightly confusing implementation of the Verhoeff algorithm
def verhoeff(string):
string, c = list(string)[::-1], 0
d, p, inv = map(lambda x:(lambda f,s:[map(int,list(f[i:i+s])) for i in range(0,len(f),s)])("0"+str(int(x,32)),10),
["1pphkblhcil6aq7anvo920aj7hpi14o8nu4t71vvat8a270c2avapk1868t7300dna",
"labkl84c4rp10j7aqnspj1hi8k79r7o790ac4n72ok70e8uale7a",
"cs4c3l"])
for i, v in enumerate(string):
c = d[c][p[i%8][int(v)]]
return c == 0