From 55e16ab995caa8e8dc045f0362bd71d1fd2d7425 Mon Sep 17 00:00:00 2001 From: vzvu3k6k Date: Thu, 29 Oct 2020 04:58:00 +0900 Subject: [PATCH 1/5] Add solution for the Project Euler Problem 4 --- Project Euler/Problem 4/problem4_sol1.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Project Euler/Problem 4/problem4_sol1.rb diff --git a/Project Euler/Problem 4/problem4_sol1.rb b/Project Euler/Problem 4/problem4_sol1.rb new file mode 100644 index 0000000..b7e9d43 --- /dev/null +++ b/Project Euler/Problem 4/problem4_sol1.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class Integer + def parindrome? + self == reverse + end + + # 123.reverse == 321 + # 100.reverse == 1 + def reverse + result = 0 + n = self + loop do + result = result * 10 + n % 10 + break if (n /= 10).zero? + end + result + end +end + +factors = (100..999).to_a +products = factors.product(factors).map { _1 * _2 } +puts products.select(&:parindrome?).max From 459f674ec2726477162693caf7cc43ff249e9e25 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 29 Oct 2020 18:53:01 +0000 Subject: [PATCH 2/5] updating DIRECTORY.md --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index e828438..80e7163 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -26,6 +26,8 @@ * [Problem2 Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/Project%20Euler/Problem%202/problem2_sol1.rb) * Problem 3 * [Problem3 Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/Project%20Euler/Problem%203/problem3_sol1.rb) + * Problem 4 + * [Problem4 Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/Project%20Euler/Problem%204/problem4_sol1.rb) * Problem 5 * [Problem5 Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/Project%20Euler/Problem%205/problem5_sol1.rb) From bcd82560aa938e5a7fd11f6c6bdf0e1236fb363a Mon Sep 17 00:00:00 2001 From: vzvu3k6k Date: Thu, 31 Dec 2020 00:42:34 +0900 Subject: [PATCH 3/5] Rename solution file --- .../Problem 4/problem4_sol1.rb => project_euler/problem_4/sol2.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Project Euler/Problem 4/problem4_sol1.rb => project_euler/problem_4/sol2.rb (100%) diff --git a/Project Euler/Problem 4/problem4_sol1.rb b/project_euler/problem_4/sol2.rb similarity index 100% rename from Project Euler/Problem 4/problem4_sol1.rb rename to project_euler/problem_4/sol2.rb From 770fc9622c5a42ee5ee6d32cd0915361e73d3de5 Mon Sep 17 00:00:00 2001 From: vzvu3k6k Date: Thu, 31 Dec 2020 00:44:04 +0900 Subject: [PATCH 4/5] Add problem description copying from sol1.rb --- project_euler/problem_4/sol2.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/project_euler/problem_4/sol2.rb b/project_euler/problem_4/sol2.rb index b7e9d43..fd881e2 100644 --- a/project_euler/problem_4/sol2.rb +++ b/project_euler/problem_4/sol2.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +# 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. + class Integer def parindrome? self == reverse From 3405abe9d35b8a3eb52a9b56daa840a929981995 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 30 Dec 2020 15:46:16 +0000 Subject: [PATCH 5/5] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 7e05b7e..6aaeca9 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -43,6 +43,7 @@ * [Sol2](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_3/sol2.rb) * Problem 4 * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_4/sol1.rb) + * [Sol2](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_4/sol2.rb) * Problem 5 * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_5/sol1.rb)