Project Euler 43

October 10th, 2021

I like to go back and re-solve Project Euler problems in different languages. Lately, I’ve been solving them in Javascript for fun. When I do this, I don’t look at previous solutions and try to do it from scratch. When I was finished, I was surprised by the performance of my solution to 43 compared to my previous attempts in other languages.

Problem 43 is as follows:

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.

Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:

  • d2d3d4=406 is divisible by 2
  • d3d4d5=063 is divisible by 3
  • d4d5d6=635 is divisible by 5
  • d5d6d7=357 is divisible by 7
  • d6d7d8=572 is divisible by 11
  • d7d8d9=728 is divisible by 13
  • d8d9d10=289 is divisible by 17

Find the sum of all 0 to 9 pandigital numbers with this property.

When I first solved this problem, I solved it in C. This was in 2014, and I was still fairly green. My solution at the time was to iterate through every 10-digit number and see if it was pandigital and then if it was, check if it met the sub-divisibility requirement.

This solution is what you would call “brute-force”. It’s inelegant, and slow. However, it does work. It took 33.948 seconds to compute.

A few years later I was doing more with Rust and Python. Both of these solutions I created used the same method. This probably happened because I wrote both solutions close together. At any case, this time I thought myself more clever and took a pandigital number, 1234567890, and discovered every permutation, and then checked for the sub-divisibility requirement of each.

This is better than brute force, but still time consuming. Python can accomplish this in 18.724 seconds and Rust in 4.621. Better, but still not great.

The general rule of thumb with Project Euler is that if a solution takes more than a second, you haven’t found the intended method of solving it.

Looking at it this time around, it seemed like a very straightforward problem with an obvious path for a solution. Instead of finding pandigital numbers and checking if they meet the sub-string divisibility requirement, this time I would build up the pandigital numbers using the sub-strings.

First I created arrays for the multiples of the first 7 primes with 2 and 3 digits. I then used a recursive function to build up a number using valid combinations of these sub-strings (since each one overlaps the next with 2 digits). This creates a much smaller group of numbers to check.

Once I have all my potential pandigital numbers, I check to make sure they are in fact pandigital. (Note that at this stage, they should be missing the first digit). When checking for pandigitality, I’m actually looking for 9 different digits, and if so, I prepend the missing 10th digit and voila, it’s a valid pandigital number!

This solution is much, much faster at .237 seconds.

I’m very pleased with that result, but a little shocked I didn’t see this method when I have solved it previously. It’s nice to know that since I first started solving these problems years ago, I can see measurable improvement in my ability to find and create solutions to these fun little puzzles.

Source on GitHub

Brisco County Jr. Orb Rod

September 10th, 2021

In 1993, The Adventures of Brisco County Jr. premiered on Fox. It was about a Bounty Hunter in the old west, and his mission to round up the gang of outlaws who killed his father, a famous Marshal. Brisco County is a Harvard educated lawyer who is eagerly looking to the future for the “coming thing”.

As he works to capture all the outlaws responsible for his father’s death, he has multiple encounters with a mysterious object only known as ‘the orb’. In the first episode we learn that the orb can grant power to people who possess it. As we continue through the season, we learn more about the orb’s power and origins, but its mystery isn’t completely unraveled until nearly the end of the season.

The orb is hard to describe. It’s a golden, spherical object with protrusions regularly distributed across it’s surface. These protrusions are the end-caps or glowing rods that can be removed from the orb. As a kid, I always thought that the orb’s mystery and power was very fantastic, and I always wanted to see it in person, or to own it.

Reference photo found on a prop auction site

I finally decided that it was time to replicate it. Not the whole thing, just one of the orb rods. I’ve done a bit of research here and there over the years and have never gotten a straight answer on the exact size of the prop. I managed to find a small image of a prop replica that was built from the same mold as the original prop. Luckily, this prop happened to be photographed next to a ruler. I inferred the measurements to the best of my ability and concluded that the prop orb rod is about 1.5 inches in diameter, and about 13.25 inches long.

Brisco County Orb Rod Plans

I was able to find blue acrylic rod in 1.5 inch diameter from a supplier on eBay for a good price. I then bought some Brass stock on Amazon, also 1.5 inches in diameter.

I don’t have any tooling for doing a rounded end of this diameter, so I used the lathe to create steps at 1/8 inch intervals in the brass that match the contour of a .75 inch radius sphere. I then used a file to smooth it down to a nice rounded end. A little bit of sanding, and then a clear coat of lacquer to prevent tarnishing, and the cap is finished. The reverse side was drilled out to 1 inch to accommodate the acrylic rod.

There wasn’t much to do on the acrylic rod, except to machine down one end in order to insert it into the cap. Additionally, the other end was fairly rough from being cut off with a band-saw by the seller. I used progressively finer sand paper on the end, finishing with a 2000 grit wet sanding to get it to be a clear and smooth as possible.

The last step was to epoxy the cap onto the acrylic rod.

Finally, after many decades, I have the prop replica I’ve always dreamed about.

Sadly, Brisco County Jr. was cancelled in its first season. Despite being cancelled, I find it to be an enduring show full of the witty one-liners you’d expect from Bruce Campbell, the charm of old spaghetti westerns, and a touch of sci-fi. Luckily, the show was able to satisfyingly conclude it’s storyline, so even while it was cancelled, it feels complete, and is one show that I frequently rewatch.

3D Printing

August 2nd, 2021

Way back when I was an itty bitty boy, I remember reading about rapid prototyping, and seeing pictures of objects created from an SLA printer. The object I remember most was a rook with an internal spiral staircase. Was was amazing about it is that it is an object that would be impossible to injection mold, or carve using a CNC machine. It had amazing detail for such a diminutive object.

When I went to college, we had a pair of powder bed printers that we could use in our manufacturing laboratory. Powder bed printing is extremely versatile because the objects being printed do not require any support structures. This allows for flexibility in design that could be difficult to achieve otherwise.

Since graduating, there has been an at-home 3D printing boom. I recall when the MakerBot went mainstream. It was very interesting, but I was very put off by the quality of the prints. The filament left a very jagged surface, there wasn’t a ton of detail, and the few prints I had seen in person had de-lamination issues in some of the layers. I’ve been very skeptical of filament printers since.

I finally gave in after seeing some prints a friend at work made using his printer. The prints still have the trademark layer lines of a filament printer, but the detail has improved so much. I got a Creality Ender 3 ($260 at time of writing) which seems so incredibly cheap. I am extremely impressed with what this machine can do.

Setup

The printer comes unassembled. It took about 30 minutes to put it together. It really required very little skill, as long as you know how to turn an Allen wrench.

Once it is assembled, the next thing to do is level the bed. This is accomplished with 4 knobs underneath the print bed. Again, it’s a pretty basic process.

Lastly, feeding the filament is a simple task. After that, it’s ready to print.

The first print I did was preloaded on the thumb drive. It was a little dog figurine. It printed perfectly!

Software

The printer came with it’s own branded software. Unfortunately, it is Windows only, but off the bat I was impressed by the ease of use. I’ve never seen or used slicing software before, but I was delighted by how intuitive and easy it is to use. It has basic presets as well as expert settings. For most things, the basic presets are great. I’ve used them for multiple projects without any real issue.

Replacement spool holder for a tape dispenser; Modeled in Fusion 360, Set up in slicer, printed in white PLA

I did eventually find out about Utilimaker’s Cura and downloaded it so I could slice on the Mac, and also so I could test tree supports. Cura had a built in printer profile for the Ender 3, which was great. My first few prints using it for slicing have also been a success.

Printing

Now, it’s not all great. I’ve had my share of failed prints. Many times this is do to positioning something sub-optimally, or trying to print something that’s just too small and delicate. In most cases I’ve been able to work around it by rotating or splitting the object up. Another issue I’ve had is with smaller items sticking to the print bed. Adding a raft certainly remedies these issues, however it uses a lot of extra material.

I did buy an upgraded glass print bed. The plastic mat that came with the printer already had visible signs of wear after just a month or two. The glass bed has been performing pretty well, The adhesion is good, and it seems to be resistant to wearing. I still have problems with larger prints pulling up around the base edges though.

Conclusion

I’ve always steered away from FDM printers because of their inherent drawbacks, such as requiring supports and the inherent layered texture of the printed piece. Despite all those misgivings, I am quite pleased with this product, and equally with it’s affordable price. One thing to be weary of though, I’ve found that with this hammer in my tool chest, most of my problems have started to look like nails.