6
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!
That last one makes this a lot harder – Cyoce – 2017-05-24T20:38:06.353
@Cyoce By "the last one", do you mean
Do not output all of them.
? – Engineer Toast – 2017-05-24T20:47:24.650I mean the concatenation one. – Cyoce – 2017-05-24T20:48:16.817
None of your test cases require concatenation. Is there any that will? I'm not even sure if there's a case where concatenating the two numbers will not be larger than the smallest prime greater than their sum. – mbomb007 – 2017-05-24T20:59:33.183
@mbomb007 I spent a few minutes thinking about that and, as far as I can tell, the concatenated results will always be greater than
n
. I'm not good enough to prove that but I think it's right. – Engineer Toast – 2017-05-24T21:00:58.9172Maybe just remove that operator, then. – mbomb007 – 2017-05-24T21:03:06.653
Also, none of your test cases require exponentiation. That might be another similar case, since exponentiation grows so quickly. – mbomb007 – 2017-05-24T21:06:18.487
@mbomb007 Floor division. I have now copied the note from the other question.
– Engineer Toast – 2017-05-24T21:18:43.207Maybe add the test case
6, 12
, which requiresb/a
. Or an example where floor division is necessary. – mbomb007 – 2017-05-24T21:20:38.837If you decide to drop exponentiation later it may affect the output of at least one of your test cases. Specifically,
2, 3 | 7 | 257B13B
. – Octopus – 2017-05-24T21:50:42.2932Say
a = 1
,b = 5
. Then exponentiation is needed to make1
. – isaacg – 2017-05-24T21:54:46.180@isaacg In that case,
1%5
also works. – Engineer Toast – 2017-05-24T21:56:49.150What if there is a case where two different operations generate the same answer. eg. 22 and 2*2, so what do I output? – Octopus – 2017-05-24T21:57:02.377
@Octopus Either one but only one. Can't be both. You can pick which one. Doesn't have to be the same every time. So long as you return a valid operation, it's OK. – Engineer Toast – 2017-05-24T21:58:09.563
@Octopus Technically, it wouldn't need to change the test case if I drop operations. I would just need to update my legend to explain that it's still hexadecimal but it's no longer just the index of where it appears in the list. – Engineer Toast – 2017-05-24T21:58:51.650
@isaacg but 1&5 is also 1 – Octopus – 2017-05-24T23:14:45.057
5
I think I've proven that the concatenation must be greater than the prime, unless I made an error: https://pastebin.com/EsR9AXNr
– faubi – 2017-05-24T23:24:39.067The final U is missing in test case 6,12 – edc65 – 2017-05-25T08:28:17.910