20
4
Introduction
For those not familiar with steam - or at least this particular aspect:
Often on peoples' profiles, people leave comments saying either "+rep _____" or "-rep _____". These are an unofficial means of showing whether you think someone in the community has a good or a bad reputation, for a number of reasons. Such comments look like:
+rep a good player
+rep helpful
-rep hacker
-rep scammer
Task
The program must take input through any consensual way. The input consists of a string with optional newlines (\n
). At the very start of each line, '+rep '
or '-rep '
might be present. The rest of the line can be discarded. If the line doesn't start with '+rep '
or '-rep '
(note the trailing space), the line should be ignored.
The program then must keep a total reputation score. Starting at 0
, this score should be incremented on every line that starts with '+rep '
and decremented on every line that starts with '-rep '
.
This result should be output in any agreed-upon way.
Test cases
Input:
+rep fast trade
+rep nice person
-rep too good
Output: 1
Input:
-rep hacker
-rep scammer
-rep was mean
Output: -3
Input:
first
i don't like him
+rep good at cs go
Output: 1
Input (note the lack of a trailing space on the third line):
+rep +rep
hi +rep
-rep
Output: 1
Input:
+ rep
Output: 0
Input:
+rep like
-thing
Output: 1
Bonus
I don't even know if it's possible, but bonus points if you can somehow get these comments from Steam.
5Assuming the bonus points are imaginary, correct? They don't actually affect your score. – Rɪᴋᴇʀ – 2017-04-10T13:39:40.987
Will we ever get empty input? What about no occurrences of
+/-rep
? Will+/-rep
always have a trailing space? – user41805 – 2017-04-10T13:43:35.1332Can we assume the only plus and minus signs are in the '+rep'/'-rep'? Will the rep only be at the start of the line, or could it be in the middle also? – Rɪᴋᴇʀ – 2017-04-10T13:44:23.637
@Riker "Each line of the text will start with either "+rep" or "-rep". The rest of the line could contain anything." – HyperNeutrino – 2017-04-10T13:45:00.083
dupe? – Matthew Roh – 2017-04-10T13:57:46.767
3I would recommend adding a test case where there is a +rep or -rep that isn't at the start of the line – fəˈnɛtɪk – 2017-04-10T14:13:52.600
s/+rep.*/1
ands/-rep.*/\x08
? – Matthew Roh – 2017-04-10T14:49:21.330Will the input contain any other symbols other than
+
and-
? – user41805 – 2017-04-10T14:49:31.647What is the set of characters the input will contain? – user41805 – 2017-04-10T15:01:19.103
1Okay: The bonus points are imaginary The input can be empty, in which case the output will be 0 +/-rep will always have a trailing space It is codegolf The +/- signs are not necessarily in the rep The +/-rep must be at the start of a line – Jacob Garby – 2017-04-10T15:33:29.983
@JacobGarby What does
+rep
output? – user41805 – 2017-04-10T15:39:10.343@KritixiLithos 1 – Jacob Garby – 2017-04-10T15:41:29.300
@JacobGarby But you said that
rep
will always have a trailing space, yet the testcase I provided does not seem to fit that rule – user41805 – 2017-04-10T15:47:35.203@KritixiLithos True... In which case no, +rep would output 0 – Jacob Garby – 2017-04-10T15:50:26.067
We aim for a strict definition of the rules so that there aren't 500 different interpretations. – fəˈnɛtɪk – 2017-04-10T15:51:28.567
By this point, there are very few interpretations, with very little variation between them. But okay - I think I've cleared everything up now. – Jacob Garby – 2017-04-10T15:53:42.877
3I believe that example 4 should have output
0
, not1
. – James – 2017-04-10T17:54:52.77310
Hi Jacob, and welcome to PPCG. You've managed to get a quite active conversation for your first challenge here! Since no one else has yet mentioned it, I'll direct you to the Sandbox where you can get meaningful feedback and hammer out any details or clarification issues before posting the challenge to Main. In the future, that will help you avoid downvotes, closevotes, and the like. I hope you stick around and enjoy your stay!
– AdmBorkBork – 2017-04-10T18:02:28.853What about
+rep -rep
? – BlueRaja - Danny Pflughoeft – 2017-04-10T18:45:43.723The spec says that there isn't any need for a trailing space, 3rd test case and you are saying the opposite. Please update the post accordingly to what you meant. – dzaima – 2017-04-10T19:16:20.720
Hey everyone, I'd like to kinda hijack the comments and note down that the reputation comments usually don't mean much as malicious people can and do pay people in items to post +rep comments to their profile. Stay safe! – Ave – 2017-04-11T16:32:25.987