[Blogging Intensifies]

Technology, Projects, Linux, Coding, Internet of Things, Music, Books, Life...

  • About
  • Privacy Policy

Advent of Code 2020 – Day 5

December 5, 2020

So Day 5, ended up being a bit easier than I though it would be. The puzzle involves locating your seat on the plane using Binary. Tickets have a code on them like “FBFBBFFRLR” and the code corresponds to “Front, Back, Left, Right. I started off working up some conditionals that would add or subtract values.

Then I had a brief epiphany moment, that the values are literally just Binary values using letters instead of 1s and 0s. So instead I wrote a quick bit that would convert each seat value into a binary number for Column and Row, then both Part 1 and Part 2 was some quick math checks. Part 1 was to calculate the highest seat number, Part 2 was to find the missing seat that was your seat.

I used basically the same code for both.

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

row='0b'
col='0b'

largest=0
ids=[]

#binary Exclusion
#0-127
#0-7

for line in lines:
  if line != '':
     for i in line:
       if i == 'F':
         row=row+'0'
       if i == 'B':
         row=row+'1'
       if i == 'L':
         col=col+'0'
       if i == 'R':
         col=col+'1'
     current=(eval(row))*8+eval(col)
     ids.append(current)

     if current>largest:
       largest=current


     row='0b'
     col='0b'

ids=sorted(ids)
#print ids

prev=ids[0]
now=ids[1]

for next in ids[2:]:
   if next-1 != now:
     print next-1
   prev=now
   now=next



print largest

This one seemed daunting but went by super quick once I figured out the trick.

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Reddit (Opens in new window)

Related

Posted in: Advent of Code 2020 Tagged: Advent of Code 2020, Coding, Python
Mastodon LinkedIn email
Instagram Instagram GitHub
JoshMiller.net
Lameazoid.com

Categories

  • collapsCat options: Array ( [title] => Categories [showPostCount] => 1 [inExclude] => exclude [inExcludeCats] => [showPosts] => 0 [showPages] => 0 [linkToCat] => 1 [olderThan] => 0 [excludeAll] => 0 [catSortOrder] => ASC [catSort] => catName [postSortOrder] => ASC [postSort] => postTitle [expand] => 0 [defaultExpand] => [debug] => 1 [postTitleLength] => 0 [catfeed] => none [taxonomy] => category [post_type] => post [postDateAppend] => after [postDateFormat] => m/d [showPostDate] => 1 [useCookies] => 1 [postsBeforeCats] => 1 [expandCatPost] => 1 [showEmptyCat] => 1 [showTopLevel] => 1 [useAjax] => 0 [customExpand] => [customCollapse] => [style] => kubrick [accordion] => 1 [title_link] => [addMisc] => 1 [addMiscTitle] => [number] => 3 [includeCatArray] => Array ( ) [expandSym] => ► [collapseSym] => ▼ ) postsToExclude: Array ( ) CATEGORY QUERY RESULTS Array ( [0] => WP_Term Object ( [term_id] => 486 [name] => Advent of Code 2020 [slug] => advent-of-code-2020 [term_group] => 0 [term_taxonomy_id] => 486 [taxonomy] => category [description] => [parent] => 172 [count] => 12 [filter] => raw ) [1] => WP_Term Object ( [term_id] => 156 [name] => Android [slug] => android [term_group] => 0 [term_taxonomy_id] => 156 [taxonomy] => category [description] => [parent] => 155 [count] => 3 [filter] => raw ) [2] => WP_Term Object ( [term_id] => 135 [name] => Arduino [slug] => arduino [term_group] => 0 [term_taxonomy_id] => 135 [taxonomy] => category [description] => [parent] => 153 [count] => 8 [filter] => raw ) [3] => WP_Term Object ( [term_id] => 438 [name] => Books [slug] => books [term_group] => 0 [term_taxonomy_id] => 438 [taxonomy] => category [description] => [parent] => 436 [count] => 4 [filter] => raw ) [4] => WP_Term Object ( [term_id] => 368 [name] => CHIP [slug] => chip [term_group] => 0 [term_taxonomy_id] => 368 [taxonomy] => category [description] => [parent] => 153 [count] => 5 [filter] => raw ) [5] => WP_Term Object ( [term_id] => 172 [name] => Coding [slug] => programming [term_group] => 0 [term_taxonomy_id] => 172 [taxonomy] => category [description] => [parent] => 153 [count] => 13 [filter] => raw ) [6] => WP_Term Object ( [term_id] => 247 [name] => Copyright and You [slug] => copyright-and-you [term_group] => 0 [term_taxonomy_id] => 247 [taxonomy] => category [description] => [parent] => 154 [count] => 3 [filter] => raw ) [7] => WP_Term Object ( [term_id] => 155 [name] => Devices [slug] => devices [term_group] => 0 [term_taxonomy_id] => 155 [taxonomy] => category [description] => [parent] => 0 [count] => 5 [filter] => raw ) [8] => WP_Term Object ( [term_id] => 281 [name] => Drafts [slug] => drafts [term_group] => 0 [term_taxonomy_id] => 281 [taxonomy] => category [description] => [parent] => 0 [count] => 0 [filter] => raw ) [9] => WP_Term Object ( [term_id] => 366 [name] => Hardware [slug] => hardware [term_group] => 0 [term_taxonomy_id] => 366 [taxonomy] => category [description] => [parent] => 153 [count] => 1 [filter] => raw ) [10] => WP_Term Object ( [term_id] => 373 [name] => Hardware [slug] => hardware-what-i-use [term_group] => 0 [term_taxonomy_id] => 373 [taxonomy] => category [description] => [parent] => 159 [count] => 4 [filter] => raw ) [11] => WP_Term Object ( [term_id] => 243 [name] => Home Security [slug] => home-security [term_group] => 0 [term_taxonomy_id] => 243 [taxonomy] => category [description] => [parent] => 153 [count] => 2 [filter] => raw ) [12] => WP_Term Object ( [term_id] => 446 [name] => Language [slug] => language [term_group] => 0 [term_taxonomy_id] => 446 [taxonomy] => category [description] => [parent] => 436 [count] => 1 [filter] => raw ) [13] => WP_Term Object ( [term_id] => 436 [name] => Lifestyle [slug] => lifestyle [term_group] => 0 [term_taxonomy_id] => 436 [taxonomy] => category [description] => [parent] => 0 [count] => 2 [filter] => raw ) [14] => WP_Term Object ( [term_id] => 224 [name] => Linux & Open Source [slug] => linux [term_group] => 0 [term_taxonomy_id] => 224 [taxonomy] => category [description] => [parent] => 279 [count] => 2 [filter] => raw ) [15] => WP_Term Object ( [term_id] => 153 [name] => Maker [slug] => maker [term_group] => 0 [term_taxonomy_id] => 153 [taxonomy] => category [description] => [parent] => 0 [count] => 1 [filter] => raw ) [16] => WP_Term Object ( [term_id] => 437 [name] => Music [slug] => music [term_group] => 0 [term_taxonomy_id] => 437 [taxonomy] => category [description] => [parent] => 436 [count] => 14 [filter] => raw ) [17] => WP_Term Object ( [term_id] => 395 [name] => My DIY Projects [slug] => my-diy-projects [term_group] => 0 [term_taxonomy_id] => 395 [taxonomy] => category [description] => [parent] => 153 [count] => 3 [filter] => raw ) [18] => WP_Term Object ( [term_id] => 367 [name] => Non-Tech [slug] => non-tech [term_group] => 0 [term_taxonomy_id] => 367 [taxonomy] => category [description] => [parent] => 153 [count] => 3 [filter] => raw ) [19] => WP_Term Object ( [term_id] => 154 [name] => Opinion/Editorial [slug] => articles [term_group] => 0 [term_taxonomy_id] => 154 [taxonomy] => category [description] => [parent] => 0 [count] => 3 [filter] => raw ) [20] => WP_Term Object ( [term_id] => 491 [name] => Organizing [slug] => organizing [term_group] => 0 [term_taxonomy_id] => 491 [taxonomy] => category [description] => [parent] => 436 [count] => 5 [filter] => raw ) [21] => WP_Term Object ( [term_id] => 279 [name] => OS [slug] => os [term_group] => 0 [term_taxonomy_id] => 279 [taxonomy] => category [description] => [parent] => 0 [count] => 0 [filter] => raw ) [22] => WP_Term Object ( [term_id] => 242 [name] => PCs [slug] => pcs [term_group] => 0 [term_taxonomy_id] => 242 [taxonomy] => category [description] => [parent] => 155 [count] => 4 [filter] => raw ) [23] => WP_Term Object ( [term_id] => 384 [name] => Photography [slug] => photography [term_group] => 0 [term_taxonomy_id] => 384 [taxonomy] => category [description] => [parent] => 159 [count] => 2 [filter] => raw ) [24] => WP_Term Object ( [term_id] => 146 [name] => Privacy [slug] => privacy [term_group] => 0 [term_taxonomy_id] => 146 [taxonomy] => category [description] => [parent] => 154 [count] => 3 [filter] => raw ) [25] => WP_Term Object ( [term_id] => 142 [name] => Raspberry Pi [slug] => raspberry-pi [term_group] => 0 [term_taxonomy_id] => 142 [taxonomy] => category [description] => [parent] => 153 [count] => 9 [filter] => raw ) [26] => WP_Term Object ( [term_id] => 407 [name] => Security [slug] => security [term_group] => 0 [term_taxonomy_id] => 407 [taxonomy] => category [description] => [parent] => 166 [count] => 1 [filter] => raw ) [27] => WP_Term Object ( [term_id] => 133 [name] => Site News [slug] => site-news [term_group] => 0 [term_taxonomy_id] => 133 [taxonomy] => category [description] => [parent] => 0 [count] => 0 [filter] => raw ) [28] => WP_Term Object ( [term_id] => 136 [name] => Social Media [slug] => social-media [term_group] => 0 [term_taxonomy_id] => 136 [taxonomy] => category [description] => [parent] => 154 [count] => 2 [filter] => raw ) [29] => WP_Term Object ( [term_id] => 160 [name] => Software [slug] => software [term_group] => 0 [term_taxonomy_id] => 160 [taxonomy] => category [description] => [parent] => 159 [count] => 5 [filter] => raw ) [30] => WP_Term Object ( [term_id] => 241 [name] => Synology NAS [slug] => synology-nas [term_group] => 0 [term_taxonomy_id] => 241 [taxonomy] => category [description] => [parent] => 155 [count] => 4 [filter] => raw ) [31] => WP_Term Object ( [term_id] => 166 [name] => Technology [slug] => technology [term_group] => 0 [term_taxonomy_id] => 166 [taxonomy] => category [description] => [parent] => 0 [count] => 7 [filter] => raw ) [32] => WP_Term Object ( [term_id] => 424 [name] => The Basement [slug] => the-basement [term_group] => 0 [term_taxonomy_id] => 424 [taxonomy] => category [description] => [parent] => 153 [count] => 6 [filter] => raw ) [33] => WP_Term Object ( [term_id] => 413 [name] => The Cloud [slug] => the-cloud [term_group] => 0 [term_taxonomy_id] => 413 [taxonomy] => category [description] => [parent] => 153 [count] => 3 [filter] => raw ) [34] => WP_Term Object ( [term_id] => 1 [name] => Uncategorized [slug] => uncategorized [term_group] => 0 [term_taxonomy_id] => 1 [taxonomy] => category [description] => [parent] => 0 [count] => 0 [filter] => raw ) [35] => WP_Term Object ( [term_id] => 159 [name] => What I Use [slug] => what-i-use [term_group] => 0 [term_taxonomy_id] => 159 [taxonomy] => category [description] => [parent] => 0 [count] => 0 [filter] => raw ) [36] => WP_Term Object ( [term_id] => 280 [name] => Windows [slug] => windows [term_group] => 0 [term_taxonomy_id] => 280 [taxonomy] => category [description] => [parent] => 279 [count] => 2 [filter] => raw ) [37] => WP_Term Object ( [term_id] => 207 [name] => Windows Phone [slug] => windows-phone [term_group] => 0 [term_taxonomy_id] => 207 [taxonomy] => category [description] => [parent] => 155 [count] => 3 [filter] => raw ) ) POST QUERY: POST QUERY RESULTS
  • ►Devices (19)
    • Android (3)
    • PCs (4)
    • Synology NAS (4)
    • Windows Phone (3)
  • ►Drafts (0)
  • ►Lifestyle (26)
    • Books (4)
    • Language (1)
    • Music (14)
    • Organizing (5)
  • ▼Maker (66)
    • Arduino (8)
    • CHIP (5)
    • ▼Coding (25)
      • Advent of Code 2020 (12)
    • Hardware (1)
    • Home Security (2)
    • My DIY Projects (3)
    • Non-Tech (3)
    • Raspberry Pi (9)
    • The Basement (6)
    • The Cloud (3)
  • ►Opinion/Editorial (11)
    • Copyright and You (3)
    • Privacy (3)
    • Social Media (2)
  • ►OS (4)
    • Linux & Open Source (2)
    • Windows (2)
  • ►Site News (0)
  • ►Technology (8)
    • Security (1)
  • ►Uncategorized (0)
  • ►What I Use (11)
    • Hardware (4)
    • Photography (2)
    • Software (5)

Hosted on…


Help support hosting with our referral link!

Copyright © 2022 [Blogging Intensifies].

Me WordPress Theme by themehall.com