This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const prob; | |
Where P(BB) = 1/2 | |
P(BB) = (B/(B+R)) * ((B-1)/(B+R-1)) = 1/2 | |
(B(B-1)) / ((B+R)(B+R-1)) = 1/2 | |
2B(B-1) / (B+R)(B+R-1) = 1 | |
2B(B-1) = (B+R)(B+R-1) | |
2B^2 - 2B = B^2 + BR - B + BR + R^2 - R | |
B^2 - B = 2BR + R^2 - R | |
B^2 - 2BR - B = R^2 - R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sys | |
sys.path.append('/home/gavin/Documents/Git Repositories/project-euler') | |
import pyfuncs | |
challenge = 'Find the sum of the digits in {}!:' | |
import math |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const factorial = n => { | |
let res = n; | |
if (!Number.isInteger(n) || n < 0) { | |
return undefined; | |
} | |
if (n === 0 || n === 1) | |
return 1; | |
while (n > 1) { | |
n--; | |
result *= n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const years = { | |
start : 1900, | |
end : 2000 | |
}; | |
const genArray = y => { | |
let arr = []; | |
for (let i = y.start; i <= y.end; i++) { | |
arr.push(i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sys | |
sys.path.append('/home/gavin/Documents/Git Repositories/project-euler') | |
import pyfuncs | |
challenge = 'Starting in the top left corner of a 2x2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.\n\nHow many such routes are there through a {}x{} grid?:' | |
import math |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const euler_15 = n => nCr(2*n,n); | |
const nCr = (n,r) => { | |
if (r > n || n < 1 || r < 1) { | |
return undefined; | |
} | |
return factorial(n) / (factorial(r) * factorial(n-r)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int nCr(int n,int r); | |
int factorial(int n); | |
int main() { | |
int n; | |
printf("Please enter a number here:\n"); | |
scanf("%d",&n); | |
printf("Here is your answer: %d\n",nCr(2*n,n)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sys | |
sys.path.append('/home/gavin/project-euler') | |
import pyfuncs | |
challenge = 'Which starting number, under {}, produces the longest chain in the Collatz problem?' | |
parser = argparse.ArgumentParser(description = 'Which starting number, under x, produces the longest chain in the Collatz problem?') | |
parser.add_argument('--num', default = 500, type = int, help = 'Insert the number here, it must be a positive integer. It defaults to 1000000 to correspond with the Project Euler Problem at https://projecteuler.net/problem=14') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sys | |
sys.path.append('/home/gavin/project-euler') | |
import pyfuncs | |
challenge = 'What is the value of the first triangle number to have over {} divisors?' | |
parser = argparse.ArgumentParser(description = 'What is the value of the first triangle number to have over x divisors?') | |
parser.add_argument('--num', default = 500, type = int, help = 'Insert the number here, it must be a positive integer. It defaults to 500 to correspond with the Project Euler Problem at https://projecteuler.net/problem=12') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$grid = [ | |
[8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8], | |
[49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,4,56,62,0], | |
[81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,3,49,13,36,65], | |
[52,70,95,23,4,60,11,42,69,24,68,56,1,32,56,71,37,2,36,91], | |
[22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80], | |
[24,47,32,60,99,3,45,2,44,75,33,53,78,36,84,20,35,17,12,50], | |
[32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70], | |
[67,26,20,68,2,62,12,20,95,63,94,39,63,8,40,91,66,49,94,21], |