Permuted multiples: Difference between revisions

Add Factor
(Changed to search only among multiples of 3 (see discussion).)
(Add Factor)
Line 7:
Find the smallest positive integer '''n''' such that, when expressed in decimal, 2*n, 3*n, 4*n, 5*n, and 6*n contain ''exactly'' the same digits but in a different order.
<br><br>
 
=={{header|Factor}}==
{{libheader|Factor-numspec}}
{{works with|Factor|0.99 2021-06-02}}
<lang factor>USING: formatting io kernel lists lists.lazy math math.ranges
math.vectors numspec present prettyprint sequences sets ;
 
: multiples ( n -- seq )
[ 2 * ] [ 6 * ] [ ] tri <range> [ present ] map ;
 
: all-set-eq? ( seq -- ? )
dup ?first [ set= ] curry all? ;
 
! Ordered lazy list of numbers that start with a '1' digit
NUMSPEC: starting-with-one 1 1_ ... ;
 
: smallest-permuted-multiple ( -- n )
starting-with-one [ multiples all-set-eq? ] lfilter car ;
 
{ 2 3 4 5 6 } " n: " write smallest-permuted-multiple dup .
over n*v [ "×%d: %d\n" printf ] 2each</lang>
{{out}}
<pre>
n: 142857
×2: 285714
×3: 428571
×4: 571428
×5: 714285
×6: 857142
</pre>
 
=={{header|Go}}==
{{trans|Wren}}
1,808

edits