fromcollectionsimportdefaultdictdefmain():guard_sleep_dict=calculate_guard_sleep_dict()part_one(guard_sleep_dict)part_two(guard_sleep_dict)defcalculate_guard_sleep_dict():withopen('input.txt','r')asdata:sorted_data=sorted(data)# This will work too... No extra key required
guard_sleep_dict=defaultdict(lambda:[0forxinrange(60)])current_guard=-1start_sleeping=-1forlineinsorted_data:ifline[25]=="#":current_guard=line.split()[3]elifline[25]=="a":start_sleeping=int(line[15:17])else:# "wakes up"
end_sleeping=int(line[15:17])forxinrange(start_sleeping,end_sleeping):guard_sleep_dict[current_guard][x]+=1returnguard_sleep_dictdefpart_one(guard_sleep_dict):guard=sorted(guard_sleep_dict.keys(),key=lambdag:-sum(guard_sleep_dict[g]))[0]gh=guard_sleep_dict[guard]minute=gh.index(max(gh))printint(guard[1:])*minutedefpart_two(guard_sleep_dict):guard=sorted(guard_sleep_dict.keys(),key=lambdag:-max(guard_sleep_dict[g]))[0]gh=guard_sleep_dict[guard]minute=gh.index(max(gh))printint(guard[1:])*minuteif__name__=='__main__':main()
First missunderstood the task, so I wasted my whole time before university for the wrong solution... Fortunately I had some time after the first seminar to fix my solution.
Then found out that I can just call sorted and sort the data and I don't need any extra key for this. This made solving the puzzle much easier.
Did that yesterday! Elegantly solved exactly the wrong problem, had to go back and re-read the whole page to figure out what I was doing wrong. Devastating.
Yeah it is just super frustrating... Especially if you notice then that you have to move on to do other things and will loose expensive points on your private leaderboards 🙈
Tomorrow I will read the task at least twice before I start typing.
I used the same approach, but I really like the tools you have for searching the structure. The Clojure ones work, but were much more manual, making the code a little more clunky.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
First missunderstood the task, so I wasted my whole time before university for the wrong solution... Fortunately I had some time after the first seminar to fix my solution.
Then found out that I can just call sorted and sort the data and I don't need any extra key for this. This made solving the puzzle much easier.
Did that yesterday! Elegantly solved exactly the wrong problem, had to go back and re-read the whole page to figure out what I was doing wrong. Devastating.
Yeah it is just super frustrating... Especially if you notice then that you have to move on to do other things and will loose expensive points on your private leaderboards 🙈
Tomorrow I will read the task at least twice before I start typing.
Damn life, getting in the way of AoC. The very nerve.
I used the same approach, but I really like the tools you have for searching the structure. The Clojure ones work, but were much more manual, making the code a little more clunky.