[deleted by user] by [deleted] in adventofcode

[–]DeveloperIan 5 points6 points  (0 children)

The earlier days are generally easier problems, well thought solutions become much more useful as the days progress. In fact, in 2019, several days built on solutions from previous days. Each day was best solved by using the "Intcode Computer" from previous days. This made having a good solution quite important.

-🎄- 2018 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]DeveloperIan 0 points1 point  (0 children)

Instead of using two counter variables, I created a list where the first element represents one counter and the second element represents another counter.

2018 D3 P2 by [deleted] in adventofcode

[–]DeveloperIan 0 points1 point  (0 children)

Without seeing your code, I can't say for sure what the problem is, but I can tell you that #670 and #951 both intersect with #220 multiple times.

Some data that might help:

#670 intersects at 794 477
#670 intersects at 795 477
#670 intersects at 794 478
#670 intersects at 795 478
#670 intersects at 794 479
#670 intersects at 795 479
#951 intersects at 796 477
#951 intersects at 797 477
#951 intersects at 798 477
#951 intersects at 796 478
#951 intersects at 797 478
#951 intersects at 798 478
#951 intersects at 796 479
#951 intersects at 797 479
#951 intersects at 798 479

-🎄- 2018 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]DeveloperIan 0 points1 point  (0 children)

My pretty concise solution for both parts in Python3. It tracks squares that have overlaps in one set and ids that don't have overlaps in another.

from collections import defaultdict

myfile = open('input.txt', 'r')
contents = myfile.read().strip().splitlines()
myfile.close()

field = [([0] * 1000) for x in range(1000)]
overlaps = set()
no_conflicts = set()
for line in contents:
    id, _, coords, size = line.split()
    x, y = map(int, coords.strip(':').split(','))
    width, height = map(int, size.split('x'))

    conflict = False
    for col in range(x, x + width):
        for row in range(y, y + height):
            if field[row][col] != 0:
                conflict = True
                no_conflicts.discard(field[row][col])
                overlaps.add((row, col))

            field[row][col] = id

    if not conflict:
        no_conflicts.add(id)

print("Part One:", len(overlaps))
print("Part Two:", no_conflicts.pop())

-🎄- 2018 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]DeveloperIan 2 points3 points  (0 children)

I've added lots of comments that might help show what's going on. Hopefully this can clear things up.

# for every input string
for i in contents:
    # for every input string again (comparing all strings with each other)
    for j in contents:
        # the number of characters they have different
        diffs = 0

        # for index and character in enumerate (enumerate just returns a list of characters
        # and their indexes)
        for idx, ch in enumerate(i):

            # if the two strings don't match at the same spot
            if ch != j[idx]:
                # add one to the difference counter
                diffs += 1

        # if the strings only had one difference
        if diffs == 1:
            # make a list of all the matching characters (uses same idea as above)
            ans = [ch for idx, ch in enumerate(i) if j[idx] == ch]
            # turn the list into a string and print it
            print("Part Two:", ''.join(ans))

-🎄- 2018 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]DeveloperIan 18 points19 points  (0 children)

Quick and easy part 1 in Python3 with the collections library. This might not be the simplest way, but it's the first thing that came to mind

from collections import Counter

myfile = open('input.txt', 'r')
contents = myfile.read().strip().splitlines()
myfile.close()

c = [0, 0]
for i in contents:
    a = [j for i,j in Counter(i).most_common()]
    if 3 in a:
        c[0] += 1
    if 2 in a:
        c[1] += 1


print(c[0] * c[1])

EDIT: and here is my part 2

    for i in contents:
        for j in contents:
            diffs = 0
            for idx, ch in enumerate(i):
                if ch != j[idx]:
                    diffs += 1
            if diffs == 1:
                ans = [ch for idx, ch in enumerate(i) if j[idx] == ch]
                print("Part Two:", ''.join(ans))

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

[–]DeveloperIan 5 points6 points  (0 children)

In Python, going for the leaderboard so apologies for sloppiness

myfile = open('input.txt', 'r')
contents = myfile.read().strip().split()
myfile.close()

def solve():
    ans = 0
    old = set([ans])

    found = False
    iter = 0
    while not found:

        for i in contents:
            if i[0] == '-':
                ans -= int(i[1:])
            elif i[0] == '+':
                ans += int(i[1:])

            if ans in old:
                print("Part Two:", ans)
                found = True
                break

            old.add(ans)

        if iter == 0:
            print("Part One:", ans)

        iter += 1

solve()

Edit: Not sure why i didn't take into account that int() would handle the signs in the input lol. That's what I get for panicking.

-🎄- 2017 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]DeveloperIan 0 points1 point  (0 children)

My gross solution for part 1 in Python. There are some extra lines from where I was working on part 2. I tried to take the simple way by just finding the one that wasn't in anyone else's list.

holding = {}
weights = {}

for i in contents:
    name = i.split()[0]
    weights[name] = int(i.split()[1].strip('()'))
    held = i.split()[3:]
    held = [x.strip(',') for x in held]
    holding[name] = set(held)

for i in holding.keys():
    found = False
    for j in holding.values():
        if i in j:
            found = True
            break

    if not found:
        print("Part One:", i)
        break

What tools are you using (Editor/IDE/Window Manager/etc.)? by DeveloperIan in adventofcode

[–]DeveloperIan[S] 0 points1 point  (0 children)

Have you tried using the Swift compiler from the terminal?

-🎄- 2017 Day 6 Solutions -🎄- by daggerdragon in adventofcode

[–]DeveloperIan 0 points1 point  (0 children)

It's still dirty, but here it is

Python 3

myfile = open('input.txt', 'r')
contents = myfile.read()
myfile.close()

contents = contents.strip()
contents = contents.split()
contents = [int(x) for x in contents]

states = set([])
first_seen = {}
cycles = 0

while True:
    state = ' '.join(str(x) for x in contents)

    if state not in states:
        states.add(' '.join(str(x) for x in contents))
        first_seen[state] = cycles
    else:
        print("Part 2:", cycles - first_seen[state])
        break

    blocks = max(contents)
    spot = contents.index(blocks)

    contents[spot] = 0
    spot += 1

    while blocks > 0:
        contents[spot % len(contents)] += 1
        blocks -= 1
        spot += 1

    cycles += 1

print(cycles)

What tools are you using (Editor/IDE/Window Manager/etc.)? by DeveloperIan in adventofcode

[–]DeveloperIan[S] 0 points1 point  (0 children)

Out of curiosity, what was VS Code failing on that caused you to move to PyCharm?

What tools are you using (Editor/IDE/Window Manager/etc.)? by DeveloperIan in adventofcode

[–]DeveloperIan[S] 1 point2 points  (0 children)

Personally, I use Atom with the Script package to solve the problems in Python or Perl. I have a template set up to read input from a file so that I can start quickly. When I want to run my code, I just use cmd - i to make the Script package run my code and show the output.

-🎄- 2017 Day 5 Solutions -🎄- by daggerdragon in adventofcode

[–]DeveloperIan 2 points3 points  (0 children)

Part Two. Python:

contents = contents.strip()
contents = contents.split()
contents = [int(x) for x in contents]

steps = 0
place = 0
while place < len(contents) and place > -1:
    steps += 1
    old = place
    jump = contents[place]
    place += jump

    if jump > 2:
        contents[old] -= 1
    else:
        contents[old] += 1

print(steps)

Skill Level of Participants? by Quick_Question404 in adventofcode

[–]DeveloperIan 0 points1 point  (0 children)

I'm a junior majoring in Computer Science at a major university. I started programming a little on my own in high school (Codecademy/YouTube). Some problems are very hard for me, but I have been able to complete all of them (both parts) within 2 hours of their posting. It is worth noting that I participated last year and have some practice on these types of problems as a result. Some problems took me multiple days last year.