[Question]
  [
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
 
 
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/116012/edit).
Closed 6 years ago.
[Improve this question](/posts/116012/edit) 
# 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.
  
[Answer]
# Python 3, 73 bytes
I'm sure this answer is garbage and will be beaten soon, but there's no other python answers yet
```
lambda x:sum(["- +".index(i[0])-1for i in x.split('\n')if i[1:4]=="rep"])
```
Use like this:
```
f = lambda x:sum(["- +".index(i[0])-1for i in x.split('\n')if i[1:4]=="rep"])
print(f("PUT INPUT HERE"))
```
  
## Fetching from steam
Here's some sample code which fetches the first 100 comments from KennyS' profile and calculates his rep.
```
import requests
from bs4 import BeautifulSoup
# Kenny's profile as Steam ID 64
# You can adjust this to whatever numbers you want
STEAM_PROFILE_URL = "76561198024905796"
payload =  {"start" : 0, "count" : 100}
r = requests.post("http://steamcommunity.com/comment/Profile/render/{}/-1/".format(STEAM_PROFILE_URL), payload)
# Comments are html inside a json object
soup = BeautifulSoup(r.json()["comments_html"], "html.parser")
# Get raw text for every comment.
# The " ".join() strips out the newlines and tabs which are part of html
comments = [" ".join(s.text.split()) for s in soup.find_all("div", {"class" : "commentthread_comment_text"})]
calculateRep = lambda x:sum(["- +".index(i[0])-1for i in x.split('\n')if i[1:4]=="rep"])
print(calculateRep("\n".join(comments)))
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~18~~ ~~16~~ 17 bytes
Saved 2 bytes thanks to *Okx*  
+1 byte due to change in spec where rep now need to be followed by a space.
```
|vy5£„+-S„·Ý «QÆO
```
[Try it online!](https://tio.run/nexus/05ab1e#@19TVmlyaPGjhnnausHqh7YfnntodeDhNv///7WLUgsU0hKLSxRKihJTUrnA/LzM5FSFgtSi4vw8Ll2QQEl@vkJ6fn4KAA "05AB1E – TIO Nexus")
**Explanation**
```
|v                   # for each line of input
  y5£                # get the first 4 chars of input
     „+-S„·Ý «       # push the list ['+rep ','-rep ']
              Q      # check each for equality
                     # results in either [1,0] for +rep, [0,1] for -rep or [0,0] for others
               Æ     # reduce by subtraction, gives either 1, -1 or 0
                O    # sum
```
[Answer]
# [Perl 5](https://www.perl.org/), 25 bytes
24 bytes of code + `-p` flag.
```
$\+=/^\+rep /-/^-rep /}{
```
[Try it online!](https://tio.run/nexus/perl5#U1YsSC3KUdAt@K8So22rHxejXZRaoKCvqx@nC2bUVv//DxZKSywuUSgpSkxJ5QLz8zKTUxWAeovz87jASkvy8xXS8/NTAA "Perl 5 – TIO Nexus")
`/^\+rep /` returns `1` if the line starts with `+rep`; `/^-rep /` returns `1` if the line starts with `-rep` (so only one of them will be one at most). We use `$\` to store the result, as it is implicitly printed at the end (thanks to `-p` flag and those unmatched `}{`).
[Answer]
# [Python 2](https://docs.python.org/2/), 54 bytes
```
q=('\n'+input()).count;print q('\n+rep ')-q('\n-rep ')
```
[Try it online!](https://tio.run/nexus/python2#@19oq6Eek6eunZlXUFqioampl5xfmldiXVCUmVeiUAiS0y5KLVBQ19QFc3QhnP//lZSUwBIgIiYvIxPKAMkDpQA "Python 2 – TIO Nexus") Takes a multiline string as input.
Counts the appearances of `'+rep '` and `'-rep '` only at starts of lines by searching for the string following a newline symbol. To catch the first line, a newline is prepended to the input. 
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~63~~ ~~51~~ ~~50~~ 49 bytes
Didn't quite comply with the spec so I fixed some issues but also golfed it a lot (by borrowing the first line from Kritixi Lithos's solution).
Saved another byte thanks to Kritixi Lithos.
```
ms`(?!^[+-]rep ).
+`\+-|-\+
(.)+
$1$.&
T`+
$^
0
```
[Try it online!](https://tio.run/nexus/retina#@59bnKBhrxgXra0bW5RaoKCpx8WlnRCjrVujG6PNxaWhp6nNpWKooqfGFZIAZMVxGfz/rw1SCCK4MjIhtC6QAAA "Retina – TIO Nexus")
**Explanation**
```
ms`(?!^[+-]rep ).
```
First, everything from the input is deleted, except for the `+` and `-` from any `+rep` or `-rep` at the start of a line.
```
+`\+-|-\+
```
Then adjacent pairs of `+` and `-` are removed until no more can be removed. After this, what's left is either a run of `+`s, a run of `-`s, or nothing.
```
(.)+
$1$.&
```
Then a run of one or more characters (either `+` or `-`) is replaced with the character making up the run followed by the length of the run. This way, `+` is preserved at the start for positive results and `-` for negatives.
```
T`+
```
Then all `+`s are removed, in the event that the rep is positive.
```
$^
0
```
Finally, if the string is empty at this point, the rep is 0, so we write 0.
[Answer]
# Mathematica, 47 bytes (ISO 8859-1 encoding)
```
(±c_:=StringCount["
"<>#,c];±"
+rep"-±"
-rep")&
```
Pure function taking a newline-separated string as input and returning an integer. Note that the three newlines in the code are flanked by quotes and are thus each equivalent to `"\n"` in a string (but this way is one byte shorter than `"\n"`). `StringCount` does the heavy lifting; we manually add a newline to the beginning of the string so that the first line matches when appropriate. `±` is a unary helping function to avoid repetition of `StringCount`.
The alternative solution
```
(±c_:=StringCount["
"<>#,"
"<>c<>"rep"];±"+"-±"-")&
```
is 4 bytes longer, but I do like the sequence `±"+"-±"-"`....
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~59~~ ~~53~~ ~~52~~ 50 bytes
```
ms`(?!^[+-]rep ).
+`\+-|-\+
-+
-$.&
\++
$.&
^$
0
```
[Try it online!](https://tio.run/nexus/retina#XYxBDkAwFET3cwqSRsjPFzdwENUgJCxooztx9@rHhs3My@Rlwuq7vE5NQ9zuk0uKEqBOE5@sCWACqzKDJoK0UahC6P0IEnteEPnGZwBLOmt/8LWGODvrIOwf4Zj2V93A8i98AQ "Retina – TIO Nexus")
Check out Basic Sunset's shorter [answer](https://codegolf.stackexchange.com/a/116016/41805) in the same language!
### Explanation
```
ms`(?!^[+-]rep ).
```
Removes everything except for `[+-]rep` s.
```
+`\+-|-\+
```
Repeatedly removes 1 `-` for every `+` and vice versa.
```
-+
-$.&
```
Prepend a `-` (because the number is negative) to `-`s as well as replacing the `-`s with the number of `-`s.
```
\+
$.&
```
Do the same for `+`s, but don't prepend a `-`.
```
^$
0
```
Finally, if there is nothing, replace it with a `0`.
[Answer]
## PHP, 118 bytes
```
function s($a,$c=0){foreach(explode("
",$a)as$b){$b=substr($b,0,1).'1';if(is_numeric($b){$c+=$b});}return$c-($a=="");}
```
[Try it online!](https://repl.it/HDXz/1)
Used like this:
```
echo s("-rep bad
+rep good
+rep very good
+rep exceeds expectation");
```
[Answer]
# [Röda](https://github.com/fergusq/roda), 53 bytes
```
{{|l|[1]if[l=~`\+rep .*`];[-1]if[l=~`-rep .*`]}_|sum}
```
[Try it online!](https://tio.run/nexus/roda#y03MzFOo/l9dXZNTE20Ym5kWnWNblxCjXZRaoKCnlRBrHa0LF9WFCdbG1xSX5tb@r/0PVgciuDIyITRIEQA "Röda – TIO Nexus")
[Answer]
# JavaScript, 55 bytes
Thanks @Neil for golfing off 12 bytes
Thanks @Arnauld for golfing off 2 bytes
```
x=>x.split(/^\+rep /m).length-x.split(/^-rep /m).length
```
[Try it online!](https://tio.run/nexus/javascript-node#S7P9X2Frp1Ghl5tYkpyhoR8Xo12UWqCgn56rWVOjrq6pl5Oal16SoYukQhebgv/J@XnF@Tmpejn56RppGkogU2LyQCSEpQsmE4tT0hJTitOUNDX/AwA "JavaScript (Node.js) – TIO Nexus")
```
var y=x=>(x.match(/^\+rep /gm)||'').length-(x.match(/^-rep /gm)||'').length
document.querySelector('div').innerText=y(document.querySelector('textarea').value)
```
```
textarea{
  width: 95%;height: 100px;
  }
```
```
<textarea oninput = "document.querySelector('div').innerText=y(this.value)">
-rep Cheater!!
+rep very good, fun to play with
+rep my friend +rep
good
</textarea>
<div></div>
```
[Answer]
# Java, 109 bytes
```
l->{int i=0;for(String s:l.split("\n")){if(s.startsWith("+rep "))i++;if(s.startsWith("-rep "))i--;}return i;}
```
Trying to make this shorter using `Stream`'s
[Answer]
# [Stacked](https://github.com/ConorOBrien-Foxx/stacked), 45 bytes
```
'^([+-])rep |.'{.a:''['#'a+]a if}mrepl'0'\+#~
```
[Try it online!](https://tio.run/nexus/stacked#HYpLCoMwEIb3OcWAi98yKF17gt7BKgzNWITUkZjShdqrp9rl9wBHnWmQJVGK4tX9eRofSrPGxSZXnSKZ0dPMu5uGYPSxGLxjOhIy@rLlqruc31ZjraUBWhQQ7oTGYX8dJeCKOxffbO@Ufw "Stacked – TIO Nexus")
Alternatively (49 bytes):
```
lines'^[-+]rep 'match$#'YES[0#0# '#'\+]"!''#`0\#~
```
## Explanation
```
'^([+-])rep |.'{.a:''['#'a+]a if}mrepl'0'\+#~
```
This basically extracts all `+` or `-` attached to the beginning of the line and `rep`. Then, to each, it prepends a `#`. Then, to the entire thing, a `0` is prepended. `#~` evaluates the string, which now looks something like:
```
0#+#+#-
```
`#+` is increment and `#-` is decrement. Thus, we obtain our desired result.
[Answer]
# [Retina](https://github.com/m-ender/retina), 38 bytes
```
M!m`^[+-]rep 
Os`.
+`\+-
*\M1!`-
[+-]
```
[Try it online!](https://tio.run/nexus/retina#@@@rmJsQF62tG1uUWqDA5V@coMelnRCjrcvFpRXja6iYoMsFkvz/XxskDyK4MjIhtC5IJD/bHsbgAivJz8/nSkzNzC@FCJenpqYCAA "Retina – TIO Nexus")
A different (and shorter) solution than the ones already posted in Retina.
### Explanation
```
M!m`^[+-]rep 
```
(This line has a trailing space). Keep only the relevant parts of the input, i.e. the `+rep` or `-rep` at the beginning of a line.
```
Os`.
```
Sort all characters (including newlines). this will put +s and -s next to each other.
```
+`\+-
```
Repeatedly remove `+-` couples until at most one of the two signs remains.
```
*\M1!`-
```
Match the first `-` (if present) and print it without modifying the string.
```
[+-]
```
Count the number of signs remaining, and print it since this is the final stage of the program.
[Answer]
# C#, 87 bytes
```
s=>{int n=0;foreach(var t in s.Split('\n'))n+=t.IndexOf("rep ")==1?44-t[0]:0;return n;}
```
Anonymous function which splits the input string by using the newline character, searches for the "rep " string prefixed by a character and, if it finds it, increments the reputation (the `n` variable) by 1 or -1.
Full program with ungolfed method and test cases:
```
using System;
class P
{
    static void Main()
    {
        Func<string, int> f =
        s=>
        {
            int n = 0;
            foreach (var t in s.Split('\n'))
                n += t.IndexOf("rep ") == 1 ?
                    44 - t[0]
                    :
                    0;
            
            return n;
        };
        
        // test cases:
        Console.WriteLine(f(@"+rep fast trade
+rep nice person
-rep too good"));       // 1
        Console.WriteLine(f(@"-rep hacker
-rep scammer
-rep was mean"));       // -3
        Console.WriteLine(f(@"first
i don't like him
+rep good at cs go"));  // 1
        Console.WriteLine(f(@"+rep +rep
hi +rep
-rep"));            // 1
        
        Console.WriteLine(f(@"+ rep"));     // 0
        Console.WriteLine(f(@"+rep like
-thing"));          // 1
    }
}
```
**Note that the ASCII code for `+` is 43 and for `-` is 45. This method passes all test cases from the OP. However, if the first character is something else, this will lead to wrong answers!**
This can be fixed at the cost of 17 bytes:
# C# fixed, 104 bytes
```
s=>{int n=0;foreach(var t in s.Split('\n'))n+=t.IndexOf("rep ")==1?t[0]==43?1:t[0]==45?-1:0:0;return n;}
```
The modified anonymous function will check for a `+` or `-` sign as the first character in each line.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 14 bytes
```
r`œp`1 f".%d 
```
[Try it online!](https://tio.run/nexus/japt#@1@UcGhOQYKhQpqSnmqKwv//StpFqQUKICImLyMTytAFkkoKuhUA "Japt – TIO Nexus")
+1 byte for `-x` flag
[Answer]
# C++, 144 bytes
```
#import<iostream>
int f(){int r=0;for(std::string s;std::getline(std::cin,s);)if((s[0]==43|s[0]==45)&s.substr(1,4)=="rep ")r-=s[0]-44;return r;}
```
[Try it online!](https://tio.run/nexus/cpp-gcc#LU5BDsIwDLv3FRFIqBUMgRgXuvIRxGGwborEminJTsDbxwrk4thx4kxL7AdirZBEOdb92WBSaK17ZuSw8y2xFW1Op9mAqQPxX9ZFfWCKv9Ed00acd9haK5fdNYTy8Po3R7eSrYy3ed3uN6ULYcFxgIXjImRLUZaeo46cgP17yrF9jck68zQw1y@ARoWqyo95857W@UJbi4Jy3UTz5QnvEYbIQskUWVAi6IiaDw)
[Answer]
## [C#](http://csharppad.com/gist/f48dd4513d8320d145251b927186b559), 104 bytes
---
Despite existing already one solution -- and mine being longer -- I still think I should post it, since the on already here might fail if something like `'=rep '` gets in it's way.
---
**Golfed**
```
i=>{var c=0;foreach(var o in i.Split('\n'))c+=o.IndexOf("rep ")!=1?0:o[0]==43?1:o[0]==45?-1:0;return c;}
```
---
**Ungolfed**
```
i => {
   var c = 0;
   
   foreach( var o in i.Split( '\n' ) )
      c += o.IndexOf( "rep " ) != 1
         ? 0
         : o[ 0 ] == 43
            ? 1
            : o[ 0 ] == 45
               ? -1
               : 0;
   
   return c;
}
```
---
**Ungolfed readable**
```
i => {
   // Counter for the 'reputation'
   var c = 0;
   
   // Cycle through every line
   foreach( var o in i.Split( '\n' ) )
      // Check if the "rep " string has index 1
      //   ( Index 0 should be the sign )
      c += o.IndexOf( "rep " ) != 1
         // Add 0 if the rep isn't on the right position
         ? 0
         // Check for the '+' sign
         : o[ 0 ] == 43
            // Add 1 if the sign is found
            ? 1
            // Check for the '-' sign
            : o[ 0 ] == 45
               // Add -1 if the sign is found
               ? -1
               // Add 0 if another char is found
               : 0;
   
   // Return the 'reputation'
   return c;
}
```
---
**Full code**
```
using System;
using System.Collections.Generic;
namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, Int32> f = i => {
            var c = 0;
            foreach( var o in i.Split( '\n' ) )
               c += o.IndexOf( "rep " ) != 1
               ? 0
                  : o[ 0 ] == 43
                  ? 1
                  : o[ 0 ] == 45
                     ? -1
                     : 0;
            return c;
         };
         List<String>
            testCases = new List<String>() {
               @"+rep fast trade
+rep nice person
-rep too good",
               @"-rep hacker
-rep scammer
-rep was mean",
               @"first
i don't like him
+rep good at cs go",
               @"+rep +rep
hi +rep
-rep",
               @"+ rep",
               @"+rep like
-thing",
         };
         foreach( String testCase in testCases ) {
            Console.WriteLine( $"{testCase}\n{f( testCase )}\n" );
         }
         Console.ReadLine();
      }
   }
}
```
---
**Releases**
* **v1.0** - `104 bytes` - Initial solution.
---
**Notes**
Nothing to add
[Answer]
# Ruby, 46 bytes
```
->x{rep=1;eval ?0+x.map{|a|a[/^[+-]rep /]}*''}
```
Get all the +/-rep from input, and put together in a single string. Then evaluate that for rep=1.
[Answer]
# JavaScript ES6, ~~85~~ 79 bytes
```
l=>eval(l.split`
`.map(i=>(r=i.slice(0,5))==`+rep `?1:r==`-rep `?-1:0).join`+`)
```
---
## Try it
```
f=l=>eval(l.split`
`.map(i=>(r=i.slice(0,5))==`+rep `?1:r==`-rep `?-1:0).join`+`);
console.log(f(`+rep fast trade
+rep nice person
-rep too good`));
console.log(f(`-rep hacker
-rep scammer
-rep was mean`));
console.log(f(`first
i don't like him
+rep good at cs go`));
console.log(f(`+rep +rep
hi +rep
-rep`));
console.log(f(`+ rep`));
console.log(f(`+rep like
-thing`));
```
---
## Ungolfed
```
const repcount=list=>{
    let array=list.split("\n");
    let values=array.map(item=>{
        let rep=item.slice(0,5);
        return rep==="+rep "?1:rep==="-rep "?-1:0;
    });
    let result=values.reduce((a,b)=>a+b);
    return result;
};
```
---
## History
### 85 bytes
```
l=>l.split`\n`.map(i=>(r=i.slice(0,5))=="+rep "?1:r=="-rep "?-1:0).reduce((a,b)=>a+b)
```
]