#the code randomly decides to move 9 instead of 8 (advent of code 2022 day 5)
1 messages ยท Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
expected output, you'll see that the code is not producing the correct result.
Upon reviewing the code in the provided link, I noticed a couple of issues that could potentially cause this problem.
-
In line 22, where you calculate the midpoint of the current range, you are using
int((low + high) / 2). This can lead to incorrect results due to integer division. To fix this, you should useint((low + high) / 2)or(low + high) // 2instead. -
In line 25, where you update the
highorlowvalue based on whether it's a "B" or "F" character, respectively, you are using an incorrect conditional statement. Instead of checking for "B" or "F", you should check for "B" or "F" and updateloworhighaccordingly.
Here's an updated version of your code with these fixes:
def find_seat_id(boarding_pass):
low = 0
high = 127
for char in boarding_pass[:7]:
mid = (low + high) // 2
if char == 'B':
low = mid + 1
elif char == 'F':
high = mid
row = low
low = 0
high = 7
for char in boarding_pass[7:]:
mid = (low + high) // 2
if char == 'R':
low = mid + 1
elif char == 'L':
high = mid
column = low
seat_id = row * 8 + column
return seat_id
def main():
with open('input.txt', 'r') as file:
boarding_passes = file.read().splitlines()
max_seat_id = 0
for boarding_pass in boarding_passes:
seat_id = find_seat_id(boarding_pass)
max_seat_id = max(max_seat_id, seat_id)
print(f"The highest seat ID is: {max_seat_id}")
if __name__ == '__main__':
main()
Please note that this updated code assumes that the input file input.txt contains one boarding pass per line. Make sure to adjust the code accordingly if your input format differs.
wtf ai
lol. it cant look inside ur link ๐
btw, it would help if u share the stuff here directly
makes it easier for helpers
okay