Ramen Junkie

Advent of Code 2020 – Day 2

Day two is a little more complicated than Day 1 was. Today’s challenge is to take a blob of passwords, and verify if they are acceptable or not, per the “company standard” at the time of the creation of each password.

For example:

1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc

For part 1, on line 1, the letter a should appear at least 1 time and at most 3 times. For line 2, the letter b should appear at least 1 time and at most 3 times. For line 3, the letter c should appear at least 2 times and at most 9 times.

My solution for Day 2, Part 1 is below:

number_valid = 0
toolow = 0
toohigh = 0
number_of_entries = 0

with open('day2data.txt') as f:
    lines = [line.rstrip() for line in f]

for x in lines:
  dashloc = x.find("-")
  spaceloc = x.find(" ")
  colloc = x.find(":")
  mincount=int(x[0:dashloc])
  maxcount=int(x[int(dashloc)+1:spaceloc])
  limitchar=x[int(spaceloc+1):int(colloc)]
  password = x[int(colloc+2):]
  checkvalue = int(password.count(limitchar))
  if(mincount <= checkvalue <= maxcount):
    number_valid=number_valid+1
  if(checkvalue<mincount):
    toolow+=1
  if(checkvalue>maxcount):
    toohigh+=1
  if(mincount>=maxcount):
    print "Problem?"

print number_valid
#print toolow
#print toohigh
#print number_valid+toolow+toohigh

On a note, I’ve got some debugging bits still in there, that are commented out. After reading the file in, I’ve initialized some variables I’ll be using in the code. Then I start looping through the data.

This is where my janky code really gets to shine, as I am sure there is a better way to handle this. First step is to locate the special characters separating the data, from the exampe, “1-3 a:abcde”, these are a dash, a space and a colon. With these located, I’ve extracted the min and max values, the letter I’m tracking, and the password itself.

After getting these core values, it’s simple enough to count the occurrences of the letter, then verify it against the min/max values and count how many are valid.

I had a bit of trouble at first because I had used “password = x[int(colloc+2):-1]” instead of “password = x[int(colloc+2):]”. I’m not a master of a lot of programming languages, but I am familiar with enough of them that I get the syntax confused a lot (I keep forgetting the colon on ifs and loops in Python). I forget which language uses -1 for “go to tot he end of a range”, but I am pretty sure there is one, because I did this a lot at first.

Part 2 changes things up a bit. Instead of the first numbers representing a range of how many, it demands that the special letter appears at one of those two positions, but not both.

My solution for part 2 is below:

number_valid = 0
number_of_entries = 0

with open('day2data.txt') as f:
    lines = [line.rstrip() for line in f]

for x in lines:
  first=0
  second=0
  dashloc = x.find("-")
  spaceloc = x.find(" ")
  colloc = x.find(":")
  mincount=int(x[0:dashloc])-1
  maxcount=int(x[int(dashloc)+1:spaceloc])-1
  limitchar=x[int(spaceloc+1):int(colloc)]
  password = x[int(colloc+2):]
  if(password[mincount]==limitchar):
    first=1
  if(password[maxcount]==limitchar):
    second=1
  if ((first==1) or (second==1)):
    if(first !=second):
      number_valid+=1

print number_valid
#print toolow
#print toohigh
#print number_valid+toolow+toohigh

More sloppy code, i didn’t even change the variable names. Now, instead of counting and comparing, I’m checking for the special character in each position, and toggling a variable if it’s there or not, then making sure it’s nor present in both. This is where the new variables “first” and “second” come in.

This biggest challenge on Day 2 was that it required more manipulation of the input data.

Github Repository of my Solutions

Advent of Code 2020 – Day 1

So, I want to say up front, I don’t know if I will finish this, but I plan to try. Also, while I intend to publish these posts on the respective day of each challenge, I may not actually DO the challenge day of. That is to say, some of these, probably most of these, will be back dated.

Advent of Code is a little 25 day advent calendar of code based challenges. I heard it mentioned on TWIT by Leo Laporte. It can be done in any language or system. There are people who solve these using game engines and such. As this is my first go, and I am not a “professional programmer”, I am doing in in sloppy Python. I’ll be posting my solutions in a Github Repo, which means this challenge serves a second purpose of helping me have an excuse to learn how to better use Github.

The first day’s challenge is pretty simple. Given a list of numbers, figure out which ones add up to 2020 and then multiply them together. Each day has two challenges, based on the same base data set. The data set for each person seems to be different. Here is my solution for Day 1 Part 1:

with open('day1data.txt') as f:
    lines = [line.rstrip() for line in f]

for x in lines:
  for y in lines:
    if((int(x)+int(y))==2020):
      print int(x)*int(y)

Each day of this puzzle (so far) involves reading in a data file, and working with it. My solution involves looping each number, and multiplying it by each other number, and checking for if they sum 2020, then posting the result of multiplying the two numbers.

Part two is essentially the same except it involves three numbers instead of two. This pretty much just meant adding another layer of loop to my loops.

with open('day1data.txt') as f:
    lines = [line.rstrip() for line in f]

for x in lines:
  for y in lines:
    for z in lines:
      if((int(x)+int(y)+int(z))==2020):
        print int(x)*int(y)*int(z)

This first days’ challenge was pretty simple. The rest of the days, not so much.

Battery Testing with Raspberry Pi

Recently I purchased a portable phone battery on clearance. I want to use it to modify my defunct Pokemon Go Gotcha band, which no longer holds a charge, to run off the battery pack. I realized that a battery pack could also be useful for powering other small electronics, such as the Raspberry Pi.

The problem is, I wanted to get an idea of how long the battery would last powering the Raspberry Pi. Figuring this out isn’t really all that hard. The tricky part is that I can’t stand over the Pi and watch it until it dies.

So instead I set up a simple cronjob task to do the job for me. I had a spare SD card, so I threw a basic fresh install of Raspbian on the card. I configured SSH and WiFi, then did a quick run of “crontab -e”, then droped the following at the end.

*/5 * * * * date >> /home/pi/date.txt

Simple.

Every 5 minutes, the Pi will now write the Date and Time to the file “date.txt”. It will do this until it can’t which would be after the battery dies, killing the Pi.

After charging the battery pack over night, I stuck the Pi on it and left it.

After checking back periodically, when I found the Pi was dead, I plugged it into a regular power source to retrieve the data. The result were both better than I had hoped, and not as great as I had hoped. The Pi started spitting out Time Stamps again after I plugged it back in, so I ended up having to skim through the file to find the time gap. I went ahead and truncated the data down to hour stamps until I came across the time jump from when the Pi had died and when I had plugged it back in.

So it turns out that the Battery pack will drive power for the Pi for around 12 hours. I also want to test this under a bit of a load and test how long it will power an Arduino writing to a remote database.

Endlessly Learning

One thing I have always done in my life is worked to constantly be learning something. It may not actually be a useful something, but it’s something. Back when I was finishing up my degree in 2003, I was telling people that I wanted to get the RA job in the dorms so I could just live there for the rest of my life taking classes. Granted, the RA position only meant your room was covered, I don’t think it covered any of the course work expense.

Fortunately, we live in a world of connected possibilities, or whatever buzz word you want to use. While I didn’t get to work from home or even end up with extra time at home from the Pandemic, it’s really given me a ton of extra online courses to take, mostly “just because”.

I have taken and completed several single courses over at Real Python. Though I am not entirely sure how useful some of them are, to anything I’ll ever do, but it was good to get some general incite into things like, Facial Detection and Functional Programming.

I took a multi week course called The Science of Well Being, over on Coursera. It was kind of more of a psychology themed course covering concepts behind what makes us happy in our daily lives. I kind of feel like I’ve already been sort of naturally using some of the ideas discussed in my life, but it was interesting.

I’m almost at 2 years of Duolingo learning spanish as well, with a 700+ day streak. Mi Espanol no es perfecto, pero es un poco bien. I guess. I’ve actually been branching out some and have been reading a few children’s books in Spanish. I’ve also been browsing bits of Spanish speaking Twitter and Reddit as well. While I can’t really speak or listen to it well, I am doing alright and comprehending the reading and okish as getting the idea across in writing.

It doesn’t always work out the first try though. Starting at the beginning of this year I started trying to learn how to play Piano. Though the Piano part is the easy part, what I’m really doing is trying to learn how to read sheet music. Unfortunately, I have not sat down at the Piano to practice in nearly 6 months now. Maybe next year on that one.

I get access to Linked in Learning through work as well, I’ve been taking a Full stack Developer course there as well. I kind of got distracted from it doing web development work at work, but it already helped improve my technique in managing PHP file layouts.

I have been doing some tutorials on how to write Markdown, which isn’t super impressive or complicated, but it’s a skill that I feel like may actually be more useful in the future.

I finished off a tutorial on basic COBOL programming. While I don’t think I could write a COBOL program if I had to, it did a pretty good job of giving me an idea of how COBOL is structured and flows.

This is all just scratching the surface of a long list of learning resources I’ve collected up over the past few months. I am hoping to pick up doing some art again next year, I used to be pretty good at drawing in my youth. If I every finish the Spanish tree in Duolingo, I hope to either brush up on the Japanese I had in High School or learn some Norwegian. I’d like to take up 3D modeling at some point as well, I always really enjoyed doing CAD work in College and 3D modeling is essentially just a less precise version of CAD.

In general, I just plan to keep on learning.

Basement – The LEGO Table

The LEGO Table space in the basement was, for the longest time, the catch all space for anything extra. It was always sort of the last space to get finished up in the basement, though it’s always going to be an ongoing project. A lot of the clean up in this space involved cleaning up other areas first. The initial set up involved a counter sort of unit that I had made years ago, that previously was in my wife’s craft room at the old house. She didn’t need it in the new house, so I inherited it and it was a place to land my LEGO Modulars.

Under was used for storage for most of my other LEGO sets, since I didn’t really have a place to put them yet. They’ve still been in boxes for a few years,

At some point we ended up with some pretty hefty book cases second hand that we were using upstairs for a while, but they were no longer needed. Originally these book cases were going to be used in the basement but they were maybe 4″ too tall, so they ended up in the upstairs space. Since they were available again, I opted to go ahead and trim them down a bit so they would fit in the basement.

This process amounted to marking a line around the top end of the book case, using a circular saw to chop all the way around on the line, then removing the top board from the chopped off scrap bit, and reattaching it to the top of the book case. I also put a fresh new coat of paint on the book cases and shelves, as well as cut a few additional shelves.

I originally wasn’t sure where these shelves would end up in the basement, but after some measuring, I decided they would work on either side of the LEGO table. This meant turning the LEGO table itself 90 degrees so it sticks out in the room. I also bought some more pre finished shelving boards, like the original table was constructed from, and build what amounted to, a second table, then strapped them together with some braces to double the available surface area.

This gave me a lot more room to work with for the LEGO city, as well as shelving on either side to display and store additional sets. Which really cleaned out some of the boxes I had stored under the table. The next part of my plan was to add some additional shelving under the table for storage, which lead me to another idea. Why just add shelving on the sides, when it would be fairly easy to add shelving to the end, for a bit more display space. It also gets rid of this ugly as hell blank white surface.

For this process, I separated the two end legs, and shuffled them back the depth of a narrower (8″ I believe) shelf. Then reattached them. I then cut and assembles a smaller shelf unit and attached it to the end of the LEGO table. On the one side, I also adjusted the secondary leg back, as well as the curtain that was there, so I could keep the trash can under the table and out of view as it was. On the opposite side, I simply removed the extra leg.

Finally, for now, I cut some more 24″ pre finished shelf boards and attached them using L braces, inside the length of the table, on both sides, so the mess inside could become a much more organized, and useful mess. I also picked up an LED shop light that I hung over the length of the table, because this particular corner of the basement is a little dark. It lights up the entire space much better than I had expected it to.

In case you noticed, the Return of the Jedi poster fell off the wall at one point. I want to buy better frames and some fresh posters anyway (these three are like 25 years old now), so I simply hadn’t replaced it on the wall yet.

The next phase of this project is to actually start sorting down the extra LEGO into bins and drawers that will go under the table. I already started this a bit with some IKEA bins but I am going to need more bins than I have and it’s slow going since right now all of the LEGO is just in a giant plastic bin.