[Question]
  [
Write a program or function that takes in a string only containing the characters `^` and `v` (you can assume there will be no other characters). Read from left to right this string represents the sequence of mouse clicks a single user made while viewing a [Stack Exchange](https://stackexchange.com/) question or answer for the first time.
Every `^` represents a click of the [upvote](https://stackoverflow.com/help/privileges/vote-up) button and every `v` represents a click of the [downvote](https://stackoverflow.com/help/privileges/vote-down) button. (For working examples look slightly left.)
Assume that no [voting limitations](https://meta.stackexchange.com/questions/5212/what-are-the-limits-on-how-i-can-cast-change-and-retract-votes) are in effect so all the clicks are registered correctly.  
Print or return:
* `1` or `+1` if the post ends up being upvoted.
* `0` if the post ends up not being voted on. (`-0` and `+0` are not valid)
* `-1` if the post ends up being downvoted.
Posts start with zero net votes from the user and the buttons change the net votes as follows:
```
Net Votes Before    Button Pressed    Net Votes After
1                   ^                 0
1                   v                 -1
0                   ^                 1
0                   v                 -1
-1                  ^                 1
-1                  v                 0
```
The shortest code in bytes wins.
**Test cases:**
```
[empty string] -> 0
^^ -> 0
^v -> -1
^ -> 1
v -> -1
v^ -> 1
vv -> 0
^^^ -> 1
vvv -> -1
^^^^ -> 0
vvvv -> 0
^^^^^ -> 1
vvvvv -> -1
^^^^^^ -> 0
vvvvvv -> 0
^^v -> -1
^v^ -> 1
^vv -> 0
vv^ -> 1
v^v -> -1
v^^ -> 0
^vvv^^vv^vv^v^ -> 1
^vvv^^vv^vv^v^^ -> 0
^vvv^^vv^vv^v^^^ -> 1
^vvv^^vv^vv^v^^v -> -1
^vvv^^vv^vv^v^^vv -> 0
^vvv^^vv^vv^v^^vvv -> -1
^vvvvvvvvvvvv -> 0
^^vvvvvvvvvvvv -> 0
^^^vvvvvvvvvvvv -> 0
vvv^^^^^^^^^^^^ -> 0
vv^^^^^^^^^^^^ -> 0
v^^^^^^^^^^^^ -> 0
```
  
[Answer]
## [Gol><> 0.3.11](https://github.com/Sp3000/Golfish/wiki), ~~13~~ ~~12~~ 11 bytes
```
iEh`^=:@)+M
```
[Try it online](https://golfish.herokuapp.com/?code=iEh%60%5E%3D%3A%40%29%2BM&input=%5Evvv%5E%5Evv%5Evv%5Ev%5E%5Evvv&debug=false). Even though this will work fine in the next update, I've listed it as 0.3.11 just in case.
### Explanation
```
i               Read char
 Eh             If EOF, halt and output top of stack as num
   `^=          Push 1 if char is ^, else 0
      :@        Dup and rotate, giving [is^ is^ votecount]
        )       Compare greater than, pushing 1 or 0 as appropriate
         +M     Add and subtract 1
```
Note that the first use of `@` pulls a 0 from the bottom of the stack to initialise the vote count for the first iteration
To illustrate with a full table:
```
Votes before    Button    Is ^?    Compare <    Add     Subtract 1
     1            ^         1         0          1          0
     1            v         0         0          0         -1
     0            ^         1         1          2          1
     0            v         0         0          0         -1
    -1            ^         1         1          2          1
    -1            v         0         1          1          0
```
[Answer]
# JavaScript (ES7), ~~47~~ ~~46~~ ~~44~~ ~~43~~ ~~37~~ 36 bytes
[Crossed out 44 is still regular 44 :(](https://codegolf.stackexchange.com/a/62833/45393)
```
s=>[for(x of s)s=x<"v"?s!=1:!~s-1]|s
```
Keeps a running total in `s`. Uses `for of` loop to iterate over each character in the string and updates `s` based on current character and previous value.
Edits: Golfed `~s&&-1` to `!~s-1`. This expression has to equal 0 if `s` equals -1 and -1 otherwise. Saved 6 bytes thanks to @nderscore.
How the expression works:
```
 ~s    // Bitwise inverse. ~s==0 only if s==-1
!      // Logical negate. Casts to boolean. Equivalent to s==-1
   -1  // Subtract. Casts to number so true-1 is 1-1 and false-1 is 0-1
```
[Answer]
# x86 machine code, 24 bytes
```
31 C0 8A 11 84 D2 75 07 C0 E0 02 C0 F8 06 C3 41 38 C2 74 EC 88 D0 EB EA
```
This is a function using the fastcall calling convention, which takes a string and returns an 8-bit integer.
I tested it with the following C program, which must be compiled for 32-bit mode.
```
#include <stdio.h>
#include <inttypes.h>
 __attribute__ ((aligned (16))) const unsigned char fun[] = {
    0x31,  //xor eax,eax
        0xC0,
    0x8A, //mov [ecx],dl
        1 | 2<<3,
    0x84, //test dl, dl
        0xC0 | 2<<3 | 2,
    0x75, // jnz
        7,
    0xC0, //shl al 2
        0xC0 | 4<<3,
        2,
    0xC0, //sar al 6
        0xC0 | 7<<3,
        6,
    0xC3, //ret
    0x41, //inc ecx
    0x38, //cmp al,dl
        0xC0 | 2,
    0x74, //je
        -20,
    0x88, //mov dl,al
        0xC0 | 2<<3,
    0xEB, //jmp
        -22,
};
int main()
{
    __fastcall int8_t (*votesimulator)(char*) = fun;
    char* s[] = {
        "",
        "^^",
        "^v",
        "^",
        "v",
        "v^",
        "vv",
        "^^^",
        "vvv",
        "^^^^",
        "vvvv",
        "^^^^^",
        "vvvvv",
        "^^^^^^",
        "vvvvvv",
        "^^v",
        "^v^",
        "^vv",
        "vv^",
        "v^v",
        "v^^",
        "^vvv^^vv^vv^v^",
        "^vvv^^vv^vv^v^^",
        "^vvv^^vv^vv^v^^^",
        "^vvv^^vv^vv^v^^v",
        "^vvv^^vv^vv^v^^vv",
        "^vvv^^vv^vv^v^^vvv",
        "^vvvvvvvvvvvv",
        "^^vvvvvvvvvvvv",
        "^^^vvvvvvvvvvvv",
        "vvv^^^^^^^^^^^^",
        "vv^^^^^^^^^^^^",
        "v^^^^^^^^^^^^",
    };
    for(int i = 0; i < sizeof(s)/sizeof(*s); i++)
        printf("%d\n", votesimulator(s[i]));
    printf("\n%d\n", sizeof(fun));
    for(int i = 0; i < sizeof(fun); i++)
        printf("%02X ", fun[i]);
    return 0;
}
```
[Answer]
# CJam, ~~18~~ 14 bytes
Updated version with significant improvements contributed by Dennis:
```
0'jqf{-g_@=!*}
```
[Try it online](http://cjam.aditsu.net/#code=0'jqf%7B-g_%40%3D!*%7D&input=%5Evvv%5E%5Evv%5Evv%5Ev%5E%5Ev)
Explanation:
```
0     Start value for running total.
'j    Push character between '^ and 'v for use in loop.
q     Get input.
f{    Apply block with argument to all input characters.
  -     Subtract character from 'j. This will give -12 for '^, 12 for 'v.
  g     Signum, to get 1 for '^, -1 for 'v, which is our increment value.
  _     Copy increment value.
  @     Bring running total to top.
  =     Compare. This will give 1 for the -1/-1 and 1/1 combinations where the new
        running total is 0. Otherwise, the new running total is the increment value.
  !     Negate to get 0 for the -1/-1 and 1/1 cases.
  *     Multiply result with increment value, to get new running total.
}     End block applied to input characters.
```
[Answer]
## Befunge 93 - 55 bytes
```
vj#p01:>#<:1+|
>~:10g-|v:g25<
^p01"j"<1^   <
./*34-g0<@
```
52 characters and 3 new lines.
Tested on [this interpreter](http://www.quirkster.com/iano/js/befunge.html).
The `j` is equidistant from `^` and `v` in ascii so it's used to make arithmetic conversions in the end, rather than space consuming conditionals.
[Answer]
# brainfuck, 146 bytes
```
,[[>->+<<-]>[[-]>[<+>-]]>[-]<<[<],]----[>-----<--]--[>>+<<++++++]+>[<-]<[->>++.<++++[<------>-]]>[<+<<]----[>+++++<--]>[,+<]>>[<<]-[>+<-----]>---.
```
This program takes each byte of input and compares it against the last. If they're the same, it throws the input away and stores "0" as the "previous input", otherwise it saves it normally.
If the final result is `v`, it prints `-`. If the final result was non-zero, 1 is added to an empty cell. Finally, 48 is added to that cell and it is printed.
[Answer]
# Javascript ES6, ~~91~~ 48 chars
```
s=>~~{'^':1,v:-1}[s.replace(/(.)\1/g).slice(-1)]
```
Explanation: `undefined` ends by `d`.
Test:
```
` -> 0
^^ -> 0
^v -> -1
^ -> 1
v -> -1
v^ -> 1
vv -> 0
^^^ -> 1
vvv -> -1
^^^^ -> 0
vvvv -> 0
^^^^^ -> 1
vvvvv -> -1
^^^^^^ -> 0
vvvvvv -> 0
^^v -> -1
^v^ -> 1
^vv -> 0
vv^ -> 1
v^v -> -1
v^^ -> 0
^vvv^^vv^vv^v^ -> 1
^vvv^^vv^vv^v^^ -> 0
^vvv^^vv^vv^v^^^ -> 1
^vvv^^vv^vv^v^^v -> -1
^vvv^^vv^vv^v^^vv -> 0
^vvv^^vv^vv^v^^vvv -> -1
^vvvvvvvvvvvv -> 0
^^vvvvvvvvvvvv -> 0
^^^vvvvvvvvvvvv -> 0
vvv^^^^^^^^^^^^ -> 0
vv^^^^^^^^^^^^ -> 0
v^^^^^^^^^^^^ -> 0`
.split("\n").map(s => s.split(" -> "))
.every(([s,key]) => (s=>~~{'^':1,v:-1}[s.replace(/(.)\1/g).slice(-1)])(s)==key)
```
Answer history:
```
s=>({'':0,'^':1,v:-1}[s.replace(/^(.)\1(\1\1)*(?=.?$)|.*(.)(((?!\3).)\5)+/,"").substr(-1)])
s=>~~{'^':1,v:-1}[s.replace(/^(.)\1(\1\1)*(?=.?$)|.*(.)(((?!\3).)\5)+/,"").substr(-1)]
s=>~~{'^':1,v:-1}[s.replace(/^.*(.)(((?!\1).)\3)+|(.)\4(\4\4)*/,"").substr(-1)]
s=>~~{'^':1,v:-1}[s.replace(/^.*(.)(((?!\1).)\3)+|(.)\4(\4\4)*/,"").slice(-1)]
s=>~~{'^':1,v:-1}[s.replace(/.*(.)(((?!\1).)\3)+|(.)\4(\4\4)*/,"").slice(-1)]
s=>~~{'^':1,v:-1}[s.replace(/.*(.)(((?!\1).)\3)+|((.)\5)*/,"").slice(-1)]
s=>~~{'^':1,v:-1}[s.replace(/((.)\2)+/g,"!").slice(-1)]
s=>~~{'^':1,v:-1}[s.replace(/(.)\1/g,"!").slice(-1)]
s=>~~{'^':1,v:-1}[s.replace(/(.)\1/g,0).slice(-1)]
s=>~~{'^':1,v:-1}[s.replace(/(.)\1/g).slice(-1)]
```
[Answer]
## Python 2, 49
```
lambda s:reduce(lambda x,c:cmp(cmp('u',c),x),s,0)
```
Iterates through with the update function
```
lambda x,c:cmp(cmp('u',c),x)
```
that takes the current vote count `x` and the new character `c` and outputs the new vote count.
The idea is to use Python 2's `cmp` function, which compares its two args and gives `-1, 0, 1` for `<, ==, >` respectively. The inner one `cmp('u',c)` gives `-1` for `v` and `1` for `^`; any character between them suffices for `'u'`. The outer one then compares that to `x`, which gives `cmp(1,x)` for `^` and `cmp(-1,x)` for `v`, which have the right values.
Direct iteration was 3 chars longer (52), though would be one char short (48) if taking an `input()` with quotes was allowed.
```
x=0
for c in raw_input():x=cmp(cmp('u',c),x)
print x
```
The best recursive function I found was one char longer (50)
```
f=lambda s:len(s)and cmp(cmp('u',s[-1]),f(s[:-1]))
```
[Answer]
# Prolog, ~~159~~ 152 bytes
**Code:**
```
v(1,^,0).
v(1,v,-1).
v(0,^,1).
v(0,v,-1).
v(-1,^,1).
v(-1,v,0).
r(X,[H|T]):-T=[],v(X,H,Z),write(Z);v(X,H,Z),r(Z,T).
p(S):-atom_chars(S,L),r(0,L).
```
**Test it yourself:**  
Online Interpreter [here](http://swish.swi-prolog.org/)  
  
**Example**
```
>p("^vvv^^vv^vv^v^^vvv").
-1
>p("^vvv^^vv^vv^v^")
1
```
**Edit:** Saved 7 bytes by unifying r-clauses with OR.
[Answer]
# CJam, 16 bytes
```
0re`W=(2%*c'a--g
```
This will [crash after printing **0**](http://meta.codegolf.stackexchange.com/q/4780), if applicable. The error can be suppressed with the Java interpreter. If you [try this online](http://cjam.aditsu.net/#code=0re%60W%3D(2%25*c'a--g&input=%5Evvv%5E%5Evv%5Evv%5Ev%5E), ignore everything but the last line of output.
### How it works
```
0                e# Push a 0 on the stack.
 r               e# Read a whitespace-separated token from STDIN.
  e`             e# Perform run-length encoding.
    W=           e# Select the last [repetitions character] pair.
                 e# This will fail for the empty string, so the
                 e# interpreter will print the stack's only element (0).
      (          e# Shift out the number of repetitions.
       2%        e# Compute its parity.
         *       e# Create a string, repeating the character 1 or 0 times.
          c      e# Cast to character.
                 e# This will fail for a zero-length string, so the
                 e# interpreter will print the stack's only element (0).
           'a-   e# Subtract the character 'a' from '^' or 'v'.
              -  e# Subtract the difference (integer) from 0.
               g e# Apply the sign function.
```
[Answer]
# Python 2, 177 159 72 bytes
Still kinda new to this code golf thing.
```
def v(s): 
 c=0 
 for i in s:c=((0,1)[c<1],(0,-1)[c>-1])[i=="^"] 
 return c
```
**EDIT:** Fixed the incorrect behavior.  
**EDIT 2:** Thanks @MorganThrapp for shaving off lots of bytes.
[Answer]
# JavaScript (ES6), ~~64~~ ~~59~~ ~~58~~ 52 bytes
```
f=v=>(t=/\^*$|v*$/.exec(v)[0]).length*(t<'v'?1:-1)%2
```
This is based on the observation that only the last stretch of the repetition (of either `^` or `v`) affects the result.
*Thanks to [Neil](https://codegolf.stackexchange.com/users/17602/neil) for golfing off 6 bytes.*
[Answer]
# Haskell, 40 bytes
```
1%'^'=0
_%'^'=1
1%_=-1
_%_=0
v=foldl(%)0
```
[Answer]
# Scala, 75 bytes
```
def d(s:String)=s./:(0){case(1,94)|(-1,'v')=>0;case(_,94)=> 1;case _=> -1}
```
Test for implemented function.
```
  object Util {
        def d(s: String) = s./:(0) { 
    case (1, '^') | (-1, 'v') => 0
    case (_, '^') => 1
    case (_, _) => -1
  }      
      def main(s: Array[String]): Unit = {
        println("1 == " + d("^vvv^^vv^vv^v^^^"))
        println("1 == " + d("^vvv^^vv^vv^v^"))
        println("-1 == " + d("^vvv^^vv^vv^v^^vvv"))
        println("0 == " + d("^^^vvvvvvvvvvvv"))
        println("0 == " + d("vvv^^^^^^^^^^^^"))
      }
    }
```
[Answer]
# APL, 17
```
(⊣×≠)/⌽0,2-'^ '⍳⍞
```
For interpreters without fork notation (like GNU APL), it would be `{⍺×⍺≠⍵}/⌽0,2-'^ '⍳⍞` (19).
This is probably the most boring of possible solutions because it works directly from the definition of the problem.
[Answer]
# Ruby, ~~41~~ 35 bytes
Regex. Only the last button pressed is interesting, so check the run-length of that. Then compare it to `"a"` (or any letter between `^` and `v`) to get `1` or `-1`.
```
->s{s[/(.?)\1*$/].size%2*(?a<=>$1)}
```
[Answer]
# C# 6, 18 + 80 = 98 bytes
Requires:
```
using System.Linq;
```
Actual function:
```
int S(string v)=>v.Split(new[]{"^^","vv"},0).Last().Length<1?0:v.Last()<95?1:-1;
```
How it works: the code first removes everything before the last `^^` or `vv`. That content is not relevant because clicking the same button twice will always cancel your vote. It does this by splitting on `^^` and `vv` and taking the last item. If this item is an empty string (`.Length<1`), then the function returns `0` because all voting has been cancelled. If the string it not empty, then it just looks at the last char of the original string: it will override all previous votes. If the char code is smaller than 95, then it will be 94, `^`, so it returns `1`, otherwise `-1`.
[Answer]
# Python 2.7, ~~79~~ ~~75~~ 88
```
s=input()
print (0,(1,-1)[s[-1]=='v'])[len(s[s.rfind(('v^','^v')[s[-1]=='v'])+1:])%2!=0]
```
[Answer]
# Go, 179 bytes
An ***extremely*** naive solution.
```
package main
import(."fmt"."strings")
func main(){a:=""
i:=0
Scanln(&a)
b:=Split(a,"")
for _,e:=range b{switch i{case 1:i--
case 0:if e=="^"{i++}else{i--}
case-1:i++}}
Println(i)}
```
Ungolfed:
```
package main
import (
    ."fmt"
    ."strings"
)
func main() {
    a := ""
    i := 0
    Scanln(&a)
    b := Split(a, "")
    for _, e := range b {
        switch i {
        case 1:
            i--
        case 0:
            if e == "^" {
                i++
            } else {
                i--
            }
        case -1:
            i++
        }
    }
    Println(i)
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
γ¤®öÓÆ.±
```
[Try it online!](https://tio.run/##yy9OTMpM/W9s5Ob5/9zmQ0sOrTu87fDkw216hzb@1/nPFRfHFVfGFcdVxlUGJICsOBAFpsEMCAvChLKhHBAPiMtABgB1g7THgUwB84EUEIMQOheDjyFQhiGARQQiBAdccehcVD5YOwJwoXOReQA "05AB1E – Try It Online")
Alternative solutions with the same length: `uγ¤®öÓÆ(`, `γ¤®ögÓÆ(`.
[Answer]
## [Minkolang 0.11](https://github.com/elendiastarman/Minkolang), ~~28~~ 22 bytes
```
0$I2&N."j"o-34*:dr=,*!
```
[Try it here.](http://play.starmaninnovations.com/minkolang/?code=0%24I2%26N%2E%22j%22o-34*%3Adr%3D%2C*!&input=%5Evvv%5E%5Evv%5Evv%5Ev%5Evvv)
### Explanation
```
0                         Push a 0 (running total)
 $I                       Push length of input
   2&N.                   Output as integer and stop if this is 0
       "j"                Push 106
          o               Take character from input (94 for ^, 118 for v)
                          <<so ^ becomes +12 and v becomes -12>>
           -              Subtract
            34*:          Divide by 12
                d         Duplicate top of stack
                 r        Reverse stack
                  =,      Push 0 if equal, 1 otherwise
                    *     Multiply
                          <<this handles two of the same vote in a row>>
                     !    Unconditional trampoline (jumps the 0 at the beginning)
```
Note that there is no `N.` at the end. That's because I let it wrap around to the beginning. When the input is empty, the final tally is output as integer and the program stops.
[Answer]
# Pyth, 13 bytes
```
ut+Jq\^H>JGzZ
```
[Answer]
# Mathematica, 60 bytes
```
Mod[#,2]Sign@#&@Tr@Last@Split@StringCases[#,{"^"->1,_->-1}]&
```
[Answer]
# [Shape Script](https://github.com/DennisMitchell/ShapeScript/), 26 bytes
```
"^"$"0>1@-"~"v"$"0<1-"~0@!
```
How it woks:
```
"^"$     split input on '^'
"
  0>         Check if the number is more than 0 (1 if true, 0 if false).
  1@-        subtract the answer from one.
"~       Join it back together, with this string in place of '^'
"v"$     Split on 'v'
"        
  0<         Check if 0 is more than the number (1 if true, 0 if false).
  1-         subtract one from the results
"~       Join it back together, with this string in place of 'v'
0@       add a zero to the stack and place it under the string just built. 
!        run the string as code
```
[Answer]
# C# 6, 18 + 97 95 = 115 113 bytes, no string methods, excessive LINQ
```
int v(string s)=>(int)s.Reverse().TakeWhile((c,i)=>i<1||c==s[s.Length-i])?.Sum(x=>x<95?1:-1)%2;
```
Truly deserves to be preceded by
```
using System.Linq;
```
Got the idea of using `x<95?1:-1` instead of `x=='^'?1:-1` from [ProgramFOX's answer](https://codegolf.stackexchange.com/questions/63369/stack-exchange-vote-simulator/63464#63464)
Coincidences:
* The tweak I stole makes use of comparing to 95 – the byte count excluding the using statement, using said tweak
* The sum of the digits of the total byte count equals the number of digits of the total byte count written as roman numeral
[Answer]
# C: ~~67~~ 66 Bytes
golfed:
```
void f(char *v){int i=0,c,s=0;for(;v[i]!=0;i++){v[i]>94?s--:s++;}}
```
ungolfed:
```
void f (char *v)
{
    int i = 0, c, s = 0;
    for (;v[i]!=0;i++)
    {
        v[i] > 94 ? s-- : s++;
    }
}
```
[Answer]
# Perl 5, 41 bytes
40 bytes, plus 1 for `-p`
```
/(.)\1*$/;$_=((length$&)%2)*($1=~v?-1:1)
```
`/(.)\1*$/;` compares the input string to the regex `/(.)\1*$/`, i.e. sees whether it ends with a single character repeated some number ≥1 of times.
If so, `$&` is the whole repetition string and `$1` is the character; otherwise (i.e. the input string is empty), those two variables are the empty string.
`$1=~v?-1:1` compares `$1` to the regex `v` and returns −1 if it matches and 1 otherwise.
And multiply that ±1 by `(length$&)%2`, the length of `$&` modulo 2.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~14~~ ~~12~~ 11 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Îvy'^QDŠ‹+<
```
Port of [*@Sp3000*'s Gol><> answer](https://codegolf.stackexchange.com/a/63383/52210).
NOTE: [*@Grimy* already posted a shorter 8 bytes alternative for 05AB1E](https://codegolf.stackexchange.com/a/185280/52210), so make sure to upvote him!
[Try it online](https://tio.run/##MzBNTDJM/f//cF9ZpXpcoMvRBY8admrb/P8fV1ZWFgckwAjEKAMA) or [verify all test cases](https://tio.run/##MzBNTDJM/V9Waa@k8KhtkoKS/X@DyrJK9bhAl6MLHjXs1Lb5X6vzP1opLk5JR0EprgxMgggwqwzChIjGQTkwHowL58MFECIIIagYhCqD2gaxBGpLHNRKmByQBcQghEUEmxA2sTJsYtgF4aJwAHUyhgiGENgoBID6Cl0ERSAWAA).
**Explanation:**
```
Î            # Push 0 (later mentioned as `r`) and the input-string
 v           # Loop over the characters of the input:
  y'^Q      '#  Does the current character equal "^"?
             #  (results in 1 for truthy; 0 for falsey - later mentioned as `b`)
      D      #  Duplicate this result `b`
       Š     #  Triple swap (`r`,`b`,`b`) to (`b`,`r`,`b`)
        ‹    #  Check if the boolean `b` is smaller than the result-integer `r`
             #  (again results in 1 for truthy; 0 for falsey)
         +   #  Add them together
          <  #  Decrease this by 1
             # (Implicitly output the result-integer `r` after the loop)
```
[Answer]
# CJam, ~~27~~ 24 bytes
```
'^_]r+e`W=(2%\(i99-g@*W*
```
[Try it Online](http://cjam.aditsu.net/#code='%5E_%5Dr%2Be%60W%3D(2%25%5C(i99-g%40*W*&input=%5Evvv%5E%5Evv%5Evv%5Ev%5E%5Evvv).
All I took from Dennis' answer is `g` (sign function) .
[Answer]
# Ruby, 43
```
->s{a=0
s.bytes{|i|b=9-i/11;a=a!=b ?b:0}
a}
```
`9-i/11` evaluates to 1 or -1 when given the ascii codes of `^` (94) or `v` (118)
In test program:
```
f=->s{a=0
s.bytes{|i|b=9-i/11;a=a!=b ?b:0}
a}
g=gets.chomp
puts f[g]
```
]