TCCC '23 Sept P9 - Digit God!

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types

Thornhill Computer Club 2023 - September Contest - Problem 9

An example digits game

Digits, a game created by the New York Times, is a numerical puzzle that uses basic mathematical operations: addition, subtraction, multiplication, and division. 348929050, often plays digits during computer science and self-proclaims himself as the "Digits God" as he is able to solve every digits problem with ease.

The game consists of 6 numbers that can be added, subtracted, multiplied, and divided by each other to reach a target number. After completing and operation using two numbers, their result is added to the list of usable numbers in place of the two numbers used. This process continues until the target number appears in the list of usable numbers. It is always be possible to create the target number using some order of operations. Additionally, the result of subtraction must always be positive and the result of division must always be an integer (Divisor must be a factor).

Unfortunately, The New York Times found the puzzle not popular enough for the public and stopped publishing daily puzzles on August 8th, 2023. Devastated by this loss, 348929050 could no longer call himself the "Digits God". However, the problem has manifested itself right onto TSSOJ, once again allowing users to self proclaim themselves the "Digits God". Are you up to the challenge of claiming the title?

Input Specification

The first line of input will contain 6 integers I where 1 \le I \le 1000, the 6 starting digits of the puzzle.
The second line of input will contain a single integer A, the desired answer, where 1 \le A \le 10^{18}.

Output Specification

On the first line, output a single integer N, the number of moves in your solution to the puzzle.
Output N more lines, each containing two integers, the operation you use, and the result of the operation.

Each line should formatted in the order NON=R where N is a integer, O is an operation, and R is the integer result.
Valid operations include + for addition, - for subtraction, * for multiplication, and / for division.

Sample Input 1

4 2 10 1 3 25
62

Sample Output 2

4
3*25=75
1+2=3
3+10=13
75-13=62

Explanation for Sample Input 1

We start with the numbers 4 2 10 1 3 25. We can multiply 3 by 25 to get 75.
After this operation, our list of numbers will be 4 2 10 1 75. Next, we can add 1 and 2 to get 3.
This leaves us with the numbers 4 3 10 75. Then we can add 3 to 10 to get 13.
Our remaining numbers are now 3 13 75. Finally, we can subtract 13 from 75 giving us our target number of 62.
The remaining numbers would now be 4 62. In total, this took 4 moves.


Comments

There are no comments at the moment.