Re: [gcj] Re: KickStart 2020 simple problem. Code runs locally, but gets WA on Google's machine

2020-03-25 Thread porker2008
You can change the following code

*if len(arr) == 1 and sum(arr) <= budget:*
*return 1*

to

*if sum(arr) <= budget:*
*return len(arr)*


This is because the loop below assume the sum of the array is greater than 
*budget *at some point
so you need to handle the case where the sum of the array is less than 
*budget*.


-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/7941cbbc-9f39-4869-8575-fd1d5faa559e%40googlegroups.com.


Re: [gcj] Re: KickStart 2020 simple problem. Code runs locally, but gets WA on Google's machine

2020-03-25 Thread Bartholomew Furrow
Try the single-house case again. What it looks like to me is that you're
making small updates to your code, trying to fix particular cases. Instead,
take a deep breath, step back, and look at the whole thing.

*What was the problem before?*
findSol wasn't always returning something.

*How can we be sure it doesn't happen again?*
Make sure there isn't a code path that doesn't return something reasonable.

*Under what circumstances does your function not return anything?*
When it reaches the end of the function body without returning.

*How did it get there?*
By going all the way through the loop without returning.

*Why might it go all the way through the loop without returning?*

*Under what circumstances does it return during the loop?*

*Is it possible those circumstances are never met?*


When you figure out how the circumstances are never met, think: Do I need
to make sure that it always returns in the loop? Or can I let it exit the
loop and then return a result?

Good luck,
Bartholomew

On Wed, Mar 25, 2020 at 4:44 AM Sourakanti Mandal 
wrote:

> Thanks a Lot <3 <3 Actually single House was returning NONE, and also it
> had some problems with house list like [25,25] with a budget of 50. I fixed
> them, but still it gets WA. Ohh..gosh !
>
> def findSol(arr, budget):
> if len(arr) == 1 and sum(arr) <= budget:
> return 1
> arr.sort()
> total = 0
> count = 0
> for i in range(0, len(arr)):
> total += arr[i]
> #if the total exactly matches budget and there are no more elements
> # ex : [25, 25] with budget 50
> if total == budget:
> count += 1
> return count
> elif total < budget:
> count += 1
> else:
> return count
>
>
>
> def main():
> t = int(input())
> output = []
> while t > 0:
> num_and_budget = input().split()
> num_and_budget = list(map(int, num_and_budget))
> budget = num_and_budget[1]
> items = input().split()
> items = list(map(int, items))
> output.append(findSol(items, budget))
> t -= 1
> for i in range(len(output)):
> print("Case #" + str(i+1) + ": " + str(output[i]))
>
>
>
> main()
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-code+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/1c2af03d-6d37-4478-a8a7-61bc97f47a24%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAHaiWHN0HNHy0o-a0TsCuL7tqJrU%2B1jcYYn5K7iLWcO2T28v2w%40mail.gmail.com.


Re: [gcj] Re: KickStart 2020 simple problem. Code runs locally, but gets WA on Google's machine

2020-03-25 Thread Sourakanti Mandal
Thanks a Lot <3 <3 Actually single House was returning NONE, and also it 
had some problems with house list like [25,25] with a budget of 50. I fixed 
them, but still it gets WA. Ohh..gosh !

def findSol(arr, budget):
if len(arr) == 1 and sum(arr) <= budget:
return 1
arr.sort()
total = 0
count = 0
for i in range(0, len(arr)):
total += arr[i]
#if the total exactly matches budget and there are no more elements
# ex : [25, 25] with budget 50
if total == budget:
count += 1
return count
elif total < budget:
count += 1
else:
return count



def main():
t = int(input())
output = []
while t > 0:
num_and_budget = input().split()
num_and_budget = list(map(int, num_and_budget))
budget = num_and_budget[1]
items = input().split()
items = list(map(int, items))
output.append(findSol(items, budget))
t -= 1
for i in range(len(output)):
print("Case #" + str(i+1) + ": " + str(output[i]))


   
main()



-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/1c2af03d-6d37-4478-a8a7-61bc97f47a24%40googlegroups.com.


Re: [gcj] Re: KickStart 2020 simple problem. Code runs locally, but gets WA on Google's machine

2020-03-24 Thread Bartholomew Furrow
Sourakanti, it took me a few minutes to find what was wrong, and I had to
run some testcases. Try testing your code a few ways with just one house.

Bartholomew

On Tue, Mar 24, 2020 at 6:31 AM Sourakanti Mandal 
wrote:

> And this one gives WA as wellWHY ?? This one is really making me
> mad
>
> def findSol(arr, budget):
> arr.sort()
> total = 0
> count = 0
> for i in range(0, len(arr)):
> total += arr[i]
> if total <= budget:
> count += 1
> else:
> return count
>
>
>
> def main():
> t = int(input())
> output = []
> while t > 0:
> num_and_budget = input().split()
> num_and_budget = list(map(int, num_and_budget))
> budget = num_and_budget[1]
> items = input().split()
> items = list(map(int, items))
> output.append(findSol(items, budget))
> t -= 1
> for i in range(len(output)):
> print("Case #" + str(i+1) + ": " + str(output[i]))
>
>
>
> main()
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-code+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/2495566b-b639-4b88-8bec-ae16631ceedc%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAHaiWHMKkKJH8MdsYSDg1DoyfTv0hwWWj%3DLBhMmnWE6G45pKaQ%40mail.gmail.com.