This commit is contained in:
David Doblas Jiménez 2022-10-07 21:36:07 +02:00
parent de1375d3f3
commit 4d53ec2b82
2 changed files with 9 additions and 9 deletions

View File

@ -19,7 +19,7 @@ function Problem8()
Find the thirteen adjacent digits in the 1000-digit number that have
the greatest product. What is the value of this product? =#
NUM = """
NUM::String = """
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
@ -42,14 +42,14 @@ function Problem8()
71636269561882670428252483600823257530420752963450
"""
num = replace(NUM, "\n" => "")
adjacent_digits = 13
target = length(num) - adjacent_digits
ans, i = 0, 1
num::String = replace(NUM, "\n" => "")
adjacent_digits::Int16 = 13
target::Int32 = length(num) - adjacent_digits
ans::Int64, i::Int64 = 0, 1
while i < target
a, j = 1, i
a::Int64, j::Int64 = 1, i
while j < (i + adjacent_digits)
a = a * parse(Int, (num[j]))
a *= parse(Int, (num[j]))
j += 1
end
if a > ans

View File

@ -20,8 +20,8 @@ function Problem9()
Find the product abc. =#
upper_limit = 1000
for a in 1:upper_limit + 1
for b in a + 1:upper_limit + 1
for a = 1:upper_limit+1
for b = a+1:upper_limit+1
c = upper_limit - a - b
if a * a + b * b == c * c
# It is now implied that b < c, because we have a > 0