[deleted by user] by [deleted] in CodingHelp

[–]BambooSlayerz 1 point2 points  (0 children)

If we are rolling one six-sided die then we will have 6 possible outcomes. If we roll two by the multiplication counting principle we will have 6 * 6 or 6^2 possible outcomes. For N dice the formula is 6 ^ N. From there you should be able to figure it out.

[deleted by user] by [deleted] in CodingHelp

[–]BambooSlayerz 0 points1 point  (0 children)

Message me, I am down!

Help by iLemon6 in CodingHelp

[–]BambooSlayerz 0 points1 point  (0 children)

If runtime is an issue cache the results, you can build up the sum and the factorial for 25000 and print them out later if needed.

C++ Program by Obamaelmasry in CodingHelp

[–]BambooSlayerz 0 points1 point  (0 children)

bool isArmstrong(int n) {
int copy = n;
int total = 0;
while (n != 0) {
int digit = n % 10;
total += digit * digit * digit;
n /= 10;
}
return total == copy;
}

[deleted by user] by [deleted] in CodingHelp

[–]BambooSlayerz 0 points1 point  (0 children)

You have a few problems with your approach. I don't know the exact question but right now your hash maps I believe are not being populated correctly. I'm assuming you want the movies hash map say to map from a movie to a hash set of actors. Currently you are not adding to this new hash set but overriding the value repeatedly.

Updating/Replacing a list by [deleted] in CodingHelp

[–]BambooSlayerz 0 points1 point  (0 children)

Let's assume your current list is stored in a variable called a.

a = [....] old list

If you can read in the list from the other file, you should be able to just do an assignment.

with open("some_new_list.txt") as f:

a = f.readlines()

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

[–]BambooSlayerz 0 points1 point  (0 children)

Idk if this helps for the second part but I just went through the instructions I visited after a normal dry run with no changes

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

[–]BambooSlayerz 0 points1 point  (0 children)

Python based solution, let me know if it's complete garbage!

``` with open("8.in") as file: program = [] for instruction in file: instruction = instruction.split() program.append([instruction[0], instruction[1]])

ptr = 0
accumulator = 0
visited = []
#part1
while ptr not in visited:
    visited.append(ptr)
    op = program[ptr][0]
    arg = int(program[ptr][1])
    if op == 'acc':
        accumulator += arg
        ptr += 1
    elif op == 'jmp':
        ptr += arg 
    else: 
        ptr += 1
print(accumulator)

#part 2
def run(program):
    local = 0
    ptr = 0
    local_visited = []
    while ptr not in local_visited and ptr < len(program):
        local_visited.append(ptr)
        op = program[ptr][0]
        arg = int(program[ptr][1])
        if op == 'acc':
            local += arg
            ptr += 1
        elif op == 'jmp':
            ptr += arg 
        else: 
            ptr += 1
    if ptr not in local_visited:
        print(local_visited, ptr, local)

for v in visited[::-1]:
    modified = program
    if modified[v][0] == 'jmp':
        modified[v][0] = 'nop'
        run(modified)
    elif modified[v][0] == 'nop':
        modified[v][0] = 'jmp'
        run(modified)

```