diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-06-20 20:10:05 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-06-20 20:10:05 +0200 |
| commit | e794020d8b881ede726338be50eaa461a134889f (patch) | |
| tree | 99f32380378fa6813d7ccf15b56d8b48fcd263c2 /julia/004-largest_palindrome_product.jl | |
| parent | 16a3e5fc6728f1c0d414983f6e1fc3fc160034b3 (diff) | |
| download | project_euler-e794020d8b881ede726338be50eaa461a134889f.tar.gz project_euler-e794020d8b881ede726338be50eaa461a134889f.tar.bz2 project_euler-e794020d8b881ede726338be50eaa461a134889f.zip | |
Refactoging julia problems with function chainning
Diffstat (limited to 'julia/004-largest_palindrome_product.jl')
| -rw-r--r-- | julia/004-largest_palindrome_product.jl | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/julia/004-largest_palindrome_product.jl b/julia/004-largest_palindrome_product.jl index 32be760..308ce48 100644 --- a/julia/004-largest_palindrome_product.jl +++ b/julia/004-largest_palindrome_product.jl @@ -7,20 +7,10 @@ # Find the largest palindrome made from the product of two 3-digit numbers. ### -function is_palindrom(n) +function is_palindrom(n::Integer)::Bool s = string(n) s == reverse(s) end - -top = -1 - -for x in 100:999 - for y in 100:999 - if is_palindrom(x * y) - global top = max(top, x * y) - end - end -end - -println(top) +result = maximum(x * y for x in 100:999, y in 100:999 if is_palindrom(x * y)) +println(result) |
