[Question]
  [
You're a professional hacker and your boss has just ordered you to help a candidate win an upcoming election. Your task is to alter the voting machines data to boost the candidate's results.
Voting machines store voting results as two integers : the number of votes for your candidate (`v1`) and the number of votes for their opponent (`v2`).
After weeks of research, you have found a security hole in the system and you can increase the value of `v1` by an integer `x`, and decrease the value of `v2` by the same `x`.
But there is a constraint, you have to keep the security hash code constant:
* security hash code : `(v1 + v2*2) modulo 7`
Also, the value for `x` must be minimal so your changes can go unnoticed.
Your program should accept as input `v1` and `v2` ; it should output the optimal value for `x` so `v1>v2`.
There are some cases for which you cannot hack the results; you don't have to handle them (this might lead to problems with your boss, but that's another story).
**Test cases**
```
100,123 --> 14
47,23 --> 0
40,80 --> 21
62,62 --> 7
1134,2145 --> 511
```
  
[Answer]
# Python 2, 30 bytes
```
lambda u,t:max(0,(t-u)/14*7+7)
```
`u` is our votes, `t` is their votes.
[Answer]
## Python 2, 30 bytes
```
lambda a,b:max((b-a)/14*7+7,0)
```
[Answer]
## Mathematica, 22 bytes
```
0//.x_/;2x<=#2-#:>x+7&
```
Pure function with arguments `#` and `#2`. Hits maximum recursion depth if the discrepancy is more than `7*2^16 = 458752`.
## Explanation
```
0                       Starting with 0,
 //.                    repeatedly apply the following rule until there is no change:
    x_                    if you see an expression x
      /;                    such that
        2x<=#2-#            2x <= #2-# (equivalently, #+x <= #2-x)
                :>        then replace it with
                  x+7       x+7 (hash is preserved only by multiples of 7)
                     &  End the function definition
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
IH:7‘×7»0
```
[Try it online!](https://tio.run/nexus/jelly#@@/pYWX@qGHG4enmh3Yb/P//P9rQwEBHwdDIOFZHIdrEXEcBygIKWhiAWGZGOgpmRiCWoaGxCVDe0MQ0FgA "Jelly – TIO Nexus")
### How it works
```
IH:7‘×7»0  Main link. Argument: [v1, v2]
I          Increments; compute [v2 - v1].
 H         Halve the result.
  :7       Perform integer division by 7.
    ‘      Increment the quotient.
     ×7    Multiply the result by 7.
       »0  Take the maximum of the product and 0.
```
[Answer]
# [Actually](https://github.com/Mego/Seriously), 13 bytes
```
7;;τ((-\*+0kM
```
[Try it online!](https://tio.run/nexus/actually#@29ubX2@RUNDN0ZL2yDb9/9/QwMDLkMjYwA "Actually – TIO Nexus")
Uses the same `max((b-a)/14*7+7,0)` formula that xnor and orlp use.
Explanation:
```
7;;τ((-\*+0kM
7;;            3 copies of 7
   τ           double one of them
    ((-        bring the inputs back to the top, take their difference
       \*+     integer divide by 14, multiply by 7, add 7
          0kM  maximum of that and 0
```
[Answer]
## Groovy, 41 ~~37~~ bytes
```
{x,y->[Math.floor((y-x)/14)*7+7,0].max()}
```
This is an unnamed closure. Thanks to `xnor` and `orlp` for the formula and `James holderness` for pointing out a bug.
The previous solution used `intdiv()` for integer division but it behaves differently from `//` used in python.
[Try it here!](http://ideone.com/cDX7Nh)
[Answer]
# Haskell, ~~30~~ 24 bytes
```
a#b=max 0$div(b-a)14*7+7
```
An infix operator taking the number of votes of your preferred candidate first. Uses the same logic as the other answers of rounding with `/14*7+7`.
[Answer]
# J, 15 bytes
```
0>.7+7*14<.@%~-
```
Kinda interesting, I was working on a problem and I thought I had a solution but as it turns out I was wrong. Oh well. [Try it online!](https://tio.run/nexus/j#@5@mYGulYGCnZ65trmVoYqPnoFqny1WSWlxSDJIwNDJWMDQwULBWADJMzIG0hYGCCYhvZgRCQHFDE1MFQ0NjE67U5Ix8BQ0dPYU0fYXUxOQMTQWwMf//AwA "J – TIO Nexus") Here's the result:
```
   f =: 0>.7+7*14<.@%~-
   tests =: 123 100 ; 23 47 ; 80 40 ; 62 62 ; 2145 1134
   (,. f/ each) tests
┌─────────┬───┐
│123 100  │14 │
├─────────┼───┤
│23 47    │0  │
├─────────┼───┤
│80 40    │21 │
├─────────┼───┤
│62 62    │7  │
├─────────┼───┤
│2145 1134│511│
└─────────┴───┘
```
[Answer]
# CJam, ~~13~~ ~~12~~ 15 bytes
* Saved a byte thanks to Martin Ender.
* Added 3 bytes thanks to Martin Ender.
* Changed `]` to `[` thanks to ETHproductions.
```
q~\-Ed/m[)7*0e>
```
Blatantly stole orlp and xnor's methods.
Input is the two numbers separated by a space: `100 123`
Explanation:
```
q~\-Ed/m])7*0e>
q~\-            e# Input two numbers, swap and subtract them.
    E           e# Push 0xE (15)
     d/m]       e# Float divide and take the floor.
         )7*    e# Increment and multiply by 7.
            0e> e# Max of this and 0.
```
[Answer]
# Excel VBA, ~~24~~ 17 Bytes
Immediates window function that takes input from cells `A1` and `B1` and outputs to the VBE immediates window.
```
?([A1-B1]\14)*7+7
```
**Subroutine Version, 43 Bytes**
takes input `b, c` as variant\integer and prints to the VBE immediates window
```
Sub a(b,c):Debug.?Int((c-b)/14)*7+7:End Sub
```
[Answer]
# [Julia 0.5](http://julialang.org/), 26 bytes
```
v\w=max(fld(w-v,14)*7+7,0)
```
[Try it online!](https://tio.run/nexus/julia5#Lc5BCsIwEIXhtT3FUCgkOoGZJDZuFO/RdiHUQKFGqZp4@5iKu@/Bv3g59ul4u3yEn0eRVES2cut2Dklmf19AREwSpgCiYyJkbQaEzjr8g/BAK1qNrV7BbCxqtvvfIKRBVpvzY5nCy4u6UcxPUCdozLsPdUkiQippuSGraxjzFw "Julia 0.5 – TIO Nexus")
[Answer]
# PHP, ~~41~~ 39 bytes
```
    <?=7*max(0,1+($argv[2]-$argv[1])/14|0);
```
takes input from command line arguments; run with `-r`.
~~7~~ 5 extra bytes just to handle $a>$b :-/
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 14 bytes
```
V-U /2+7 f7 w0
```
[Run it here!](http://ethproductions.github.io/japt/?v=1.4.3&code=Vi1VIC8yKzcgZjcgdzA=&input=MTEzNCwyMTQ1)
Thank you ETHproductions for shaving off 3 bytes!
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
-14÷>7*0M
```
[Try it online!](https://tio.run/nexus/05ab1e#@69raHJ4u525loHv//@GhsYmXEaGJqYA)
**Explanation**
```
-          # push difference of inputs
 14÷       # integer divide by 14
    >      # increment
     7*    # times 7
       0   # push 0
        M  # take max
```
Or a corresponding function with same byte-count operating on a number-pair
```
Î¥14÷>7*M
```
[Try it online!](https://tio.run/nexus/05ab1e#@3@479BSQ5PD2@3MtXz//482NDQ20TEyNDGNBQA)
[Answer]
# [Dyalog APL](http://dyalog.com/download-zone.htm), 14 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
Takes `v1` as right argument and `v2` as left argument.
```
0⌈7×1+(⌊14÷⍨-)
```
`0 ⌈` the maximum of zero and
`7 ×` seven times
`1 + (`...`)` one plus...
 `⌊` the floor of
 `14 ÷⍨` a fourteenth of
 `-` the difference (between the arguments)
[TryAPL online!](http://tryapl.org/?a=f%u21900%u23087%D71+%28%u230A14%F7%u2368-%29%20%u22C4%20123%20f%20100%20%u22C4%2023%20f%2047%20%u22C4%2080%20f%2040%20%u22C4%2062%20f%2062%20%u22C4%202145%20f%201134&run)
[Answer]
# Befunge, 19 bytes
```
777+:&&\-+\/*:0`*.@
```
[Try it online!](http://befunge.tryitonline.net/#code=Nzc3KzomJlwtK1wvKjowYCouQA&input=MTEzNCAyMTQ1)
This relies on a slightly different formula to that used by orlp and xnor, since the Befunge reference interpreter has different rounding rules to Python. Befunge also doesn't have the luxury of a `max` operation.
The basic calculation looks like this:
```
x = (v2 - v1 + 14)/14*7
x = x * (x > 0)
```
Examining the code in more detail:
```
7                     Push 7                                      [7]
 77+:                 Push 14 twice.                              [7,14,14]
     &&               Read v1 and v2 from stdin.                  [7,14,14,v1,v2]
       \-             Swap the values and subtract.               [7,14,14,v2-v1]
         +            Add the 14 that was pushed earlier.         [7,14,14+v2-v1]
          \/          Swap the second 14 to the top and divide.   [7,(14+v2-v1)/14]
            *         Multiply by the 7 that was pushed earlier.  [7*(14+v2-v1)/14 => x]
             :        Make a copy of the result                   [x,x]
              0`      Test if it's greater than 0.                [x,x>0]
                *     Multiply this with the original result.     [x*(x>0)]
                 .@   Output and exit.
```
[Answer]
# [Go](http://golang.org), 36 bytes
`func(a,b int)int{return(b-a)/14*7+7}`
[Try it online!](https://play.golang.org/p/0eZ1UaF0_K)
[Answer]
# JavaScript (ES6), 31 bytes
```
(a,b,c=(b-a)/14|0)=>c>0?c*7+7:0
```
```
f=(a,b,c=(b-a)/14|0)=>c>0?c*7+7:0
document.write(f(1134,2145))
```
[Answer]
# Java 8, 31 bytes
`(a,b)->b<a?0:(a=(b-a)/2)+7-a%7;`
This is a lambda expression assignable to `IntBinaryOperator`.
a is your candidate's votes, b is your opponent's.
java rounds down for division with positive integers, so `+7-a%7` is used to bump up the value to the next multiple of 7.
[Answer]
## Ruby, ~~26~~ 27 bytes
```
->a,b{[(b-a)/14*7+7,0].max}
```
Basically the same as xnor's and orlp's Python solution, ~~with a twist (no need to add 7, because of negative modulo, saves 1 byte in ruby, don't know about python)~~
No twist, the twist was just a bad case of cognitive dissonance. Forget it. Really. :-)
[Answer]
# Scala, 31 bytes
```
(a,b)=>Math.max((b-a)/14*7+7,0)
```
The ternary version is 2 bytes longer
[Answer]
# [Noodel](https://tkellehe.github.io/noodel), 16 [bytes](https://tkellehe.github.io/noodel/docs/code_page.html)
```
⁻÷14ɲL×7⁺7ḋɲl⁺÷2
```
Pulled equation from [xor](https://codegolf.stackexchange.com/a/106436/52270) and [orlp](https://codegolf.stackexchange.com/a/106435/52270) answers, but since *Noodel* does not have a max capability had to work around that.
[Try it:)](https://tkellehe.github.io/noodel/editor.html?code=%E2%81%BB%C3%B714%C9%B2L%C3%977%E2%81%BA7%E1%B8%8B%C9%B2l%E2%81%BA%C3%B72&input=40%2C80&run=false)
### How it works
```
⁻÷14ɲL×7⁺7       # The equation...
⁻                # v2 - v1
 ÷14             # Pops off the difference, then pushes on the (v2 - v1)/14
    ɲL           # Applies lowercase which for numbers is the floor function.
      ×7         # Multiplies that by seven.
        ⁺7       # Then increments it by seven.
          ḋɲl⁺÷2 # To relate with the other answers, this takes the max between the value and zero.
          ḋ      # Duplicates what is on the top of the stack (which is the value just calculated).
           ɲl    # Pops off the number and pushes on the magnitude (abs value).
             ⁺   # Add the abs to itself producing zero if the number came out negative (which means we are already winning).
              ÷2 # Divides the result by two, which will either be zero or the correct offset.
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 16 bytes
```
MtS+0[+7*7/-HG14
```
[Try it here!](http://pyth.herokuapp.com/?code=MtS%2B0%5B%2B7%2A7%2F-HG14%3BghQeQ&input=100%2C123%0A47%2C23%0A40%2C80%0A62%2C62%0A1134%2C2145&test_suite=1&test_suite_input=100%2C123%0A47%2C23%0A40%2C80%0A62%2C62%0A1134%2C2145&debug=0)
]