Naomi Liu's weblog

My blog about code, more code, and anything else I have time to write about.

the Art and Technical Challenges of Coding for Online Games

Writing code for online games, particularly for mobile or web-based slot games like this one, involves a mix of advanced graphics rendering, real-time networking, security implementations, and intricate game logic. Developers need to balance between performance optimization, cross-platform compatibility, and the unique requirements of the online gambling industry, such as randomization and fairness.

Read More »

subverting the software interview

Cans. Cans everywhere. Some alcoholic, some diabetic, all of them eclectic. Remnants of nights long gone, spent hunched over in front of the pale glow of a text editor. Time you’ll never recover, lost to the ethereal dance of progress. There’s an old pizza box in the corner, a faint memory of a lonely meal. You miss being able to go out and eat. More specifically, you miss having the cash to do so. You think back to a happier period in your life, one where your wallet was unbare, and the numbers on your bank statement left no negative space for interpretation. Those times are gone, and you’re desperate for the chance to be able to feed yourself again. You’ve conjured software magick for most of your life; regretfully, your supernatural programming ability is hindered by mortal desires like eating and not being homeless. You came across a posting one night, one that offered the prospect of potential employment. The words of the HR manager echoed softly in your ears – among the sea of corporate jargon, unrealistic requirements, and a slightly boring job description, your eyes lit up when they scanned the salary range. Across the gossamer threads of the internet, where datagrams twirl and spin across fibre-optic highways, this one reached your browser, and by extension – your soul. It’s enough money to shop at Whole Foods without selling a kidney. You jump back, your posture restored by the rejuvinating shock of motivation, and fire your resume

Read More »

write you a parser for okay acceptable!

Parsec is a beautiful library, but it’s DIFFICULT. Every time I’m working on a problem that requires an actual parser beyond regex, I die a little inside. I used Parsec for my Scheme interpreter, and it was probably the most frustrating part of the project. This isn’t the fault of the authors, though. Parsers are complicated beasts, and I definitely didn’t know what I was doing the first time around. There’s an interesting problem on Codewars – given an arbitrary molecule string, return the count of each constituent atom. Sounds pretty simple, right? That’s it, we’re done. End of post. Obviously, we’re not done. Even organic chemists deal with atoms beyond C, H, O, N. To make matters more complicated, chemists are just like programmers – lazy. For polymeric materials with repeating groups, there’s a handy way to express their structure. For example, the formula for PVC is C2H3Cl. I guess that would just be VC – because it forms arbitrarily long chains, it’s written as (C2H3Cl)n. What a tradeoff – chemists making their lives easier at our expense. If we had to parse something like It seems like we can treat a group of parentheses as a subexpression on its own, multiplying every number by the coefficient that comes after it. You can look at this notation as a form of run-length encoding, where you express repeating substructures of data as pairs (s, n). It’s the simplest form of data compression, and it’s easy to encode an arbitrary string.

Read More »

advent of code 2020, day 7: droste and bourke

The previous few days of Advent have been kinda boring – day 4 was regex, then binary search, then set intersections. We’re finally back to graph traversals, and so I felt like this was worth a post. The problem goes as follows – you’ve sledded to the airport, made it past security, boarded your plane, and gotten through customs. Now that you’re out of the North Pole and at your layover, bizarre baggage rules are only the next obstacle on your trip. Specifically, bags must be colour-coded and must contain specific quantities of other colour-coded bags. The input consists of several hundred lines that each describe the colour of a bag, and its required contents, like That’s a ton of nested bags, and it’s starting to sound like a graph theory problem. We can label each node by its colour description, and assign a weight to each edge by bag quantity. Since logically, a bag can’t contain itself, and inner bags can’t contain outer bags (forming a cycle), we can look at this as a directed acyclic graph. Part 1 seems like it’s asking a lot at first. The prompt reads, “You have a shiny gold bag. If you wanted to carry it in at least one other bag, how many different bag colors would be valid for the outermost bag?”. My first thought was just to do a topological sort of our graph, count the number of nodes that occur before shiny gold, and call it a day. There’s

Read More »

advent of code 2020, day 3: lazy tobogganing

Part 1 of 2 in this series. It’s December, so you know what that means. Debt? Maybe. Alcoholism? No time. Time to save Santa again? Yep. Advent of Code is finally back, and so everybody’s in full motion trying to contort their favourite languages into workable problem-solving tools, me included. I’ve been a huge fan of Advent of Code ever since I started programming, and I love going back and working on old problems when Leetcode and Codewars get boring. I’m hoping for some problems spread out over several days that involve incremental and visible progress, like last year’s Intcode computer. Today’s problem is relatively simple – after saving Christmas for the past five years, you’ve earned yourself a little tropical vacation. Even though you’ve travelled through space, time, and into Santa’s computer, you still have to rely on sled-based transportation to get to the airport. This is a task fraught with danger, because trees litter the landscape more than potholes mark the 401. Given an ASCII map of the area and two integers denoting rise and run, your task is to figure out how many trees you’ll collide with on your path. #’s represent trees and .’s are empty land. Mercifully, we won’t need to deal with floating-point calculations for this problem. The landscape repeats itself horizontally, so running off the right side of the map will just put you back where you started. Starting from the top left of the map and a rise and run of (3,

Read More »

beauty and the bytestring

event that aims to showcase some of the cool, unknown features of Haskell that newcomers might not know. Ok, let’s talk about Linked Lists. You’ve likely come across them before, either in Leetcode problems or in a pretentious whiteboard interview. They’re a simple data structure, and a great way to learn how to use structs or Option<Rc<RefCell<Box<ListNode>>>> when you’re starting out. As a refresher, the canonical definition of a linked list is something like or where each node contains a value, and a pointer to the next element in the list. They’re intuitive, and allow you grow/shrink collections of objects without having to shift everything else over or reallocate when you run out of slots. Magic, right? There’s no such thing as a free lunch. When you construct a new node, you still need memory for it. Ignoring byte padding and assuming we’re on a 64-bit machine using GCC, a single LinkedList node will require 96 bits. 32 bits for val, and 64 bits for your next pointer. That’s a ton of bloat compared to arrays. A linked list will incur 66% more overhead over an equally sized array of ints, not to mention the cost of switching contexts every time you ring up malloc() to lend you a chunk of memory. If you’re le epic C hacker already, you probably know better than to keep malloc on speed-dial. It’s faster to create a “pool” of memory at first, carving off chunks whenever memory is needed. You make an array

Read More »