Skip to content

Instantly share code, notes, and snippets.

@jeek
jeek / ex5-1.pl
Created September 14, 2009 08:23
# "Currently it takes each of the three files, shoves it into a big array, reverses the whole mess, then prints it backwards. How would I make this flip each file and print it before moving to the next?" -Malfeas
# Solution by jeek, obv
# Improved by Malfeas
foreach (@ARGV) {
open CURRENT, $_;
@backwards=reverse <CURRENT>;
foreach (@backwards) {
chomp;
print "$_\n";
}
use strict;
my @map=(
[split (//,"###############")],
[split (//,"# # #")],
[split (//,"# #")],
[split (//,"# ### ####")],
[split (//,"#### ### # #")],
[split (//,"# # #")],
[split (//,"# # #")],
$total=0;
for ($trial=1;$trial<=10000;$trial++) {
$answer=1+int(rand()*52);
print "Trial: $trial\tAnswer: $answer\tGuesses: ";
$guess=-1; $tries=0;
while ($guess != $answer) {
$guess=1+int(rand()*52);
$tries++;
}
print "$tries\n";
$|=1;
for ($n=1;$n<=7;$n++) {
print "-\n"; $answer="";
@set=();
%bad=(); %good=();
$max=10**10;
for ($i=1;$i<=$n;$i++) {push @set,$i;}
while ($count<$max) {
increment();
@jeek
jeek / anothersolution.pl
Created October 5, 2009 09:43
My Project Euler Solutions
$\="\n"; sub ct {($_[0]+$_[0]*int(999/$_[0]))/2*int(999/$_[0]);} print (ct(3)+ct(5)-ct(15));
@jeek
jeek / mastermindsolver.pl
Created October 5, 2009 09:51
a mastermind solver
#!/usr/bin/perl
sub generate {
return int(rand() * 6 + 1) . int(rand() * 6 + 1) . int(rand() * 6 + 1) . int(rand() * 6 + 1);
}
$solution=generate();
for ($x1 = 1 ; $x1 < 7 ; $x1++) {
for ($x2 = 1 ; $x2 < 7 ; $x2++) {
@jeek
jeek / README.txt
Created October 5, 2009 09:53
A little bit of code I wrote involving Swiss tournaments with four participants in each match
A little bit of code I wrote involving Swiss tournaments with four participants in each match
@jeek
jeek / MediaWikiToTiddlyWiki.pl
Created October 17, 2009 02:40
This script converts a MediaWiki to a TiddlyWiki
#!/usr/bin/perl
# MediaWikiToTiddlyWiki.pl
# tossed together by T.J. Eckman on October 16th, 2009
use warnings;
use strict;
use DBI;
my $db = ''; # The name of the database
my $dbhost = 'localhost'; # Where the Wiki is hosted
@jeek
jeek / problem001.py
Created October 16, 2011 03:45
project euler
sum = 0
for i in range(0,1000):
if (i % 3 == 0 or i % 5 == 0):
sum += i
print sum
@jeek
jeek / euler.py
Created December 26, 2011 19:24
Learning to Test
import unittest
from time import time
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
"""
def __init__(self, fn):
self.fn = fn
self.memo = {}