Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Keyword there being exam. I think that's a great approach for a high-enough level course; that is, let the students do whatever they want with whatever language they want in the assignments (hard to generalize a build-test-diff system though for submissions), then test concepts on the test.

I have a friend in a Python intro whose assignment was to make a program encrypting user input with the Caesar Cipher and (optionally) decrypting, and optionally supporting ROT13 as well. I'm pretty sure the teacher wanted them using ord(), chr(), for loops, etc., but the solution I suggested after my friend tried that way is much simpler:

    import string
    normal = 'abcd...ABCD...'
    caesar = 'defg...DEFG...'
    caesar_table = string.maketrans(normal, caesar)
    reverse_caesar_table = string.maketrans(caesar, normal)
    msg.translate(caesar_table) # for encryption
    msg.translate(reverse_caesar_table) # for decryption
Add in string.ascii_letters, string.ascii_uppercase, string.ascii_lowercase, and collections.deque (for string rotation) to generalize the alphabet sets, it was all very simple. And used a completely different 'algorithm' of a translation table that's done in C and performs super-fast, easily handles non-ascii characters (since the translation just leaves them alone), easily generalizable to whatever simple encryption scheme, etc.

Of course my friend doesn't want to learn programming therefore everything's complicated and she doesn't remember anything and even after 6 months which ends in a couple weeks I doubt she could do FizzBuzz. :(



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: