diff --git a/config.json b/config.json index e86a11d..633f74c 100644 --- a/config.json +++ b/config.json @@ -578,6 +578,14 @@ "prerequisites": [], "difficulty": 6 }, + { + "slug": "palindrome-products", + "name": "Palindrome Products", + "uuid": "2810c41a-49c6-4db3-9afe-7f39bb2de651", + "practices": [], + "prerequisites": [], + "difficulty": 6 + }, { "slug": "parallel-letter-frequency", "name": "Parallel Letter Frequency", diff --git a/exercises/practice/palindrome-products/.docs/instructions.md b/exercises/practice/palindrome-products/.docs/instructions.md new file mode 100644 index 0000000..aac6652 --- /dev/null +++ b/exercises/practice/palindrome-products/.docs/instructions.md @@ -0,0 +1,36 @@ +# Instructions + +Detect palindrome products in a given range. + +A palindromic number is a number that remains the same when its digits are reversed. +For example, `121` is a palindromic number but `112` is not. + +Given a range of numbers, find the largest and smallest palindromes which +are products of two numbers within that range. + +Your solution should return the largest and smallest palindromes, along with the factors of each within the range. +If the largest or smallest palindrome has more than one pair of factors within the range, then return all the pairs. + +## Example 1 + +Given the range `[1, 9]` (both inclusive)... + +And given the list of all possible products within this range: +`[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 15, 21, 24, 27, 20, 28, 32, 36, 25, 30, 35, 40, 45, 42, 48, 54, 49, 56, 63, 64, 72, 81]` + +The palindrome products are all single digit numbers (in this case): +`[1, 2, 3, 4, 5, 6, 7, 8, 9]` + +The smallest palindrome product is `1`. +Its factors are `(1, 1)`. +The largest palindrome product is `9`. +Its factors are `(1, 9)` and `(3, 3)`. + +## Example 2 + +Given the range `[10, 99]` (both inclusive)... + +The smallest palindrome product is `121`. +Its factors are `(11, 11)`. +The largest palindrome product is `9009`. +Its factors are `(91, 99)`. diff --git a/exercises/practice/palindrome-products/.meta/config.json b/exercises/practice/palindrome-products/.meta/config.json new file mode 100644 index 0000000..dbac82f --- /dev/null +++ b/exercises/practice/palindrome-products/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "erikschierboom" + ], + "files": { + "solution": [ + "palindrome-products.ua" + ], + "test": [ + "tests.ua" + ], + "example": [ + ".meta/example.ua" + ] + }, + "blurb": "Detect palindrome products in a given range.", + "source": "Problem 4 at Project Euler", + "source_url": "https://projecteuler.net/problem=4" +} diff --git a/exercises/practice/palindrome-products/.meta/example.ua b/exercises/practice/palindrome-products/.meta/example.ua new file mode 100644 index 0000000..dcbd3c2 --- /dev/null +++ b/exercises/practice/palindrome-products/.meta/example.ua @@ -0,0 +1,85 @@ +IsPalindrome ← ≍⇌.°⋕ +Palindromes ← ◌◌ ⍢(+1 ⨬(∘|⊃(⊙∘|⊂⊙◌)) ⊸IsPalindrome|≥) ⊙⊙[] +Candidates ← ⍜(--1)⇡ ∩(×.) + +Candidates ← ⍜(--1)⇡ ∩(×.) +Palindrome ← ⍜(°⋕|⊂⟜⇌) +Palindromes ← ≡Palindrome Candidates +Factors ← ( + ◡(⋅Candidates) + ◡÷ + ◡(×⊃( + ⊙⋅⋅∘ + : + ≥ + | ⊙⋅⋅⋅∘ + : + ≤ + )) + ⊃(▽|▽⊙◌) + (=⌊.). + ⊃(▽|▽⊙◌) + ◴≡(⍆⊂) +) + +Largest ← ( + ◡Palindromes + ⍚Factors + + /◇⊂⊸⍚(>0⧻) + ▽ + ≡(⊂⊂◡× °⊂)°□⊣ + ⊙⋅⋅⋅ # TODO: fix +) +Smallest ← ( + ◡Palindromes + ⍚Factors + + /◇⊂⊸⍚(>0⧻) + ▽ + ≡(⊂⊂◡× °⊂)°□⊢ + ⊙⋅⋅⋅ # TODO: fix +) + +Candidates ← ⍜(--1)⇡ ∩(×.) +IsPalindrome ← ≍⇌.°⋕ +Palindromes ← ▽⊸≡IsPalindrome Candidates + +# Palindrome ← ⍜(°⋕|⊂⟜⇌) +# Palindromes ← ≡Palindrome Candidates +# Factors ← ( +# ◡(⋅Candidates) +# ◡÷ +# ◡(×⊃( +# ⊙⋅⋅∘ +# : +# ≥ +# | ⊙⋅⋅⋅∘ +# : +# ≤ +# )) +# ⊃(▽|▽⊙◌) +# (=⌊.). +# ⊃(▽|▽⊙◌) +# ◴≡(⍆⊂) +# ) + +# 100 999 +# 906609 +# Factors + +# Candidates 1 9 + +Palindromes 1000 9999 + +# IsPalindrome + +# ⍚Factors +# +# /◇⊂⊸⍚(>0⧻) +# ▽ +# ≡(⊂⊂◡× °⊂)°□⊣ +# ⊙⋅⋅⋅ # TODO: fix +# + +# https://www.uiua.org/pad?src=0_14_0-dev_7__Q2FuZGlkYXRlcyAgIOKGkCDijZwoLS0xKeKHoSDiiKkow5cuKQpJc1BhbGluZHJvbWUg4oaQIOKJjeKHjC7CsOKLlQpQYWxpbmRyb21lcyAg4oaQIOKWveKKuOKJoUlzUGFsaW5kcm9tZSBDYW5kaWRhdGVzCgojIFBhbGluZHJvbWUgIOKGkCDijZwowrDii5V84oqC4p-c4oeMKQojIFBhbGluZHJvbWVzIOKGkCDiiaFQYWxpbmRyb21lIENhbmRpZGF0ZXMKIyBGYWN0b3JzIOKGkCAoCiMg4pehKOKLhUNhbmRpZGF0ZXMpCiMg4pehw7cKIyDil6Eow5fiioMoCiMg4oqZ4ouF4ouF4oiYCiMgOgojIOKJpQojIHwg4oqZ4ouF4ouF4ouF4oiYCiMgOgojIOKJpAojICkpCiMg4oqDKOKWvXzilr3iipnil4wpCiMgKD3ijIouKS4KIyDiioMo4pa9fOKWveKKmeKXjCkKIyDil7TiiaEo4o2G4oqCKQojICkKCiMgMTAwIDk5OQojIDkwNjYwOQojIEZhY3RvcnMKCiMgQ2FuZGlkYXRlcyAxIDkKClBhbGluZHJvbWVzIDEwMDAgOTk5OQoKIyBJc1BhbGluZHJvbWUKCiMg4o2aRmFjdG9ycwojIAojIC_il4fiioLiirjijZooPjDip7spCiMg4pa9CiMg4omhKOKKguKKguKXocOXIMKw4oqCKcKw4pah4oqjCiMg4oqZ4ouF4ouF4ouFICMgVE9ETzogZml4CiMgCg== diff --git a/exercises/practice/palindrome-products/.meta/tests.toml b/exercises/practice/palindrome-products/.meta/tests.toml new file mode 100644 index 0000000..a3bc417 --- /dev/null +++ b/exercises/practice/palindrome-products/.meta/tests.toml @@ -0,0 +1,49 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[5cff78fe-cf02-459d-85c2-ce584679f887] +description = "find the smallest palindrome from single digit factors" + +[0853f82c-5fc4-44ae-be38-fadb2cced92d] +description = "find the largest palindrome from single digit factors" + +[66c3b496-bdec-4103-9129-3fcb5a9063e1] +description = "find the smallest palindrome from double digit factors" + +[a10682ae-530a-4e56-b89d-69664feafe53] +description = "find the largest palindrome from double digit factors" + +[cecb5a35-46d1-4666-9719-fa2c3af7499d] +description = "find the smallest palindrome from triple digit factors" + +[edab43e1-c35f-4ea3-8c55-2f31dddd92e5] +description = "find the largest palindrome from triple digit factors" + +[4f802b5a-9d74-4026-a70f-b53ff9234e4e] +description = "find the smallest palindrome from four digit factors" + +[787525e0-a5f9-40f3-8cb2-23b52cf5d0be] +description = "find the largest palindrome from four digit factors" + +[58fb1d63-fddb-4409-ab84-a7a8e58d9ea0] +description = "empty result for smallest if no palindrome in the range" + +[9de9e9da-f1d9-49a5-8bfc-3d322efbdd02] +description = "empty result for largest if no palindrome in the range" + +[12e73aac-d7ee-4877-b8aa-2aa3dcdb9f8a] +description = "error result for smallest if min is more than max" + +[eeeb5bff-3f47-4b1e-892f-05829277bd74] +description = "error result for largest if min is more than max" + +[16481711-26c4-42e0-9180-e2e4e8b29c23] +description = "smallest product does not use the smallest factor" diff --git a/exercises/practice/palindrome-products/palindrome-products.ua b/exercises/practice/palindrome-products/palindrome-products.ua new file mode 100644 index 0000000..742d6cb --- /dev/null +++ b/exercises/practice/palindrome-products/palindrome-products.ua @@ -0,0 +1,7 @@ +# Find the smallest palindrome product of two numbers in a range +# PalindromeProducts ? Min Max +Smallest ← |2 ⊙⋅(⍤ "Please implement Smallest" 0) + +# Find the largest palindrome product of two numbers in a range +# PalindromeProducts ? Min Max +Largest ← |2 ⊙⋅(⍤ "Please implement Largest" 0) diff --git a/exercises/practice/palindrome-products/tests.ua b/exercises/practice/palindrome-products/tests.ua new file mode 100644 index 0000000..9c0df3e --- /dev/null +++ b/exercises/practice/palindrome-products/tests.ua @@ -0,0 +1,47 @@ +~ "palindrome-products.ua" ~ Largest Smallest + +# Find the smallest palindrome from single digit factors +Expected ← [1_1_1] +⍤⤙≍ Expected Smallest 1 9 + +# Find the largest palindrome from single digit factors +Expected ← [9_1_9 9_3_3] +⍤⤙≍ Expected Largest 1 9 + +# Find the smallest palindrome from double digit factors +Expected ← [121_11_11] +⍤⤙≍ Expected Smallest 10 99 + +# Find the largest palindrome from double digit factors +Expected ← [9009_91_99] +⍤⤙≍ Expected Largest 10 99 + +# Find the smallest palindrome from triple digit factors +Expected ← [10201_101_101] +⍤⤙≍ Expected Smallest 100 999 + +# Find the largest palindrome from triple digit factors +Expected ← [906609_913_993] +⍤⤙≍ Expected Largest 100 999 + +# Find the smallest palindrome from four digit factors +Expected ← [1002001_1001_1001] +⍤⤙≍ Expected Smallest 1000 9999 + +# Find the largest palindrome from four digit factors +Expected ← [99000099_9901_9999] +⍤⤙≍ Expected Largest 1000 9999 + +# # Empty result for smallest if no palindrome in the range +# Expected = (None_[] +# ⍤⤙≍ Expected Smallest 1002 1003 + +# # Empty result for largest if no palindrome in the range +# Expected = (None_[] +# ⍤⤙≍ Expected Largest 15 15 + +# # Error result for smallest if min is more than max +# (fun () -> smallest 10000 1 |> ignore) |> should throw typeof + +# # Error result for largest if min is more than max +# (fun () -> largest 2 1 |> ignore) |> should throw typeof