This commit is contained in:
madmaurice 2014-08-31 06:14:41 +02:00
parent 122e673838
commit f867230642
14 changed files with 160 additions and 3 deletions

7
azzzzz.py Normal file
View file

@ -0,0 +1,7 @@
def fn(pre,n):
p = (lambda c: print(pre+c),lambda c: fn(pre+c,n-1))[min(n,1)]
list(map(p,['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']))
p = lambda n: fn('',n)
list(map(p,[0,1,2,3,4]))

View file

@ -241,7 +241,7 @@ class Deriver:
Numeric(1)
),
DRule( #d/dx (x^c) = c * x ^ (c-1)
Power( DeriveVarIdMark(), IdMark("c") ),
Power( DeriveVarIdMark(), IdMark("c",constant=True) ),
Multiplication(
IdMark("c"),
Power(

BIN
fb2 Executable file

Binary file not shown.

View file

@ -0,0 +1,22 @@
from math import sqrt
def pq(p,q):
a = -p/2
b = sqrt(a**2-q)
return (a+b,a-b)
(l1,l2) = pq(-1,-1)
c2 = -l1/(l2-l1)
c1 = 1-c2
c1 *= l1
c2 *= l2
fib = lambda k: int(c1*pow(l1,k) + c2*pow(l2,k))
if __name__ == '__main__':
print("fib(k) = (%f) * (%f)^k + (%f) * (%f)^k)" % (c1,l1,c2,l2))
for i in range(0,51):
print("%d: %d" %(i,fib(i)))
y

7
fibonacci_small.py Normal file
View file

@ -0,0 +1,7 @@
from math import sqrt
psi = (1+sqrt(5))/2
phi = 1/sqrt(5)
fib = lambda k: int(phi*(psi**k - (-1/psi)**k))
for i in range(100):
print(fib(i))

BIN
fizzbuzz Executable file

Binary file not shown.

17
fizzbuzz.c Normal file
View file

@ -0,0 +1,17 @@
#include <stdio.h>
int main() {
int i;
for(i = 1; i <= 100; i++) {
if(i % 15 == 0) {
printf("FizzBuzz\n");
} else if(i % 3 == 0) {
printf("Fizz\n");
} else if(i % 5 == 0) {
printf("Buzz\n");
} else {
printf("%d\n",i);
}
}
return 0;
}

21
fizzbuzz.py Normal file
View file

@ -0,0 +1,21 @@
a = [ 3,0,0,1,0,2,1,0,0,1,2,0,1,0,0 ]
b = [ "%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n" ]
boff = [ 0 for z in b ]
for i in range(len(b)):
boff[i] = 0
for j in range(i):
boff[i] += len(b[j])
s = ""
for i in range(len(a)):
s += "\\x%x" % (a[i]+len(a)+boff[a[i]])
for n in b:
for c in n:
s += "\\x%x" % (ord(c))
s += "\\x0"
print s

BIN
fizzbuzz.sh.gz Normal file

Binary file not shown.

11
fizzbuzz2.c Normal file
View file

@ -0,0 +1,11 @@
#include <stdio.h>
int main() {
const char *d = "\x1f\xf\xf\x13\xf\x19\x13\xf\xf\x13\x19\xf\x13\xf\xf\x25\x64\xa\x0\x46\x69\x7a\x7a\xa\x0\x42\x75\x7a\x7a\xa\x0\x46\x69\x7a\x7a\x42\x75\x7a\x7a\xa\x0";
int i;
for(i = 1; i <= 100; i++)
printf(d+d[i%15],i);
return 0;
}

19
namegenerator.py Normal file
View file

@ -0,0 +1,19 @@
import random as pseudorandom
consonants = ['b','c','d','f','g','h','k','l','m','n','p','r','s','t','v','w','x','z']
vocals = ['a','e','i','o','u','y']
both = [consonants,vocals]
def generate_name(length=3):
gid = pseudorandom.randint(0,1)
name = ""
for i in range(length):
ch = pseudorandom.choice(both[gid])
name += ch
gid = (gid + 111) % 2
return name
for i in range(10):
print(generate_name(pseudorandom.randint(3,10)))

24
pascaltriangle.py Normal file
View file

@ -0,0 +1,24 @@
#python 3
def pascaltriangle(length):
l = [1]
yield l
for i in range(length-1):
nl = [1]
for j in range(len(l)-1):
nl.append(l[j]+l[j+1])
nl.append(1)
yield nl
l = nl
def prettyprint(l,w):
s = " ".join(map(str,l))
indent = int((w - len(s))/2)
s = (indent * " ") + s
print(s)
length = int(input('Length of pascal triangle: '))
for n in pascaltriangle(length):
prettyprint(n,length*3)

22
pseudorandomquotes.py Normal file
View file

@ -0,0 +1,22 @@
import random as pseudorandom
subjects = [
("is",['A car','Technology','A woman','A person','A dog','A cat','My neighbor','My fiancee','4chan','Obama']),
("am",['I']),
("are",['People','My friends','Teachers','Policemen','Politicians','Things'])
]
adjectives = ['dumb','gay','intelligent','evil','religious','sick','unhealthy','wrong','right','idiotic','lazy','green','black','whiny']
people = ['4chan','/g/','Anonymous','Random Citizen','That guy at school','My mother','My uncle']
def generate_quote():
verb,subjectlist = pseudorandom.choice(subjects)
subject = pseudorandom.choice(subjectlist)
adjective = pseudorandom.choice(adjectives)
person = pseudorandom.choice(people)
return '"%s %s %s" - %s' % (subject, verb, adjective, person)
for i in range(10):
print(generate_quote())

7
sorter.py Normal file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env python
a = [ [5,2,3], [1], [6,1,9], [2,0] ]
a = sorted(a, key = lambda item: sum(item)/len(item) )
print(a)