Programming Update


C#

Back when I was doing GameDev.Tv‘s Unity 2D class, I really wanted to know how to do multiplayer games (I also wanted some better support on using Xbox/PS3 remotes in games). Well, this year they released their Multiplayer class. So, naturally, I bought it up. I started working on it, resulting in two Github Repos. In the first section we were learned the basics of the Mirror add-on. I’m currently working through the second section, where we will create a basic RTS. I haven’t reached a real differentiation point from the GameDev folks. That may come later after we get past the basics.

Scratch

This summer when I was doing Scratch projects with the kids, I’d bookmarked a couple and then I went back to work on a normal schedule. So I wanted to finally get to these. Since Scarlett really loves art, I chose to do the Pattern Pen project with her. It was a great project to do, as it taught me about lists in Scratch as well as the Pen module, which, essentially, add capabilities like the Turtle programming language. The final program looked like this:

In order to get the values for the degrees and increase lists, there was an intermediate step where the program would ask the user for values. Then the programmer was supposed to take note of the ones they liked for use in the final version. Scarlett preferred the interactivity so we did save off a version of the program at that point in development so she could play with it some more in the future. I thought she’d like it because she’s art oriented, I had no idea how much she’d love it.

Here’s a video of it in action:

Python

Since the last time I wrote about my programming projects, I had mostly been focused on the C# Unity Multiplayer class and getting the footage ready for the End of the Year video game post. But it turned out that I still had a couple Python Morsels left in my free trial and then I happened to be on discord when the Python discord mentioned something called Advent of Code…

Python Morsels

This one turned out not to be too bad. Trey wanted us to “write a function that takes a nested list of numbers and adds up all the numbers”. I somewhat tried to outsmart myself trying to be Pythonic. After a while I gave up and went for recursion. I ended up with:

def sums(iterable):                    
    sum = 0       
    for number in iterable:       
        if isinstance(number, list):       
            if len(number) == 0:       
                sum = sum + 0       
            else:       
                sum = sums(number) + sum       
        else:       
            sum = number + sum       
    return sum       

def deep_add(iterable):       
    # print(f"The iterable {iterable}")       
    return sums(iterable)

Turns out I wasn’t too far off from one of Trey’s recommended solutions. The only thing he did to make it more efficient was to make it use a generator in the recursion. Bonus 1 had to take in any iterable, not just a list. Bonus 2 adds a start value. Basically an extra number to add in addition to the iterable. Bonus 3 had to work on anything “number-like”. That meant things like time deltas. My final code looked like:

from collections import Iterable
 def sums(iterable, start):
     sum = start
     for number in iterable:
         if isinstance(number, Iterable):
             if len(number) == 0:
                 sum = sum + 0
             else:
                 sum = sums(number, sum)
         else:
             sum = number + sum
     return sum
 def deep_add(iterable, start=0):
     # print(f"The iterable {iterable}")
     return sums(iterable, start)

Overall, thanks to all that I’d learned during my various Python Morsels lessons, it was an easy problem set and I only needed a small break during part 3 to get my brain to solve it for me.

Advent of Code

As I mentioned above, I heard about Advent of Code in the Python discord. It’s a series of brain teaser programming word problems with an over-arching story being told within the problems. This year, the programmer is going to take a vacation from helping Santa. Each day presents another aspect of his journey where programming helps him solve a problem and get on to the next task. As I write this, today is Day 9. So far, Day 7 has given me the most trouble. In fact, I still haven’t finished part 2 of the Day 7 task. Outside of Day 7 I’ve been having a blast. Some puzzles have been really hard while others (like Days 8 and 9) have been really easy. Day 9 was especially easy because I learned about deques in Python Morsels. Each day, accomplishing the teaser for that day fills me with a sense of joy akin to any other puzzle solving endeavor. I also love seeing how others are solving the problems, including someone who is coding each problem in Unreal Engine. Here’s an example:

I’ve got a Github repo where I’m keeping track of all of my solutions. I’ll certainly have more to say about this during the end of year wrapup blog post on programming.