A street brawl is going down. The even and odd sides of the street are trying to figure out who's tougher, and absolutely everybody, even little babies, are joining the fray. Let's determine which side has a higher chance of winning (more residents means better chances). We'll create an array of 15 numbers (15 houses, the array index is the house number). Then we'll write the number of residents in each cell and tally up the number of people on the even and odd sides of the street.
Streets and houses
- 5
Locked
Comments (15)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
25 August 2021, 18:21
This is a very simple task. Consider which number is the house numbers (the array index) and which number is the people living at each house number (the number at that index). So if you had an array like this:
[1, 4, 2, 1, 3, 2, 3, 2, 1, 4, 2, 4, 2, 3, 3]
It could be visualized like this:
So if you:
- sum up the number living on the even side of the street you get 1+2+3+3+1+2+2+3 for a total 17
- sum up the number living on the odd side you get 4+1+2+2+4+4+3 for a total of 20
Therefore the correct output for this example would be that more people live on the odd side +2
Usman Full Stack Developer at QA
5 July 2021, 10:07
Enjoyed this one :D
0
Karas Java Developer
4 September 2020, 22:36
You basically have to sum the number of residents. and the side who has the most then has the most.
0
hidden #10568956
28 January 2020, 11:03
2 for's and 3 if's did the trick for me.
0
Usman Full Stack Developer at QA
5 July 2021, 10:06
interesting, i used three fors and one if/else
First for to fill in the array,
Second to get the even sum value,
Third to get the odd sum value,
Lastly do a simple if/else.
+1
Justin Smith
13 November 2019, 06:25
The requirements should state the value of the odd/even index, not the odd/even element.
"The program should display "Odd-numbered houses have more residents." if the sum of odd array elements is greater than the sum of even ones."
It could be confused for figuring out if the element itself is even or odd, which isn't what the task is looking for.
+1
Guadalupe Gagnon
25 August 2021, 18:26
It says "the sum of"... it doesn't say if the element itself is even/odd
0
Tommy Guinness
10 October 2019, 21:59
/* Comment has been deleted */
0
Roman
11 October 2019, 06:31
Posting the solution in the comments is prohibited.
0
Tommy Guinness
10 October 2019, 21:45
Getting correct output, still shows not working. What wrong?
0
Roman
11 October 2019, 06:31
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
0
Goff
10 October 2019, 02:47
Just a tip: you may read input in pairs, even house - odd house.
0
Dipti singh Bhadouriya
5 July 2019, 06:31
can't get why the requirements are not filled .
although the code woks fine ...
0
Roman
8 July 2019, 05:46
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
0
Rakesh Kumar
25 June 2019, 20:37
Can anyone tell me problem here, please
0