Skip to content

Instantly share code, notes, and snippets.

@adrianmoses
adrianmoses / fib_sum_of_even_numbers.js
Created September 11, 2012 06:54
Sum of even numbers in a fib sequence less than four million
function Fib(){
this.num1 = 1;
this.num2 = 2;
this.sequence = [this.num1, this.num2];
this.sum = 2;
}
Fib.prototype.fibSequence = function (){
var num1 = this.num1;
var num2 = this.num2;
@adrianmoses
adrianmoses / temp_converter.c
Created November 24, 2012 07:14
temp_converter
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double convert_to_faren(double celcius);
double convert_to_celsius(double faren);
double convert_to_faren(double celcius){
#include <stdio.h>
#include <stdlib.h>
// given a number find its factorial
int get_factorial(int num);
int get_factorial(int num){
int i, j;
@adrianmoses
adrianmoses / pe_problem_1.c
Created December 31, 2012 05:40
Project Euler Problem 1
#include <stdio.h>
int sum_of_multiples(int range);
int sum_of_multiples(int range){
int i, sum;
sum = 0;
for(i=0;i<range;i++){
if( i%3 == 0 || i%5 == 0 ) {
@adrianmoses
adrianmoses / pe_problem_2.c
Last active December 10, 2015 09:59
Project Euler Problem 2
#include <stdio.h>
int fib_sum_of_even_numbers(int n);
int fib_sum_of_even_numbers(int n){
int num1 = 1, num2 = 2, temp_num = 0;
int sum = num2;
while(num2 < n){
@adrianmoses
adrianmoses / pe_problem_3.c
Created January 5, 2013 03:58
Project Euler Problem 3
#include <stdio.h>
#include <math.h>
int main(void)
{
long long num = 600851475143;
long long limit = (long long) sqrt(num);
long long i;
// find a number that is divisible by the num (has a modulus 0)
@adrianmoses
adrianmoses / pe_problem_4.c
Last active December 10, 2015 16:59
Project Euler Problem 4
#include <stdio.h>
// loop up three digit numbers
// get the product and check
// if it is a palindrome
// first test with two-digit
void *itoarr(int n, int arr[]);
int is_palindrome(int n);
@adrianmoses
adrianmoses / pe_problem_5.c
Created January 6, 2013 02:40
Project Euler Problem 5
#include <stdio.h>
int main(void){
unsigned int i = 20;
unsigned int j = i;
while(i>0){
if(j%i != 0){
@adrianmoses
adrianmoses / pe_problem_6.c
Created January 7, 2013 07:23
Project Euler Problem 6
#include <stdio.h>
#include <math.h>
int main(void){
double i = 1;
double x, y;
int diff;
while(i<=100){
#include <stdio.h>
int main(void){
int i, j, last_not_prime, last_prime;
int count = 0;
i = 2;
while(count < 10001){