Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
80562e78bc | |||
44bc28ec17 | |||
7201fa6e8b | |||
2da8957aac |
src
C
Task67 - Maximum path sum II.pytask1 - Multiples of 3 and 5.hstask1 - Multiples of 3 and 5.pytask10 - Summation of primes.pytask104 - Pandigital Fibonacci ends.pytask11 - Largest product in a grid.pytask12 - Highly divisible triangular number.pytask13 - Large sum.pytask14 - Longest Collatz sequence.pytask15 - Lattice paths.pytask16 - Power digit sum.pytask17 - Number letter counts.pytask18 - Maximum path sum I.pytask19 - Counting Sundays.pytask20 - Factorial digit sum.pytask21 - Amicable numbers.pytask22 - Names scores.pytask23 - Non-abundant sums.pytask24 - Lexicographic permutations.pytask25 - 1000-digit Fibonacci number.pytask26 - Reciprocal cycles.pytask27 - Quadratic primes.pytask28 - Number spiral diagonals.pytask29 - Distinct powers.pytask30 - Digit fifth powers.pytask32 - Pandigital products.pytask33 - Digit cancelling fractions.pytask34 - Digit factorials.pytask35 - Circular primes.pytask36 - Double-base palindromes.pytask40 - Truncatable primes.pytask42 - Coded triangle numbers.pytask43 - Sub-string divisibility.pytask44 - Pentagon numbers.pytask45 - Triangular pentagonal and hexagonal.pytask48 - Self powers.pytask49 - Prime permutations.pytask52 - Permuted multiples.pytask53 - Combinatoric selections.pytask56 - Powerful digit sum.pytask57 - Square root convergents.pytask58 - Spiral primes.pytask59 - XOR decryption.pytask6 - Sum square difference.pytask69 - Totient maximum.pytask7 - 10001st prime.pytask70 - Totient permutation.pytask8 - Largest product in a series.pytask9 - Special Pythagorean triplet.pytask92 - Square digit chains.pytask97 - Large non-Mersenne prime.pytest.py@@ -1,35 +0,0 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int fib(int a) {
|
|
||||||
if(a==0){
|
|
||||||
return 0;
|
|
||||||
}else if(a==1){
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return (fib(a-1) + fib(a-2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
while(1){
|
|
||||||
int x = fib(count);
|
|
||||||
|
|
||||||
if(x>4000000){
|
|
||||||
printf("%d", result);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(x%2==0){
|
|
||||||
result = result + x;
|
|
||||||
}
|
|
||||||
count = count+1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
BIN
src/C/task20
BIN
src/C/task20
Binary file not shown.
120
src/C/task20.c
120
src/C/task20.c
@@ -1,120 +0,0 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
int isPrime(int n){
|
|
||||||
for(int i=2;i<sqrt(n);i++){
|
|
||||||
if(n%i==0){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Returns amount of primes between 0 and n*/
|
|
||||||
int amountPrimes(int n){
|
|
||||||
int x=0;
|
|
||||||
|
|
||||||
for (int i = 2; i < n; i++)
|
|
||||||
{
|
|
||||||
if (isPrime(i)){
|
|
||||||
x+=1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Returns array with primes between 0 and n*/
|
|
||||||
int * primesIn(int n){
|
|
||||||
|
|
||||||
int x = amountPrimes(n);
|
|
||||||
|
|
||||||
int * primes;
|
|
||||||
primes = malloc(sizeof(int)*x);
|
|
||||||
x=0;
|
|
||||||
|
|
||||||
for (int i = 2; i < n; i++)
|
|
||||||
{
|
|
||||||
if (isPrime(i)){
|
|
||||||
primes[x]=i;
|
|
||||||
x+=1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return primes;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Factorial of n*/
|
|
||||||
long fact(int n){
|
|
||||||
if (n==1){
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return n*fact(n-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Retrieves the amount of factors in a number*/
|
|
||||||
int factoramount(int n){
|
|
||||||
|
|
||||||
if (isPrime(n)){
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
for
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Returns array with factors of n*/
|
|
||||||
int * factorize(int n){
|
|
||||||
|
|
||||||
int x = amountPrimes(n);
|
|
||||||
|
|
||||||
int * primes;
|
|
||||||
primes = malloc(sizeof(int)*x);
|
|
||||||
|
|
||||||
if(isPrime(n)) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
for (size_t i = 2; i < n; i++)
|
|
||||||
{
|
|
||||||
if (i%j==0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
int * primes = primesIn(100);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < amountPrimes(100); i++){
|
|
||||||
printf("Prime: %d\n", *(primes+i));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int * factCounter[amountPrimes(100)]
|
|
||||||
|
|
||||||
for (size_t i = 1; i < 100; i++){
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long x = fact(100);
|
|
||||||
|
|
||||||
//SUM OF DIGITS OF X
|
|
||||||
|
|
||||||
printf("%ld\n", x);
|
|
||||||
|
|
||||||
}
|
|
BIN
src/C/task3
BIN
src/C/task3
Binary file not shown.
@@ -1,35 +0,0 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
int isPrime(long n){
|
|
||||||
for(int i=2;i<sqrt(n);i++){
|
|
||||||
if(n%i==0){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
long count=1;
|
|
||||||
int big=0;
|
|
||||||
long number=600851475143;
|
|
||||||
|
|
||||||
while(count<number){
|
|
||||||
if(isPrime(count)){
|
|
||||||
//printf("Prime: %ld \n", count);
|
|
||||||
if (number%count==0){
|
|
||||||
printf("New big: %ld \n", count);
|
|
||||||
big=count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
count+=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
BIN
src/C/task4
BIN
src/C/task4
Binary file not shown.
@@ -1,39 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
int biggest = 0;
|
|
||||||
|
|
||||||
for (int i = 100; i < 1000; i++)
|
|
||||||
{
|
|
||||||
for (int j = 100; j < 1000; j++)
|
|
||||||
{
|
|
||||||
int x=i*j;
|
|
||||||
int z=x;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
while (x != 0)
|
|
||||||
{
|
|
||||||
y = y * 10;
|
|
||||||
y = y + x%10;
|
|
||||||
x = x/10;
|
|
||||||
}
|
|
||||||
|
|
||||||
//printf("%d - %d\n", y, z);
|
|
||||||
|
|
||||||
if (y==z & y>biggest){
|
|
||||||
biggest = z;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%d\n", biggest);
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@@ -1,13 +0,0 @@
|
|||||||
#include <std.io>
|
|
||||||
|
|
||||||
int main{
|
|
||||||
|
|
||||||
long a=0
|
|
||||||
|
|
||||||
for(int i=0;i<=1000;i++){
|
|
||||||
a+=(i^i);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%ld", a);
|
|
||||||
|
|
||||||
}
|
|
BIN
src/C/task5
BIN
src/C/task5
Binary file not shown.
@@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
int x=5;
|
|
||||||
|
|
||||||
while(1){
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 2; i <= 20; i++)
|
|
||||||
{
|
|
||||||
if (x%i!=0){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(i==20){
|
|
||||||
printf("%d\n", x);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
x+=1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
#Same as task 18
|
|
||||||
|
|
||||||
with open('67.txt') as fp:
|
|
||||||
data = [list(map(int, line.strip().split(' '))) for line in fp]
|
|
||||||
|
|
||||||
data.reverse()
|
|
||||||
|
|
||||||
for i in range(len(data)):
|
|
||||||
for j in range(len(data[i])-1):
|
|
||||||
data[i+1][j]+= (data[i][j] if data[i][j]>data[i][j+1] else data[i][j+1])
|
|
||||||
print(data[len(data)-1][0])
|
|
15
src/task1 - Multiples of 3 and 5.hs
Normal file
15
src/task1 - Multiples of 3 and 5.hs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import System.IO
|
||||||
|
import Data.List
|
||||||
|
|
||||||
|
isDivisibleBy3 :: Int -> Bool
|
||||||
|
isDivisibleBy3 n = mod n 3 == 0
|
||||||
|
|
||||||
|
isDivisibleBy5 :: Int -> Bool
|
||||||
|
isDivisibleBy5 n = mod n 5 == 0
|
||||||
|
|
||||||
|
isDivisibleBy3Or5 :: Int -> Bool
|
||||||
|
isDivisibleBy3Or5 n = isDivisibleBy3 n || isDivisibleBy5 n
|
||||||
|
|
||||||
|
main = do
|
||||||
|
let numbersDivisibleBy3Or5 = filter isDivisibleBy3Or5 [1..1000]
|
||||||
|
putStrLn $ show $ sum numbersDivisibleBy3Or5
|
@@ -1 +0,0 @@
|
|||||||
print(sum([i for i in range(1, 1000) if i%3==0 or i%5==0]))
|
|
@@ -1,14 +0,0 @@
|
|||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
print(sum([i for i in range(1,2000001) if is_prime(i)]))
|
|
@@ -1,32 +0,0 @@
|
|||||||
def fib(n):
|
|
||||||
if( n == 0):
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
x = 0
|
|
||||||
y = 1
|
|
||||||
for i in range(1,n):
|
|
||||||
z = (x + y)
|
|
||||||
x = y
|
|
||||||
y = z
|
|
||||||
return y
|
|
||||||
|
|
||||||
digits=list(range(0,10))
|
|
||||||
def containsPandigits(n):
|
|
||||||
first = [int(str(n)[i]) for i in range(0,10)]
|
|
||||||
last = [int(str(n)[len(str(n))-i-1]) for i in range(0,10)]
|
|
||||||
if set(digits).issubset(first) and set(digits).issubset(last):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
# for i in range(0,10):
|
|
||||||
# if (not i in first) or (not i in last):
|
|
||||||
# return False
|
|
||||||
# return True
|
|
||||||
|
|
||||||
i=2
|
|
||||||
while True:
|
|
||||||
if (len(str(fib(i))) >= 18) and (containsPandigits(fib(i))):
|
|
||||||
print(fib(i))
|
|
||||||
break
|
|
||||||
i+=1
|
|
||||||
|
|
@@ -1,62 +0,0 @@
|
|||||||
with open('11.txt') as fp:
|
|
||||||
data = [list(map(int, line.strip().split(' '))) for line in fp]
|
|
||||||
|
|
||||||
#I is y axis, J is x axis
|
|
||||||
|
|
||||||
def scanHorizontal():
|
|
||||||
#Horizontal, offset i, offset j, number
|
|
||||||
max = ["Horizontal", 0, 0, 0]
|
|
||||||
for i in range(0, len(data[0])):
|
|
||||||
for j in range(0, len(data)-3):
|
|
||||||
x= data[i][j]*data[i][j+1]*data[i][j+2]*data[i][j+3]
|
|
||||||
if x > max[3]:
|
|
||||||
max[1] = i
|
|
||||||
max[2] = j
|
|
||||||
max[3] = x
|
|
||||||
return max
|
|
||||||
|
|
||||||
def scanVertical():
|
|
||||||
#Vertical, offset i, offset j, number
|
|
||||||
max = ["Vertical", 0, 0, 0]
|
|
||||||
for i in range(0, len(data[0])-3):
|
|
||||||
for j in range(0, len(data)):
|
|
||||||
x = data[i][j]*data[i+1][j]*data[i+2][j]*data[i+3][j]
|
|
||||||
if x > max[3]:
|
|
||||||
max[1] = i
|
|
||||||
max[2] = j
|
|
||||||
max[3] = x
|
|
||||||
return max
|
|
||||||
|
|
||||||
def scanDiagonal():
|
|
||||||
#Diagonal, offset i, offset j, number
|
|
||||||
max = ["Diagonal", 0, 0, 0]
|
|
||||||
for i in range(0, len(data[0])-3):
|
|
||||||
for j in range(0, len(data)-3):
|
|
||||||
x = data[i][j]*data[i+1][j+1]*data[i+2][j+2]*data[i+3][j+3]
|
|
||||||
if x > max[3]:
|
|
||||||
max[1] = i
|
|
||||||
max[2] = j
|
|
||||||
max[3] = x
|
|
||||||
return max
|
|
||||||
|
|
||||||
def scanInvertDiagonal():
|
|
||||||
#IDiagonal, offset i, offset j, number
|
|
||||||
max = ["IDiagonal", 0, 0, 0]
|
|
||||||
for i in range(0, len(data[0])-3):
|
|
||||||
for j in range(3, len(data)):
|
|
||||||
x = data[i][j]*data[i+1][j-1]*data[i+2][j-2]*data[i+3][j-3]
|
|
||||||
if x > max[3]:
|
|
||||||
max[1] = i
|
|
||||||
max[2] = j
|
|
||||||
max[3] = x
|
|
||||||
return max
|
|
||||||
|
|
||||||
x=scanHorizontal()
|
|
||||||
if scanVertical()[3] > x[3]:
|
|
||||||
x = scanVertical()
|
|
||||||
if scanDiagonal()[3] > x[3]:
|
|
||||||
x = scanDiagonal()
|
|
||||||
if scanInvertDiagonal()[3] > x[3]:
|
|
||||||
x = scanInvertDiagonal()
|
|
||||||
print(x)
|
|
||||||
|
|
@@ -1,69 +0,0 @@
|
|||||||
|
|
||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
def factorize(n):
|
|
||||||
factors = []
|
|
||||||
if is_prime(n):
|
|
||||||
factors.append(n)
|
|
||||||
else:
|
|
||||||
while not is_prime(n):
|
|
||||||
for i in range(2,int(n)):
|
|
||||||
if n%i==0:
|
|
||||||
factors.append(i)
|
|
||||||
n=n/i
|
|
||||||
break
|
|
||||||
factors.append(n)
|
|
||||||
return factors
|
|
||||||
|
|
||||||
|
|
||||||
n=3
|
|
||||||
addNum=3
|
|
||||||
while True:
|
|
||||||
x=-1
|
|
||||||
counter = []
|
|
||||||
pointer = 0
|
|
||||||
|
|
||||||
#Make an array Counter[] that contains the amount of each prime factor in the number
|
|
||||||
for i in factorize(n):
|
|
||||||
if i==pointer:
|
|
||||||
counter[x]+=1
|
|
||||||
else:
|
|
||||||
x+=1
|
|
||||||
pointer=i
|
|
||||||
counter.append(1)
|
|
||||||
|
|
||||||
factors = 1
|
|
||||||
for i in counter:
|
|
||||||
factors = factors * (i+1)
|
|
||||||
if factors > 500:
|
|
||||||
print(n)
|
|
||||||
break
|
|
||||||
|
|
||||||
n+=addNum
|
|
||||||
addNum+=1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# x=3
|
|
||||||
# y=3
|
|
||||||
# max = 0
|
|
||||||
|
|
||||||
# while factorCount(x)!=501:
|
|
||||||
# x+=y
|
|
||||||
# y+=1
|
|
||||||
# if factorCount(x)>max:
|
|
||||||
# max = factorCount(x)
|
|
||||||
# print str(x) + " -> " + str(max)
|
|
||||||
|
|
||||||
# print x
|
|
@@ -1,102 +0,0 @@
|
|||||||
number = 37107287533902102798797998220837590246510135740250 + \
|
|
||||||
46376937677490009712648124896970078050417018260538 + \
|
|
||||||
74324986199524741059474233309513058123726617309629 + \
|
|
||||||
91942213363574161572522430563301811072406154908250 + \
|
|
||||||
23067588207539346171171980310421047513778063246676 + \
|
|
||||||
89261670696623633820136378418383684178734361726757 + \
|
|
||||||
28112879812849979408065481931592621691275889832738 + \
|
|
||||||
44274228917432520321923589422876796487670272189318 + \
|
|
||||||
47451445736001306439091167216856844588711603153276 + \
|
|
||||||
70386486105843025439939619828917593665686757934951 + \
|
|
||||||
62176457141856560629502157223196586755079324193331 + \
|
|
||||||
64906352462741904929101432445813822663347944758178 + \
|
|
||||||
92575867718337217661963751590579239728245598838407 + \
|
|
||||||
58203565325359399008402633568948830189458628227828 + \
|
|
||||||
80181199384826282014278194139940567587151170094390 + \
|
|
||||||
35398664372827112653829987240784473053190104293586 + \
|
|
||||||
86515506006295864861532075273371959191420517255829 + \
|
|
||||||
71693888707715466499115593487603532921714970056938 + \
|
|
||||||
54370070576826684624621495650076471787294438377604 + \
|
|
||||||
53282654108756828443191190634694037855217779295145 + \
|
|
||||||
36123272525000296071075082563815656710885258350721 + \
|
|
||||||
45876576172410976447339110607218265236877223636045 + \
|
|
||||||
17423706905851860660448207621209813287860733969412 + \
|
|
||||||
81142660418086830619328460811191061556940512689692 + \
|
|
||||||
51934325451728388641918047049293215058642563049483 + \
|
|
||||||
62467221648435076201727918039944693004732956340691 + \
|
|
||||||
15732444386908125794514089057706229429197107928209 + \
|
|
||||||
55037687525678773091862540744969844508330393682126 + \
|
|
||||||
18336384825330154686196124348767681297534375946515 + \
|
|
||||||
80386287592878490201521685554828717201219257766954 + \
|
|
||||||
78182833757993103614740356856449095527097864797581 + \
|
|
||||||
16726320100436897842553539920931837441497806860984 + \
|
|
||||||
48403098129077791799088218795327364475675590848030 + \
|
|
||||||
87086987551392711854517078544161852424320693150332 + \
|
|
||||||
59959406895756536782107074926966537676326235447210 + \
|
|
||||||
69793950679652694742597709739166693763042633987085 + \
|
|
||||||
41052684708299085211399427365734116182760315001271 + \
|
|
||||||
65378607361501080857009149939512557028198746004375 + \
|
|
||||||
35829035317434717326932123578154982629742552737307 + \
|
|
||||||
94953759765105305946966067683156574377167401875275 + \
|
|
||||||
88902802571733229619176668713819931811048770190271 + \
|
|
||||||
25267680276078003013678680992525463401061632866526 + \
|
|
||||||
36270218540497705585629946580636237993140746255962 + \
|
|
||||||
24074486908231174977792365466257246923322810917141 + \
|
|
||||||
91430288197103288597806669760892938638285025333403 + \
|
|
||||||
34413065578016127815921815005561868836468420090470 + \
|
|
||||||
23053081172816430487623791969842487255036638784583 + \
|
|
||||||
11487696932154902810424020138335124462181441773470 + \
|
|
||||||
63783299490636259666498587618221225225512486764533 + \
|
|
||||||
67720186971698544312419572409913959008952310058822 + \
|
|
||||||
95548255300263520781532296796249481641953868218774 + \
|
|
||||||
76085327132285723110424803456124867697064507995236 + \
|
|
||||||
37774242535411291684276865538926205024910326572967 + \
|
|
||||||
23701913275725675285653248258265463092207058596522 + \
|
|
||||||
29798860272258331913126375147341994889534765745501 + \
|
|
||||||
18495701454879288984856827726077713721403798879715 + \
|
|
||||||
38298203783031473527721580348144513491373226651381 + \
|
|
||||||
34829543829199918180278916522431027392251122869539 + \
|
|
||||||
40957953066405232632538044100059654939159879593635 + \
|
|
||||||
29746152185502371307642255121183693803580388584903 + \
|
|
||||||
41698116222072977186158236678424689157993532961922 + \
|
|
||||||
62467957194401269043877107275048102390895523597457 + \
|
|
||||||
23189706772547915061505504953922979530901129967519 + \
|
|
||||||
86188088225875314529584099251203829009407770775672 + \
|
|
||||||
11306739708304724483816533873502340845647058077308 + \
|
|
||||||
82959174767140363198008187129011875491310547126581 + \
|
|
||||||
97623331044818386269515456334926366572897563400500 + \
|
|
||||||
42846280183517070527831839425882145521227251250327 + \
|
|
||||||
55121603546981200581762165212827652751691296897789 + \
|
|
||||||
32238195734329339946437501907836945765883352399886 + \
|
|
||||||
75506164965184775180738168837861091527357929701337 + \
|
|
||||||
62177842752192623401942399639168044983993173312731 + \
|
|
||||||
32924185707147349566916674687634660915035914677504 + \
|
|
||||||
99518671430235219628894890102423325116913619626622 + \
|
|
||||||
73267460800591547471830798392868535206946944540724 + \
|
|
||||||
76841822524674417161514036427982273348055556214818 + \
|
|
||||||
97142617910342598647204516893989422179826088076852 + \
|
|
||||||
87783646182799346313767754307809363333018982642090 + \
|
|
||||||
10848802521674670883215120185883543223812876952786 + \
|
|
||||||
71329612474782464538636993009049310363619763878039 + \
|
|
||||||
62184073572399794223406235393808339651327408011116 + \
|
|
||||||
66627891981488087797941876876144230030984490851411 + \
|
|
||||||
60661826293682836764744779239180335110989069790714 + \
|
|
||||||
85786944089552990653640447425576083659976645795096 + \
|
|
||||||
66024396409905389607120198219976047599490197230297 + \
|
|
||||||
64913982680032973156037120041377903785566085089252 + \
|
|
||||||
16730939319872750275468906903707539413042652315011 + \
|
|
||||||
94809377245048795150954100921645863754710598436791 + \
|
|
||||||
78639167021187492431995700641917969777599028300699 + \
|
|
||||||
15368713711936614952811305876380278410754449733078 + \
|
|
||||||
40789923115535562561142322423255033685442488917353 + \
|
|
||||||
44889911501440648020369068063960672322193204149535 + \
|
|
||||||
41503128880339536053299340368006977710650566631954 + \
|
|
||||||
81234880673210146739058568557934581403627822703280 + \
|
|
||||||
82616570773948327592232845941706525094512325230608 + \
|
|
||||||
22918802058777319719839450180888072429661980811197 + \
|
|
||||||
77158542502016545090413245809786882778948721859617 + \
|
|
||||||
72107838435069186155435662884062257473692284509516 + \
|
|
||||||
20849603980134001723930671666823555245252804609722 + \
|
|
||||||
53503534226472524250874054075591789781264330331690
|
|
||||||
|
|
||||||
print(str(number)[:10])
|
|
@@ -1,16 +0,0 @@
|
|||||||
counter = [0, 0]
|
|
||||||
|
|
||||||
for i in range(1, 1000001):
|
|
||||||
x=1
|
|
||||||
i2= i
|
|
||||||
while i>1:
|
|
||||||
if i%2==0:
|
|
||||||
i=i/2
|
|
||||||
x+=1
|
|
||||||
else:
|
|
||||||
i=3*i+1
|
|
||||||
x+=1
|
|
||||||
if x > counter[1]:
|
|
||||||
counter[0] = i2
|
|
||||||
counter[1] = x
|
|
||||||
print(counter)
|
|
@@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
#https://betterexplained.com/articles/navigate-a-grid-using-combinations-and-permutations/
|
|
||||||
|
|
||||||
import math
|
|
||||||
|
|
||||||
def factorial(n):
|
|
||||||
x=1
|
|
||||||
for i in range(1, n+1):
|
|
||||||
x=x*i
|
|
||||||
return x
|
|
||||||
|
|
||||||
#print(factorial(40)/(factorial(20)*factorial(40-20)))
|
|
||||||
print(math.comb(40,20))
|
|
@@ -1,9 +0,0 @@
|
|||||||
num = 2**1000
|
|
||||||
result = 0
|
|
||||||
|
|
||||||
while num > 0:
|
|
||||||
d = num%10
|
|
||||||
num = num//10
|
|
||||||
result += d
|
|
||||||
|
|
||||||
print(result)
|
|
@@ -1,75 +0,0 @@
|
|||||||
wordNumber = {
|
|
||||||
1 : "one",
|
|
||||||
2 : "two",
|
|
||||||
3 : "three",
|
|
||||||
4 : "four",
|
|
||||||
5 : "five",
|
|
||||||
6 : "six",
|
|
||||||
7 : "seven",
|
|
||||||
8 : "eight",
|
|
||||||
9 : "nine",
|
|
||||||
10 : "ten",
|
|
||||||
11 : "eleven",
|
|
||||||
12 : "twelve",
|
|
||||||
13 : "thirteen",
|
|
||||||
14 : "fourteen",
|
|
||||||
15 : "fifteen",
|
|
||||||
16 : "sixteen",
|
|
||||||
17 : "seventeen",
|
|
||||||
18 : "eighteen",
|
|
||||||
19 : "nineteen",
|
|
||||||
20 : "twenty",
|
|
||||||
30 : "thirty",
|
|
||||||
40 : "forty",
|
|
||||||
50 : "fifty",
|
|
||||||
60 : "sixty",
|
|
||||||
70 : "seventy",
|
|
||||||
80 : "eighty",
|
|
||||||
90 : "ninety",
|
|
||||||
100 : "hundred",
|
|
||||||
1000 : "thousand",
|
|
||||||
"and" : "and"
|
|
||||||
}
|
|
||||||
|
|
||||||
for i in wordNumber:
|
|
||||||
wordNumber[i] = len(wordNumber[i])
|
|
||||||
|
|
||||||
def belowHundred(n):
|
|
||||||
if n <=20:
|
|
||||||
return wordNumber[n]
|
|
||||||
elif n<100:
|
|
||||||
d1=int(str(n)[0]) # 00x0
|
|
||||||
d2=int(str(n)[1]) # 000x
|
|
||||||
if d2==0:
|
|
||||||
return wordNumber[n]
|
|
||||||
else:
|
|
||||||
return wordNumber[d1*10] + wordNumber[d2]
|
|
||||||
|
|
||||||
def wordsofNum(n):
|
|
||||||
|
|
||||||
if n<100:
|
|
||||||
return belowHundred(n)
|
|
||||||
elif n<1000:
|
|
||||||
answersum = 0
|
|
||||||
|
|
||||||
d1=int(str(n)[0]) # 0x00
|
|
||||||
d2=int(str(n)[1]) # 00x0
|
|
||||||
d3=int(str(n)[2]) # 000x
|
|
||||||
|
|
||||||
answersum+=wordNumber[d1] + wordNumber[100]
|
|
||||||
|
|
||||||
if d2!=0 or d3!=0:
|
|
||||||
answersum+=belowHundred(int(str(n)[1:3]))
|
|
||||||
answersum+=wordNumber["and"]
|
|
||||||
|
|
||||||
|
|
||||||
return answersum
|
|
||||||
elif n==1000:
|
|
||||||
return wordNumber[1] + wordNumber[1000]
|
|
||||||
|
|
||||||
|
|
||||||
x=0
|
|
||||||
for n in range(1, 1001):
|
|
||||||
x+=wordsofNum(n)
|
|
||||||
|
|
||||||
print(x)
|
|
@@ -1,11 +0,0 @@
|
|||||||
#Same as task 67
|
|
||||||
|
|
||||||
with open('18.txt') as fp:
|
|
||||||
data = [list(map(int, line.strip().split(' '))) for line in fp]
|
|
||||||
|
|
||||||
data.reverse()
|
|
||||||
|
|
||||||
for i in range(len(data)):
|
|
||||||
for j in range(len(data[i])-1):
|
|
||||||
data[i+1][j]+= (data[i][j] if data[i][j]>data[i][j+1] else data[i][j+1])
|
|
||||||
print(data[len(data)-1][0])
|
|
@@ -1,38 +0,0 @@
|
|||||||
#Day number, month, year
|
|
||||||
date = [366, 1, 1901]
|
|
||||||
|
|
||||||
Month = {
|
|
||||||
1:31,
|
|
||||||
2:28,
|
|
||||||
3:31,
|
|
||||||
4:30,
|
|
||||||
5:31,
|
|
||||||
6:30,
|
|
||||||
7:31,
|
|
||||||
8:31,
|
|
||||||
9:30,
|
|
||||||
10:31,
|
|
||||||
11:30,
|
|
||||||
12:31
|
|
||||||
}
|
|
||||||
|
|
||||||
result = 0
|
|
||||||
|
|
||||||
while date[2]<=2000:
|
|
||||||
date[1]=1
|
|
||||||
Month[2]=28
|
|
||||||
|
|
||||||
if date[2]%4==0:
|
|
||||||
if date[2]%100==0 and date[2]%400!=0:
|
|
||||||
print("special: " + str(date[2]))
|
|
||||||
break
|
|
||||||
Month[2]=29
|
|
||||||
|
|
||||||
for i in range(1,13):
|
|
||||||
|
|
||||||
date [0]+=Month[i]
|
|
||||||
if date[0]%7==0:
|
|
||||||
result+=1
|
|
||||||
date[2]+=1
|
|
||||||
|
|
||||||
print(result)
|
|
@@ -1,64 +0,0 @@
|
|||||||
import math
|
|
||||||
|
|
||||||
def factorial(n):
|
|
||||||
if n==1:
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return n*factorial(n-1)
|
|
||||||
|
|
||||||
def isPrime(n):
|
|
||||||
for i in range(2, int(n)):
|
|
||||||
if (n%i==0):
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def primesIn(n):
|
|
||||||
counter = 0
|
|
||||||
primes = []
|
|
||||||
for i in range(2, n):
|
|
||||||
if isPrime(i):
|
|
||||||
primes.append(i)
|
|
||||||
counter+=1
|
|
||||||
return primes
|
|
||||||
|
|
||||||
def factorize(n):
|
|
||||||
factors = []
|
|
||||||
if isPrime(n):
|
|
||||||
factors.append(n)
|
|
||||||
else:
|
|
||||||
while not isPrime(n):
|
|
||||||
for i in range(2,int(n)):
|
|
||||||
if n%i==0:
|
|
||||||
factors.append(i)
|
|
||||||
n=n/i
|
|
||||||
break
|
|
||||||
factors.append(n)
|
|
||||||
return factors
|
|
||||||
|
|
||||||
|
|
||||||
primes = []
|
|
||||||
for i in range(2,101):
|
|
||||||
if isPrime(i):
|
|
||||||
primes.append(i)
|
|
||||||
|
|
||||||
primeDict = { i : 0 for i in primes }
|
|
||||||
|
|
||||||
for i in range(2,101):
|
|
||||||
num = factorize(i)
|
|
||||||
print(i)
|
|
||||||
for j in range(0, len(num)):
|
|
||||||
primeDict[num[j]] = primeDict[num[j]] + 1
|
|
||||||
print("Primedict " + str(num[j]) + " ++")
|
|
||||||
|
|
||||||
|
|
||||||
print(primeDict)
|
|
||||||
|
|
||||||
num = factorial(100)
|
|
||||||
result = 0
|
|
||||||
|
|
||||||
while num > 0:
|
|
||||||
d = num%10
|
|
||||||
num = num//10
|
|
||||||
result += d
|
|
||||||
|
|
||||||
int(str(num)[:10])
|
|
@@ -1,35 +0,0 @@
|
|||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
def factorize(n):
|
|
||||||
factors = [1]
|
|
||||||
if not is_prime(n) and n>1:
|
|
||||||
for i in range(2,n):
|
|
||||||
if n%i==0:
|
|
||||||
factors.append(i)
|
|
||||||
return factors
|
|
||||||
|
|
||||||
def sumFactors(factors):
|
|
||||||
result = 0
|
|
||||||
for i in factors:
|
|
||||||
result+=i
|
|
||||||
return result
|
|
||||||
|
|
||||||
result = 0
|
|
||||||
for i in range(2, 10001):
|
|
||||||
b = sumFactors(factorize(i))
|
|
||||||
if i==sumFactors(factorize(b)) and i!=b:
|
|
||||||
result+=i
|
|
||||||
|
|
||||||
print(result)
|
|
||||||
|
|
@@ -1,22 +0,0 @@
|
|||||||
import csv
|
|
||||||
|
|
||||||
def wordSum(n):
|
|
||||||
wordsum=0
|
|
||||||
for character in n:
|
|
||||||
wordsum+=ord(character)-64
|
|
||||||
return wordsum
|
|
||||||
|
|
||||||
data =[]
|
|
||||||
|
|
||||||
with open('22.txt') as file:
|
|
||||||
reader = csv.reader(file, delimiter=",", quotechar='"')
|
|
||||||
data = list(reader)[0]
|
|
||||||
|
|
||||||
data.sort()
|
|
||||||
|
|
||||||
totalsum=0
|
|
||||||
counter=1
|
|
||||||
for i in data:
|
|
||||||
totalsum+=wordSum(i)*counter
|
|
||||||
counter+=1
|
|
||||||
print(totalsum)
|
|
@@ -1,50 +0,0 @@
|
|||||||
import math
|
|
||||||
from functools import reduce
|
|
||||||
|
|
||||||
def factors(x):
|
|
||||||
result = [1]
|
|
||||||
i = 2
|
|
||||||
while i*i <= x: #Other way of writing i<=sqrt(x)
|
|
||||||
if x % i == 0:
|
|
||||||
result.append(i)
|
|
||||||
if x//i != i:
|
|
||||||
result.append(x//i)
|
|
||||||
i += 1
|
|
||||||
return result
|
|
||||||
|
|
||||||
def is_abundant(n):
|
|
||||||
return sum(factors(n)) > n
|
|
||||||
|
|
||||||
abundants= [i for i in range(28123) if is_abundant(i)]
|
|
||||||
|
|
||||||
range28 = [range(28123+1)]
|
|
||||||
abundantsums = []
|
|
||||||
result = []
|
|
||||||
for i in range(len(abundants)):
|
|
||||||
for j in range(len(abundants)-i):
|
|
||||||
if abundants[i]+abundants[i-j]<=28123 and abundants[i]+abundants[i-j] in range28:
|
|
||||||
abundantsums.append(abundants[i]+abundants[i-j])
|
|
||||||
range28.pop(range28.index(abundants[i]+abundants[i-j]))
|
|
||||||
result.append(abundants[i]+abundants[i-j])
|
|
||||||
print(len(abundantsums)) #24 266 061
|
|
||||||
print("calculated abundantsums")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#result = sum([i for i in range(28123+1) if not i in abundantsums])
|
|
||||||
|
|
||||||
# result = 0
|
|
||||||
# for i in range(28123+1):
|
|
||||||
# print(i)
|
|
||||||
# if not i in abundantsums:
|
|
||||||
# result+=i
|
|
||||||
|
|
||||||
# range28 = [range(28123+1)]
|
|
||||||
# result = []
|
|
||||||
# for i in abundantsums:
|
|
||||||
# if i in range28:
|
|
||||||
# range28.pop(range28.index(i))
|
|
||||||
# result.append(i)
|
|
||||||
|
|
||||||
print(result)
|
|
||||||
|
|
@@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
import itertools
|
|
||||||
|
|
||||||
perms = list(itertools.permutations([0,1,2,3,4,5,6,7,8,9], 10))
|
|
||||||
|
|
||||||
print(''.join(map(str, perms[1000000-1])))
|
|
@@ -1,27 +0,0 @@
|
|||||||
#!/usr/bin/env python2.7
|
|
||||||
|
|
||||||
def fib(n):
|
|
||||||
if n==1 or n==2:
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return fib(n-1)+fib(n-2)
|
|
||||||
|
|
||||||
def fibn(n):
|
|
||||||
var1=1
|
|
||||||
var2=1
|
|
||||||
bet=0
|
|
||||||
for i in range(2, n):
|
|
||||||
bet=var2
|
|
||||||
var2=var2+var1
|
|
||||||
var1=bet
|
|
||||||
return var2
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
i = 1
|
|
||||||
|
|
||||||
while len(str(fibn(i)))<1000:
|
|
||||||
i+=1
|
|
||||||
|
|
||||||
print(i)
|
|
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
for i in range(1,1000):
|
|
||||||
x = 1/i
|
|
||||||
|
|
@@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
a=0
|
|
||||||
b=0
|
|
||||||
maxn=0
|
|
||||||
|
|
||||||
for i in range(-1000, 1001):
|
|
||||||
for j in range(-1000, 1001):
|
|
||||||
n = 1
|
|
||||||
while True:
|
|
||||||
if not is_prime(n**2+i*n+j):
|
|
||||||
break
|
|
||||||
n+=1
|
|
||||||
if n > maxn:
|
|
||||||
a=i
|
|
||||||
b=j
|
|
||||||
maxn = n
|
|
||||||
print(a*b)
|
|
@@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
split = 2
|
|
||||||
x = 1
|
|
||||||
result = 1
|
|
||||||
|
|
||||||
while split != 1000:
|
|
||||||
|
|
||||||
for i in range(4):
|
|
||||||
x += split
|
|
||||||
result+=x
|
|
||||||
split +=2
|
|
||||||
|
|
||||||
print(result)
|
|
@@ -1,15 +0,0 @@
|
|||||||
powerList = []
|
|
||||||
for i in range(2, 101):
|
|
||||||
for j in range(2, 101):
|
|
||||||
powerList.append(i**j)
|
|
||||||
|
|
||||||
powerList.sort()
|
|
||||||
|
|
||||||
i=0
|
|
||||||
while i < len(powerList):
|
|
||||||
if powerList[i]==powerList[i-1]:
|
|
||||||
powerList.pop(i)
|
|
||||||
i-=1
|
|
||||||
i+=1
|
|
||||||
|
|
||||||
print(len(powerList))
|
|
@@ -1,7 +0,0 @@
|
|||||||
def isDigitSum(n):
|
|
||||||
x=sum([int(i)**5 for i in str(n)])
|
|
||||||
if n==x:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
print(sum([i for i in range(2,1000000) if isDigitSum(i)]))
|
|
@@ -1,16 +0,0 @@
|
|||||||
totalSum=0
|
|
||||||
usedFactors = []
|
|
||||||
for i in range(1, 10000):
|
|
||||||
if i%100==0:
|
|
||||||
print(str(i/100) + "%")
|
|
||||||
for j in range(1, 10000):
|
|
||||||
x=i*j
|
|
||||||
if len(str(i))+len(str(j))+len(str(x))==9:
|
|
||||||
result = sum([int(k) for k in str(x)])
|
|
||||||
result += sum([int(k) for k in str(i)])
|
|
||||||
result += sum([int(k) for k in str(j)])
|
|
||||||
if sum==1+2+3+4+5+6+7+8+9:
|
|
||||||
totalSum+=x
|
|
||||||
|
|
||||||
print(totalSum)
|
|
||||||
#HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.
|
|
@@ -1,40 +0,0 @@
|
|||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
def factorize(n):
|
|
||||||
factors = []
|
|
||||||
if is_prime(n):
|
|
||||||
factors.append(n)
|
|
||||||
else:
|
|
||||||
while not is_prime(n):
|
|
||||||
for i in range(2,n):
|
|
||||||
if n%i==0:
|
|
||||||
factors.append(i)
|
|
||||||
n=n/i
|
|
||||||
break
|
|
||||||
factors.append(n)
|
|
||||||
return factors
|
|
||||||
|
|
||||||
for i in range(10, 100):
|
|
||||||
for j in range(10, 100):
|
|
||||||
if \
|
|
||||||
(int(str(i)[0]) == int(str(j)[1]) or \
|
|
||||||
int(str(i)[1]) == int(str(j)[0]) or \
|
|
||||||
int(str(i)[1]) == int(str(j)[1]) or \
|
|
||||||
int(str(i)[0]) == int(str(j)[0])) and \
|
|
||||||
not (i%10==0 and j%10==0):
|
|
||||||
if not any(elem in factorize(i) for elem in factorize(j)):
|
|
||||||
print(str(i) + " : " + str(j))
|
|
||||||
|
|
||||||
#Trivial examples betyr muligens at det er snakk om alt som ikke kan deles på en integer...
|
|
||||||
|
|
@@ -1,20 +0,0 @@
|
|||||||
def factorial(n):
|
|
||||||
x=1
|
|
||||||
for i in range(1, n+1):
|
|
||||||
x=x*i
|
|
||||||
return x
|
|
||||||
|
|
||||||
def sumFact(n):
|
|
||||||
sumfact=0
|
|
||||||
for i in str(n):
|
|
||||||
sumfact+=factorial(int(i))
|
|
||||||
return sumfact
|
|
||||||
|
|
||||||
|
|
||||||
result = 0
|
|
||||||
for i in range(3, 1000000):
|
|
||||||
if sumFact(i)==i:
|
|
||||||
result+=i
|
|
||||||
|
|
||||||
print(result)
|
|
||||||
|
|
@@ -1,26 +0,0 @@
|
|||||||
import itertools
|
|
||||||
|
|
||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
result=0
|
|
||||||
for i in range(1,1000001):
|
|
||||||
if not any(num in str(i) for num in ("0","2","4","6","8")):
|
|
||||||
x = list(itertools.permutations(str(i), len(str(i))))
|
|
||||||
x=["".join([str(a) for a in elem]) for elem in x]
|
|
||||||
if any([True for n in x if is_prime(int(n))]):
|
|
||||||
result+=1
|
|
||||||
print(result)
|
|
||||||
# for j in range(len(str(i))):
|
|
||||||
|
|
||||||
|
|
@@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
def isPalindromic(n):
|
|
||||||
if n==int(str(n)[::-1]):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
print(sum([i for i in range(1,1000001) if isPalindromic(i) and isPalindromic(int(str(bin(i))[2:]))]))
|
|
@@ -1,4 +0,0 @@
|
|||||||
from math import prod
|
|
||||||
|
|
||||||
longNum = "".join([str(i) for i in range(1000000)])
|
|
||||||
print (prod([int(longNum[10**i]) for i in range(7)]))
|
|
@@ -1,21 +0,0 @@
|
|||||||
import csv
|
|
||||||
import math
|
|
||||||
|
|
||||||
with open('42.txt') as file:
|
|
||||||
reader = csv.reader(file, delimiter=",", quotechar='"')
|
|
||||||
words = list(reader)[0]
|
|
||||||
|
|
||||||
def wordValue(n):
|
|
||||||
return sum([ord(i.lower())-96 for i in n])
|
|
||||||
|
|
||||||
def triangleBase(n):
|
|
||||||
return (math.sqrt(8*n+1)-1)/2
|
|
||||||
|
|
||||||
result = 0
|
|
||||||
for i in words:
|
|
||||||
n = wordValue(i)
|
|
||||||
if triangleBase(n).is_integer():
|
|
||||||
result+=1
|
|
||||||
print(result)
|
|
||||||
|
|
||||||
#inverse triangle: (sqrt(8*n+1)-1)/2
|
|
@@ -1,18 +0,0 @@
|
|||||||
from itertools import permutations
|
|
||||||
|
|
||||||
|
|
||||||
pan = "".join([str(i) for i in range(0,10)])
|
|
||||||
panPerms = ["".join(i) for i in permutations(pan)]
|
|
||||||
primes = [2,3,5,7,11,13,17]
|
|
||||||
sum=0
|
|
||||||
isDivisible=True
|
|
||||||
for i in range(len(panPerms)):
|
|
||||||
isDivisible=True
|
|
||||||
for j in range(len(primes)):
|
|
||||||
x = panPerms[i][1+j:4+j]
|
|
||||||
if not int(x)%primes[j]==0:
|
|
||||||
isDivisible = False
|
|
||||||
break
|
|
||||||
if isDivisible:
|
|
||||||
sum+=int(panPerms[i])
|
|
||||||
print(sum)
|
|
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
#Inverse Pentagonal: (sqrt(24*n+1)+1)/6
|
|
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
import math
|
|
||||||
|
|
||||||
def hex(n):
|
|
||||||
return n*(2*n-1)
|
|
||||||
|
|
||||||
i=144
|
|
||||||
while True:
|
|
||||||
x=hex(i)
|
|
||||||
if ((math.sqrt(24*x+1)+1)/6).is_integer() and ((math.sqrt(8*x+1)-1)/2).is_integer():
|
|
||||||
print(x)
|
|
||||||
break
|
|
||||||
i+=1
|
|
||||||
|
|
||||||
#Inverse Pentagonal: (sqrt(24*n+1)+1)/6
|
|
||||||
#Inverse Triangle: (sqrt(8*n+1)-1)/2
|
|
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
sum= sum([i**i for i in range(1,1001)])
|
|
||||||
|
|
||||||
print(str(sum)[-10:])
|
|
@@ -1,43 +0,0 @@
|
|||||||
from itertools import permutations
|
|
||||||
|
|
||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
num = []
|
|
||||||
for i in range (1000, 10000):
|
|
||||||
perms = list(permutations(str(i)))
|
|
||||||
perms = ["".join([str(x) for x in elem]) for elem in perms]
|
|
||||||
|
|
||||||
x = (lambda a, b: any(j in b for j in a))(perms, num)
|
|
||||||
if not x:
|
|
||||||
num.append(str(i))
|
|
||||||
|
|
||||||
num.pop(num.index("1478"))
|
|
||||||
|
|
||||||
#For all 4 digit numbers:
|
|
||||||
#If any permutation of i is already in num[], don't append, else append
|
|
||||||
#Remove 1487 from num[]
|
|
||||||
|
|
||||||
for i in num:
|
|
||||||
perms = list(permutations(str(i)))
|
|
||||||
perms = ["".join([str(x) for x in elem]) for elem in perms]
|
|
||||||
for j in range(len(perms)):
|
|
||||||
if not (int(perms[j])>=1000):
|
|
||||||
perms.pop(j)
|
|
||||||
primes=0
|
|
||||||
for j in perms:
|
|
||||||
if is_prime(int(j)):
|
|
||||||
primes+=1
|
|
||||||
if primes<=3:
|
|
||||||
pass
|
|
||||||
|
|
@@ -1,19 +0,0 @@
|
|||||||
def containsSameDigits(a, b):
|
|
||||||
if sorted(a) == sorted(b):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
i=1
|
|
||||||
while True:
|
|
||||||
counter = 0
|
|
||||||
for j in range(6):
|
|
||||||
if not containsSameDigits(str(i),str(i*(j+1))):
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
counter+=1
|
|
||||||
if counter==6:
|
|
||||||
print(i)
|
|
||||||
break
|
|
||||||
i+=1
|
|
||||||
|
|
||||||
|
|
@@ -1,12 +0,0 @@
|
|||||||
import math
|
|
||||||
|
|
||||||
result = 0
|
|
||||||
for i in range(22,101):
|
|
||||||
for j in range(0,101):
|
|
||||||
if j > i:
|
|
||||||
break
|
|
||||||
if math.comb(i,j)>1000000:
|
|
||||||
result+=((i-(j-1))-j)
|
|
||||||
break
|
|
||||||
|
|
||||||
print(result)
|
|
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
def digitSum(n):
|
|
||||||
return sum([int(i) for i in str(n)])
|
|
||||||
|
|
||||||
max = 0
|
|
||||||
for a in range(100):
|
|
||||||
for b in range(100):
|
|
||||||
if digitSum(a**b)>max:
|
|
||||||
max = digitSum(a**b)
|
|
||||||
|
|
||||||
print(max)
|
|
@@ -1,36 +0,0 @@
|
|||||||
# def SQRConvergent(n):
|
|
||||||
# if n==0:
|
|
||||||
# return (0)
|
|
||||||
# else:
|
|
||||||
# return 1+(1/(2+SQRConvergent2(n-1)))
|
|
||||||
|
|
||||||
# def SQRConvergent2(n):
|
|
||||||
# if n==0:
|
|
||||||
# return (0)
|
|
||||||
# else:
|
|
||||||
# return (1/(2+SQRConvergent2(n-1)))
|
|
||||||
|
|
||||||
def memoize(f):
|
|
||||||
memo = {}
|
|
||||||
def helper(x):
|
|
||||||
if x not in memo:
|
|
||||||
memo[x] = f(x)
|
|
||||||
return memo[x]
|
|
||||||
return helper
|
|
||||||
|
|
||||||
#(p/r) -> r2=r1+p1
|
|
||||||
# p2=p1+2*r1
|
|
||||||
def SQRCFraction(n):
|
|
||||||
x = [3,2]
|
|
||||||
for i in range(n-1):
|
|
||||||
x = [x[0]+2*x[1], x[0]+x[1]]
|
|
||||||
return x
|
|
||||||
|
|
||||||
def countDigits(n):
|
|
||||||
return sum([1 for i in str(n)])
|
|
||||||
|
|
||||||
result=0
|
|
||||||
for i in range(1000):
|
|
||||||
if countDigits(SQRCFraction(i+1)[0]) > countDigits(SQRCFraction(i+1)[1]):
|
|
||||||
result+=1
|
|
||||||
print(result)
|
|
@@ -1,33 +0,0 @@
|
|||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
split = 2
|
|
||||||
x = 1
|
|
||||||
primes = 0
|
|
||||||
total=1
|
|
||||||
|
|
||||||
while True:
|
|
||||||
|
|
||||||
for i in range(4):
|
|
||||||
total+=1
|
|
||||||
x += split
|
|
||||||
if is_prime(x):
|
|
||||||
primes+=1
|
|
||||||
|
|
||||||
if (primes/total<0.1):
|
|
||||||
break
|
|
||||||
|
|
||||||
#print(str(primes) + " - " + str(total) + "→" + str(primes/total))
|
|
||||||
split +=2
|
|
||||||
|
|
||||||
print(split+1)
|
|
@@ -1,16 +0,0 @@
|
|||||||
import csv
|
|
||||||
|
|
||||||
with open('59.txt') as file:
|
|
||||||
reader = csv.reader(file, delimiter=",")
|
|
||||||
numbers = list(reader)[0]
|
|
||||||
numbers = [int(i) for i in numbers]
|
|
||||||
|
|
||||||
#Det finnes mange 80 i txt-filen. Derfor kan vi anta at dette bør være mellomrom, altså 32
|
|
||||||
#80 -> 01010000
|
|
||||||
#XOR 01110000 -> 112
|
|
||||||
#32 -> 00100000
|
|
||||||
|
|
||||||
xored=[i^112 for i in numbers]
|
|
||||||
message = [chr(i) for i in xored]
|
|
||||||
|
|
||||||
print(message)
|
|
@@ -1,7 +0,0 @@
|
|||||||
def squaresum(n) :
|
|
||||||
return (n*(n+1)*(2*n+1))//6
|
|
||||||
|
|
||||||
sum1= squaresum(100)
|
|
||||||
sum2= sum(range(1,101))**2
|
|
||||||
|
|
||||||
print(sum2-sum1)
|
|
@@ -1,57 +0,0 @@
|
|||||||
import math
|
|
||||||
|
|
||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
def tot(n):
|
|
||||||
if is_prime(n):
|
|
||||||
return n-1
|
|
||||||
else:
|
|
||||||
return len([i for i in range(1,n) if math.gcd(i,n)==1])
|
|
||||||
|
|
||||||
def phi(n) :
|
|
||||||
|
|
||||||
result = n # Initialize result as n
|
|
||||||
|
|
||||||
# Consider all prime factors
|
|
||||||
# of n and for every prime
|
|
||||||
# factor p, multiply result with (1 - 1 / p)
|
|
||||||
p = 2
|
|
||||||
while(p * p<= n) :
|
|
||||||
|
|
||||||
# Check if p is a prime factor.
|
|
||||||
if (n % p == 0) :
|
|
||||||
|
|
||||||
# If yes, then update n and result
|
|
||||||
while (n % p == 0) :
|
|
||||||
n = n // p
|
|
||||||
result = result * (1.0 - (1.0 / (float) (p)))
|
|
||||||
p = p + 1
|
|
||||||
|
|
||||||
|
|
||||||
# If n has a prime factor
|
|
||||||
# greater than sqrt(n)
|
|
||||||
# (There can be at-most one
|
|
||||||
# such prime factor)
|
|
||||||
if (n > 1) :
|
|
||||||
result = result * (1.0 - (1.0 / (float)(n)))
|
|
||||||
|
|
||||||
return (int)(result)
|
|
||||||
|
|
||||||
max = [0,0]
|
|
||||||
for n in range(2,1000001):
|
|
||||||
totn = phi(n)
|
|
||||||
if n/totn > max[1]:
|
|
||||||
max = [n, n/totn]
|
|
||||||
|
|
||||||
print(max)
|
|
@@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
def isPrime(n):
|
|
||||||
for i in range(2, int(n**0.5)):
|
|
||||||
if (n%i==0):
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def is_prime(n):
|
|
||||||
if n == 2 or n == 3: return True
|
|
||||||
if n < 2 or n%2 == 0: return False
|
|
||||||
if n < 9: return True
|
|
||||||
if n%3 == 0: return False
|
|
||||||
r = int(n**0.5)
|
|
||||||
f = 5
|
|
||||||
while f <= r:
|
|
||||||
if n%f == 0: return False
|
|
||||||
if n%(f+2) == 0: return False
|
|
||||||
f +=6
|
|
||||||
return True
|
|
||||||
|
|
||||||
x=0
|
|
||||||
y=0
|
|
||||||
while y!=10001:
|
|
||||||
x+=1
|
|
||||||
if is_prime(x):
|
|
||||||
y+=1
|
|
||||||
# print(str(y) + " -> " + str(x))
|
|
||||||
|
|
||||||
print(x)
|
|
@@ -1,46 +0,0 @@
|
|||||||
def phi(n) :
|
|
||||||
|
|
||||||
result = n # Initialize result as n
|
|
||||||
|
|
||||||
# Consider all prime factors
|
|
||||||
# of n and for every prime
|
|
||||||
# factor p, multiply result with (1 - 1 / p)
|
|
||||||
p = 2
|
|
||||||
while(p * p<= n) :
|
|
||||||
|
|
||||||
# Check if p is a prime factor.
|
|
||||||
if (n % p == 0) :
|
|
||||||
|
|
||||||
# If yes, then update n and result
|
|
||||||
while (n % p == 0) :
|
|
||||||
n = n // p
|
|
||||||
result = result * (1.0 - (1.0 / (float) (p)))
|
|
||||||
p = p + 1
|
|
||||||
|
|
||||||
|
|
||||||
# If n has a prime factor
|
|
||||||
# greater than sqrt(n)
|
|
||||||
# (There can be at-most one
|
|
||||||
# such prime factor)
|
|
||||||
if (n > 1) :
|
|
||||||
result = result * (1.0 - (1.0 / (float)(n)))
|
|
||||||
|
|
||||||
return (int)(result)
|
|
||||||
|
|
||||||
def containsSameDigits(a, b):
|
|
||||||
if sorted(str(a)) == sorted(str(b)):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
result = 0
|
|
||||||
minimum = 1000
|
|
||||||
for i in range(2,10**7):
|
|
||||||
x = phi(i)
|
|
||||||
if containsSameDigits(i, x) and i/x< minimum:
|
|
||||||
result = i
|
|
||||||
minimum = i/x
|
|
||||||
print(result)
|
|
||||||
print(result)
|
|
||||||
|
|
||||||
|
|
@@ -1,17 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
x = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
|
|
||||||
|
|
||||||
max1 = 0
|
|
||||||
|
|
||||||
for i in range(0, 1000-12):
|
|
||||||
y=x[i:i+13]
|
|
||||||
z=1
|
|
||||||
for j in range(0,13):
|
|
||||||
z = z*int(y[j])
|
|
||||||
|
|
||||||
if z > max1:
|
|
||||||
print(z)
|
|
||||||
max1 = z
|
|
||||||
|
|
||||||
print(max1)
|
|
@@ -1,11 +0,0 @@
|
|||||||
for i in range(1,1001):
|
|
||||||
a = i
|
|
||||||
for j in range(1,1001-i):
|
|
||||||
b= j
|
|
||||||
if (a+b)>=1000:
|
|
||||||
break
|
|
||||||
c=1000-a-b
|
|
||||||
if a**2+b**2==c**2:
|
|
||||||
print(a*b*c)
|
|
||||||
exit()
|
|
||||||
|
|
@@ -1,19 +0,0 @@
|
|||||||
def squareOfDigits(n):
|
|
||||||
n=str(n)
|
|
||||||
return sum([int(n[i])**2 for i in range(0, len(n))])
|
|
||||||
|
|
||||||
result=0
|
|
||||||
for i in range(1, 10000000):
|
|
||||||
|
|
||||||
if i%100000==0:
|
|
||||||
print(str(i/100000) + "%")
|
|
||||||
|
|
||||||
while True:
|
|
||||||
i=squareOfDigits(i)
|
|
||||||
if i==1:
|
|
||||||
break
|
|
||||||
elif i==89:
|
|
||||||
result+=1
|
|
||||||
break
|
|
||||||
|
|
||||||
print(result)
|
|
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
print(str(28433*(2**7830457)+1)[-10:-0])
|
|
||||||
|
|
||||||
# for i in range(40):
|
|
||||||
# print(2**i)
|
|
23
src/test.py
23
src/test.py
@@ -1,23 +0,0 @@
|
|||||||
b = ["ABAR 200", "CDXE 500", "BKWR 250", "BTSQ 890", "DRTY 600"]
|
|
||||||
c = ["A", "B"]
|
|
||||||
|
|
||||||
def stock_list(listOfArt, listOfCat):
|
|
||||||
n = []
|
|
||||||
for item in listOfArt:
|
|
||||||
n.append(item.split(" "))
|
|
||||||
|
|
||||||
sum = []
|
|
||||||
for item in range(len(listOfCat)):
|
|
||||||
sum.append(0)
|
|
||||||
#sum[item]+= [int(x[1]) for x in n if listOfCat[item]==x[0][0]
|
|
||||||
for x in n:
|
|
||||||
if listOfCat[item]==x[0][0]:
|
|
||||||
sum[item]+=int(x[1])
|
|
||||||
return sum
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print(stock_list(b,c))
|
|
Reference in New Issue
Block a user