# [racket] Using Racket to solve Professor Layton puzzles

 From: Jay McCarthy (jay.mccarthy at gmail.com) Date: Thu Jul 28 00:22:53 EDT 2011 Previous message: [racket] Using Racket to solve Professor Layton puzzles Next message: [racket] Using Racket to solve Professor Layton puzzles Messages sorted by: [date] [thread] [subject] [author]

```On Wed, Jul 27, 2011 at 7:02 PM, Eli Barzilay <eli at barzilay.org> wrote:
> Yesterday, Jay McCarthy wrote:
>> My blog now has what I believe is a solution. At least, the test
>> case you provide passes and the next few elements make sense.
>
> That looks right, though pretty verbose...  (And BTW, you're missing
> some way to mark the code as such -- there's no indentation!)

Oi, I posted it wrong... I just fixed it.

> Here's my code:
>
>  #lang lazy
>  (define (counts l num count)
>    (cond [(= count 0) (counts (cdr l) (car l) 1)]
>          [(= (car l) num) (counts (cdr l) num (add1 count))]
>          [else (list* count num (counts l 0 0))]))
>  (define foo (list* 1 1 2 1 (counts (cddr foo) 0 0)))
>
> The interesting bit here is that I need to start it with 4 numbers.
> (And an amusing fact: once I told Matthias what the problem was, it
> took him about two seconds to see that problem coming up.)
>
> I think that you're "cheating" around this problem here:
>
>     (if (empty? elements)
>       (loop #f 0 (list count last))
>       ...)
>
> Another thing that looks like it could be unkosher is that instead of
> feeding the sequence to itself you're building a description then go
> in a loop with the new description.  It looks like that could break if
> a description chunk begins with the same element the list it's
> describing ends with.

It actually never adds the final number to the description for exactly
this reason... it feeds it back in to the next round of the describe

Jay

>
> code and used `1 1' to bootstrap it, it failed with a reentrant
> promise.  I immediately thought that there was a bug in the code
> before I realized that it works exactly as it should.  The lazy
> stepper should help clarify that!
>
> (But apparently Stephen is taking one of these mysterious "vakeyshon"
> things that seem to be getting popular recently.  I don't know how one
> looks but they sound very dangerous.)
>
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!
>

--
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

```

 Posted on the users mailing list. Previous message: [racket] Using Racket to solve Professor Layton puzzles Next message: [racket] Using Racket to solve Professor Layton puzzles Messages sorted by: [date] [thread] [subject] [author]