Skip to content

Instantly share code, notes, and snippets.

def checkdist(a,b,c,d,e,f,g):
array = sorted([abs(0-a),abs(1-b),abs(2-c),abs(3-d),abs(4-e),abs(5-f),abs(6-g)])
i = 0
goodanswer = 1
while (i + 1 < len(array)):
if (array[i] == array[i + 1]):
goodanswer = 0
i += 1
if (goodanswer == 1):
print a,b,c,d,e,f,g,array,"GOOD"
@jeek
jeek / anus.pl
Created April 27, 2012 06:53
Anus evaluation
$| = 1;
use Memoize;
memoize(pullcard);
# Dredger + Faithless Looting + LED + Dredger
# AABC
# Dredger + LED/Putrid Imp + Faithless Looting/Careful Study/Breakthrough/Cephalid Coliseum + Rainbow land
@jeek
jeek / dredge.py
Created April 29, 2012 00:07
Finding Dredge
from collections import defaultdict
import string
import os
def deckstring(deck):
return int("1" * deck[0] + "2" * deck[1] + "3" * deck[2] + "4" * deck[3] + "5" * deck[4] + "6" * deck[5] + "7" * deck[6] + "8" * deck[7] + "9" * deck[8])
def breakdown(deck):
deck = str(deck)
return [deck.count("1"),deck.count("2"),deck.count("3"),deck.count("4"),deck.count("5"),deck.count("6"),deck.count("7"),deck.count("8"),deck.count("9")]
@jeek
jeek / deck.py
Created June 10, 2012 08:15 — forked from anonymous/deck.py
Deck
from random import choice
from copy import deepcopy
import string
def do_save(current_cards, save_file="mydeck.txt"):
filehandle = file(save_file, "w")
for card in current_cards:
filehandle.writelines(card)
filehandle.close()
print "Current card list saved."
@jeek
jeek / euler101.py
Created September 23, 2012 21:50
euler 101
def solve(polynomial):
polymatrix = []
for i in range(len(polynomial)):
polymatrix.append([])
for j in range(len(polynomial)):
polymatrix[i].append(polynomial[i][0] ** j)
polymatrix[i].append(polynomial[i][-1])
for i in range(len(polymatrix)):
divisor = polymatrix[i][i]
for j in range(len(polymatrix[0])):
@jeek
jeek / problem408.py
Last active December 10, 2015 13:19
Euler #408 (Work in progress)
from multiprocessing import Pool
import gmpy
bigmod = 1000000007
class Memoize: # stolen from http://code.activestate.com/recipes/52201/
"""Memoize(fn) - an instance which acts like fn but memoizes its arguments
Will only work on functions with non-mutable arguments
"""
@jeek
jeek / smith.sh
Created March 3, 2013 06:11
The goal here is to build an LFS system by booting a blank VirtualBox guest off an Ubuntu live CD and executing: wget -O - http://wherethisscriptis/smith.sh|sudo bash - work in progress
echo "o
n
p
1
n
w"|sudo fdisk /dev/sda
mke2fs -jv /dev/sda1
export LFS=/mnt/lfs
@jeek
jeek / minecalc.py
Last active December 14, 2015 18:09
A minecraft crafting calculator prototype I put together for a friend of mine.
"""Minecraft crafting calculator"""
from math import ceil
from copy import copy
from difflib import get_close_matches
from re import search
from collections import defaultdict
RAW_MATERIALS = set([
"Iron Ore",
@jeek
jeek / nibbles.py
Created May 19, 2013 03:36
Attempt at writing nibbles
from time import sleep
import curses
import random
screenwidth = 22
screenheight = 22
if __name__ == "__main__":
# Build it all up
path = [-1 for x in range(screenwidth) for y in range(screenheight)]
@jeek
jeek / bored.py
Created December 4, 2013 03:13
Sometimes, I get bored.
print 1, sum([i for i in range(1000) if i % 3 == 0 or i % 5 == 0])
print 2, sum([j for j in [int((((1.0 + 5.0 ** .5) / 2) ** i - ((1 - 5 ** .5) / 2) ** i) / (((1.0 + 5.0 ** .5) / 2) - ((1 - 5 ** .5) / 2))) for i in range(1000)] if j % 2 == 0 and j < 4000000])
print 3, max([i for i in reduce( (lambda r,x: (r.difference_update(range(x*x,int(600851475143 ** .5),2*x)) or r) if (x in r) else r), range(3, int((int(600851475143 ** .5)+1)**0.5+1), 2), set([2] + range(3,int(600851475143 ** .5),2))) if 600851475143 % i == 0])
print 4, max([i * j for i in xrange(100, 1000) for j in range(100, 1000) if str(i * j) == str(i * j)[::-1]])
print 5, reduce(lambda a, b: a * b / sorted(set(map(lambda x: (x*int(a/x)==a) * x, xrange(1,a+1))).intersection(set(map(lambda x: (x*int(b/x)==b) * x, xrange(1,b+1)))))[-1], range(1, 21))
print 6, sum(range(101)) ** 2 - sum([i ** 2 for i in range(101)])
print 7, (lambda table: [[table.__setitem__(mult,False) for mult in range(i**2,1000000,i)] for i in range(2,int(1000000**0.5)+1) if table[