<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/pandigital-products-euler-problem-32/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r.prevos.net/pandigital-products-euler-problem-32/"> The Devil is in the Data</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Euler Problem 32 returns to <a rel="nofollow" href="http://r.prevos.net/euler-problem-29-distinct-powers/" target="_blank">pandigital numbers</a>, which are numbers that contain one of each digit. Like so many of the Euler Problems, these numbers serve no practical purpose whatsoever, other than some entertainment value. You can find all pandigital numbers in base-10 in the Online Encyclopedia of Interegers (<a rel="nofollow" href="https://oeis.org/A050278" target="_blank">A050278</a>). The Numberhile video explains everything you ever wanted to</p>
<p>The Numberhile video explains everything you ever wanted to know about pandigital numbers but were afraid to ask.</p>
<p><iframe allowfullscreen="true" src="https://www.youtube.com/embed/gaVMrqzb91w?version=3&rel=1&%23038;fs=1&%23038;autohide=2&%23038;showsearch=0&%23038;showinfo=1&%23038;iv_load_policy=1&%23038;start=9&%23038;wmode=transparent" width="450" type="text/html"></iframe></p>
<h2>Euler Problem 32 Definition</h2>
<p>We shall say that an <em>n</em>-digit number is pandigital if it makes use of all the digits 1 to <em>n</em> exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.</p>
<p>The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.</p>
<p>Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.</p>
<p>HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.</p>
<h2>Proposed Solution</h2>
<p>The pandigital.9 function tests whether a string classifies as a pandigital number. The pandigital.prod vector is used to store the multiplication.</p>
<p>The only way to solve this problem is brute force and try all multiplications but we can limit the solution space to a manageable number. The multiplication needs to have ten digits. For example, when the starting number has two digits, the second number should have three digits so that the total has four digits, e.g.: 39 × 186 = 7254. When the first number only has one digit, the second number needs to have four digits.</p>
<pre>
pandigital.9 &lt;- function(x) # Test if string is 9-pandigital
    (length(x)==9 &amp; sum(duplicated(x))==0 &amp; sum(x==0)==0)

t &lt;- proc.time()
pandigital.prod &lt;- vector()
i &lt;- 1
for (m in 2:100) {
    if (m &lt; 10) n_start &lt;- 1234 else n_start &lt;- 123
    for (n in n_start:round(10000 / m)) {
        # List of digits
        digs &lt;- as.numeric(unlist(strsplit(paste0(m, n, m * n), &quot;&quot;)))
        # is Pandigital?
        if (pandigital.9(digs)) {
            pandigital.prod[i] &lt;- m * n
            i &lt;- i + 1
            print(paste(m, &quot;*&quot;, n, &quot;=&quot;, m * n))
        }
    }
}
answer &lt;- sum(unique(pandigital.prod))
print(answer)
</pre>
<p>Numbers can also be checked for pandigitality using mathematics instead of strings.</p>
<p>You can view the most recent version of this code on <a rel="nofollow" href="https://github.com/pprevos/r.prevos.net/blob/master/ProjectEuler/problem032.R" target="_blank">GitHub</a>.</p>
<p>The post <a rel="nofollow" href="http://r.prevos.net/pandigital-products-euler-problem-32/" target="_blank">Pandigital Products: Euler Problem 32</a> appeared first on <a rel="nofollow" href="http://r.prevos.net/" target="_blank">The Devil is in the Data</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r.prevos.net/pandigital-products-euler-problem-32/"> The Devil is in the Data</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/DRIk90R362Y" height="1"></a></div>