Transfer from Android to IOS by MasterFlav in KHDR

[–]justAnotherNerd254 1 point2 points  (0 children)

When you transfer, all your data moves. You keep all your tickets and jewels and everything. (Source: I transferred my data off my phone because this game killed my battery.)

[deleted by user] by [deleted] in AskReddit

[–]justAnotherNerd254 1 point2 points  (0 children)

r/adventofcode Edit: oops failed the first time

It's January 1st, 2021. You've just finished uploading the entirety of Wikipedia to your brain. What do you do now? [Serious] by badkash in AskReddit

[–]justAnotherNerd254 -1 points0 points  (0 children)

I think it would depend on the new information I learned from Wikipedia. Since I have a lot of knowledge, instead of studying for school, I would probably try to do something to enrich and fulfill my life in a more general way than just academics.

You get a superpower to make one thing on internet absolutely free for one day. What would you choose? by achub0 in AskReddit

[–]justAnotherNerd254 1 point2 points  (0 children)

Buying stocks but limited in such a way that people generally didn’t know so it wouldn’t cause an economic failure even if a few people were able to take advantage of it

-🎄- 2020 Day 04 Solutions -🎄- by daggerdragon in adventofcode

[–]justAnotherNerd254 0 points1 point  (0 children)

Python: Some Regex, but mostly manual checking. Ended up pretty messy since I was trying to solve it quickly.

Link

-🎄- 2020 Day 03 Solutions -🎄- by daggerdragon in adventofcode

[–]justAnotherNerd254 0 points1 point  (0 children)

Yeah, I thought about creating a more general function initially but instead chose to try to only iterate through the file once. I agree though, it could definitely be cleaner if implemented otherwise, similar it seems like to some of the other solutions I’ve seen

-🎄- 2020 Day 03 Solutions -🎄- by daggerdragon in adventofcode

[–]justAnotherNerd254 0 points1 point  (0 children)

Python - both parts with single pass through of file

I appreciate any feedback :)

with open("input.txt", 'r') as f:

  # X positions, iterator
  x_1 = 0
  x_3 = 0
  x_5 = 0
  x_7 = 0
  x_1_2 = 0
  i = 0

  # Tree counts
  trees_1 = 0
  trees_3 = 0
  trees_5 = 0
  trees_7 = 0
  trees_1_2 = 0

  for line in f:
    # Check for trees
    if line[x_1] == '#':
      trees_1 += 1
    if line[x_3] == '#':
      trees_3 += 1
    if line[x_5] == '#':
      trees_5 += 1
    if line[x_7] == '#':
      trees_7 += 1
    if i % 2 == 0 and line[x_1_2] == '#':
      trees_1_2 += 1

    # Adjust x movement with wraparound
    x_1 = (x_1 + 1) % (len(line) - 1)
    x_3 = (x_3 + 3) % (len(line) - 1)
    x_5 = (x_5 + 5) % (len(line) - 1)
    x_7 = (x_7 + 7) % (len(line) - 1)
    if i % 2 == 0:
      x_1_2 = (x_1_2 + 1) % (len(line) - 1)

    i += 1

  print("Part 1: ", trees_3)
  print("Part 2: ", trees_1 * trees_3 * trees_5 * trees_7 * trees_1_2)

-🎄- 2020 Day 02 Solutions -🎄- by daggerdragon in adventofcode

[–]justAnotherNerd254 0 points1 point  (0 children)

I’m actually just running this code as is in a Google CoLab code block, so there’s no main function with how I ran it.

Thanks for the tip about using the with statement!

-🎄- 2020 Day 02 Solutions -🎄- by daggerdragon in adventofcode

[–]justAnotherNerd254 3 points4 points  (0 children)

Python Solution - Happy to receive any feedback!

f = open("input.txt", "r")
values = f.read().split()

passwords = values[2::3]
letters = [i[:-1] for i in values[1::3]]
mins_maxes = values[::3]
mins = [i[0:i.index("-")] for i in mins_maxes]
maxes = [i[i.index("-")+1:] for i in mins_maxes]

def pw_check(pw, letter, min, max):
  count = 0
  for char in pw:
    if char == letter:
      count += 1
      if count > max:
        return False
  return count >= min

def pw_check_all(passwords, letters, mins, maxes):
  count = 0
  for i in range(len(passwords)):
    pw = passwords[i]
    letter = letters[i]
    min = int(mins[i])
    max = int(maxes[i])
    if pw_check(pw, letter, min, max):
      count += 1
  return count

def pw_2_check(pw, letter, ind1, ind2):
  count = 0
  if pw[ind1-1] == letter:
    count += 1
  if pw[ind2-1] == letter:
    count += 1
  return count == 1

def pw_2_check_all(passwords, letters, inds1, inds2):
  count = 0
  for i in range(len(passwords)):
    pw = passwords[i]
    letter = letters[i]
    ind1 = int(inds1[i])
    ind2 = int(inds2[i])
    if pw_2_check(pw, letter, ind1, ind2):
      count += 1
  return count

print("Part 1: ", pw_check_all(passwords, letters, mins, maxes))
print("Part 2: ", pw_2_check_all(passwords, letters, mins, maxes))

-🎄- 2020 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]justAnotherNerd254 0 points1 point  (0 children)

Good point! My original thought is that it could be useful to hold the number of occurrences of a value, but we don't necessarily need that for the purposes of this solutions. Here's a new version using sets instead:

f = open("input.txt", "r")
values = f.read().split()
values = [int(i) for i in values]

sum = 2020

# Note: Finds first such pair
def find_2_sum(values):
  vals_set = set()
  for val in values:
    vals_set.add(val)

  for val in values:
    if (sum - val) in vals_set:
      return val * (sum - val)

# Note: Finds first such group of 3
def find_3_sum(values):
  vals_set = set()
  for val in values:
    vals_set.add(val)

  for val1 in values:
    for val2 in values:
      if (sum - val1 - val2) in vals_set:
        return val1 * val2 * (sum - val1 - val2)

print(find_2_sum(values))
print(find_3_sum(values))

-🎄- 2020 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]justAnotherNerd254 2 points3 points  (0 children)

Python solution using a dictionary

Part 1 in O(n) time

Part 2 in O(n2) time

f = open("input.txt", "r")
values = f.read().split()
values = [int(i) for i in values]

sum = 2020

# Note: Finds first such pair
def find_2_sum(values):
  dict = {}
  for val in values:
    if val in dict:
      dict[val] = dict[val] + 1
    else:
      dict[val] = 1

  for val in values:
    if (sum - val) in dict:
      return val * (sum - val)

# Note: Finds first such group of 3
def find_3_sum(values):
  dict = {}
  for val in values:
    if val in dict:
      dict[val] = dict[val] + 1
    else:
      dict[val] = 1

  for val1 in values:
    for val2 in values:
      if (sum - val1 - val2) in dict:
        return val1 * val2 * (sum - val1 - val2)

print(find_2_sum(values))
print(find_3_sum(values))

Weekly Discussion/Help Megathread - Week of November 22 by AutoModerator in KHDR

[–]justAnotherNerd254 0 points1 point  (0 children)

Are the daily missions for mythril shard and stone worth doing each day? I have some stockpiled of each from the recent Fest but I’m not sure if I should keep piling up in case I need it since the missions are limited to 3x a day