Note that there are some explanatory texts on larger screens.

plurals
  1. POConcatenating a list of numbers into one integer in haskell
    text
    copied!<p>I am doing yet another Project Euler problem - <a href="https://projecteuler.net/problem=38" rel="nofollow noreferrer">Problem 38</a>. I have this function which returns a list of numbers but what I need is that list of numbers to be one number. It calculates the concatenated product of an integer.</p> <pre><code>f (a,b) = a*b conProInt x n = map f (zip (replicate n x) ([1..n])) prob38 = maximum [ (conProInt (x) (n)) | x &lt;- [100..500], n &lt;- [1..9], (sort $ nub $ (decToList $ (conProInt x n) )) == (sort $ (decToList $ (conProInt x n) )), (sort $ nub $ (decToList $ (conProInt x n))) == [1..9] ] </code></pre> <p>eg:</p> <pre><code>conProInt 192 3 </code></pre> <p>returns: [192,384,576]</p> <p>what I need returned is: 192384576</p> <p>I have searched around and can't find a function or think of a function I could construct that would deliver what I need. How would I go about this?</p> <p>EDIT:</p> <p>I have updated the script to incorporate faster concatenation, but it doesn't return the correct result:</p> <pre><code>f (a,b) = a*b conProInt x n =( combine (map f (zip (replicate n x) ([1..n])))) prob38 = maximum [ (conProInt (x) (n)) | x &lt;- [1..50000], n &lt;- [2..40], (sort $ nub $ (decToList $ (conProInt x n) )) == (sort $ (decToList $ (conProInt x n) )), (sort $ nub $ (decToList $ (conProInt x n))) == [1..9] ] </code></pre> <p>I'm pretty sure the pandigital test</p> <pre><code>(sort $ nub $ (decToList $ (conProInt x n) )) == (sort $ (decToList $ (conProInt x n) )), (sort $ nub $ (decToList $ (conProInt x n))) == [1..9] </code></pre> <p>won't fail. I tried to make the search as large as possible, but the maximum 9-pandigital I got was 986315724. Any suggestions? Is the range of values for n a very large one?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload