Dec-06-2022, 05:54 PM
Dec-06-2022, 06:27 PM
Kind of a question that answers itself. Don't break.
You already have enough loops. no need for more.
You already have enough loops. no need for more.
Dec-06-2022, 06:50 PM
okay, i'm lost
i know you guys try to give me the best advice...but i think i need to back track a little and try do some simpler stuff (this should've been fairly simple) but what can i do\
i know you guys try to give me the best advice...but i think i need to back track a little and try do some simpler stuff (this should've been fairly simple) but what can i do\
Dec-06-2022, 07:38 PM
It will be hard to find a challenge simpler than this one.
A Compute total for a group of numbers.
B Repeat for multiple groups.
C Print the largest total.
You already did A.
B is just repeating A.
C is the trickiest part. Ignore for now as it will be easier when you have done A and B
To start computing a total what do you have to do? You already did this for the first group. It's not like your program has a lot of code. What step(s) did you perform in your existing program to prepare for computing the total? When you start computing the total for the second group you'll need to perform these same steps.
A Compute total for a group of numbers.
B Repeat for multiple groups.
C Print the largest total.
You already did A.
B is just repeating A.
C is the trickiest part. Ignore for now as it will be easier when you have done A and B
To start computing a total what do you have to do? You already did this for the first group. It's not like your program has a lot of code. What step(s) did you perform in your existing program to prepare for computing the total? When you start computing the total for the second group you'll need to perform these same steps.
Dec-06-2022, 07:50 PM
One solution is in this Thread,just need to put it together.
Put your input instead of test.txt.
Look at something like CheckiO where task is much more beginner friendly.
Put your input instead of test.txt.
sum_tot = [] with open("test.txt") as file: sum_list = [] for line in file: if line != "\n": sum_list.append(int(line)) else: sum_tot.append(sum(sum_list)) sum_list = [] print(max(sum_tot))
astral_travel Wrote:but i think i need to back track a little and try do some simpler stuff (this should've been fairly simple) but what can i doYes the Advent of code can be tricky in new to Python.
Look at something like CheckiO where task is much more beginner friendly.
Dec-06-2022, 08:41 PM
thank you Dean and snippsat,
i understood a bit more,
there is one thing i don't understand and which i'm stuck on - is how to sum up the group, without using a list,
snippsat did it with line 8
one element in my mind - if there is no way to save the groups's sum side by side in a list - there is a necessity to compare the sum variable in each loop to the previous sum - and replace if it's higher
snippsat thank you for the link !
i understood a bit more,
there is one thing i don't understand and which i'm stuck on - is how to sum up the group, without using a list,
snippsat did it with line 8
sum_tot.append(sum(sum_list))using
sum
one element in my mind - if there is no way to save the groups's sum side by side in a list - there is a necessity to compare the sum variable in each loop to the previous sum - and replace if it's higher
snippsat thank you for the link !
Dec-06-2022, 09:19 PM
No lists at all.
elf, calories = 1, 0 # For keeping track of current elf max_elf, max_calories = 1, 0 # For keeping track of elf with most calories with open("test.txt", "r") as file: for line in file: if line != '\n': calories += int(line) else: # End of number group Does this elf have the most calories? if calories > max_calories: max_elf, max_calories = elf, calories # This remembers which elf has most calories # Set up to process the next number group elf, calories = elf+1, 0 # Have to process the last number group that is not followed by a blank line if calories > max_calories: max_elf, max_calories = elf, calories print(max_elf, max_calories)
Dec-06-2022, 09:35 PM
ok, that's awesome
i had something like this in mind, like the general lines, i guess it got me confused a little
i'll try the website snippsat brought, it seems very cool, with missions/exercises that has a rising up level of difficulty
thank you !
i had something like this in mind, like the general lines, i guess it got me confused a little
i'll try the website snippsat brought, it seems very cool, with missions/exercises that has a rising up level of difficulty
thank you !
Dec-06-2022, 09:53 PM
This was the next step. Compute the total for each group and print:
calories = 0 with open("test.txt", "r") as file: for line in file: if line != '\n': calories += int(line) else: print(calories) calories = 0To get the max calories.
calories, max_calories = 0, 0 with open("test.txt", "r") as file: for line in file: if line != '\n': calories += int(line) else: max_calories = max(calories, max_calories) calories = 0 print(max_calories)And then to remember the elf with the max calories add in elf and max_elf like in my previous example.
Dec-07-2022, 05:14 PM
that's awesome !
i'm not fond of being given the end result, so maybe (with the tunnel-vision i had) i had to just be given more hints (like...use an additional
but i appreciate it
i'm not fond of being given the end result, so maybe (with the tunnel-vision i had) i had to just be given more hints (like...use an additional
if
condition)...and so on...but i appreciate it