Largest palindrome product: Difference between revisions

Line 567:
Largest palindromic product of two 9-digit integers: 999980347 x 999920317 = 999900665566009999
</pre>
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq>def reverseNumber:
tostring|explode|reverse|implode|tonumber;
def task:
{ pow: 10}
| foreach range(2;8) as $n (.;
(.pow * 9) as $low
| .pow *= 10
| (.pow - 1) as $high
| .emit = null
| .nextN = false
| label $out
| foreach range($high; $low - 1; -1) as $i (.;
($i|reverseNumber) as $j
| ($i * .pow + $j) as $p
# k can't be even nor end in 5 to produce a product ending in 9
| .k = $high
| .done = false
| until(.k <= $low or .done;
if (.k % 10 != 5)
then ($p / .k) as $l
| if $l > $high
then .done = true
elif $p % .k == 0
then .emit = "Largest palindromic product of two \($n)-digit integers: \(.k) x \($l) = \($p)"
| .nextN = true
| .done = true
else .
end
else .
end
| .k += -2 )
| if .nextN then ., break $out else . end;
select(.emit) );
.emit ) ;
 
task</lang>
{{out}}
<pre>
Largest palindromic product of two 2-digit integers: 99 x 91 = 9009
Largest palindromic product of two 3-digit integers: 993 x 913 = 906609
Largest palindromic product of two 4-digit integers: 9999 x 9901 = 99000099
Largest palindromic product of two 5-digit integers: 99979 x 99681 = 9966006699
Largest palindromic product of two 6-digit integers: 999999 x 999001 = 999000000999
Largest palindromic product of two 7-digit integers: 9998017 x 9997647 = 99956644665999
</pre>
 
 
=={{header|Julia}}==
Line 708 ⟶ 760:
62.575515 seconds (241.50 M allocations: 16.491 GiB, 25.20% gc time, 0.07% compilation time)
</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>palindromeQ[n_] := (* faster than built in test PalindromeQ *)
2,442

edits