Skip to content

Instantly share code, notes, and snippets.

@kkchengaf
Last active June 14, 2023 07:48
Show Gist options
  • Save kkchengaf/80feb1c3b8bf8f779704fd35e8feb663 to your computer and use it in GitHub Desktop.
Save kkchengaf/80feb1c3b8bf8f779704fd35e8feb663 to your computer and use it in GitHub Desktop.

Solving 5 digits minus 4 digits = 33333

workflow

Introduction

Get to know this puzzle from the game "レイトン教授と不思議な町":

1から9までの数字を1回ずつ使って、○○○○○-○○○○=33333になるようにするには、どの数字をどこにいれたらよいか。

fill in the ○ using the numbers 1-9 once each:

m1

Intuitive approach

we know that 6 - 3 = 3, 4 - 1 = 3, 8 - 5 = 3, ... by intuitive, we try to fill in column by column, pairing two numbers with difference of 3 together:

m2_1

but some numbers will be repeat.

Solve the puzzle using graph

  • Subtraction

let take a look in this graph, where each neighbor difference by 3.

p1

what we have been doing, is linking up two neighbors horizontally and fill in a column.

p2 - 複製 m2_1

no matter how we pair the numbers, some of them will be leave. This means we cannot solve without borrowing.

besides horizontal link, we need other links to pair the numbers! if we can pair up all the numbers, that means we have a solution to the puzzle!

lets define "horizontal line" as "cancel", since we can fill the pairs in to any columns freely.

p3

  • Borrowing

we also know that 11 - 8 = 3, 12 - 9 = 3. if we use the concept of borrowing, we can define more ways to pair the numbers.

lets use the following example:

m3_1

this involves 2 borrowing, 11 - 8 = 3, 13(12) - 9 = 3, 6(5) - 2 = 3

starting from the hundreds digit, we have 6 - 2 = 4

however, we know that the tens digit will borrow 1 from it. this makes the result become 3.

this means we can pair up 2 numbers with difference of 4 together, if we use them at the start of borrowing.

we can link the number diagonally"╲"in the graph.

p4 p5

note that 7 - 3 = 4, we can define a special link for that.

p6 p7

back to the exmaple, the tens digit borrow from hundreds digit and get borrowed from ones digit:

m3_2

the tens digit borrow from hundreds digit and get borrowed from ones digit.

it "continues" the borrowing with only 3 cases: 3 - 9 = -4, 2 - 8 = -4, 1 - 7 = -4

this means we can pair up the above numbers together, if we use them in the continuous of borrowing.

we can link the edges numbers on the same row in the graph.

p8 p9

lets consider the ones digit:

m3_3

the ones digit end the borrowing chain with only 2 cases: 2 - 9 = -3, 1 - 8 = -3

this means we can pair up the above numbers together, if we use them in the end of borrowing.

p10 p10_2

  • Ten Thousands digit

the last rule is the case of 4 at the ten thousands digit. this will trigger the start of borrowing chain.

p11

  • Pairing up

alright we have defined all the rules.

what we have to do, is to link/use all the numbers based on the above rules in the graph.


lets put 3 at the ten thousands digit and link the numbers by horizontal lines:

p12 3 is cancel, we group 1 and 4, 2 and 5, 6 and 9 together, 7 and 8 is leave

2 numbers will be remain. lets try to use the borrowing chain:

p13 3 is cancel, we start the chain using 5 and 1, and end the chain using 2 and 9, 4 and 7 is cancelled freely, 6 and 8 is leave

not work.


lets put 4 at the ten thousands digit. we can also link 1 and 7 to continue the borrowing chain.

p14

we need to end the borrowing chain using 2 and 9. fortunately, we can link the remaining numbers freely: 3 and 6, 5 and 8.

p15

this will concludes the first 3 columns:

m4

and the last 2 columns with 8 - 5 and 6 - 3.

m5

p16

Conclusion

Using the graph method, we can also solve something like:

  • ○○○○○-○○○○ = 22222
  • ○○○○○-○○○○ = 44444

general workflow:

  1. create a graph with digits 1 to 9, so that each neighbor digit different by X
  2. define links that pairs up two digits
  3. link the graph so that all digits are cancelled
  4. rewrite the solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment