Skip to content
Snippets Groups Projects
Commit e1c25d6c authored by miwer106's avatar miwer106
Browse files

fix some typos

parent 54b632e8
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Crack the Code Puzzle
Use `:help` to get an overview for the jupyter notebook commands. If you need more insight on how to use this tool, consider reading *ProB Jupyter Notebook Overview*.
A while ago a member of our team stumbled across this puzzle in a mailing list.
We took a look at it and found it was very suitable to be represented in a ProB Jupyter Notebook.
This is the puzzle:
<img src="https://raw.githubusercontent.com/williamokano/lock-challenge-solver/master/assets/challenge.png" width=400 height=400 />
To solve this puzzle, we have to think about a way to represent this lock as a machine.
We chose to represent each digit of the code in a Digits function. This function enables us to place some assertions about the correct digits that we take from the hints on the picture. Additionally we make assertions about the correctly placed digits and ,eventually, we come to a solution that is stored in our Digits constant.
To solve this puzzle, we have to think about a way to represent this lock challenge as a machine.
We chose to represent each digit of the code in a Digits constant. This constant enables us to place some assertions about the correct digits that we take from the hints on the picture. Additionally, we make assertions about the correctly placed digits. Eventually, we come to a solution that is stored in our Digits constant.
To access the constant from the machine, we have to set it up with `:constants` and initialize the machine with `:init`.
%% Cell type:code id: tags:
``` prob
::load
MACHINE LockChallenge
// https://stackoverflow.com/questions/42373479/lock-challenge-in-prolog/
CONSTANTS Digits
PROPERTIES
// A numeric Lock has a 3 digit key:
Digits : 1..3 --> 0..9 &
// Hints
// [6,8,2] : one number is correct and well-placed
// [6,1,4]: one number is correct but wrongly placed
// [2,0,6]: two numbers are correct but wrongly placed
// [7,3,8]: nothing is correct
// [7,8,0]: one number is correct but wrongly placed
// Assertions about correct digits:
card(ran(Digits) /\ {6,8,2})=1 &
card(ran(Digits)/\{6,1,4})=1 &
card(ran(Digits)/\{2,0,6})=2 &
ran(Digits) /\ {7,3,8} = {} &
card(ran(Digits)/\{7,8,0})=1 &
// Assertions about correctly placed digits
card(Digits /\ [6,8,2])=1 &
(Digits /\ [6,1,4])={} &
(Digits /\ [2,0,6])={} &
(Digits /\ [7,8,0])={}
END
```
%% Output
Loaded machine: LockChallenge
%% Cell type:code id: tags:
``` prob
:constants
```
%% Output
Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags:
``` prob
:init
```
%% Output
Machine initialised using operation 1: $initialise_machine()
%% Cell type:markdown id: tags:
As we can see when we use the `:browse` functionality, our constant Digits can be called now, by simply typing it in.
As we can see when we use the `:browse` functionality: Our constant Digits can be called now, by simply typing it in.
%% Cell type:code id: tags:
``` prob
:browse
```
%% Output
Machine: LockChallenge
Sets: (none)
Constants: Digits
Variables: (none)
Operations:
%% Cell type:code id: tags:
``` prob
Digits
```
%% Output
$\{(1\mapsto 0),(2\mapsto 4),(3\mapsto 2)\}$
{(1↦0),(2↦4),(3↦2)}
%% Cell type:markdown id: tags:
This means our solution for the crack the code puzzle is 0, 4, 2. If you are interested in the runtime of the operations, you can use `:time` before each operation to track it.
%% Cell type:code id: tags:
``` prob
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment