Inspired by: Find an Unrelated Number
Challenge
Given two positive integers as input, output the mathematical operations that can be used on those inputs to generate every number from 1
to n
inclusive where n
is the smallest prime greater than the sum of the two inputs. If the number cannot be generated using the list of mathematical operations below, the output for that number should indicate that it is "unrelated".
For example, for the inputs 2
and 3
, n=7
so one valid output would be
Subtraction, Modulus, Bitwise OR, Unrelated, Addition, Multiplication, Unrelated
(see Output section below for clarification on valid outputs)
(If Erik the Outgolfer's answer is valid, the last term will always be unrelated
.)
Operations that must be considered are:
Addition (a + b)
Subtraction (a - b) and (b - a)
Multiplication (a * b)
Division (a / b) and (b / a)
Modulus (a % b) and (b % a)
Bitwise OR (a | b)
Bitwise XOR (a ^ b)
Bitwise AND (a & b)
In cases where an operation would lead to a non-integer (such as 2/3
), always floor. So 2/3=0
and 3/2=1
.
Exponentiation is not included because it is never required. a**b
and b**a
will always be larger than 2(a+b)-2
(which is (probably) the largest possible n
) except for the cases a=1|b=1
or a=b=2
. The cases a=b=1
and a=b=2
have valid solutions that do not use exponents: *
and /|U+U
, respectively. For the rest of the cases where a=1,b>1
, a**b=1
which can also be found with a%b
and b**a=b
which can also be found with b*a
.
Concatenation is not included because it was shown to always be larger than n
.
Input
2 positive integers.
Standard I/O methods are accepted. Standard loopholes are forbidden.
You can assume the input will always be within a valid range for your given language.
Output
A list or array of the mathematical operations that can be used with the inputs to generate every number from 1
to n
inclusive where n
is the smallest prime larger than the sum of the two inputs. (You do not need to output the value of n
.)
Output can be in any format valid for your language so long as it is clearly understood. For instance, it can be an array where each value is a separate operation, a string with a delimiter between each value, or even just a solid string where each character is a different value.
You can use any character(s) so long as each possible result has a unique representation. For instance, +-*/%|^&U
will work and so will 123456789
, UNRELATID
, and CODEgolf!
. You are advised to include a legend or explanation of how the output can be read.
If more than one operation can be used to generate a given number, you may output any one of them. Do not output all of them.
Testcases
Input | n | Example Valid Output
-----------------------------------------
2, 3 | 7 | Subtraction, Modulus, Bitwise OR, Unrelated, Addition, Multiplication, Unrelated
2, 3 | 7 | -%|U+*U
2, 3 | 7 | 2579139
1, 1 | 3 | [*,+,U]
6, 6 | 13 | ["/","U","U","U","U","&","U","U","U","U","U","+","U"]
6,12 | 19 | U/U&U-UUU^UUU|UUU+U
12,6 | 19 | U/U&U-UUU^UUU|UUU+U
7,11 | 19 | /U&-UU%UUUU^UU|UU+U
7,15 | 23 | %/UUUU%-UUUUUU|UUUUUU+U (2nd value is a floor divide)
(I can easily add more test cases if someone finds an interesting one.)
I think the test case outputs are all valid but I've been known to mistakes. Please tell me if you spot one.
Scoring
This is code-golf so fewest bytes wins!
Do not output all of them.
? \$\endgroup\$a = 1
,b = 5
. Then exponentiation is needed to make1
. \$\endgroup\$