# Finding the question

## Recommended Posts

If you have at least 2 examples of the input and the output.  What is the most efficient way to determine a common question for all examples, if there is? Solutions that add the possibility of even a second operation seem to make the problem much more difficult, for example:

50 "mathed by X" = 29
22 "mathed by X" = 15

it seems like getting to "divided by 2 plus 4" is tough to automate, but easy to come to just looking at it.

```,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)```

##### Share on other sites

Depending on the number of operators and operations included, there are likely to be a multitude of solutions in many (if not possibly all) solvable situations. I believe the general solution leads to infinite recursion. You may still be able to solve this for a small defined set of numbers and operations.

Edited by czardas

##### Share on other sites

in the confines of 2 operators (+ , /).  does that make it easier?

My thought is, that it is a pretty effective captcha - fairly easy to build questions (maybe even automate some random input output) that only has to be validated by executing the users answers to see if they are == and both return true.

Edited by iamtheky

```,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)```

##### Share on other sites

Would it not be easier to generate all the info rather than two numbers and brute force the rest.

Silly little unrefined example ...

```Global \$Divisors[2] = [2, 4]

\$DividedBy = \$Divisors[Random(0, 1, 1)]
\$Plus = Random(1, 9, 1)

ConsoleWrite(\$Answer1 & " / " & \$DividedBy & " + " & \$Plus & " = " & \$Answer1 / \$DividedBy + \$Plus & @LF)

ConsoleWrite(\$Answer2 & " / " & \$DividedBy & " + " & \$Plus & " = " & \$Answer2 / \$DividedBy + \$Plus & @LF)```

Monkey's are, like, natures humans.

##### Share on other sites

I would suggest Simulated Annealing (link in sig, adapt example 1). But as czardas already pointed out, the fundamental issue here is non-uniqueness. Your present example is underdetermined. So you'd need several more given solutions to uniquely resolve for two operators and two values. Not sure that would still make a quick captcha then.

Edited by RTFC

My Contributions and Wrappers

Spoiler

##### Share on other sites

For a brute force approach (two operations / & +): find all the prime factors of the smaller number, reject the ones that are not also prime factors of the larger number, start in the mid-range of the remaining factors and do the division, test the difference for both numbers. The difference will be either greater, less or nothing. Decide which factor to test next based on the previous result. You can quit at the point when one difference suggests you aim higher and the next adjacent factor suggests you aim lower, in which case there is no solution. Once you have a solution add on the difference, it is either the target or (once again) there is no solution. This gives a rough outline at least.

Edit: I forgot one very important detail -  - some multiples of prime factors may also turn out to be factors common to both numbers, so they also have to be considered. If all factors common to both numbers are in ascending sequence, then the above binary-search-type method should do the trick.

Edited by czardas

## Create an account

Register a new account