Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7455521

Browse files
committed
update solutions
1 parent ea47eba commit 7455521

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎implementation/birthday-chocolate.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# https://www.hackerrank.com/challenges/the-birthday-bar/problem
2+
3+
# Lily has a chocolate bar that she wants to share it with Ron for his birthday.
4+
# Each of the squares has an integer on it.
5+
# She decides to share a contiguous segment of the bar selected such that the length of the segment
6+
# mathches Ron's birth month and the sum of the integers on the squares is equal to his birth day.
7+
# You must determine how many ways she can divide the chocolate.
8+
9+
10+
#!/bin/python3
11+
12+
import sys
13+
14+
def solve(n, s, d, m):
15+
# the length of the segment mathches Ron's birth month
16+
# the sum of the integers on the squares is equal to his birth day
17+
nb_solutions = 0
18+
for i in range(len(s)-m+1):
19+
nb_solutions += int(sum(s[i:i+m]) == d)
20+
return nb_solutions
21+
22+
23+
24+
n = int(input().strip())
25+
s = list(map(int, input().strip().split(' ')))
26+
d, m = input().strip().split(' ')
27+
d, m = [int(d), int(m)]
28+
result = solve(n, s, d, m)
29+
print(result)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /