[plt-scheme] Code review: garden fence encryption

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Sun Mar 15 10:46:36 EDT 2009

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.

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 suspect you can do this with no more than half the amount of code you 
currently have.

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.


Posted on the users mailing list.