aboutsummaryrefslogtreecommitdiff
path: root/julia/004-largest_palindrome_product.jl
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-06-18 21:50:31 +0200
committerCharles Cabergs <me@cacharle.xyz>2021-06-18 21:50:31 +0200
commit93b4c2a215556153ed948260678cd8e840493b39 (patch)
tree393edc821a5cd00db7971b4612c98855ff762945 /julia/004-largest_palindrome_product.jl
parentc0aeed4578bdaea39ddbed1b55896948f56b23f3 (diff)
downloadproject_euler-93b4c2a215556153ed948260678cd8e840493b39.tar.gz
project_euler-93b4c2a215556153ed948260678cd8e840493b39.tar.bz2
project_euler-93b4c2a215556153ed948260678cd8e840493b39.zip
problem 3 4 5 6 6 in julia
Diffstat (limited to 'julia/004-largest_palindrome_product.jl')
-rw-r--r--julia/004-largest_palindrome_product.jl26
1 files changed, 26 insertions, 0 deletions
diff --git a/julia/004-largest_palindrome_product.jl b/julia/004-largest_palindrome_product.jl
new file mode 100644
index 0000000..32be760
--- /dev/null
+++ b/julia/004-largest_palindrome_product.jl
@@ -0,0 +1,26 @@
+###
+# Largest palindrome product
+# Problem 4
+#
+# A palindromic number reads the same both ways. The largest palindrome made from the
+# product of two 2-digit numbers is 9009 = 91 × 99.
+# Find the largest palindrome made from the product of two 3-digit numbers.
+###
+
+function is_palindrom(n)
+ 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)