Skip to content

Commit

Permalink
Create README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Oghenevwogaga Ebresafe committed Apr 19, 2021
1 parent 65226cd commit 2ac8172
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
### Solving cryptarithmetic problems in Racket

This is just a simple library to solve simple cryptarithmetic problems.

You just call a single function `solve`.

For example to solve this:

![SEND + MORE = MONEY](send.png)

You'd just have to call the `solve` function like so:

```racket
(solve '(S E N D)
'(M O R E)
'(M O N E Y))
```

This returns a (lazy) stream of solutions:

```racket
#<stream>
```

Most *good* crytarithmetic problems usually have a single solution.

To get a solution just use the standard `racket/stream` functions:


```racket
(define s
(solve '(S E N D)
'(M O R E)
'(M O N E Y)))
(stream-first s)
```
And sure enough, you'd get:

```racket
'((M . 1)
(N . 6)
(O . 0)
(Y . 2)
(D . 7)
(E . 5)
(R . 8)
(S . 9))
```
If a particular crytparithmetic problem doesn't have a solution and you
try to invoke `stream-first` on its stream you'd get an exception saying
you it expected a non-empty stream:

```racket
stream-first: contract violation
expected: (and/c stream? (not/c stream-empty?))
given: #<stream>
```

Note that it might take a while to get a solution because it searches
for a solution and returns the first it finds and stops seraching.

if



0 comments on commit 2ac8172

Please sign in to comment.