2
klutch
4y

Great practice/skill sharpening idea for my fellow mad dogs that like to get down in multiple languages/syntaxes:

Pick something simple that won't cause too much stress, but will make you sweat a little bit and put up a good fight, ha!!!

For example, I picked the classic "Caesars Cipher" and picked 5 languages to create it in! I picked Dart, Java, Python, CPP, and C. Each version does the same thing:
1. Asks for a message
2. Runs the logic
3. Prints the message cipher.
4. To decrypt, you just run the same program again and enter the cipher text at the message input prompt. The message gets deciphered using the same logic an shows up as the original text.

The kicker:
Only dox/books allowed for reference. Otherwise it wouldn't push you to get better!!!

Python, C, and CPP were EASY, even with me never having used C before. I am great at using Dart, and that one really challenged me for some reason, but I finally got it. The previous 3 langs took less than 40 lines of code each (with Python being only 18 I believe). Dart actually took somewhere around 50, and Java took about 371784784. (Much love to Java though for real!)

Kinda boring as shit, but I gotta tell you it felt fuckin GREAT to look at all 5 of those programs after completing them, no matter how barbaric... especially when you complete 1 or 2 in a language you've never used or maybe felt really challenged by. Simple exercises that hold a lot of important, relatable logic no matter the subject is our lifeblood!!!

Comments
  • 2
    Great, now do the same in C, but for arbitrary long inputs (only limited by SIZE_MAX or memory).
    This should keep you busy for an hour.
  • 1
    @metamourge and no second array to copy to
  • 1
    I am gonna get on that right now actually
  • 0
    That's gonna be a good one, because I haven't the chance to do anything with it outside of some little tidbits here and there or reading about it
  • 0
    This is what I wrote, and it's first thing I did with C
  • 1
    ``strlen()`` in C counts the characters up to but excluding the terminal null every time. Don't use it inside a loop unless you must.

    Your two conditions in the while loop are arguably the same. If the buffer is full of valid characters, it will not hold a terminal null, and both conditions may fail (depending on what comes after the buffer).
  • 1
    @klutch You should probably refactor your ``caesarCipher()`` function to take a source buffer, a destination buffer, and a maximum length, then print the destination buffer in ``main()``. Unless you want to compete with whatever people post in /r/badcode…

    Here's a little F# solution that I hacked up in about 15 minutes:
  • 0
    @SomeNone That's the good stuff right there!!!!!! Well done haha
  • 0
    @SomeNone Noted, thanks so much!!! I'm gonna throw that in my code notes as I carry on. I've never done anything with C, so I'm all ears! I wanna make sure when the time comes down the road I can squeak by just enough to get it done, but done right. I NEVER half ass stuff when it's the real deal.
Add Comment