Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum Earnings #8

Open
rosdyana opened this issue Oct 4, 2018 · 5 comments
Open

Sum Earnings #8

rosdyana opened this issue Oct 4, 2018 · 5 comments
Labels
beginner beginner challenges Hacktoberfest

Comments

@rosdyana
Copy link
Contributor

rosdyana commented Oct 4, 2018

Challenge

  • write a function that accepts a comma-separated string input of earning/spending activity and returns the sum of earnings as a single int value
  • if at any point the spending (negative) value is greater than the sum of earned (positive) values before it then the streak ends and the count should start over

We have a list in string type separated by commas that represented buy or sell activity. Positive value for selling and negative value for buying activity.
For example, in the following string, this user sold something for $7 on the 2nd day, and something for $2 on the 4th day, and then bought something for $12 on the 5th day, and so on.

0,7,0,2,-12,3,0,2

This user's highest earnings streak is $5, which started on the 6th day and ended on the 8th day. The streak does not start before the 6th day because the user spent $12 on the 5th and broke earlier streak on $9.

test data

input:
1,3,-2,1,2
output:
5

input:
0,7,0,2,-12,3,0,2
output:
5

starter code

def sum_earnings(input):

notes

  • If the user did not do anything (i.e. 0,0,0,0,0) or only bought things without selling anything (i.e. -4,-3,-7,-1), then it should output with 0.
  • Your program should be able to handle a comma-separated string consisting of any number of values.
  • Your program should also be able to handle invalid input. If an invalid input is given, it should output 0. some examples of invalid input:
    qwerty
    ,,3,,4
    1,2,v,b,3
@the-vampiire
Copy link
Owner

@rosdyana hey thanks for the new challenge! i think you forgot the goal / challenge of the problem. would this be correct?

your function should accept a comma-separated string input of earning/spending activity and return the sum of earnings as a single int value

@the-vampiire the-vampiire added beginner beginner challenges Hacktoberfest labels Oct 4, 2018
@rosdyana
Copy link
Contributor Author

rosdyana commented Oct 5, 2018

@the-vampiire yeah, you're correct 👍

@mikelane
Copy link
Contributor

mikelane commented Oct 5, 2018

In the test data, can you explain why the streak is 5?

input:
1,3,-2,1,2
output:
5

I think it should be 4 starting on the 1st day and ending on the 2nd day.

@rosdyana
Copy link
Contributor Author

rosdyana commented Oct 5, 2018

hi @mikelane , it's 5 because the spending (-2) is less than earning (1+3), he still have $2 , so it's not broke the rules.
the second example
0,7,0,2,-12,3,0,2
after got $9 from earning, he spent $12, and the balance become minus, so it's broke the rules and need start counting the highest earning from 6th till 8th days

@the-vampiire the-vampiire added intermediate intermediate challenges beginner beginner challenges and removed beginner beginner challenges intermediate intermediate challenges labels Oct 5, 2018
@mikelane
Copy link
Contributor

mikelane commented Oct 5, 2018

Should this be able to handle float values?

the-vampiire added a commit that referenced this issue Oct 5, 2018
This was referenced Oct 8, 2018
the-vampiire added a commit that referenced this issue Oct 8, 2018
the-vampiire added a commit that referenced this issue Oct 11, 2018
dsargento added a commit to dsargento/hacktoberithms that referenced this issue Oct 12, 2018
AnilKumarTeegala added a commit to AnilKumarTeegala/hacktoberithms that referenced this issue Oct 9, 2019
Sum Earnings issue for the beginners solved
the-vampiire added a commit that referenced this issue Oct 14, 2019
minhduccao added a commit to minhduccao/hacktoberithms that referenced this issue Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner beginner challenges Hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants