Refactor output
This commit is contained in:
parent
768a3278dd
commit
1209566e4a
@ -4,13 +4,15 @@ Created on 08 Aug 2021
|
|||||||
@author: David Doblas Jiménez
|
@author: David Doblas Jiménez
|
||||||
@email: daviddoji@pm.me
|
@email: daviddoji@pm.me
|
||||||
|
|
||||||
Solution for Problem 22 of Project Euler
|
Solution for Problem 022 of Project Euler
|
||||||
https://projecteuler.net/problem=22 =#
|
https://projecteuler.net/problem=22
|
||||||
|
=#
|
||||||
|
|
||||||
using BenchmarkTools
|
using BenchmarkTools
|
||||||
using DelimitedFiles
|
using DelimitedFiles
|
||||||
|
using MethodAnalysis
|
||||||
|
|
||||||
function Problem22()
|
function Problem022()
|
||||||
#=
|
#=
|
||||||
Using names.txt, a 46K text file containing over five-thousand first names,
|
Using names.txt, a 46K text file containing over five-thousand first names,
|
||||||
begin by sorting it into alphabetical order. Then working out the
|
begin by sorting it into alphabetical order. Then working out the
|
||||||
@ -21,19 +23,23 @@ function Problem22()
|
|||||||
is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So,
|
is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So,
|
||||||
COLIN would obtain a score of 938 × 53 = 49714.
|
COLIN would obtain a score of 938 × 53 = 49714.
|
||||||
|
|
||||||
What is the total of all the name scores in the file? =#
|
What is the total of all the name scores in the file?
|
||||||
file = "../files/Problem22.txt"
|
=#
|
||||||
|
|
||||||
|
file = "files/Problem22.txt"
|
||||||
names = sort(readdlm(file, ',', String)[:])
|
names = sort(readdlm(file, ',', String)[:])
|
||||||
|
|
||||||
result = 0
|
ans::Int64 = 0
|
||||||
for (idx, name) in enumerate(names)
|
for (idx, name) in enumerate(names)
|
||||||
result += sum(Int(c) - 64 for c in name) * idx
|
ans += sum(Int(c) - 64 for c in name) * idx
|
||||||
end
|
end
|
||||||
return result
|
|
||||||
|
return ans
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
println("Time to evaluate Problem $(lpad(22, 3, "0")):")
|
println("Took:")
|
||||||
@btime Problem22()
|
@btime Problem022()
|
||||||
println("")
|
println("")
|
||||||
println("Result for Problem $(lpad(22, 3, "0")): ", Problem22())
|
println("Result for Problem $(lpad(22, 3, "0")): ", Problem022())
|
||||||
|
# @code_warntype debuginfo=:source Problem022()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user