This was a project designed to make a functional kaleidoscope and as a use case for learning how to use a lathe. It took a few revisions to get the scale and dimensions correct but the result is one that I am pretty proud of

This was a project designed to make a functional kaleidoscope and as a use case for learning how to use a lathe. It took a few revisions to get the scale and dimensions correct but the result is one that I am pretty proud of

Advertisements

Another week, another puzzle. This one comes from MindYourDecisions on YouTube as suggested by a friend. Here’s the problem:

While I was able to logic out a solution that would find the cat in 7 steps the program I wrote was able to do it in 6. That solution is:

#Round 0 I select box 2 #Possible boxes the cat can be in: [1, 0, 1, 1, 1] #Round 1 I select box 3 #Possible boxes the cat can be in: [0, 1, 0, 1, 1] #Round 2 I select box 4 #Possible boxes the cat can be in: [1, 0, 1, 0, 1] #Round 3 I select box 4 #Possible boxes the cat can be in: [0, 1, 0, 0, 0] #Round 4 I select box 3 #Possible boxes the cat can be in: [1, 0, 0, 0, 0] #Round 5 I select box 2 #Possible boxes the cat can be in: [0, 0, 0, 0, 0]

The benefit of this program is that it is easily able to find solutions for cases where there are more than five boxes, the cat can move one or two, etc.

Of course his explanation was cleaner but its a little nice to be able to say you exhaustively searched all the cases đź™‚

import random import copy def select_box(sel_box,boxes): #Input a box, it does the proceeding logic old_boxes = copy.deepcopy(boxes) for i in range(0,len(boxes)): if old_boxes[i] > 0: if (i>0) : boxes[i-1] += 1 if (i 0) for x in boxes] #reduces all non-zero box values to one return boxes def print_history(path,box_hist): for i in range(0,len(path)): print("Round " + str(i) + " I select box " + str(path[i]+1)) #plus one because the problem uses 1-indexing print("Possible boxes the cat can be in: " + str(box_hist[i])) def find_path(thresh): #set base values boxes = [1,1,1,1,1] #A 1 indicates the cat can be in the box min_cat_spots = len(boxes) path = [] box_hist = [] #Select a random box, check state after each selection. Repeat until finished or it won't work while min_cat_spots !=0 and len(path) < thresh: selection = random.randint(0,len(boxes)-1) path.append(selection) box_hist.append(boxes) boxes = select_box(selection,boxes) cat_spots = sum(boxes) if cat_spots < min_cat_spots: min_cat_spots = cat_spots return [len(path),path,box_hist] #Search for paths while the the search has a chance to be the new low-score thresh = 14 #any large number for i in range(0,10000): results = find_path(thresh) if results[0] < thresh: thresh = results[0] print_history(results[1],results[2])

Another week, another Riddler. The question:

*During their descent, three paratroopers were blown off course and crash-landed in the desert â€” an infinite, uniform, two-dimensional plane. They come to at a random time after the crash and must find a way to meet up. The only tool they each have is a device that displays a snapshot of the positions (but not the velocities) of all three of them in the desert. They can each use this tool only once. To make things more annoying, theyâ€™ve all been nearly blinded by sandstorms and wonâ€™t be able to physically see the others until theyâ€™ve all arrived at the same point.*

*Can you devise a strategy that they can agree upon beforehand and that will guarantee they will meet up? (Note that the snapshot does not indicate the specific identities of the other paratroopers, so a strategy like â€śletâ€™s agree that A stands still and B and C walk to himâ€ť will not work.)*

*Extra credit:Â Is there a strategy that would work for any number of paratroopers?*

Here is the strategy I devised: Everyone gets to decide their unique walking velocity — the only thing that matters is that everyone’s speed is different than the others. Then we will, when we wake up, draw a circle that is constrained by the three points of our buddies (including ourselves). This represents the path that we will walk at our set velocity in a set direction (say, clockwise). Then as we walk if another person were to wake up they would inevitably draw the same circle and embark along the same path, eventually running into one another. If we meet up we will stay exactly where we met. The third person will either be on the same path or wake up and see that the other two have met and make a bee line for the group of two.

Extrapolating this to more people, we just make a closed shape that has as many variables as there are people. For four we can use an ellipse with horizontally constrained foci, for five we can use an ellipse with unconstrained foci, etc.

In the case with more than three people if two meet they continue to move along their path. Anyone who wakes up after two have met will again just make a bee line for where ever the two person group is at that time, knowing they will be collected at the next revolution. This should work for all cases.

At work I’ve been been put in charge of doing some web design. After spending more time in the space I realized just how bad my previous version of my website was — so I went ahead and redid it:

This also served as a way for me to test CSS Grid. This allowed me to have drastic differences in layout from the mobile page and desktop page with lots of shared code.

Overall it was a pretty pleasant experience. CSS Grid didn’t get rid of the standard CSS tomfoolery (letter spacing adjustment, weird nesting attributes, the feeling of CSS bloat) but made the general layout step much easier. **Check out the website here.**

Another week, another Riddler. This first question:

*Choose three points on a circle at random and connect them to form a triangle. What is the probability that the center of the circle is contained in that triangle?*

The method of finding if a point was in the center was as follows: Take Triangle ABC. Find the cross product of the vectors BA and BCenter. If the resulting vector is in the same direction (As measured by the dot product) as the cross product between the vectors BA and BC then the point is on the correct side of the line BA. Put another way, the center and the point C are on the same side of line AB. Repeat this for lines AC and BC. If the center is on the correct side of all the triangle’s lines then it is inside ABC.

This simulation was iterated to yield the answer of **25%**.

Next question:

*Choose four points at random (independently and uniformly distributed) on the surface of a sphere. What is the probability that theÂ tetrahedronÂ defined by those four points contains the center of the sphere?*

This was much more tricky. Firstly we had to find four points randomly distributed on a sphere. For this I used the Marsaglia method detailed here:

Next I needed to see if the center was enclosed. To do this I took the determinant 5 matrices of this form:

The other four matrices are of that form, but replacing A’s with c’s, then B’s with c’s, then C’s with c’s and finally D’s with c’s. If all these determinants have the same sign then the point is enclosed.

This simulation was iterated to yield the answer of **12.5%**.

These graphs required a bunch of code to make the graphs. This can be found here

Super Smash Bros Melee is a wild game – its 17 years old at this point but still played both casually and competitively by many and considered one of theÂ best games of all time. In part because of it’s extended age it has seen many mods (some by me) both in software and in hardware. This serves as an additional controller hardware mod

The goal for this controller is to make an ergonomic controller in the spirit of fight sticks. The inspiration comes from the player Hax$ whose hands were hurt to the point of being unable to play the game with a standard controller — in response to this he assisted in designing a controller like this and then became the best player with it.

Fast forward a year, he still hasn’t started selling them. So I took it upon myself to make one. For this I used Simple Controller’s guide to get an idea of how to do it. I wanted a different physical design so I went ahead and rendered it in Solidworks. Inspired by the retro electronics I wanted a see through design, which would have lots of wiring implications later:

Looked nice! Because it was going to be clear I needed to make the wiring look ~~clean and orderly~~Â cool — hence the huge grounding bar. Next I had to just build it. Two hardware trips, two McMaster orders, three Amazon orders, one broken piece of acrylic and one burnt thumb I had it assembled.

Next the code had to be edited. Thankfully Simple Controllers had created a good basis – however his controller was based on the Smashbox style controller — I wanted mine to be based on Hax’s B0XX. This meant changing some logic to reflect the changes Hax implemented, as well as those I wanted. The changes I put on github.

Just like that, its done! Now just to get good with it đź™‚

Data can be pretty sweet – I think its real fun to see progression and adds an aspect of gamification to otherwise mundane things. However, something to track piano playing didn’t exist – yet.

Therefore what I created is a piano keylogger, heatmap generator and session tracker. The idea is with this you can accurately see what keys you played and for how long you practiced – reducing my ability to lie about practice length (the initial purpose of this) while getting some cool graphs. I imagine the heatmaps for various composers works or genres of music could be insightful.

Heatmap Creation:

To make the piano diagram we use the PIL module and lots of polygons. To get the layering I wanted (black keys over white keys) I had to draw the black keys second. This is fine but introduced a mapping problem.

Green numbers represent the MIDI ID’s. Because I am drawing these in first I have to also fill them with the heatmap coloration first. I drew them in a simple incremental pattern (red #’s) – but now I’d need something to map the red numbers to green numbers (this problem will occur again for drawing black keys). The solution was to create mappings in a CSV file and reference the file for every key drawn in. Its obviously not optimal from a performance point of view but it is configurable and works.