Skip to content

Instantly share code, notes, and snippets.

View captainsafia's full-sized avatar

Safia Abdalla captainsafia

View GitHub Profile
@captainsafia
captainsafia / pe_001.py
Created August 17, 2012 20:50
Solution to Project Euler Problem 1 in Python
sum=0
for x in range (0,1000):
if x%3==0 or x%5==0: sum+=x
print sum
@captainsafia
captainsafia / pe_001.scm
Created August 17, 2012 20:51
Solution to Project Euler Problem 1 in Scheme
(define sum 0)
(define (3or5 start limit inc)
(if (< start limit)
(begin
(if (= (remainder start 3) 0) (set! sum (+ sum start)) (if (= (remainder start 5) 0) (set! sum (+ sum start))))
(3or5 (+ start inc) limit inc))) sum)
(print (3or5 0 1000 1))
@captainsafia
captainsafia / pe_002.py
Created August 17, 2012 20:53
Solution to Project Euler Problem 2 in Python
x,y,n,total=0,1,0,0
while n<=4000000:
n=x+y
x=y
y=n
if n%2==0:
total+=n
print total
@captainsafia
captainsafia / pe_002.scm
Created August 17, 2012 20:54
Solution to Project Euler Problem 2 in Scheme
(define x 0)
(define y 1)
(define n 0)
(define sum 0)
(define (evenfibsum)
(set! n (+ x y))
(set! x y)
(set! y n)
(if (= (modulo n 2) 0) (set! sum (+ sum n)))
(if (<= n 4000000) (evenfibsum)) sum)
@captainsafia
captainsafia / queue.c
Created August 17, 2012 20:58
Queue Data Structure in C
#include "queue.h"
void init(int *head, int *tail) {
*head = *tail = 0;
}
void push(int *q,int *tail, int element) {
q[(*tail)++] = element;
}
@captainsafia
captainsafia / queue.h
Created August 17, 2012 20:59
Queue Data Structure in C
void push(int *q, int *tail, int element);
int pop(int *q, int *head);
int empty(int head, int tail);
void init(int *head, int *tail);
@captainsafia
captainsafia / test_queue.c
Created August 17, 2012 20:59
Queue Data Structure in C
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
int main(int argc, char const *argv[])
{
int head,tail,element;
int queue[4];
@captainsafia
captainsafia / pe_017.py
Created August 17, 2012 21:05
Solution to Project Euler Problem 17 in Python
num_word_dict={1:len("one"),2:len("two"),3:len("three"),
4:len("four"),5:len("five"), 6:len("six"),7:len("seven"),
8:len("eight"),9:len("nine"),10:len("ten"),11:len("eleven"),
12:len("twelve"),13:len("thirteen"),14:len("fourteen"),
15:len("fifteen"),16:len("sixteen"),17:len("seventeen"),
18:len("eighteen"),19:len("nineteen"),20:len("twenty"),
30:len("thirty"),40:len("fourty"),50:len("fifty"),
60:len("sixty"),70:len("seventy"),80:len("eighty"),
90:len("ninety"),100:len("onehundred"),200:len("twohundred"),
300:len("threehundred"),400:len("fourhundred"),
@captainsafia
captainsafia / pe_015.py
Created August 17, 2012 21:19
Solution to Project Euler Problem 15 in Python
def paths(n):
p=1
for x in xrange(1, n+1): p=p*x
return p
print paths(40)/paths(20)/paths(20)
@captainsafia
captainsafia / pe_018.py
Created August 17, 2012 21:31
Solution to Project Euler Problem 18 in Python
tri_num=[
[75],
[95, 64],
[17, 47, 82],
[18, 35, 87, 10],
[20, 04, 82, 47, 65],
[19, 01, 23, 75, 03, 34],
[88, 02, 77, 73, 07, 63, 67],
[99, 65, 04, 28, 06, 16, 70, 92],
[41, 41, 26, 56, 83, 40, 80, 70, 33],