From e794020d8b881ede726338be50eaa461a134889f Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 20 Jun 2021 20:10:05 +0200 Subject: Refactoging julia problems with function chainning --- julia/004-largest_palindrome_product.jl | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'julia/004-largest_palindrome_product.jl') 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) -- cgit