11
1
Break two numbers up into their factorials; if they share any, return a falsey value. Otherwise, return a truthy value. (inspired by this recent question)
In other words, write each input number as the sum of factorials (of positive integers) in the greediest possible way; return a truthy value if no factorial appears in both representations, a falsey value otherwise.
Example
Given 20 and 49:
20 = 3! + 3! + 3! + 2!
49 = 4! + 4! + 1!
No factorial appears in both representations, so return a truthy value.
Given 32 and 132:
132 = 5! + 3! + 3!
32 = 4! + 3! + 2!
3! appears in both representations, so return a falsey value.
I/O
Input and output can be through any standard means.
Input will always be two nonnegative integers; no upper bound on these integers other than what your language requires.
Output should be a truthy or falsey value. These values don't necessarily have to be consistent for different inputs, as long as every output is correctly truthy/falsey.
Test Cases
If one input is 0
, the answer will always be truthy. Other truthy test cases:
{6, 3}, {4, 61}, {73, 2}, {12, 1}, {240, 2}, {5, 264}, {2, 91}, {673, 18},
{3, 12}, {72, 10}, {121, 26}, {127, 746}
If both inputs are odd integers, or if both inputs are the same positive integer, then the output will always be falsey. Other falsey test cases:
{8, 5}, {7, 5}, {27, 47}, {53, 11}, {13, 123}, {75, 77}, {163, 160}, {148, 53},
{225, 178}, {285, 169}, {39, 51}, {207, 334}, {153, 21}, {390, 128}, {506, 584},
{626, 370}, {819, 354}
This is code-golf, so fewest bytes wins!
"write each input number as the sum of factorials (of positive integers) in the greediest possible way" don't you mean the laziest possible way instead? – user41805 – 2017-06-05T06:58:05.203
4@KritixiLithos no. He's referring to the class of algorithms known as greedy algorithms, which work by maximizing some metric after each step. As in, always taking as much as they can. – John Dvorak – 2017-06-05T07:20:07.060