The post Project Euler 172 Solution appeared first on Dreamshire.
]]>How many 18-digit numbers n (without leading zeros) are there such that no digit occurs more than three times in n?
The post Project Euler 172 Solution appeared first on Dreamshire.
]]>The post Project Euler 163 Solution appeared first on Dreamshire.
]]>Project Euler 163: Consider an equilateral triangle in which straight lines are drawn from each vertex to the middle of the opposite side, such as in the size 1 triangle in the sketch below.
Sixteen triangles of either different shape or size or orientation or location can now be observed in that triangle. Using size 1 triangles as building blocks, larger triangles can be formed, such as the size 2 triangle in the above sketch. One-hundred and four triangles of either different shape or size or orientation or location can now be observed in that size 2 triangle.
It can be observed that the size 2 triangle contains 4 size 1 triangle building blocks. A size 3 triangle would contain 9 size 1 triangle building blocks and a size n triangle would thus contain n^{2} size 1 triangle building blocks.
If we denote T(n) as the number of triangles present in a triangle of size n, then
T(1) = 16
T(2) = 104
Find T(36).
The post Project Euler 163 Solution appeared first on Dreamshire.
]]>The post Project Euler 190 Solution appeared first on Dreamshire.
]]>Project Euler 190: Let S_{m} = (x_{1}, x_{2}, … , x_{m}) be the m-tuple of positive real numbers with x_{1} + x_{2} + … + x_{m} = m for which P_{m} = x_{1} * x_{2}^{2} * … * x_{m}^{m} is maximised.
For example, it can be verified that [P_{10}] = 4112 ([ ] is the integer part function).
Find Σ[P_{m}] for 2 ≤ m ≤ 15.
The post Project Euler 190 Solution appeared first on Dreamshire.
]]>The post Project Euler 183 Solution appeared first on Dreamshire.
]]>Let N be a positive integer and let N be split into k equal parts, r = N/k, so that N = r + r + … + r.
Let P be the product of these parts, P = r × r × … × r = r^{k}.
For example, if 11 is split into five equal parts, 11 = 2.2 + 2.2 + 2.2 + 2.2 + 2.2, then P = 2.2^{5} = 51.53632.
Let M(N) = P_{max} for a given value of N.
It turns out that the maximum for N = 11 is found by splitting eleven into four equal parts which leads to P_{max} = (11/4)^{4}; that is, M(11) = 14641/256 = 57.19140625, which is a terminating decimal.
However, for N = 8 the maximum is achieved by splitting it into three equal parts, so M(8) = 512/27, which is a non-terminating decimal.
Let D(N) = N if M(N) is a non-terminating decimal and D(N) = -N if M(N) is a terminating decimal.
For example, ΣD(N) for 5 ≤ N ≤ 100 is 2438.
Find ΣD(N) for 5 ≤ N ≤ 10000.
The post Project Euler 183 Solution appeared first on Dreamshire.
]]>The post Project Euler 179 Solution appeared first on Dreamshire.
]]>Find the number of integers 1 < n < 10^{7}, for which n and n + 1 have the same number of positive divisors. For example, 14 has the positive divisors 1, 2, 7, 14 while 15 has 1, 3, 5, 15.
Let’s take a subset of this problem and define the range to include the integers 1 < n ≤ 25. A simple way to find the number of divisors is to increment an array element for every n integers by one for each multiple of the divisors, not including 1 or itself. We need only check divisors from 2 to int(n/2).
That is, add 1 to each multiple of 2: 4, 6, 8, … then 3: 6, 9, 12, … then 4: 8, 12, 16, … and so on until we reach 12. Here’s a table to show the results:
n | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | # Divisors |
2 | 0 | |||||||||||
3 | 0 | |||||||||||
4 | 1 | 1 | ||||||||||
5 | 0 | |||||||||||
6 | 1 | 1 | 2 | |||||||||
7 | 0 | |||||||||||
8 | 1 | 1 | 2 | |||||||||
9 | 1 | 1 | ||||||||||
10 | 1 | 1 | 2 | |||||||||
11 | 0 | |||||||||||
12 | 1 | 1 | 1 | 1 | 4 | |||||||
13 | 0 | |||||||||||
14 | 1 | 1 | 2 | |||||||||
15 | 1 | 1 | 2 | |||||||||
16 | 1 | 1 | 1 | 3 | ||||||||
17 | 0 | |||||||||||
18 | 1 | 1 | 1 | 1 | 4 | |||||||
19 | 0 | |||||||||||
20 | 1 | 1 | 1 | 1 | 4 | |||||||
21 | 1 | 1 | 2 | |||||||||
22 | 1 | 1 | 2 | |||||||||
23 | 0 | |||||||||||
24 | 1 | 1 | 1 | 1 | 1 | 1 | 6 | |||||
25 | 1 | 1 |
Note how you can identify the prime numbers as those with zero divisors (ignoring 1 and itself).
Now, check adjacent array elements for equality and you’ll have your answer. In this simple case of L=25, the answer would be 3. We’ve highlighted the results above.
The post Project Euler 179 Solution appeared first on Dreamshire.
]]>The post Project Euler 188 Solution appeared first on Dreamshire.
]]>The hyperexponentiation or tetration of a number a by a positive integer b, denoted by a↑↑b or ^{b}a, is recursively defined by:
a↑↑1 = a,
a↑↑(k+1) = a^{(a↑↑k)}.
Thus we have e.g. 3↑↑2 = 3^{3} = 27, hence 3↑↑3 = 3^{27} = 7625597484987 and 3↑↑4 is roughly 10^{3.6383346400240996*10^12}.
Find the last 8 digits of 1777↑↑1855.
Using the optional third parameter of Python’s pow(x, y [,z]) function which calculates the modulo z of x to the power y (computed more efficiently than pow(x, y) % z) we loop through the pow function b times to calculate the tetration of a↑↑b. Modding the result by some power of 10, 10^{8} in this case, we can reduce this unwieldy number to its last 8 digits.
We can exit the loop early, reducing the number of iterations, when the modded result begins to repeat.
The post Project Euler 188 Solution appeared first on Dreamshire.
]]>The post Project Euler 197 Solution appeared first on Dreamshire.
]]>Given is the function f(x) = ⌊2^{30.403243784-x2}⌋ × 10^{-9} ( ⌊ ⌋ is the floor-function),
the sequence u_{n} is defined by u_{0} = -1 and u_{n+1} = f(u_{n}).
Find u_{n} + u_{n+1} for n = 10^{12}.
Give your answer with 9 digits after the decimal point.
We first made a plot of this function to see what we were dealing with. It seemed to oscillate and converge very quickly bouncing back and forth between 0.6811… and 1.0294… ad infinitum. This means that instead of 10^{12} iterations only a few hundred are required.
The post Project Euler 197 Solution appeared first on Dreamshire.
]]>The post Project Euler 174 Solution appeared first on Dreamshire.
]]>We shall define a square lamina to be a square outline with a square "hole" so that the shape possesses vertical and horizontal symmetry.
Given eight tiles it is possible to form a lamina in only one way: 3×3 square with a 1×1 hole in the middle. However, using thirty-two tiles it is possible to form two distinct laminae.
If t represents the number of tiles used, we shall say that t = 8 is type L(1) and t = 32 is type L(2).
Let N(n) be the number of t ≤ 1000000 such that t is type L(n); for example, N(15) = 832.
What is ∑ N(n) for 1 ≤ n ≤ 10?
Wanting a solution that could solve both problem 173 and 174 we decided that in a couple of minutes we could put something together that would run quickly. Instead of determining factors for each iteration we just modeled the building of the lamina which is faster than a solution counting even factors. In fact when the scale increases to, say 10,000,000 this program will outperform most others.
One drawback is the use of memory, but for the sake of development time it was of little consequence.
The post Project Euler 174 Solution appeared first on Dreamshire.
]]>The post Project Euler 173 Solution appeared first on Dreamshire.
]]>We shall define a square lamina to be a square outline with a square "hole" so that the shape possesses vertical and horizontal symmetry. For example, using exactly thirty-two square tiles we can form two different square laminae:
With one-hundred tiles, and not necessarily using all of the tiles at one time, it is possible to form forty-one different square laminae.
Using up to one million tiles how many different square laminae can be formed?
Ran a brute force for the first 10,000 tiles and found the series. So the next step is to form a generating function to calculate the answer, but, alas, this is unlikely to ever happen.
The post Project Euler 173 Solution appeared first on Dreamshire.
]]>The post Project Euler 162 Solution appeared first on Dreamshire.
]]>In the hexadecimal number system numbers are represented using 16 different digits:
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
The hexadecimal number AF when written in the decimal number system equals 10×16+15=175.
In the 3-digit hexadecimal numbers 10A, 1A0, A10, and A01 the digits 0,1 and A are all present.
Like numbers written in base ten we write hexadecimal numbers without leading zeroes.
How many hexadecimal numbers containing at most sixteen hexadecimal digits exist with all of the digits 0,1, and A present at least once?
Give your answer as a hexadecimal number.
(A,B,C,D,E and F in upper case, without any leading or trailing code that marks the number as hexadecimal and without leading zeroes , e.g. 1A3F and not: 1a3f and not 0x1a3f and not $1A3F and not #1A3F and not 0000001A3F)
This is a typical application of the inclusion-exclusion principle. It is helpful in answering questions where the number of elements of a set are required but not the elements themselves. We just need to know the number of elements in two sets and subtract the number in the intersection.
The equation, after combining some terms looks like: 15 x 16^{(n-1)} + 41 x 14^{(n-1)} – (43 x 15^{(n-1)} + 13^{n}) for each possible hex number containing n digits {3..16}.
Since the first digit is non zero the total possibilities without consideration for the constraints is 15 x 16^{(n-1)}. Then remove those with no {0, 1, A}. But we need to add back in those that have no 1 or 0, no 1 or A, no 0 or A. Then remove the duplicates that, again, have no {0, 1, A}. There are 258 4 digit hex numbers that follow this pattern.
The post Project Euler 162 Solution appeared first on Dreamshire.
]]>