#๐Ÿ”’ Hello

10 messages ยท Page 1 of 1 (latest)

main cobaltBOT
#

@mental ice

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

mental ice
#

Excuse the terrible title

#

I needed some help figuring out what my code is doing incorrectly

#
data = [rule.split(' => ') for rule in open('rules.txt', 'r').read().split('\n')]
rules = {}
for rule in data:
    rules[rule[0]] = rule[1]

def flip(grid):
    grid = grid.split('/')
    grid = grid[::-1]
    return '/'.join(grid)

def rotate(grid):
    grid = grid.split('/')
    new_grid = []
    for i in range(0, len(grid[0])):
        current = ''
        for j in range(0, len(grid)):
            current += grid[j][i]
        new_grid.append(current[::-1])
    return '/'.join(new_grid)
            
def combinations(arrangement):
    arrangements = []
    if arrangement in rules:
        solution = rules[arrangement]
    
    else:
        for i in range(4):
            flipped = flip(arrangement)
            rotated = rotate(arrangement)
            if flipped in rules:
                solution = rules[flipped]
                break
            elif rotated in rules:
                solution = rules[rotated]
                break
            else:
                arrangement = rotated
    return solution
#
count = 0
start = '.#./..#/###'
while count < 5:
    grid = start.split('/')
    final_grid = []
    if len(grid) % 3 == 0:
        for i in range(0, len(grid), 3):
            block = []
            for j in range(0, len(grid), 3):
                mini_grid = []
                for row in range(i, i+3):
                    mini_grid_line = ''
                    for column in range(j, j+3):
                        mini_grid_line += grid[row][column]
                    mini_grid.append(mini_grid_line)
                block.append(combinations('/'.join(mini_grid)).split('/'))

            for subrow in range(len(block[0])):
                string = ''
                for subblock in range(len(block)):
                    string += block[subblock][subrow]
                final_grid.append(string)

    elif len(start.split('/')) % 2 == 0:
        for i in range(0, len(grid), 2):
            block = []
            for j in range(0, len(grid), 2):
                mini_grid = []
                for row in range(i, i+2):
                    mini_grid_line = ''
                    for column in range(j, j+2):
                        mini_grid_line += grid[row][column]
                    mini_grid.append(mini_grid_line)
                block.append(combinations('/'.join(mini_grid)).split('/'))
            
            
            for subrow in range(len(block[0])):
                string = ''
                for subblock in range(len(block)):
                    string += block[subblock][subrow]
                final_grid.append(string)

    count += 1
    start = '/'.join(final_grid)
print(start.count('#'))  
#

do excuse me for the length, but ive been breaking my head trying to figure out where its going wrong for almost 2 hours with no leads. Would appreciate any help

#

Debugging assistance (Advent of code problem)

main cobaltBOT
#

@mental ice

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.