[plt-scheme] Code review: garden fence encryption
Hi,
On Sun, 15 Mar 2009 10:46:36 -0400
Neil Van Dyke <neil at neilvandyke.org> wrote:
> If I understand correctly, there is a very simple non-functional
> solution: just iterate in one pass over the input string, filling in
> characters in the mutable target string at the appropriate positions
> as you go.
Yes, with mutable, iterative solutions it would be a bit easier. That
was part of the exercise but I'm sure that there is a nicer
functional version than mine.
> To do it functionally, remember that building a result is easy in a
> recursive algorithm if you're cons-ing a list, and also that in
> Scheme you can *read* characters at arbitrary positions in a string.
>
> Also, I don't think you need to build an explicit list of positional
> numbers. Think about how those numbers change at each step of the
> algorithm, and how you can do that in recursive function calls in one
> pass, at the same time you are building the result.
I wasn't able to figure out how to get the numbers in one pass. I'll
look into Davids code to find out how he did it.
> Caveat: I haven't worked through this myself. I just wanted to offer
> quick, possibly-helpful pointers to get you by until the pedagogy
> people check email this Sunday morning.
Thank you!
regards,
Marek