Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
34980ed0b4 | |||
d770dd831e | |||
ddc4943f57 | |||
20933b4f16 | |||
7201fa6e8b | |||
2da8957aac |
src
C
Task67 - Maximum path sum II.pytask11 - Largest product in a grid.pytask18 - Maximum path sum I.pytask22 - Names scores.pytask23 - Non-abundant sums.pytask26 - Reciprocal cycles.pytask32 - Pandigital products.pytask42 - Coded triangle numbers.pytask59 - XOR decryption.pytask62 - Cubic permutations.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,6 +1,6 @@
|
||||
#Same as task 18
|
||||
|
||||
with open('67.txt') as fp:
|
||||
with open('./../67.txt') as fp:
|
||||
data = [list(map(int, line.strip().split(' '))) for line in fp]
|
||||
|
||||
data.reverse()
|
||||
|
@ -1,4 +1,4 @@
|
||||
with open('11.txt') as fp:
|
||||
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
|
||||
|
@ -1,6 +1,6 @@
|
||||
#Same as task 67
|
||||
|
||||
with open('18.txt') as fp:
|
||||
with open('./../18.txt') as fp:
|
||||
data = [list(map(int, line.strip().split(' '))) for line in fp]
|
||||
|
||||
data.reverse()
|
||||
|
@ -8,7 +8,7 @@ def wordSum(n):
|
||||
|
||||
data =[]
|
||||
|
||||
with open('22.txt') as file:
|
||||
with open('./../22.txt') as file:
|
||||
reader = csv.reader(file, delimiter=",", quotechar='"')
|
||||
data = list(reader)[0]
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
import math
|
||||
from functools import reduce
|
||||
|
||||
def factors(x):
|
||||
result = [1]
|
||||
i = 2
|
||||
while i*i <= x: #Other way of writing i<=sqrt(x)
|
||||
while i*i <= x:
|
||||
if x % i == 0:
|
||||
result.append(i)
|
||||
if x//i != i:
|
||||
@ -12,39 +9,18 @@ def factors(x):
|
||||
i += 1
|
||||
return result
|
||||
|
||||
def is_abundant(n):
|
||||
return sum(factors(n)) > n
|
||||
def isAbundant(x):
|
||||
return sum(factors(x)) > x
|
||||
|
||||
abundants= [i for i in range(28123) if is_abundant(i)]
|
||||
abundantNumbers = [num for num in range(1, 28123) if isAbundant(num)]
|
||||
sums = [True for _ in range(1,28123)]
|
||||
|
||||
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")
|
||||
for i in range(len(abundantNumbers)):
|
||||
for k in range(len(abundantNumbers)):
|
||||
try:
|
||||
sums[abundantNumbers[i] + abundantNumbers[k]] = False
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
#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)
|
||||
print(sum([i for i, x in enumerate(sums) if x]))
|
||||
|
||||
|
@ -1,4 +1,16 @@
|
||||
|
||||
for i in range(1,1000):
|
||||
x = 1/i
|
||||
|
||||
|
||||
numsWithRecurringCycles = [n for n in range(2,1000) if n % 2 != 0 and n % 5 != 0]
|
||||
|
||||
def digits(num, divisor):
|
||||
x = num
|
||||
storedSums = []
|
||||
while not x*10 in storedSums:
|
||||
x *= 10
|
||||
storedSums.append(x)
|
||||
x %= divisor
|
||||
return len(storedSums)
|
||||
|
||||
digitNumList = [digits(1, n) for n in numsWithRecurringCycles]
|
||||
|
||||
print(numsWithRecurringCycles[digitNumList.index(max(digitNumList))])
|
||||
|
@ -1,16 +1,14 @@
|
||||
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
|
||||
from itertools import permutations
|
||||
from math import ceil
|
||||
|
||||
print(totalSum)
|
||||
#HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.
|
||||
def isPanDigital(i,j,x):
|
||||
return sorted(str(i) + str(j) + str(x)) == ['1' ,'2', '3', '4', '5', '6', '7', '8', '9']
|
||||
|
||||
panDigits = []
|
||||
for i in range(1,10000):
|
||||
for j in range(1,ceil(10000/i)):
|
||||
prod = i*j
|
||||
if isPanDigital(i, j, prod) and not prod in panDigits:
|
||||
panDigits.append(prod)
|
||||
|
||||
print(sum(panDigits))
|
@ -1,7 +1,7 @@
|
||||
import csv
|
||||
import math
|
||||
|
||||
with open('42.txt') as file:
|
||||
with open('./../42.txt') as file:
|
||||
reader = csv.reader(file, delimiter=",", quotechar='"')
|
||||
words = list(reader)[0]
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import csv
|
||||
|
||||
with open('59.txt') as file:
|
||||
with open('./../59.txt') as file:
|
||||
reader = csv.reader(file, delimiter=",")
|
||||
numbers = list(reader)[0]
|
||||
numbers = [int(i) for i in numbers]
|
||||
|
18
src/task62 - Cubic permutations.py
Normal file
18
src/task62 - Cubic permutations.py
Normal file
@ -0,0 +1,18 @@
|
||||
def has5Permutations(n):
|
||||
return numberList[len(n)].count(n) == 5
|
||||
|
||||
numberList = [[] for _ in range(100)]
|
||||
|
||||
i=1
|
||||
while True:
|
||||
|
||||
n = i**3
|
||||
sortedN = ''.join(sorted(str(n)))
|
||||
numberList[len(sortedN)].append(sortedN)
|
||||
|
||||
if has5Permutations(sortedN):
|
||||
index = numberList[len(sortedN)].index(sortedN)
|
||||
print((sum([len(numberList[j]) for j in range(len(sortedN)) ]) + index+1) ** 3)
|
||||
exit(0)
|
||||
|
||||
i += 1
|
Reference in New Issue
Block a user