16
\$\begingroup\$

Given a natural number n write a program or function to get a list of all the possible two factors multiplications that can be used to achieve n. To understand better what is pretended you can go to http://factornumber.com/?page=16777216 to see when n is 16777216 we get the following list:

   2 × 8388608  
   4 × 4194304  
   8 × 2097152  
  16 × 1048576  
  32 ×  524288  
  64 ×  262144  
 128 ×  131072  
 256 ×   65536  
 512 ×   32768  
1024 ×   16384
2048 ×    8192
4096 ×    4096

No need to pretty print things like here. The requirement is that each entry (pair of factors) is well distinguished from each other and inside each pair, the first factor is also well distinguished from the other. If you choose to return a list/array, the inside element can be a list/array with two elements, or some structure of your language that supports a pair of things like C++ std::pair.

Do not print the multiplication by 1 entry, nor repeat entries with the first factor commuted by the second, as they are pretty useless.

No winner; it will be a per language basis code golf.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Could you possibly add a smaller test case, such as 30? \$\endgroup\$ Dec 2, 2017 at 22:27
  • 1
    \$\begingroup\$ @cairdcoinheringaahing You can use factornumber.com to generate more test cases. \$\endgroup\$ Dec 2, 2017 at 22:39
  • 1
    \$\begingroup\$ I've seen this "per language" competition recently. What's the point? Most Qs don't get more than 1 or 2 As per language, and you still can select just one A as correct. \$\endgroup\$
    – fede s.
    Dec 2, 2017 at 23:54
  • 8
    \$\begingroup\$ @fedes. It's usually because there's no point in comparing between languages (i.e. Java vs. Jelly). \$\endgroup\$ Dec 3, 2017 at 0:06
  • 1
    \$\begingroup\$ @totallyhuman yeah, I know. Most of my answers are in Factor, or even Smalltalk. No chance against the golfing languages. Maybe there could be some way of ranking languages by verbosity and boilerplatery \$\endgroup\$
    – fede s.
    Dec 3, 2017 at 0:28

33 Answers 33

1
2
0
\$\begingroup\$

Pyt, 67 65 bytes

←ĐðĐ0↔/⅟ƖŽĐŁ₂20`ŕ3ȘĐ05Ș↔ŕ↔Đ4Ș⇹3Ș⦋ƥ⇹⁺Ɩ3ȘĐ05Ș↔ŕ↔Đ4Ș⇹3Ș⦋ƤĐ3Ș⁺ƖĐ3Ș<łĉ

I'm pretty sure this can be golfed.

Basically, the algorithm generates a list of all of the divisors of the input (let's call it n), makes the same list, but flipped, interleaves the two (e.g., if n=24, then, at this point, it has [1,24,2,12,3,8,4,6,6,4,8,3,12,2,24,1]), and prints out the elements from index 2 until half the array length, printing each number on a new line, and with an extra new line in between every pair.

Most of the work is done in actually managing the stack.


Saved 2 bytes by using increment function.

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 50 bytes

sub{map[$_,$_[0]/$_],grep!($_[0]%$_),2..sqrt$_[0]}

Ungolfed:

sub {
    return map  { [$_, $_[0] / $_] }
           grep { !($_[0] % $_) }
           (2 .. sqrt($_[0]));
}

Try it online.

\$\endgroup\$
0
\$\begingroup\$

Japt, 9 bytes

Outputs a 2D array.

â ¤ò
£ÎîX

Try it

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.