Skip to content

Instantly share code, notes, and snippets.

View soimort's full-sized avatar

Mort Yao soimort

View GitHub Profile
@soimort
soimort / kalendar
Created September 14, 2011 13:39
HKR kursschema ics converter
<?php
$file = file_get_contents($_GET['URL'], "r") or die("Error. File not found");
$lower = html_entity_decode(strstr($file, "</tr><tr"), ENT_QUOTES);
$line = (explode("</tr>", $lower));
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:PHP\n";
@soimort
soimort / main.c
Created December 1, 2011 15:42
ECB-DES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void exor4(char *destination, const char *source1, const char *source2)
{
*destination &= 0x0F;
for (int i = 0; i < 4; i++)
*destination |= (((*source1 >> (7 - i)) & 1) ^ ((*source2 >> (7 - i)) & 1)) << (7 - i);
@soimort
soimort / pe001.py
Created March 5, 2012 00:47
Project Euler - Problem 1
print(3 * (999 // 3 + 1) * (999 // 3) // 2
+ 5 * (999 // 5 + 1) * (999 // 5) // 2
- 15 * (999 // 15 + 1) * (999 // 15) // 2)
@soimort
soimort / pe002.py
Created March 5, 2012 00:52
Project Euler - Problem 2
a, b, i, sum = 1, 2, 2, 0
while b <= 4000000:
if b % 2 == 0:
sum += b
a, b, i = b, a + b, i + 1
print(sum)
@soimort
soimort / pe003.py
Created March 5, 2012 00:54
Project Euler - Problem 3
n = 600851475143
while n % 2 == 0:
n //= 2
i = 1
while n > 1:
i += 2
while n % i == 0:
n //= i
print(i)
@soimort
soimort / pe004.py
Created March 5, 2012 15:44
Project Euler - Problem 4
for n in range(999, 99, -1):
m = int(str(n) + str(n)[::-1])
for i in range(999, 99, -1):
if m % i == 0 and len(str(m // i)) == 3:
print(m)
exit()
@soimort
soimort / pe005.py
Created March 5, 2012 15:47
Project Euler - Problem 5
def gcd(a, b):
if a:
return gcd(b % a, a)
else:
return b
lcm = lambda a, b: a * b // gcd(a, b)
m = 1
for i in range(2, 21):
m = lcm(m, i)
print(m)
@soimort
soimort / pe006.py
Created March 5, 2012 15:47
Project Euler - Problem 6
print(((100 + 1) * 100 // 2) ** 2
- sum([i ** 2 for i in range(1, 101)]))
@soimort
soimort / pe007_1.py
Created March 5, 2012 19:50
Project Euler - Problem 7
def prime(n):
if n == 1:
return 2
else:
i = prime(n - 1)
isPrime = False
while not isPrime:
i += 1
isPrime = True
for j in range(1, n):
@soimort
soimort / pe007_2.py
Created March 5, 2012 19:52
Project Euler - Problem 7
def prime(n):
primes = [2]
for k in range(1, n):
i = primes[k - 1]
isPrime = False
while not isPrime:
i += 1
isPrime = True
for j in range(0, k):
if i % primes[j] == 0: