7 kyu
Dee, The Generous Tipper
118 of 264DiegoSalazar
Description:
Dee is lazy but she's kind and she likes to eat out at all the nice restaurants and gastropubs in town. To make paying quick and easy she uses a simple mental algorithm she's called The Fair %20 Rule. She's gotten so good she can do this in a few seconds and it always impresses her dates but she's perplexingly still single. Like you probably.
This is how she does it:
- She rounds the price
P
at the tens place e.g:- 25 becomes 30
- 24 becomes 20
- 5 becomes 10
- 4 becomes 0
- She figures out the base tip
T
by dropping the singles place digit e.g:- when
P = 24
she rounds to 20 drops 0T = 2
P = 115
rounds to 120 drops 0T = 12
P = 25
rounds to 30 drops 0T = 3
P = 5
rounds to 10 drops 0T = 1
P = 4
rounds to 0T = 0
- when
- She then applies a 3 point satisfaction rating
R
toT
i.e:- When she's satisfied:
R = 1
and she'll add 1 toT
- Unsatisfied:
R = 0
and she'll subtract 1 fromT
- Appalled:
R = -1
she'll divideT
by 2, rounds down and subtracts 1
- When she's satisfied:
Your Task
Implement a method calc_tip
that takes two integer arguments for price p
where 1 <= p <= 1000
and a rating r
which is one of -1, 0, 1
.
The return value T
should be a non negative integer.
Note: each step should be done in the order listed.
Dee always politely smiles and says "Thank you" on her way out. Dee is nice. Be like Dee.
Mathematics
Algorithms
Stats:
Created | Jan 5, 2016 |
Published | Jan 5, 2016 |
Warriors Trained | 562 |
Total Skips | 11 |
Total Code Submissions | 2164 |
Total Times Completed | 264 |
Ruby Completions | 118 |
Python Completions | 139 |
Haskell Completions | 23 |
Total Stars | 8 |
% of votes with a positive feedback rating | 83% of 87 |
Total "Very Satisfied" Votes | 61 |
Total "Somewhat Satisfied" Votes | 22 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 14 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |