The Midlife Geek

Ramblings of a middle aged engineer, runner and open source enthusiast

Tag: Project Euler (page 1 of 2)

Project Euler 19

Project Euler again, problem 19. How many Sundays fell on the first of the month in the twentieth century?

Brute force solution in R but it let me play around with the way R handles dates. Seems more straight forward than in many languages (looking at you Java).

Continue reading

First 1000 digit Fibonacci number

Project Euler problem 25 is to find the index of the first Fibonacci number of 1000 characters. I used the gmp library – I couldn’t find a way to get the length of a bigz data type so converted it to a string:
Continue reading

Number letter counts

Project Euler problem 17:

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?

Continue reading

Names scores

Project Euler again, this time Python. The problem is to sort a list of 5000 names alphabetically then give them a value. For example “COLIN” is 3 + 15 + 12 + 9 + 14 = 53 and is the 938th item – so its value is 49714 (53*938).

Continue reading

Find the sum of amicable numbers under 10000

Project Euler problem 21 is to find the sum of all amicable numbers under 10000. An amicable number is:

Let \(d(n)\) be the sum of proper divisors of \(n\) then \(d(a)=b\) and \(d(b)=a\) if \(a!=b\) then \(a\) and \(b\) are amicable numbers.

Continue reading

Sum a list of 50 digit numbers

Problem 13 is summing a list of fifty digit numbers. I used the gmp library and R to solve in 2 lines:

print(substring((sum(as.bigz(readLines("euler13.txt")))), 0, 10))

Not much more to say really. I forgot the problem asks for the first 10 digits, so my first answer was wrong.

First triangular number with 500 divisors

OK so today I’m trying problem 12 – find the first triangular number with over 500 divisors. This is the first Project Euler problem I’ve really struggled to find a solution in a reasonable amount of time. Continue reading

Product of 4 consecutive numbers

I’m beginning to like R. You can capture table data from a connection (a generalised file), one of which is the clipboard, to a data frame.

problem.matrix <- 
    as.matrix(read.table("clipboard",sep=" "))

Continue reading

Project Euler, Visual Studio and playing with Python

I got Visual Studio 2017 through Microsoft’s Dreamspark promotion and thought I’d give it a try. I haven’t done a lot of development under Windows because its only on my laptop and my Linux desktop has 12 Gb RAM.
Continue reading

Largest product of five consecutive numbers in a 1000 digit number

Haven’t done much Project Euler recently – I’ve been busy studying. So here is an answer to problem eight which asks:

Find the greatest product of five consecutive digits in the 1000-digit number.

Continue reading

Older posts

© 2018 The Midlife Geek

Theme by Anders NorenUp ↑