[Question]
      [
You have two values each of which is either `0` representing "unknown", or one of `1,2,3`. Merge them into a single value as follows:
* If both values are nonzero and equal, output that value:
`(3,3) -> 3`
* If both values are nonzero but unequal, output 0 for unknown:
`(1,2) -> 0`
* If one value is zero and the other is not, output the nonzero value:
`(2,0) -> 2, (0,1) -> 1`
* If both values are zero, output zero:
`(0,0) -> 0`
**Test cases:**
There are 16 possible input pairs.
```
  | 0 1 2 3
--+--------
0 | 0 1 2 3
1 | 1 1 0 0
2 | 2 0 2 0
3 | 3 0 0 3
(0, 0) -> 0
(0, 1) -> 1
(0, 2) -> 2
(0, 3) -> 3
(1, 0) -> 1
(1, 1) -> 1
(1, 2) -> 0
(1, 3) -> 0
(2, 0) -> 2
(2, 1) -> 0
(2, 2) -> 2
(2, 3) -> 0
(3, 0) -> 3
(3, 1) -> 0
(3, 2) -> 0
(3, 3) -> 3
```
## Leaderboards
```
var QUESTION_ID=165314,OVERRIDE_USER=8478;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), ~~46~~ ~~43~~ 42 bytes
```
import StdEnv
?[a,b]|a<1||a==b=b=0
```
#
```
?o sort
```
[Try it online!](https://tio.run/##S85JTcz7n5ufUpqTqpCbmJn3PzO3IL@oRCG4JMU1r4zLPjpRJym2JtHGsKYm0dY2CQgN/geXJBaVcCkrpJXmJZdk5ucp2CrY5ysUA7Vx2SIEo410DGL//0tOy0lML/6v6@nz36UyLzE3M7kYAA)
Anonymous composition `:: [Int] -> Int`, sorts the pair and then matches off the first member.
Doing it as a composed lambda is the same length:
```
import StdEnv
```
#
```
(\[a,b]|a<1||a==b=b=0)o sort
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~7~~ 6 bytes
```
×¬o=a»
```
[Try it online!](https://tio.run/##y0rNyan8///w9ENr8m0TD@3@//@/wX8jAA) or [Try all combinations!](https://tio.run/##ARsA5P9qZWxsef//w5fCrG89YcK7/zPFu8Onw75gR/8 "Jelly – Try It Online")
**How?**
```
×¬o=a»   Dyadic link
×        Multiply the two arguments.
 ¬       Logical not. Gives 1 if one argument is 0, 1 otherwise.
   =     Are the two arguments equal?
  o      Logical or the result of = and ¬.
     »   Greater of the two arguments.
    a    Logical and. Gives the greater of the two arguments if they are equal
         or if one of them is zero and gives 0 otherwise.
```
Using the method in the [APL answer](https://codegolf.stackexchange.com/a/165318/75553), we get the same byte count. One byte longer than that answer because lowest common multiple is two bytes.
**6 bytes**
```
«=æl×»
```
[Try it online!](https://tio.run/##ARwA4/9qZWxsef//wqs9w6Zsw5fCu/8zxbvDp8O@YEf/ "Jelly – Try It Online")
[Answer]
# TI-Basic, 10 bytes
```
max(Ans)not(prod(Ans)ΔList(Ans
```
Multiply maximum value by result of (some element equals zero OR elements are equal)
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 22 bytes
```
f(x,y){x=x*y&2?0:x|y;}
```
[Try it online!](https://tio.run/##Rc5BDoIwFATQdXuKHwymlWoQXFGQs5hitYkWg5D0Bzl7LXbhapJ5sxi1vynlvWZOIJ9d43a4Ldq8ch@Ui98Yqx5Td4X6PXamP9zPlBo7wvNiLON0pkT3A7C1ctBALkPUcAqRZZySv2JUjIpRyWsIplmSTqlKBKwnALn4zUpooSyggmPOJV38Fw "C (gcc) – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 27 bytes
```
a#b=max a b*0^(a*b*(a-b)^2)
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P1E5yTY3sUIhUSFJyyBOI1ErSUsjUTdJM85I839uYmaegq1CbmKBb7xCQVFmXolCdDRQg0INULmNrkK0gZ6ecWxsTZKNLpT5HwA "Haskell – Try It Online")
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 28 bytes
```
@(a,b)~(a*b*(a~=b))*max(a,b)
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999BI1EnSbNOI1ErSUsjsc42SVNTKzexAiz6Py2/SCHT1tDKWAfEygKzFFIyiws0ojN1snTSNICkZqymTmpeCgj/BwA "Octave – Try It Online")
or
```
@(a,b)(a==b|~(a*b))*max(a,b)
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999BI1EnSVMj0dY2qaZOI1ErSVNTKzexAiz6Py2/SCHT1sDKWAfEygKzFFIyiws0ojN1snTSNICkZqymTmpeCgj/BwA "Octave – Try It Online")
---
### Explanation:
The maximum value should be outputted if `a*b=0` or if `a==b`. The function takes `a` and `b` as inputs. It multiplies `a*b`, thus getting a zero if one of them is zero, and checks that `a~=b`, thus getting a zero if the two are equal. We negate both, so that both conditions gives us a truthy value telling us that we should output the maximum value. We then multiply this boolean (`0/1`) by the maximum value, and outputs it.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
```
`α*P_*Z
```
[Try it online!](https://tio.run/##MzBNTDJM/W98eO7hxWWVlZX/E85t1AqI14r6X6l0eL@Crp3C4f1KOjH/AQ "05AB1E – Try It Online")
**Explanation**
```
`α        # absolute difference of the inputs
  *       # multiplied by the inputs
   P      # product of the result
    _     # logically negated
     *    # multiplied by the inputs
      Z   # max
```
[Answer]
# JavaScript (ES6)
## 27 bytes
A rather long formula, but without any conditional statement.
```
a=>b=>(a|4)*(b|4)*6%61%27&3
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i7J1k4jscZEU0sjCUSaqZoZqhqZqxn/T87PK87PSdXLyU/X4FJQiDbQMdQx0jGO1ctNLNBIVLC1AwqiCycBhRXSNBI1NZI0NfWy8jPzNNQV1DWBKmG8mDwgV/M/AA "JavaScript (Node.js) – Try It Online")
## 17 bytes
Simply a port of [Dennis' method](https://codegolf.stackexchange.com/a/165326/58563).
```
a=>b=>a*b&2?0:a|b
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i7J1i5RK0nNyN7AKrEm6X9yfl5xfk6qXk5@ugaXgkK0gY6hjpGOcaxebmKBRqKCrR1QEF04CSiskKaRqKmRpKmpl5WfmaehrqCuCVQJ48XkAbma/wE "JavaScript (Node.js) – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~12~~ 9 bytes
Takes input as an array of integers.
```
×&2?0:Ur|
```
[Try it online!](https://tio.run/##y0osKPn///B0NSN7A6vQopr//6MNdAxjAQ "Japt – Try It Online")
[Answer]
# [Elixir](https://elixir-lang.org/), 34 bytes
Pretty simple in a functional programming language, just get the first match. No maths here!
```
fn a,a->a
a,0->a
0,a->a
_,_->0 end
```
[Try it online!](https://tio.run/##VY6xCgMhEER7v2KxWsET8wGxT5UibUDkshFBjHh7kOL@3XgJhKQa5jE8hnJ6ptYjsU@lrgxHuBeYHJzOZsAFpVSwObhwSyWaRjWHmTy3kPIAKK9Favgf8WO4mCI1VEDlJrAPZ9BhckEEbfewn@a1n5zdR10Z/L4wqDT8NiW296VUlkozo@pWHF4 "Elixir – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 35 bytes
```
rep(unique(sort(c(0,scan()))),4)[4]
```
[Try it online!](https://tio.run/##K/r/vyi1QKM0L7OwNFWjOL@oRCNZw0CnODkxT0MTCHRMNKNNYv8bKxj8BwA "R – Try It Online")
Shameless port of [Sok's well-explained Pyth answer](https://codegolf.stackexchange.com/a/165434/80010).
[Answer]
# [Befunge-93](https://github.com/catseye/Befunge-93), 20 bytes
```
&::&*#v_&+.@
@.*!-&<
```
[Try it online!](https://tio.run/##S0pNK81LT/3/X83KSk1LuSxeTVvPgctBT0tRV83m/39jBWMA "Befunge-93 – Try It Online")
## Explanation
this boils down to:
```
if(A * B = 0) {
    output (A + B)
    end
} else {
    output A * (A = B)
    end
}
```
[Answer]
# [Python 3](https://docs.python.org/3/), 30 bytes
```
lambda a,b:0==a*b*(a-b)and a|b
```
[Try it online!](https://tio.run/##XcxBCsIwFATQfU4xZJP8mkC1rgq5STc/tNEU/S2lG6F3j2gVxIHZvZn5sV4naUoKXbnxPfYMdrGtQ@AqVpZ9JJYevMUyL1lWq4ENNY44oenE@4P/RJNSaVqQkQULy2WwZ2oV9tm75PQG7QbpgzGk8OLjH//xyWY3Eu0ehvA9o/IE "Python 3 – Try It Online")
-5 bytes thanks to Oliver
-1 byte thanks to Jo King
[Answer]
# [Befunge-93](https://github.com/catseye/Befunge-93), 17 bytes
```
&::&-!_&*!\&+*.@.
```
[Try it online!](https://tio.run/##S0pNK81LT/3/X83KSk1XMV5NSzFGTVtLz0Hv/39DBQMA "Befunge-93 – Try It Online")
As psuedo-code:
```
f(a,b):
  if a-b==0:
    print(b)
  else:
    print((!(a*b))*(a+b))
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~20~~ 18 bytes
-2 bytes thanks to Martin Ender.
```
(.)\1|0
$1
..|^$
0
```
[Try it online!](https://tio.run/##BcGhDYBAEERR/@uA5DCXmd0iaIIQEAgMgiCv9@W99/ru56y5rUe1vmweYjK9j31CVRIyCpRY2DhwEiJMBJGkSJNB5g8 "Retina 0.8.2 – Try It Online")
[Answer]
# **JavaScript, 24 Bytes**
```
x=>y=>!x*y|!y*x|(x==y)*x
```
Allows all numbers, no conditional, doesn't require sorted input
[Answer]
# Python 2, ~~42~~ 34 bytes
```
lambda a,b:(0in(a,b)or a==b)*(a|b)
```
EDIT: -8 thanks to @TIO and @JonathanAllan
[Answer]
# [Shakespeare Programming Language](https://github.com/TryItOnline/spl), ~~216~~ 208 bytes
```
,.Ajax,.Ford,.Act I:.Scene I:.[Enter Ajax and Ford]Ajax:Listen tothy!Ford:Listen tothy!Am I as bad as you?If soyou zero.Is the product ofyou I worse a cat?If soyou be the sum ofyou I.If notyou zero.Open heart
```
[Try it online!](https://tio.run/##VY0xC8IwEIV3f8VzL4GuXaSDQkBwcBSHtLlSxeZKckHrn4@JoOJ079777l6YbylVqr2aR6V27G3WvUA36tiToyJOWyfkURAYZ1Goc9ma/SUIOQjLuKyL/e@0EzRMQGdsGQvHjR4QOAs8ybPSATISZs825lIeSqJxZx8IBr2R30FHbzbE6cOpnDmW77fDnJtHMl5Sqlf1Cw "Shakespeare Programming Language – Try It Online")
As psuedo-code:
```
f(a,b):
  if a==b:
    b=0
  if a*b<1:
    b=a+b
  else:
    b=0
  return b
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 27 bytes
```
N+N+N.
N+0+N.
0+N+N.
_+_+0.
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/308bCPW4/LQNQJQBhBevHa9toPffXlfBACgepKNQXpRZkpqmoaRaoKCkoxAdFKupxwWWNcQra4RX1hhVNiYPWdoQr8WGeC02xGuxIX6LjfBabITXYiO8Fhvht9gYr8XGeC02xmuxMbrFcNn/AA "Prolog (SWI) – Try It Online")
The most naive translation ever.
[Answer]
# [Glee](https://withglee.com/Frames/GFMain.htm), ~~24~~ ~~22~~ 20 bytes
Idea to append zero taken from Sok’s [Pyth solution](https://codegolf.stackexchange.com/a/165434/39407).
`~~=>n,0& \*>0\+ >1~ \*n\>>~~`
```
=>n,0& *>0\+ <2*n\>>             $$<2 instead of >1~ (not > 1)
```
Explanation:
```
a b=>n,0& *>0\+ <2*n\>>
a b=>n                      3 1     2 2     0 3     0 0     assign a b to n
      ,0                    3 1 0   2 2 0   0 3 3   0 0 0   catenate 0
        &                   0 1 3   0 2     0 3     0       unique elements
          *>0               011     01      01      0       mark all > 0 (boolean)
             \+             2       1       1       0       reduce by addition
                <2          0       1       1       1       result <2 ?
                  *n        0 0     2 2     0 3     0 0     multiply with n
                    \>>     0       2       3       0       largest element
```
Old version
```
=>n--[2]=0|(n\* =0)*n\>>
```
Explanation for a pair of numbers (a b):
```
                              result for a b pairs
                               3 1    2 2    0 3
a b=>n--[2]=0|(n\* =0)*n\>>
a b                            3 1    2 2    0 3   create vector (a b)
   =>n                                             assign vector to n
      --                       0 _2   0 0    0 3   calculate the first difference vector of n (monadic --)
        [2]=0                  0      1      0     result vector at index 2 equal to 0 ? (boolean)
              (n\*             3      4      0     n reduced by multiplication
                   =0)         0      0      1     equal to 0 ? (boolean)
             |                 0      1      1     OR (boolean) (dyadic |)
                      *n       0 0    2 2    0 3   multiplied by n (dyadic *)
                        \>>    0      2      3     largest element (monadic \>>)
```
[Answer]
# [QBasic 1.1](http://www.qbasic.net/), 38 bytes
```
INPUT A,B
IF A*B THEN?A*-(A=B)ELSE?A+B
```
-1 thanks to [DLosc](https://codegolf.stackexchange.com/users/16766/dlosc).
Input is two comma-separated integers.
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 32 bytes
```
{If[_=_2,_,If[Min!__,0,Max!__]]}
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBl@7/aMy063jbeSCdeB8jyzcxTjI/XMdDxTawAMmJja//7paamFEerFBQkp8dyBRRl5pWEpBaXOCcWpxZHq6XpKLjlJJZE@5eWpBZFh@koGFgZg4lYHQXD2Nj/AA "Attache – Try It Online")
Takes input as two arguments, such as `f[0, 1] = 1`.
## Other solutions
## 34 bytes
```
{If[Same!_,_@0,If[Min!_,0,Max!_]]}
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBl@7/aMy06ODE3VTFeJ97BQAfI883MA3IMdHwTKxTjY2Nr//ulpqYUR6sUFCSnx3IFFGXmlYSkFpc4JxanFken6Si45SSWRPuXlqQWRYfpKBhYGYOJWB0Fw9jY/wA "Attache – Try It Online") The same as above, but takes input as an array
## 39 bytes
```
{ToBase[47483073034,5][FromBase&4!_]-1}
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBl@786JN8psTg12sTcxMLYwNzYwNhExzQ22q0oPxckrmaiGB@ra1j73y81NaU4WqWgIDk9liugKDOvJCS1uMQZqKQ4Ok1HwS0nsSTav7QktSg6TEfBwMoYTMTqKBjGxv4HAA "Attache – Try It Online")
Hardcodes the solution in a base-5 integer. More interesting IMO but longer.
[Answer]
# Pyth, 11 bytes
```
e+Z.-+xFQQ{
```
[Try it here](https://pyth.herokuapp.com/?code=e%2BZ.-%2BxFQQ%7B&test_suite=1&test_suite_input=0%2C%200%0A0%2C%201%0A0%2C%202%0A0%2C%203%0A1%2C%200%0A1%2C%201%0A1%2C%202%0A1%2C%203%0A2%2C%200%0A2%2C%201%0A2%2C%202%0A2%2C%203%0A3%2C%200%0A3%2C%201%0A3%2C%202%0A3%2C%203&debug=0)
### Explanation
```
e+Z.-+xFQQ{
     +xFQQ      Prepend the XOR of the inputs to the inputs.
   .-     {Q    Remove one copy of the deduplicated (implicit) input.
 +Z             Prepend 0.
e               Take the last.
```
### Alternative solution, 11 bytes
```
e+0.-F{B+xF
```
[Answer]
# [Pyth](https://pyth.readthedocs.io), 10 bytes
```
-iFQ&.AQnF
```
[Try it online!](http://pyth.herokuapp.com/?code=-iFQ%26.AQnF&input=%280%2C+0%29+-%3E+0%0A%280%2C+1%29+-%3E+1%0A%280%2C+2%29+-%3E+2%0A%280%2C+3%29+-%3E+3%0A%281%2C+0%29+-%3E+1%0A%281%2C+1%29+-%3E+1%0A%281%2C+2%29+-%3E+0%0A%281%2C+3%29+-%3E+0%0A%282%2C+0%29+-%3E+2%0A%282%2C+1%29+-%3E+0%0A%282%2C+2%29+-%3E+2%0A%282%2C+3%29+-%3E+0%0A%283%2C+0%29+-%3E+3%0A%283%2C+1%29+-%3E+0%0A%283%2C+2%29+-%3E+0%0A%283%2C+3%29+-%3E+3&test_suite=1&test_suite_input=0%2C+0%0A%0A0%2C+1%0A%0A0%2C+2%0A%0A0%2C+3%0A%0A1%2C+0%0A%0A1%2C+1%0A%0A1%2C+2%0A%0A1%2C+3%0A%0A2%2C+0%0A%0A2%2C+1%0A%0A2%2C+2%0A%0A2%2C+3%0A%0A3%2C+0%0A%0A3%2C+1%0A%0A3%2C+2%0A%0A3%2C+3%0A&debug=0&input_size=2)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 20 bytes
```
a=>b=>a-b&&a*b?0:a|b
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i7J1i5RN0lNLVEryd7AKrEm6X9yfl5xfk6qXk5@ukaahoEmEGlyoQoa4RA0xCZohCFogE3QEJsgVu3G2Gw3xma7MQ7txticZIzNScbYnGSMw8z/AA "JavaScript (Node.js) – Try It Online")
[Answer]
# 12-basic, 36 bytes
```
FUNC M(A,B)?(A or B)*(!A~!B|A==B)END
```
This can probably be shortened.
`~` is bitwise XOR (as well as bitwise NOT when used as a unary operator) (Just like in Lua)
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 28 bytes
```
[pq]sqsidli=qd0rli*0!=qli++p
```
[Try it online!](https://tio.run/##S0n@b6xg@D@6oDC2uLA4MyUn07YwxaAoJ1PLQNG2MCdTW7vg/38A "dc – Try It Online")
I'll keep mulling over this, it feels like it must be golfable. `[pq]sq` just makes a print & quit macro. `sidli` stores one of our values in the register `i`, duplicates the other value, and then recalls `i`. `=q` consumes two values on the stack, and executes macro `q` if they're equal (so, prints the one value left behind). `d0r` duplicates the value on the stack again, and then puts a `0` on the stack in between them. `li*0!=` loads `i`, multiplies the two values, and runs `q` to print the `0` that we left on the stack if the two values were not equal. If none of these things has happened yet, we `li` to load `i`, and we now have three values on the stack - two zeroes and our one non-zero value. `++` add the three together, and `p`rint.
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 25 bytes
```
/ /;$_=($'|$`)>>($'*$`&2)
```
[Try it online!](https://tio.run/##K0gtyjH9/19fQd9aJd5WQ0W9RiVB084OyNBSSVAz0vz/30jB6F9@QUlmfl7xf90CAA "Perl 5 – Try It Online")
Steals the method from @Dennis's Python answer.
[Answer]
# [Tcl](http://tcl.tk/), 43 bytes
```
proc M a\ b {expr !$a?$b:!$b?$a:$a-$b?0:$a}
```
[Try it online!](https://tio.run/##LcoxCsMwDIXhPad4AQ0ttGBLm5ecICdoMsghW0pNmkIh@OzuGzr8PH2gY9laK/trwQifkHGu37KjFx8kp17yIJ7E7zwCt7bt6eX/2QUEFpky6yId6UhHWmmllVbaaKONNrriLJ/jjYv4TfI1TXiMEIfkubYf "Tcl – Try It Online")
[Answer]
# **PHP - 52 bytes**
```
<?=($a=$argv[1])==($b=$argv[2])?$a:($a*$b?0:$a|$b);
```
[Try it online!](https://tio.run/##K8go@P/fxt5WQyXRViWxKL0s2jBW0xbITYJyjWI17VUSrYDyWipJ9gZWKok1Kkma1lz///83/m/8L7@gJDM/r/i/bopCcUZ@UUl8fkFqXnxJYrptfh4A "PHP – Try It Online")
Explanation:
```
$a==$b  Check for equality, display first value if equal
$a*$b   If multiplication equates to non-zero, display 0 (Unknown) else...
$a|$b   Display the non-zero value.
```
]


[Question]
      [
Having a function *f* that takes arguments *x1*, *x2*, …, *xn*
                                               – ie.  *f : X1 × X2 × … × Xn → Y*
– [currying](https://en.wikipedia.org/wiki/Currying) redefines *f* as a function taking a single argument *a1* which maps to yet another function. This technique is useful for partial application, for example with a curried `pow` function we could write `exp = pow(e)`.
### Example
Assuming we have the following function *f* taking three arguments (*f : X1 × X2 × X3 → Y*):
```
def f(a,b,c):
  return a + b * c
```
Currying this function leaves us with *f\_curry: X1 → (X2 → (X3 → Y))*, if we would now call that function twice with `f_curry(1)(2)` we would get a function (`h`) equivalent to the following returned:
```
def h(c):
   return 1 + 2 * c
```
The curried function `f` could be written like this (Python 3):
```
def f_curry(a):
  def g_curry(b):
    def h(c):
      return a + b * c
    return h
  return g_curry
```
[Try it online!](https://tio.run/##lZFfS8MwFMXf8ykO7CFJV8VuUqToo99AfFEZaZf@wS4rSSoO2WevSZe1E0GwD83Juef@btN0B1vv1XoYtrJEuSl6rQ9M8IwA3qmCk4/OyatZEXaAlrbXCgJL5IhQkAuzJpMMGEKIXxtp8IAXV6ZhIo0xPwtY8e4iCYSu@p1UNg4cg7JXhW32ykcaVWEFdiJu@ZQ2F2CW8Jn9H/Cc@UljqzPwL5rqd7nUvzrZemxeoGyUaCE/Oy2NcVMzR1m6w0RYk7eh042yjD5OZeqKdxGFX@mzaHvpVZqcradDJ1/HVHKziugV5YSUez0eamOsRqMQfry/OG@7C5AfomXnCHd@mPuV4T5JzRHwKr0d1ZFeO@JO2KkjhnuNOx7Dui84ac6Hbw "Python 3 – Try It Online")
## Challenge
Your challenge will be to curry a function as described above, here are the rules:
* Input will be a [blackbox function](https://codegolf.meta.stackexchange.com/a/13706/48198) which takes at least 2 arguments
* The input function will always have a fixed number of arguments (unlike `printf` or similar, note: you need to support functions with any number of arguments ≥2)
* If your language uses curried functions by default (eg. Haskell), you may expect the input function to be defined over *N*-tuples, instead of a "higher-order function"
* You may take the number of arguments as input
* Output will be the input's curried equivalent\*
* You may assume that the output function will only ever be:
	+ called with less or equal to the number of arguments that the input function takes
	+ called with arguments of the right type
---
\* This would mean for an input `f` with `N` arguments and an output `h` that for all valid arguments `a1,…,aN` it holds that `f(a1,a2,…,aN) == h(a1)(a2)…(aN)`.

[Answer]
## JavaScript (ES6), 35 bytes
```
f=g=>g.length<2?g:a=>f(g.bind(f,a))
```
[Answer]
# [Idris](https://www.idris-lang.org/), 204 bytes
```
import Data.HVect
C:(a:Vect n Type)->(HVect a->Type)->Type
C[]T=T[]
C(h::t)T=(x:h)->C t(T .(x::))
c:{a:Vect n Type}->{T:HVect a->Type}->((b:HVect a)->T b)->C a T
c{a=[]}f=f[]
c{a=h::t}f=\v=>c(\u=>f(v::u))
```
[Try it online!](https://tio.run/##VY0xb4MwFIR3/4pTJjtAlmSyZC90aKWqHWp1IR6MgeAhgIhJW6H8dmpoqiTLe3f3Tt9zRe9O0@SOXdt7PBlvNs@fpfUk5dTwWaGB@ulKlki6XGASeQ3mRdJMK6EyTVJac@6ZEvSb1@GawlOFTXCcMWL5@MC7JHJU/IEYIkrz/2zmI184BorY0YhMXypRhVezmZ8Fuz8Lael@ELKiZ84HxqahsUPfu7IAxx8sezM@xjI@fO@ag0Yir5Lc6pmJkcewGgKnuv0CNWuDCPk6Z4giWEKOxjX85Z2yRYmiJUAXMP61Ab0jbWPsYqx8vdLsvmJxK22xWxps@gU "Idris – Try It Online")
Sounds like a job for dependent types! Well, maybe.
---
**C** is a currying type function. Given a vector of types **a = [t1, t2, … tn]** and a type function **T : HVect a → Type**, it returns a new type:
>
> 　　　　　　　　　　　**(x1 : t1) → (x2 : t2) → … → (T [x1, x2, … xn])**
>
>
>
Here, **HVect** is the [heterogeneous vector type](https://www.idris-lang.org/docs/current/base_doc/docs/Data.HVect.html) from the Idris Prelude — the type of *n*-tuples whose elements are of *n* different types.
**c** is a function that takes **a** and **T** as implicit arguments, and then converts an *uncurried* function `f` of type **((b : HVect a) → T b)** into a *curried* one of type **C a T**.
(**C** simply describes what we wish to do; **c** actually does it. But we can't get away with not defining **C**, as Idris demands that every top-level definition have a type signature.)
---
The TIO link gives a usage example. If we define a function on 3-tuples **(Nat, Nat, String)** as follows:
```
uncurried : HVect [Nat, Nat, String] -> String
uncurried [a, b, c] = show (a*a + b*b) ++ c
```
then **`uncurried [3, 4, "th"]`** yields the same result as **`c uncurried 3 4 "th"`**. Idris infers the arguments `a=[Nat, Nat, String]` and `T=const String` for us, I believe.
I based this code on [this gist](https://gist.github.com/timjb/6258302) by timjb.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~54~~ 53 bytes
```
c=lambda n,f,*x:lambda y:(f,c)[n>1](*1%n*(n-1,f)+x,y)
```
[Try it online!](https://tio.run/##LctBCsIwEEDRtTnFbISZdLqIRZBAvYi4SNIOCjotIUJz@thFlx/eX2t5LTq0lsZP@MYpgLKw3fxR1aNwoofe3ROtO6tF7R0LdRtXatMsIBg47sabU57LLysE6CCChWTMmt9aMOGwL3ghvBLeiNof "Python 3 – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 96 bytes
```
y=function(f,n=length(formals(f)),p=list())function(x,u=c(p,x))`if`(n<2,do.call(f,u),y(f,n-1,u))
```
[Try it online!](https://tio.run/##ZcxNCsIwEIbhfU8x4GZGp2q0BZXmLqZpooWYlNpCi3j2Gn8QxFnN4vnedppGaXuvuzp4tOylM/7UndGG9qLcFS0RN9LV1w6JvnDgXmpseCA61vaIvthwFZZaORcjPfH4bKUivjTZEKBI4TtWXLImuIGCBZQwBw33pFTtP@LqzdIPW0F1T2I6BMKccEO4JXjdDMzQGN2Z6gBCRBN7hGK9JsxeMKcfs98ts2R6AA "R – Try It Online")
---
[Previous version (97 bytes)](https://tio.run/##PYxBDsIgFAX3nuIv/1NqYo27chiKoCTIbwokbYxnx3bT5SQzM7e2al@TLUESe5V0dOlV3uxl/piY2QNq0jHkwsAhLqpqy5NagOA5DT2ecrUmxm1R4WJ2p3W/dbcNmxehoaOjNmpUFvQlQxca6UyWfrsvAn6Ae/Ad7Q8 "R – Try It Online")
-1 byte thanks to @JayCE
[Answer]
# [Coconut](http://coconut-lang.org/), 54 bytes
```
def c(f,*a):
 try:return f(*a)
 except:return c$(f,*a)
```
[Try it online!](https://tio.run/##NY1BCoAgFAX3nuItWvxftqh2Qt3FfgptLEShoLubEG2HYUYOOUJOpWzOQ8jr1rJRSPE20aUcAzxVpOAucWf6oTSfWjxmkNWrFka/wKLDihaiVI0xDUwj08R4FpxxD3X0Ag "Coconut – Try It Online")
---
# [Coconut](http://coconut-lang.org/), 40 bytes
Port of [Erik's Python answer](https://codegolf.stackexchange.com/a/162240/64121).
```
def c(f,n,*a)=n and c$(f,n-1,*a)or f(*a)
```
[Try it online!](https://tio.run/##FYwxDoAgEAR7X7GFxR1igdTwFzglsTkM0c6/o1STTDIjVao@d@/7USBUrFqTOCiS7pB5iNUNVRsK/ewFAZRstsJYIxIWZBjINI3cMzmmjckz3oirnfrPPw "Coconut – Try It Online")
[Answer]
# C++~~17~~ 20, ~~214~~ ~~200~~ ~~189~~ 184 bytes
```
#include<regex>
template<class R,class A,class...B>auto c(std::function<R(A,B...)>f){if constexpr(sizeof...(B))return[=](A a){return c<R,B...>({std::bind_front(f,a)});};else return f;}
```
[Try it on Wandbox](https://wandbox.org/permlink/tHGtWjVuRWMc4hlv) (TIO doesn't support gcc 9+ which is needed for std::bind\_front)
This is a template function that takes an std::function of any arity/type and returns a curried lambda expression. Uses constexpr if FTW. If any template gurus have any idea how to eliminate or reduce the need for std::function let me know.
Edit: replaced inner lambda with std::bind\_front.
Edit: replaced include with shorter <regex>
Ungolfed version:
```
#include <functional>
template <class R, class A, class... B>
auto curry(std::function<R(A, B...)> f) {
    if constexpr(sizeof...(B) > 0) {
        return [=](A a) {
            return curry(std::function<R(B...)>{std::bind_front(f, a)});
        };
    } else {
        return f;
    }
}
```
[Answer]
# [Python 2](https://docs.python.org/2/), 60 bytes
```
c=lambda f,n,l=[]:lambda a:n-1and c(f,n-1,l+[a])or f(*l+[a])
```
[Try it online!](https://tio.run/##PYxNCsIwFIT3PUV2SeyrUN0FepKQxTM/WIkvIaZQj@UZPFhUrG5mvo@Byfd6TnRozU4RryeHLABBnLRRm6OiYURyzIr3NIwQe41GpsKC2H255TJTZcW7xXrx/1lVEKsEbcVMealCwtbS9D9qt1r2xeeI1nfHTvMLRsyeEgfG6RPPBzcv "Python 2 – Try It Online")
The footer is a tester which uses STDIN in the following way per line:
1. The function itself
2. The number of the function's arguments, ≥2
3. A list of the arguments (`[a,b,...]`)
Note that, while a list of the arguments is given as input in the tester, in reality, the curried equivalent gets prepended to the list and the list is reduced by function call.
A similar 55-byte version has been kindly provided by [ovs](https://codegolf.stackexchange.com/users/64121/ovs):
```
c=lambda f,n,*l:lambda a:n-1and c(f,n-1,*l,a)or f(*l,a)
```
[Try it online!](https://tio.run/##VYxBCsIwEEX3niK7zGgqlO4KnqSUMKYpVtJJSFOpx/IMHiy2ooKbz388eOGeLp6rnM3J0XjuSPSK1d7VH6Kai5K4EwZWUZSrUoQ@ih7eL4c4cAKthzH4mLQG2c9skvdukniMtpuNhV96qXtYUDUG7I0cDBzmBIhqa3wB28OfRMxTimsqODJ2V@0aeSVHwbKXSkje5vmQ7Qs "Python 3 – Try It Online")
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/attache), 5 bytes
```
Curry
```
[Try it online!](https://tio.run/##SywpSUzOSP2fbGX737m0qKjyP1diSkp0hY5CZayCla1ChYK2QiVIyBgspqNQhRAG4iqugKLMvJLo5Gigkthoo9ho49hYZDHj2GjD2GiT2GhzoDhXbkF0Hlh/mH4eXBVQEKgpOhqIlRKVwCb8BwA "Attache – Try It Online")
Simple built in, largely uninteresting. But, here's a version from scratch:
## Attache, 35 bytes
```
{If[#__2<#_,Fold[`&:,$'__],_@@__2]}
```
Explanation:
```
{If[#__2<#_,Fold[`&:,$'__],_@@__2]}
{                                 }    lambda
 If[       ,              ,      ]     if
    #__2                                 the number of parameters after the first
        <#_                              is less than the arity of the first
            Fold[   ,    ]             then fold:
                 `&:                     right-function bonding
                     $                     over this function
                      '__                  paired with the rest of the parameters
                          ,            otherwise:
                           _@@           call the first parameter
                              __2        with the rest of them
```
[Answer]
# [Rust](https://www.rust-lang.org/), 73 69 bytes
```
macro_rules!c{($f:tt$(($n:tt:$a:ty))*)=>{$(move|$n:$a|)*$f($($n),*)}}
```
[Try it online!](https://tio.run/##PcpBDoMgEIXhfU@BySxmDF1odzT2KoYaSEwEU0CDEc9O0SadxbzF97vFh5yNHNzcu2VSvhp2BC1CAESwZQVIETaimrrXDmjmVaUCIBPVoBFKRbym48jaMiNHi7TfWLlJBRZZx1IU46Pl2/lTvG/Pv@qiQ4UR5WmE72voF0jvlQu9@pxBw1viGhvCy4/8BQ)
Rust is statically typed and because of this taking in a function with an unknown number of arguments is not allowed. Fortunately, macros have no such restrictions. This macro takes in a function of the form `name(arg1:type1)(arg2:type2)...(argN:typeN)`. and outputs a function that outputs an appropriately long chain of `impl FnOnce`s that ends with the desired function call. I shaved a few bytes by changing the input form to something more natural with the question. Ungolfed version:
```
macro_rules! c{       //declare a macro named c
  (                   //match on
    $f:tt             //A token tree (should be an ident, but this is codegolf)
    $(                //followed by zero or more sequences of
      ($n:tt : $a:ty) //a token tree (again, should be ident) colon type in parentheses
    )*                //end repetition
  )=>{                //replace with
    $(move|$n:$a|)*   //FnOnce closure heads for every matched name:type
    $f(               //call initially matched function
      $($n),*         //with a comma separated list of closure argument names
    )                 //end call
  }                   //end rule
}                     //end macro
```
[Answer]
# [Cauliflower](https://github.com/broccoli-lang/broccoli), 84 bytes
```
(:= c(\($f$n(@a))(if$n(\($a)(call c(cat(list$f(-$n 1))@a(list$a))))else(call$f@a))))
```
[Try it online!](https://tio.run/##LYy9CsMwDIRf5QYNEqVD2i1Q8IN0EaoNBuEUx6GP7zpupzu@@zE9PCffPrH2zusDxk@mRIWDinA@3QAqbOo@UtPGnvdGia9UsIgE/YHRF4m@x1mlFCbo/K65NHCNr8Mi5j2oCP46zDkHGy64Cxbchkj/Ag "Cauliflower – Try It Online")
[Answer]
# Java 8, 19 + 126 = 145 bytes
This is a curried (hah) lambda taking a function and an argument count and returning the curried function.
```
import java.util.*;
```
```
f->p->new C(){List a=new Stack();public Object f(Object r)throws Throwable{a.add(r);return a.size()<p?this:f.f(a.toArray());}}
```
[Try It Online](https://tio.run/##fVJLbxoxED7DrxjlEjsFp0lu3UBFkSpVatUDuUUchl0vGLy2a3sXbdH@djK7LAJFaS/jh@bxPWaLFY6tk2ab7Y6qcNZH2NKfKKPS4i4ZDpWJ0ueYSpiZ@ntp0qisgcNw8Hu1lWmEnJ0ur0tAvw4c4sbbfYCX9sCVlsmwue4y/6C2rfxHoStXWqWQagwBfqHqRoeIkT4vQPMelzgDfL4CO/pv4g9CtpZ@BPPpFNLS@xomx3w8deOpkXuYM374qQJBnLTPRcR0x3jSw3rPw/P3JA4oMMuY54mXsfQGUAT1VzL@7L7GjQpfcpEzFNHOvMeacZ40zXFAug/6ET3XyqoMCuLPFtErsya529fsQ8lbjQbXdinjyggTuHjlcX@qHU@77MH9PdVLL28DGAs3FXqFGQ1eSyO9SsPNCIKFvYQNVhKiBVdqDbb0ne10iWBzQCLYEhF9y2/0nVlzG2FvSdoEVA61LSH8KWklQEXip6iPtnYXILWF0zJKXZ/Gou76UGa/XUTh4mWnWBAheokFOxMSBboXS66yquXGen85VPyictK2PRtCVa@fl/DpdHtYwt3p9rhs05o2zLvNUDIjAN2OCHRO16zTlfePp67tog5RFoL0EI6MitowxuYcutB3IcsfOKf42MUn3lY2w@b4Bg)
## Submission type
The submission defines appropriate functional interfaces for the input and output functions. The definitions of the interfaces aren't included in the byte count because they only provide type information and don't contribute any code to the solution. (In fact, both of them are general enough that they could well have been included in the set of functional interfaces in the standard library.) For more details see the TIO.
## Usage
Because the submission returns a function (instance of `C`), the output may be invoked directly (with `f`), but subsequent intermediate return values must be cast to an appropriate type before being invoked. Consult the TIO for a usage example.
Note that in Java functions (i.e. methods) are not first-class objects. Thus the syntax used in the output bullet of the challenge description is meaningless in Java. Rather than `f(a1, a2, a3)` we have `f.f(a1, a2, a3)`, and rather than `f(a1)(a2)(a3)` we have `f.f(a1).f(a2).f(a3)` (modulo typecasting).
## Limitations
When an intermediate result is applied (an argument added), the result is actually a mutated copy of the original result. This violates the spirit of currying, but meets the specific requirement stated in the challenge.
The form of input functions is limited by the decision to use functional interfaces, since a fully general functional interface has to use variadics or otherwise pack function parameters, and as a result the implementors of the interface must do so as well rather than listing parameters in the standard fashion. Technically this might disqualify the solution, since it is possible to support fully general non-variadic multi-parameter input functions by invoking them using reflection. My [solution using this strategy](https://tio.run/##dZHNjtMwEIDP8VOM9mQvrSXYG2mLUBACiRXSdm@Ig@M4qVvHjuxJl1Ll2YvjpAsCVrLG4/H8fDOzF0exdJ2y@@pw0W3nPMI@2niP2vDbnBBtUflaSAXF6mEDZ5I9QE2/lnslEYRvGODOu6cAj@MlSqNyMvwZtnUmJnMW1A9Utgok@12g7q0c//jHWVmRbPo2wjbcq9rEMvxe4c5Vi@vfC6GfY8lG@QUUG5LFcx5I5O/60mgJ0ogQ4F5oO7YQUGA0PqPJ3vsTrC/tctMtN1Y9QUHZ@YsOscX1@NyikAfK8jnb3P7zHDz7ewhnwUVVUc9yr7D3FgQP@qeibNW9w50Ob1uu7dEdFBULwdG9916cKGP5MFyyiH1FnLg/uUgSua/WOF0QXWdONGmLZCinS7LkmV3rwiso4RZkHo0DiYdkcxdzsqPTFbRxMnSLXtvm2/dxr@Hfxaa8L20HWlgnTp6QeaPwg4qqV9XkQG8S8U2inJz@r7KRtACvQm8wJk3L4VO7LZuVu@S1PQVULXc98i6io7GU0oJBElMCXtPXjEX5Jsk7NgYOZLj8Ag) (taking a `java.lang.reflect.Method` instead of an instance of a functional interface thanks to @user) is a bit longer, so I stick with this one.
## Ungolfed
```
f -> p -> new C() {
    List a = new Stack();
    public Object f(Object r) throws Throwable {
        a.add(r);
        return a.size() < p ? this : f.f(a.toArray());
    }
}
```
## Acknowledgments
* -211 bytes thanks to ideas from KrystosTheOverlord
[Answer]
# [Python 2](https://docs.python.org/2/), 78 bytes
```
c=lambda f,*a:f.func_code.co_argcount>len(a)and(lambda x:c(f,*a+(x,)))or f(*a)
```
[Try it online!](https://tio.run/##LctBCsMgEEDRvaeY5YyRQNOd0F4ljKO2hXQMopCe3qbQ3V/8t3/as@gyhtw2fofIkJ1ln@fcVVYpMc1SVq4PKV3bfUuKTKwR//fhBX9iwsMRUamQ0TKNmPJZ7IIT8gagptarAsMEASyIMXt9aYNTE14IF8IrjS8 "Python 2 – Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~42~~ 40 bytes
```
my&c={.count>1??{c(.assuming($^a))}!!$_}
```
[Try it online!](https://tio.run/##K0gtyjH7/z@3Ui3ZtlovOb80r8TO0N6@OllDL7G4uDQ3My9dQyUuUVOzVlFRJb4WqFBBLUPBViFZoxoorKCtoBKXpKAFJJNrNa25ihMrFTI0DDU1jDQ1jDWt/wMA "Perl 6 – Try It Online")
-2 bytes thanks to [Brad Gilbert b2gills](https://codegolf.stackexchange.com/users/1147/brad-gilbert-b2gills).
[Answer]
# [Haskell](https://www.haskell.org/), ~~211~~ ~~209~~ ~~189~~ 163 bytes
Flags:
```
-XMultiParamTypeClasses
-XFlexibleInstances
```
Actual code (119 bytes):
```
class C a b c where c::(a->b)->c
instance C()b b where c f=f()
instance C a b c=>C(d,a)b(d->c)where c a b=c(\d->a(b,d))
```
[Try it online!](https://tio.run/##bVBNS8NAEL3nV7yDh12aHNreAglIQCgoCnrwIMjsR5rFTVqyG2r/vHGSpqDoLm@HnXnz5jENhQ/r/ThqTyGgAkFB49TY3kLnuaCsVDIrdeK6EKnTFpWQikkLBXVRC/mjelEoykqYlKQShpvllcy1Qos3zpFQqZFybMl1yHPsHsEy86@AOSTAcYjPsb/vcIPQHE4c2vOtMRDrFGLD2DIkH@Z6G6GHvnfWcLsWM1POul1EVv4N/w64SqyxwTZJLvNYRHBD@vuVEtNdxBZnxAXF0Cne2RhbIax4HSvo8UvXnvZhzF4fBh/dE/XUvpyPtpoWb6f8nbefTnm7W3YZvgE)
The input type of the function to be curried is a nested tuple in a cons-like structure. The uncurried version of a function that adds 3 numbers together would look something like this, where it ends in an empty tuple.
```
myAdd :: (Int, (Int, (Int, ()) ) ) -> Int
myAdd (a, (b, (c, _))) = a + b + c
```
It works from the bottom up. There's an instance to curry a function of type `() -> r` that just applies the empty tuple to the function. Then there's another instance of `C` that can curry a function of type `(a,b)->c` if there is already an instance of `C` for `b -> c`.
Here's an `uncurr` function to accompany the currying function:
```
class Uncurry a b c d where
  uncurr :: (a->b)->c->d
instance Uncurry a r (a,()) r where
  uncurr f (a,()) = f a
instance Uncurry a b c d => Uncurry e (a->b) (e,c) d where
  uncurr f (e,c) =(uncurr(f e) c)
```
[Try it online!](https://tio.run/##zZNda4MwFIbv8ysOdBcJMxe1d4JCka0Uug/YejcYMUmpzNriB10Z@@3uRONMP9jF2MWUaPS85z2PJ3EtyjedZc0HH8Fiej9bTmc3cFdnVfooCrF5Pux0nImy1CWM@Cc5kt1m@j1NMj3Py0rk0krIRqQ5BAHMH4Cy7ikEtSUAu7p6qopFDldQrrd7vG0OU6WAjj2gPo4JDoYHajNdgayLItUK0yVtlaz1zSvg0fntYoHeYgw@TKxtnQ/GtHvodX0Nin6eczFQQxmHzTdwjuMv@XwLSLqG9ATHV0Qwp3WzrRMYSHBID14NZAgCriHBIQkZvupHMEcmMFWemJj1h9iGFOzXutAgg4AKHiWMR5JHiqR2E0CMSIiatHqrNfNQICcGHOW3ZRjFVHsCkzQ1bszNk/RF8chkK8wmTcezbFt@OKbCFtv1NB108YaqQ2IBHSpOTrJXfSTEqbiY3IN/v9K2IOCXSHZOtLKB0G45ugLNQLLmH/8vf7odmy8)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 5 bytes
Good ol' Mathematica built-ins
```
Curry
```
Takes 2 arguments, the function and the number of arguments.
[Try it online!](https://tio.run/##TY29CsJAEIT7PMWAnZ7kvzAhlS9gvyxh70dMESPHCfr05xkRMrDbzHwzs4SbmyVMRqJ5ej/Ec/rveF0WklFBpzMjoxsgOEBjD9NnWvzGVbD/xPGXQA7bZxc/3QN9WynVKdRMLVPFVDNj1Q7u9XAmONuhLLdAWlBomMqiYGpWqk3UFmhOVd5m8QM "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Julia 1.0](http://julialang.org/), 40 bytes
```
f>n=n<2 ? f : ((x...)->y->f(x...,y))>n-1
```
[Try it online!](https://tio.run/##LYkxDgIxDAT7vGJLWzjROdchzvAVGh8gFAqESO7zuQhRrDQz@/g871etvbuVpZwyznAcQVRTShytRfMfS2O2ErU7FlCVJhsjGupBpzY2bWEdj9scwuV9e33hpJJl5r@upEyZaYS@Aw "Julia 1.0 – Try It Online")
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), ~~58~~ 57 bytes
```
∇r←(a f g)x
:If a[1]=≢a
r←g 1↓a,x
:Else
r←(a,x)f g
:End
∇
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v//UUd70aO2CRqJCmkK6ZoVXFaeaQqJ0Yaxto86FyVygaTSFQwftU1O1AHKueYUp3JBlOtUaAI1AIXyUriAZvx/1DdVASihoKGhYaxgDDSs@lFXk7b@o96ttZoKhgqaRpr/AQ "APL (Dyalog Classic) – Try It Online")
Calling syntax (with curried function `g`, arguments `x1` through `x3`, and number of arguments `n`):
`((n x1 f g) x2) x3`
Requires `⎕IO←1`
[Answer]
# [Julia 0.6](http://julialang.org/), 48 bytes
```
c=(f,n,a=[])->n>1?x->c(f,n-1,[a;x]):x->f(a...,x)
```
[Try it online!](https://tio.run/##TYy9CsJAEIT7e4r1SLGrm4C/iJIIVpY2VmKxuURzcjklKOTt4x1aWAyzM8s397ezshpgMDle2bPk5wulhS@muz4tTOzSKZ9l219oE5orSpZl3NNgxBkULtkQ5CAwgRLGYNQtJIPxyzAn9eysfzmPN5wRLgnXREo19ktyFVl9qJ17MCQSVAYFUnwFCVY00r/BxjIs/uf0QTqrCfWplWjHrm6j75s6HqSGDw "Julia 0.6 – Try It Online")
Port of @EricTheOutgolfer's Python answer.
[Answer]
**Java 8... Using lambda insanity, 152 bytes**
Ok so I know that there is already a java 8 answer, but I wanted to use one using almost entirely lambdas without the use of java's Function<> class.
Here is the functional interface for the lambda expressions
```
interface K{Object f(int...x);}
```
And here is the actual expression
```
a->a.length==2?(K)c->a[0]+a[1]*c[0]:a.length==3?a[0]+a[1]*a[2]:(K)b->(b.length == 1)?(K)c->a[0]+b[0]*c[0]:a[0]+b[0]*b[1];
```
Yeah, so I know this looks really crazy, but the latter is mainly just using ternary operators to distinguish different number of arguments to what needs to be returned.
Given the submitted function
```
K function = a->a.length==2?(K)c->a[0]+a[1]*c[0]:a.length==3?a[0]+a[1]*a[2]:(K)b->(b.length == 1)?(K)c->a[0]+b[0]*c[0]:a[0]+b[0]*b[1];
```
`function(a, b, c)` is `function.f(a, b, c)`, `function(a)(b)(c)` is `((K)((K)function.f(a)).f(b)).f(c)`
Basically any situation that results in a curried result, the answer must be cast to `(K)` so then it can have a function called on it, otherwise the result is an integer. You can even do the following! `(function(a))(a,b)` which would be `((K)function.f(a)).f(b,c)` etc...
This probably took me way too long, and we already have a java 8 answer, but I feel like it is still an interesting way to go about it.
[Answer]
**[Lispy](https://github.com/andrakis/node-lispy), 169 bytes**
```
(define f(lambda A(begin(define G(lambda(X)(if(>=(length X)C)(proc:apply(head A)X)(lambda Args(G(concat X Args))))))(define C(length(lambda:args(head A))))(G(tail A)))))
```
Implements the [generic abritrary ES5 currying algorithm](https://rosettacode.org/wiki/Currying#Generic_currying) on Rosetta Code.
Ungolfed and test:
```
(begin
;; f is a lambda that captures all arguments
(define f (lambda Arguments (begin            ;; function extraCurry(f) {
    (define F (head Arguments))
    (define A (tail Arguments))
    (define _curry (lambda (XS)               ;; function _curry(xs) {
        (if (>= (length XS) intArgs)          ;; xs.length >= intArgs ?
            (proc:apply F XS)                 ;;   f.apply(null, xs)
            (lambda Args                      ;; : function() {
                (_curry (concat XS Args)))    ;; return _curry(xs.concat([].slice.apply(arguments)))
        )
    ))
    (define intArgs (length (lambda:args F))) ;; intArgs = f.length
    (_curry A)                                ;; return _curry([].slice.call(arguments, 1))
)))
(define product3 (lambda (a b c) (* a b c)))
;; [14, 28, 42, 56, 70, 84, 98, 112, 126, 140]
(print (map [1 2 3 4 5 6 7 8 9 10] (((f product3) 7) 2))))
```
Try online link coming soon.
[Answer]
# Dotty, ~~345~~ ... ~~221~~ 186 bytes
```
def>[F,T,X](f:F)(using? :F TupledFunction T,e:T=>X)=e(?tupled f)
given[A]as((EmptyTuple=>A)=>A)=_(Tuple())
given[A<:Tuple,B,C,D](using t:(A=>B)=>C)as((D*:A=>B)=>D=>C)=f=>h=>t(c=>f(h*:c))
```
[Try it in Scastie](https://scastie.scala-lang.org/YZMS7304S8e11GAlA9N0RQ)
**This will not work in Scala 3.0 as `TupledFunction` will be [removed](https://github.com/lampepfl/dotty/commit/f4e1ca4f565c74fbe1aa56ea88ce6f59409ccdf0).** However, it may be added back later.
This one doesn't do any unsafe casting or other trickery.
`>` is the method to call. The type parameters `F`, `T`, and `X` represent the type of the input function, the type of the input function if it took a single tuple instead of multiple arguments, and the type of the resulting curried function, respectively. The first parameter, `f`, is the function to be curried. There are also two implicit parameters, `?` and `e`. `?` is a `TupledFunction` object that can convert between `F` and `T`, i.e., tuple and untuple a function. It is provided in the standard library automatically, and makes it easier for `e` to do its work.
`e` operates on the tupled form of `f`. There's a base implicit function that takes an a function `EmptyTuple=>A` and returns an `A` by just passing an empty tuple to that function. Another `given` builds on top of that by deconstructing `f` into `D *: A => B` (`D` is the type of the first parameter of `f`, `A` is the type of the rest of the parameters as a tuple, and `B` is the type of `f`'s result). It uses another implicit function of type `(A => B) => C`, where `C` is the curried version of `A => B`. This second case returns a function taking a `D` and then applying `t` to a new function where the `D` from before is cons-ed to an `A` before applying `f` to it.
## Dotty, 144 bytes
```
def a[T](x:Any)=x.asInstanceOf[T]
def c[T,R](f:T=>R,n:Int):Any=>Any=h=>a(n match{case 1=>f(a(Tuple1(h)))case _=>c(t=>f(a(h*:a[Tuple](t))),n-1)})
```
[Try it in Scastie](https://scastie.scala-lang.org/3QJTPxrITk2tA0A2xns7Jw)
Requires function to be tupled beforehand.
[Answer]
# [Factor](https://factorcode.org/), 6 bytes
```
ncurry
```
[Try it online!](https://tio.run/##BcExDkBAEAXQ3il@TSJBxwFEoxGVKCabwcYaMkbB5dd7Czk7NY5D17c1VhZWCv4j86fc2FmFAw6yDZey2XupF0OTJAVKVJiQIsOMMop7VN@Y33CBSeMP "Factor – Try It Online")
Builtin.
A non-trivial implementation might be:
```
[ [ curry ] times ]
```
Currying is a pretty uncomplicated affair in a concatenative language. :)
[Answer]
# [Ruby](https://www.ruby-lang.org/), 12 bytes
Ruby has a built-in method `curry` which can be called on a lambda that gives the desired behavior. The below code returns a lambda that calls `curry` on its argument.
```
proc &:curry
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhZrCorykxXUrJJLi4oqIUI3ddMVbBV07RJ1knSSqxUStZO0khVqubjS44HCbtHpsVxcBQrp8dGGOkax0caxEE0LFkBoAA)
]


[Question]
      [
We all know that a lot of exercises only affect one half of your body, so you have to do them twice, once for each side. Such exercises have two counterparts, one for the left side and one for the right. However, there's no need to execute the two counterparts consecutively, as long as the exercises for both sides are in the same order. You may as well switch between sides in your exercise program, but it wouldn't make sense to start some exercises with one side and some with the other.
## Challenge
An *exercise part* is a list of non-zero integers, where its second half consists of the integers of the first half negated and in the same order, and the signs of the integers on each half are equal. The sign of the first half of an exercise part is its *leading side*.
An *exercise set* is zero or more exercise parts with the same leading side concatenated together.
Given a list of non-zero integers as input, determine if it is an exercise set. The integers aren't necessarily unique. The list's length isn't necessarily even.
Your solution may not use any of the [standard loopholes](https://codegolf.meta.stackexchange.com/q/1061/41024). You may use any two different consistent values for output. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest solution wins.
## Examples
`[-5, -1, -7, -6, -5, 5, 1, 7, 6, 5]` is an example of an exercise part. The first half is `[-5, -1, -7, -6, -5]`, and the last half is `[5, 1, 7, 6, 5]`, which is each integer in the first half negated. Additionally, the first half's integers are all of the same sign. This exercise part's leading side is `-1`.
`[3, 6, 5, -3, -6, -5, 1, 6, 4, 3, -1, -6, -4, -3]` is an example of an exercise set. Its individual exercise parts are `[3, 6, 5, -3, -6, -5]` and `[1, 6, 4, 3, -1, -6, -4, -3]`, and they both have leading side `1`.
`[4, -4, -5, 5]`, despite only consisting of valid exercise parts, isn't an exercise set, since the first part, `[4, -4]`, has leading side `1`, while the second part, `[-5, 5]`, has leading side `-1`.
## Test cases
Valid test cases:
```
[]
[1, -1]
[1, -1, 1, -1]
[-6, 6, -5, -4, -3, 5, 4, 3]
[-1, -5, -8, 1, 5, 8, -7, -6, -5, -3, 7, 6, 5, 3]
[-1, -5, -8, 1, 5, 8, -1, 1]
```
Invalid test cases:
```
[1]
[1, -2]
[1, 2, -3, -1, -2, 3]
[1, 2, 3, -3, -1, -2]
[-1, -5, -8, 1, 5, 8, 7, 6, 5, 3, -7, -6, -5, -3]
[1, 2, 3, 5, 1, 2, 3, 5]
[1, 2, -5, 4, -6, 5, 5, -6]
[1, 2, -1, 3, -2, -3]
[1, -2, 1]
[-1, -1, 1]
[1, -1, 1]
```

[Answer]
# [Python 2](https://docs.python.org/2/), ~~69~~ 67 bytes
```
a,b=x=[[],[]];k=0
for n in input():x[n>0]+=n*n,n*k>0;k=n
print a==b
```
[Try it online!](https://tio.run/##fVCxbsMgEJ3DV9xGk4JkcJ1UqciWrl26UQY7IorlCluIqM7Xu4ex66hSK3Hw4O69e0d3C5fWyeHrUn9aePdXuyer4G@4r2xvT0ApHUpWqV5pbZg25qVRGTm3HhzUcXXX8LDe99odMvOo3MYxt2kOGZY50vnaBSiVqgbUIah4sl2A49vr0fvWxyaVt2UzaEO0YMDFfDKYr3zLABcvMJ4wcgYIEeUxKabM80hAhIDvMGYKlu9GgeI/RuxnSBqGfji6RhuTFZlOmbRGukxS6TW/T/zVYLHw2969TjEyJry0TePyJBBJ2yUnkqRcpCIWs48018@Xmm8 "Python 2 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
ṁṠŒg$+2/FẸ
```
[Try it online!](https://tio.run/##y0rNyan8///hzsaHOxccnZSuom2k7/Zw147/h9sfNa0BIvf//6Ojo2N1uBQUog11FHQNkZg6CkgiumY6CkCkawrEJkBsrKMAZAJZxlB5Q6ikBVgbkAVk6JoDMUwXUIc52AxTkCaQruhoJOuM4EwjiGKwiUZwCyASxshyeGxG2ITuCjTTTMGaoGwUJ0C8pwsxBqTVDEXaEGI22LGxsVyxAA "Jelly – Try It Online")
[Answer]
# Java 8, ~~186~~ ~~183~~ 185 bytes
```
a->{int i=a.length-1,t,j;boolean r=i%2>0,f;if(i<0)return!r;for(f=a[i]<0;i>0;){for(r&=f==(t=a[j=i])<0;j>0&&t>>>31==a[--j]>>>31;);for(t=i-j,i-=2*t;j>=0&j>i;)r&=a[j+t]==-a[j--];}return r;}
```
+2 bytes due to a bug-fix for test cases of size 3 (almost all permutations of `1` and `-1` at the end of my TIO-link).
Can definitely be golfed.. The challenge looks to-the-point, but it's pretty hard to implement. Especially the test case `[4,-4,-5,5]` was annoying to fix.. But it works now. Will golf it down from here.
[Try it online.](https://tio.run/##nVRNU6QwEL37K7KHnQJNj3wMo7UxHL3pRW9THCKChsVghYxb1hS/fbYTxq31orYFFHS6@3W/1wmdelHQ3f/e170aR3altNkdMaaNa2yr6oZde5Oxu2HoG2VYHaFrUzEVC1yf8MF7dMrpml0zwyTbKyh3GMS0VMu@MQ/uEVLueCfeMKzUP7My4a3QbaQvktg2bmvNDyvawUatVBtdXSRCl4mId37JLmQrZeTQ00ldxejsymSxcGVZ5qnEZYCuCoaIA4iTGjquQWbHDmNlsuhKLWIEQogTV0kJ@AFQiWkuzqyY9mKm87y965HOgdXLoO/ZE@oS3TirzUMgP4tyespu7dY9vv4K5s3r6Jqn5bB1y2eMdL2JzLKOTPPH67lJqjiI9mlgtUs5pBMpmtNSYM3XHAoOKw45L/iK54TkNKSeY82Cn3M44zCD5fwMYQsSVuGb/wdRIGbA@DpCHkpi7RkhRRPZBNT1zO8jrIMHJ3mp@rH52iRRctJ0Mkp0Frj4LIqOPi8/ZGbfHqWXPv9/oNQGvP7hTWTsdyD4OWLRNTE39S1npGZXYWMUtDbxooXTzzAxnnTiiQTovxQqBXjPYTqa9n8B)
**Explanation:**
```
a->{                   // Method with integer-array parameter and boolean return-type
  int i=a.length-1,j,  //  Index integers (`i` starting at the last index)
      t;               //  Temp integer
  boolean r=i%2>0,     //  Result-boolean, starting at true if the input-list is even
          f;           //  Flag-integer
  if(i<0)              //  If the input was empty (edge case)
    return!r;          //   Return true
  for(f=a[i]<0;        //  Set the flag-boolean to "Is the current item negative?"
      i>0;){           //  Loop down over the array
    for(r&=f==(t=a[j=i])<0;
                       //   Set `s` to the current number
                       //   And verify if the initial flag and `s` have the same sign
        j>0            //   Loop `j` from `i` down as long as `j` is larger than 0,
        &&t>>>31==a[--j]>>>31;);
                       //   and both `s` and the current item have the same sign
                       //    Decreasing `j` by 1 every iteration
    for(t=i-j,         //   Set `t` to `i-j` (amount of same signed adjacent values)
        i-=2*t;        //   Decrease `i` by two times `t`
        j>=0           //   Loop as long as `j` is larger than or equal to 0,
        &j>i;)         //   and also larger than `i`
      r&=a[j+t]==-a[j--];}
                       //    Verify if the pairs at index `j+t` and `j`
                       //    are negatives of each other
  return r;}           //  Return if `r` is still true (if all verifications succeeded)
```
[Answer]
# [R](https://www.r-project.org/), 91 bytes
Inputs a whitespace-separated vector of numbers. Outputs `FALSE` for valid and `TRUE` for invalid.
```
x=scan()
y=x<0
z=rle(y)
"if"(sum(x|1),any(x[y]+x[!y],z$v==rev(z$v),z$l[!0:1]-z$l[!1:0]),F)
```
`rle` gives the run length encoding, in this case of the sequence of positive and negative values.
The *completely and totally unfair empty edge case ;)* adds a whopping 15 bytes.
Many bytes shaved off by @Giuseppe.
Here is a 92 byte version expressed as a function which is better for testing:
[Try it online!](https://tio.run/##fZHdasMwDIXv8xRu6YXMZIiTpR1lvu1LhFyEkLCAl5X8FLvs3VPFTppssIEFnyTOkWy3Y98O/YdVuu56KIBjUIBEJuRKyNaCOCKjIxKKV4oYGSFR7Nty7r05ERGBOFEsIhKcnEXyv2aaynkQVLnuyud661bRQpE3dS7R4unr8bb196x1n9@7/vRKnGbm7Xj/AsKbTMLjtiu9cbQ1nDJ/PTVWQ1P09VcDBq0y7yHeVatLsJzv62oP3fAJ5psunjcWTGqzF5PubIb3w02ptrwBAadMp7vwLDPhSJ7DjOOFj11@vWoL/pORVTyYK/5dp8r4AA "R – Try It Online")
[Answer]
# JavaScript (ES6), 54 bytes
Optimized version, inspired by [Dennis' Python answer](https://codegolf.stackexchange.com/a/165378/58563).
Returns **0** or **1**.
```
a=>a.map(b=p=x=>b[+(x<0)]+=[x*x,p*(p=x)>0])|b[1]==b[0]
```
[Try it online!](https://tio.run/##jVBLDoIwFNx7Cna22hIKgi4sF2m6aBX8BIUAGky8Oz4pxh81Jn3JZDqdN9O9OqtqVe6Kmmqlk4we83XSprxVPFbuQRVI84I3PNZiipqlh@WUi2bSkGKCgMexJ/FVCyY518KT7So/VnmWuFm@QWNRl6d6e5FjPHrlUyQk/qIYcSiz8cSxXdOIOHBoCDODCYgDEFAwJGa9ctEZAgJA5zAPC3g@7wzD3mH03ihVWTVUyJbcH@Z9s6rL4w9nNargVfhvo2eDz3a/9oSdQ4/tsc3vUrPgbhrZtcxE8PvV7Q0 "JavaScript (Babel Node) – Try It Online")
---
# Original version, 74 bytes
```
a=>a.map(x=>b[i^=p*(p=x)<0&&-~(b[i]+=0)]+=[,x*x],b=[p=0,i=0])|b[1]+0==b[0]
```
[Try it online!](https://tio.run/##jVDRboIwFH33K3jSVlvTwlAfvP5I0yWtgmNh0ggaliz7dXZHWaYbXZZwm5PT03PP4dlcTb0/F67h1tis5KfqkHU5dAZ2ZvliHGlhZ1XxCG5OHLR0K6ZT/k6Q0gsQFA/F2nmrmQXlQLAChKZvVkm9EABWCd3tq1NdldmyrI5kpprzpXl61TM6ueVzojT9RUkWcRniWRS65isW4cdTnAechEUIESVjYjkoN70hIgR8jfNlgc/XvWE6OEzuG@WmrMcKhZLH43zsV/V54vGsXpXcCv/b6LvBz3Z/7Ul7hwGHY/u/y/2CT9NVWCt9hHhY3X0A "JavaScript (Babel Node) – Try It Online")
### How?
We store the first halves of all exercise parts in **b[0]** and the second halves in **b[1]**, switching between **b[0]** and **b[1]** each time the sign is changing. Entries are squared to get rid of the sign. We prefix each entry with a comma and suffix each part with a **0**.
There's some extra logic to handle the 'empty input' edge case at basically no cost (see the comment near the end of the source code).
```
a =>                    // given the input array a[]
  a.map(x =>            // for each x in a[]:
    b[i ^=              //   access b[i]:
      p * (p = x)       //     we keep track of the previous entry in p
      < 0 &&            //     if p and x have opposite signs:
      -~(b[i] += 0)     //       append a '0' to b[i] and update i: 0 -> 1, 1 -> 0
    ] += [, x * x],     //   append a comma followed by x² to b[i]
    b = [p = 0, i = 0]  //   start with p = 0, i = 0 and b = [0, 0]
  ) |                   // end of map()
  b[1] + 0              // this will append a '0' to b[1] if it was turned into a string
                        // or let it unchanged if it's still equal to zero (integer),
                        // which handles the 'empty input' edge case
  == b[0]               // compare the result with b[0]
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~147~~ ~~130~~ ~~113~~ ~~112~~ 106 bytes
```
from itertools import*
def f(s):l=[map(abs,g)for v,g in groupby(s+[0],0 .__cmp__)];print l[1::2]==l[:-1:2]
```
[Try it online!](https://tio.run/##fY/NDoIwEITvPsUeQVtji6DB8CQNIf4VSYA2pZr49Li0qODBpNt8MJmZrX7am2p530ujGqjs1Vil6g6qRitjl4vLVYIMujCtM9EcdXA8daQMpTLwICVULZRG3fXpGXQrscnJBtZFcW50UYT5QZuqtVALlqY8z7JapJQh9TIQebjAmxGgbIIEJn9oQgAPjXG2OBEBRKRo1Nko7p0NCYHucN4udOxcRuxNbh9X9u3kH@Te4WL5p8UL0VT7U/@t@13lJy12ppFnK/g3Uh8zWJOZzHw2n2UOn8Ob@hc "Python 2 – Try It Online")
---
Saved:
* -27 bytes, thanks to Dennis
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 57 bytes
```
^\b|,\b
$&=
(.)(\d+),(?=\1)
$2_
-|=
.$
$&,
^((\w+,)\2)*$
```
[Try it online!](https://tio.run/##dU@9DsIgEN7vKRjQgD2aQG3r0vgSbqU/Njq4OBgTl747XqGExsSEy33w/YXX/f14Xt1OXMaWdePgejvNaCfg@wZELoW9ZRLFubFaAjcDqLkByDnxCL0Q9pOhtEYeuHNtB61GpnTcyOJVVcjoqJLmSFMgI0ioWEi9MidvIERA1TTRQvLaB5TBERtM2CZIfI5ZFf612BL/mlLyb@s2p/SOFafa8AsVAhZTlTgdIk2KWrDuvg "Retina 0.8.2 – Try It Online") Takes comma-separated input, but link includes header that processes test cases. Explanation:
```
^\b|,\b
$&=
```
Insert a marker before each positive integer.
```
(.)(\d+),(?=\1)
$2_
```
Change the commas between integers of the same sign to underscores.
```
-|=
```
Delete the remaining signs.
```
.$
$&,
```
Append a comma if the input is not empty.
```
^((\w+,)\2)*$
```
Check that the string consists of pairs of runs of the same integers.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~18~~ 14 bytes
```
~c{ḍz{ṅᵈ¹ṡ}ᵛ}ᵛ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/vy65@uGO3qrqhztbH27tOLTz4c6FtQ@3zgbh//@jjXXMdEx14o114s104k11DIFcEx0gzxAsYAKUiQUA "Brachylog – Try It Online")
Saved 4 bytes thanks to @ErikTheOutgolfer.
### Explanation
```
                    Succeed if and only if:
~c                  You can deconcatenate the input list…
  {         }ᵛ      …and verify that for each of the sublists:
   ḍ                  Split it in half
    z                 Zip the elements of each half together
     {    }ᵛ          Verify that for each couple:
      ṅᵈ¹               The first integer is the negation of the second one
         ṡ              Take the sign of the first one
                      All signs should be equal in a sublist
                    All leading signs of the sublists should be equal

```
[Answer]
# [Python 2](https://docs.python.org/2/), 111 bytes
```
x=input()
o=[];p=[]
for a,b in zip(x,x[1:]):
 if 0<a*x[0]:
	p+=a,-a
	if b*a<0:o+=p[::2]+p[1::2];p=[]
print o==x
```
[Try it online!](https://tio.run/##dU9da8QgEHw@f8WSl8uHQkyau2LPXyJSvGuO@hLlSMH2z6erJuQoFFx3dHZm1H/Pn27qlpv7GGVRFEuQdvJfc1kRJ5V@87iRu3uAoVewE/xYXwYaFBe6EgTsHdqLqYNqtSAH30hDmSEHvL7W5tIK10ivhOh041GCPRv6h51mcFKGBTORYTynvMeMIxxr3osxjLcyvqsiC2oUpxDHcqewHdmJAi42YL1g9RQQIuojyVfmNQkQIWBnrE2C4@dkMGTFltDl3uWR5NOtE@m2fyb@S9qd/6Y@@wxJseI9Nv@CZYMoOu0cz5bpdfoX "Python 2 – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 155 bytes
```
b=>eval('i=b.length-1;r=i%2;0>i&&!r;for(f=0>b[i];0<i;){for(r&=f==(s=0>b[j=i]);0<j&&s&0>b[--j]|!s&0<b[j];);t=i-j;for(i-=2*t;0<=j&j>i;)r&=b[j+t]==-b[j--]}r')
```
[Try it online!](https://tio.run/##jZBBboMwEEX3PQVZ1MEpE4EJSSVnuEjkBaSQ2kJQGZRN27PTwaRqVeEqkkf6mvl@821TXIv@bPXbAG33Uo0tjiXm1bVowrXGcttU7WV4hURa1I9CxrlmbGVl3dmwxjgvT1rJ@Kglf59almGNGPZuYlArTkPDWM@mBoBRHyvSRxoqyeWAGoxjaUCxGciMhpmccEQi09OgEIEEgPq0az6eu7bvmmrbdJewDU9JFECiOH9Y6keBbwz7KKADGdWOKo0CkqTSJXNycz47ICkScKD6RtD1gwNmywRfQrHcFzPS7RUeonOlv433Jv9J@vcV/@3JHOGm/bHnX4R5wQTd@73JHEH4V0@z6e/GLw "JavaScript (Node.js) – Try It Online")
---
Inspiration was @KevinCruijssen's answer
Also thanks to him for correcting 2 test cases of mine
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 13 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
Ç¥├W╦╣∩T~≥▌╨c
```
[Run and debug it](https://staxlang.xyz/#p=809dc357cbb9ef547ef2ddd063&i=[]%0A[1,+-1]%0A[1,+-1,+1,+-1]%0A[-6,+6,+-5,+-4,+-3,+5,+4,+3]%0A[-1,+-5,+-8,+1,+5,+8,+-7,+-6,+-5,+-3,+7,+6,+5,+3]%0A[1]%0A[1,+-2]%0A[1,+2,+-3,+-1,+-2,+3]%0A[1,+2,+3,+-3,+-1,+-2]%0A[-1,+-5,+-8,+1,+5,+8,+7,+6,+5,+3,+-7,+-6,+-5,+-3]%0A[1,+2,+3,+5,+1,+2,+3,+5]%0A[1,+2,+-5,+4,+-6,+5,+5,+-6]%0A[1,+2,+-1,+3,+-2,+-3]%0A[1,+-2,+1]&a=1&m=2)
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 48 bytes
```
{0::1⋄0≠+/×¨⍵:0⋄(~0∊⊢∨2|⍳∘⍴)2{⍺≡-⍵}/⍵⊂⍨1,2≠/×¨⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@/2sDKyvBRd4vBo84F2vqHpx9a8ah3q5UBUESjzuBRR9ejrkWPOlYY1Tzq3fyoY8aj3i2aRtWPenc96lyoC1RYqw8kHnU1PepdYahjBDQCZkLt/0d9Uz39FR61TVAw4HIDUrSyiAtoEdgaN4VD6011gIQhiDAHEWY6EDEgAgoChYACpv8B "APL (Dyalog Classic) – Try It Online")
]


[Question]
      [
# Background
[Boggle](https://en.wikipedia.org/wiki/Boggle) is a board game where the players have to find English words on a 4-by-4 board of random alphabets. Words can be constructed by selecting sequentially adjacent cells on the board. ("adjacent" means horizontally, vertically or diagonally adjacent.) Also, same cell can't be used more than once in a word.
The following is an example board:
```
I L A W
B N G E
I U A O
A S R L
```
On this board, `BINGO`, `ORANGE` and `WEARS` are valid words, but `SURGE` and `RUSSIA` are not:
* `SURGE` : There's no adjacent pair on the board having `RG`.
* `RUSSIA` : `S` cannot be used twice.
**Modified Boggle** is a modified version of Boggle, with the following rules:
* The board size is `n`-by-`n`, where `n` can be any positive integer.
* Each cell can contain any one byte between 0 and 255 inclusive.
* A cell can be used more than once, *but not twice in a row*.
Using the example board above, in addition to `BINGO`, `ORANGE` and `WEARS`, `LANGUAGE` becomes a valid string (since `G` is used twice, but not twice in a row) but `RUSSIA` is still not (due to `SS` pair).
Here is another example using a code fragment. The string `from itertools import*\n` can be found on the following board, but not `from itertoosl import*` or `from itertools import *`:
```
f   i   ' ' s
r   t   m   l
e   o   o   p
\n  *   t   r
```
Note that you need two `o`'s in order to match the `oo` sequence.
# Challenge
Write a function or program that, given a Modified Boggle board `B` (of any size) and a string `s`, determines if `s` can be found on `B`.
# Restrictions
**Your code itself should also fit on a Modified Boggle board `b`.** That is, you must show the board `b` in your submission along with your code, so that your function/program outputs true if it is given `b` and your code as input.
# Scoring
**The score of your submission is the side length of the smallest board `b` where you can fit your code.** Ties are broken by the usual [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules, i.e. the length of your code in bytes. The submission with the **lowest score** (for both criteria) wins.
For example, `from itertools import*\n` has the score of 4 (using the board above) and code length of 23 bytes.
# Input and Output
For input, you can take any convenient method for both `B` and `s`. This includes list of chars and list of charcodes, 2D or flattened or whatever makes sense. Also, you can optionally take the board size as a part of the input.
For output, you can choose one of the following:
* Truthy and falsy values following your language's convention, or
* One predefined value for true and false respectively.
Please specify your input/output method in your submission.

[Answer]
# Python 2, score 3, 20972 bytes
```
exec'cecxc%c'%(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1)+…
```
Full code is the output of: [Try it online!](https://tio.run/##XVLBbtswDD3HX8FpCCTNnpH0GMQFvGEoCmQdMKPYIfNBU9RUmyMLthsk@/mMpGtgqQ8SST@Sj4@K5@G5DTcX2@4cFCCE@Hmxzp5sYcI5sRnahQ/xZVA6sSd0GheURduxYw6/dmaGcATSQfgVmetCyrajP1sM1VtbFwXFt4v6drHmDoprqCl5u1zVGTrknhCgn8b8k515bPlR2duFpg6pSpepXRMbPYHcCHIEcyPQMZkR7Ca4f1L/t3hXKEZpGs4WnQl7pxiZxM6HYXZF9LUmZ0/8HNMjCrORipt8fUEx864fOh9RvOQ9fEaN9y4AAsGAfTadsYPr8mSPyo9Sgl2BkHMr50pACjKV@e8WJ5NL@aHtdqi8xrDQgup9NX8cFgrGHx30bfMy@DbkeZ5UtEnifFXjYKLaZ7RozXTKGJsz5h0ctHHwB//XUIE@T4jgEXzAXBYP6ALWAnBCOqk6sIjAglKcw@wDxwE797Hx@HZWCeBHvKq8c7Ex1qk3xOCodUbD91LMjzq5BgtEkywCIXzzCMyiQoO3BfQ2q9fVQXXZyvtN@UNm8tPD3Re87h/Lb3iV1feNrDOQm/Lh7rHEX/8A "Python 2 – Try It Online")
Fits on the Boggle board:
```
e x (
c % 1
' + )
```
Decodes and executes this program:
```
cecxc=any
c,cec=input()
cxec=len(c)
cexec=lambda    cxc,cexc,c,cec:cexc<=''or   cxc[cec][c]==cexc[0]>0<cecxc(cexec(cxc,cexc[1:],cxcxc,cxcec)for cxcxc   in(c-(c>0),c,c+(+1+c<cxec))for  cxcec   in(cec-(cec>0),cec,cec+(+1+cec<cxec))if(cxcxc,cxcec)!=(c,cec))
cxc=range(cxec)
print   cecxc(cexec(c,cec,cexc,cxec)for cexc    in  cxc for cxec    in  cxc)
```
Which takes input like: `['ILAW','BNGE','IUAO','ASRL'], 'LANGUAGE'`
[Answer]
# [CJam](https://sourceforge.net/p/cjam), score 2, 9351 bytes
```
'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~)))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))~))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))~'))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))~'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))~'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))~
```
[Try it online!](https://tio.run/##7VmxCgMhDN37FcVF7jNSOORArtBydCgdSrdCf8FftzcUOisx9@LFxcnkvZgXo77ez0/OfviNNAiObby2wdGQS51pWFIsRiFSRwYEeHYq3FYdEYUJKCvV5sVMrDL0U4Lgzq4tXCgRNIQc8diY6jGZIKpKjdJ5PQhlLtCdoXRVJ4qAlASoCxMF6IFX43a3JxpqFyOYO5WuQJppNhx4Txv23IeNg5sVSJQKYSh5ZO02/lph2x5qLC96vztbIscNrfwPqN16rDeyTmknnVLRSJ7L0n@tb0MwabOb891N8Ubu6E5zGNdpWui8TnS9RPc4RJrDQmH8Ag "CJam – Try It Online") Expects input like:
```
["ILWA" "BNGE" "IUAO" "ASRL"]
LANGUAGE
```
and fits on the Boggle board:
```
' )
~ )
```
Constructs the string `l~:Q,:K;{\:Y;\:X;:C,!_{;QY=X=C0==_{;[X(XX)]K,&[Y(YY)]K,&m*[XY]a-C1>:D;{~DF}%:|}&}|}:F;l:R;K,2m*{~RF}%:|~` then evaluates it as CJam code.
[Answer]
# [Clean](http://clean.cs.ru.nl), score 12 (175 bytes)
(This is almost certainly going to be outgolfed by an esolang and probably normal languages as well.)
```
import StdEnv;>[]_ _ _ _=True;>[c:s]i j n a=i<n&&j<n&&i>=0&&j>=0&&a.[i,j]==c&&or[>s k l n a\\k<-[i-1..i+1],l<-[j-1..j+1]|i<>k||j<>l];$n c a=or[>c i j n a\\i<-[0..n],j<-[0..n]]
```
This defines a function `$ :: Int [Char] {#String} -> Bool` which checks whether the second argument (the word) can be found in the third argument (the board) given the first argument as width.
In the board on which this fits (see below), `*` marks unused places. There are 16 of those, on a board of size 12×12 = 144, meaning 128 are used effectively (an **efficiency** of **175/128 ≈ 1.37**). It may be possible to get the same program on 11×11, but this is all done by hand and very tedious; my boss probably wouldn't be happy if I would try to get it on 11×11.
```
* * & & * * * * * * * ;
s [ n < j * * u r T > v
  > r & i > * e =   [ n
l k o & 0 = n   ; _ ] E
  & a . = ] a j i > [ d
a n & c [ j . + ] s c t
\ k < - i , - . 1 | : S
\ * 1 l . + 1 = i j |
[ i \ . , ] o a < > k t
0 - < \ a   r >   l ] r
. j , * n j [ i c $ ; o
. n ] ] * *     n i m p
```
[Try it online (with the program itself as input)!](https://tio.run/##tZHBjtsgEIbP9VOMspEjEZuNe1wbn7qHSr0lNxutWEyzYAxZIJFWdV@9LiG7PfVWFaTRzKcZ4P/hWjCzTHY4awETk2aR08m6APswPJpL3Xb0CdImB3cWseYPnkpQYIAR2Zg8V9cgW7KLaYoMd7JQlBCe59Z1rYcR9LW/78em7GRZYSy3FS10rNS1UrGaZdOO86yaVtN6bYDH86/THN5v63sZ@3cYG1qoj4wu@8DicwmsofoMJ2ePjk3wbJkbsuz@Hg4vAjybBHA7CGAe2LO9iOyjkUC3@a@K/1Xz31Vv6B9xSWoNxgYB4YUF6MGJ17N0woPwnJ2kORbgLcgAgxXebAJoa8folQjhLUvz0Ycfd9mnFUJ5jm6rXhUR@M40CqGzO7SXBKB1UToS0TiTgB5tviMG6if6eOuIdhDKlGy7IQFmct4pvKWehwSSJ7IocTU/7N8JqjTeVkSqGRLpZN/jgloWHbpN7cqm7xm4FjR1iWBVIKM6yde1vYFoDUIAJn7p6me2/OLfNTv6pfz6bfnyZtgkuf8N "Clean – Try It Online")
[Answer]
# Java, score 23, ~~538~~ 507 bytes
NSFW
```
import java.util.function.*;import java.util.stream.*;class B{static BiFunction<char[][],String,BiFunction<Integer,Integer,Byte>>f;{f=(b,s)->(i,j)->{try{if(b[i][j]!=s.charAt(0))return 0;}catch(Exception e){return 0;}if(s.length()<2)return 1;byte t=0;for(int k=9;k-->1;){t|=f.apply(b,s.substring(1)).apply(i+~k%3+1,j+~(k/3)%3+1);}return t;};BiFunction<char[][],String,Byte>g=(b,s)->{int l=b.length;return (byte)IntStream.range(0,l*l).map(i->f.apply(b,s).apply(i%l,i/l)).reduce((x,y)->x+y-x*y).getAsInt();};}}
```
[Try it online!](https://tio.run/##tVLBjtsgEL3vV9CVVoYEs0n3VLG2tJZaqeccrRywgx1sQiwYb2NR76@nOOtkV6rUW5HQAE/z3pthGvEq4mbXns/q0B0toCY8sB6UZlVvSlBHwxb8L8yBleIQkFIL51DmHQhQJcrUjznrudwLm2/zLd2AVaamn6CfBmQtLb3GbACZphX3VYIL6kicYkWbEDzYwasKF7na5s32S@LYRPsCeEWIldBbg1Z8LAWUe/z9VMpu4keS@A8wpDumpalhj8nz12vamhdBFUGy4tXRYmUAtck33sZxuubEw@@kYqLr9DA5Yq4v3KUMvCZkflfLt/bhabmmzfINt49PZLoQPs4CwEf@r3ZMNdfXev2kr5NiNspnDjx5JKFNm/d@W2FqiVdULzRhB9FhFaefbN6cPWiqHnVwauWuLyXGJzoEldNyiE@LgbBawosLtDjY5Wc0r83gQB7YsQfWBY@gDa5nRiN/oWsF3kcuopEIW0Yj9VERTibs9nIrw6m84ONI0b0zopX3hPC7/ysTxvCmMt5dQtcXOszkPJqvR7VDB6EMfv@BfIuErR1B/uYsQwVK0GQiwzeq8fwH "Java (JDK 10) – Don't Try It Online")
Compiled with JDK 9, but should work with 8.
I didn't know what to do with the imports and static field (which is in fact necessary), so I decided to just take the whole class and stick the lambdas in a initializer.
The lambda `g` can then be applied on a 2D array and a string, and returns `1` if the string is in the board and `0` if not (as a `Byte`, 3 characters shorter than `Integer`).
Credit to [this](https://codegolf.stackexchange.com/a/164762) guy for a (in my case) shorter than hardcoding way to address neighbouring cells.
Somewhere in the progress of making this monstrosity I got invested in making it work with lambdas it got progressively worse and worse until this happened. It doesn't even get close to the other answers and it is probably not even close to the optimal solution in Java, but hey, it fits pretty neatly on a 23x23 board (which is not optimal, but perhaps closer than the program itself):
```
duce((x,y)->x+y-x*y).ge
e l=b.length;return (bt
rt3+1,j+~(k/3)%3+1);}yA
.n%te t=0;for(int k=rts
)iky0;}catchExcepti9e)I
){~b (b,s)->(i,j)-o;tIn
l>+;n=ring,iFunct>nkunt
/-i1rftass B{stai{ -rt(
i)( u{Slport jatote-nS)
,synt;,cmutil.vinr)> t;
l,lref];i.porfac<y{1tr}
%bpur>[*;amitu. I{r;}e;
i(pt)>].*vaj nuBnie);a}
y=ae)e[m.noitctitft{Bm}
lg.r0traerts.liFe(uti.}
p>))(yhc<noitcnugbr|Fr
pe12tB,regetnI,re[n=ua
at(<Arahc.s=!]j[]i fng
.yg)(htgnel.s(fi};0.ce
)Bnirtsbus.s,b(ylppat(
s,gnirtS,][][rahc<noi0
,b(ylppa.f>-i(pm.)l*l,
```
Of course, at that point there was no point in trying to make that by hand. So as a bonus, here's the (naive) function I used to compress the code onto the board:
```
static char[][] toBoggleBoard(String s, int n) {
    char[][] board = new char[n][n];
    int i = n / 2;
    int j = i;
    int[] d = {1, 0};
    s = s + s.charAt(s.length() - 1); //the last char gets eaten don't ask me why PS editing loop condition does make it work but causes a StringIndexOutOfBoundsException
    board[i][j] = s.charAt(0);
    s = s.substring(1);
    while (s.length() > 0)
    {
        int[] ra = add(d, right(d));
        int[] r = right(d);
        int[] l = left(d);
        if (board[i + d[0]][j + d[1]] > 0)
        {
            if (board[i + d[0]][j + d[1]] == s.charAt(0))
            {
                i += d[0];
                j += d[1];
                s = s.substring(1);
            }
            else
            {
                i += l[0];
                j += l[1];
                board[i][j] = s.charAt(0);
                s = s.substring(1);
            }
        }
        else if (board[i + ra[0]][j + ra[1]] == s.charAt(0))
        {
            i += ra[0];
            j += ra[1];
            s = s.substring(1);
        }
        else if (board[i + r[0]][j + r[1]] > 0)
        {
            i += d[0];
            j += d[1];
            board[i][j] = s.charAt(0);
            s = s.substring(1);
        }
        else
        {
            int[] rb = sub(r, d);
            d = r;
            if (board[i + rb[0]][j + rb[1]] > 0)
            {
                continue;
            }
            else
            {
                i += d[0];
                j += d[1];
                board[i][j] = s.charAt(0);
                s = s.substring(1);
            }
        }
    }
    for (int k = 0; k < board.length; ++k)
    {
        for (int l = 0; l < board.length; ++l)
        {
            if (board[k][l] == 0)
            {
                board[k][l] = ' ';
            }
        }
    }
    return board;
}
static int[] left(int[] d) {
    return new int[]{-d[1], d[0]};
}
static int[] right(int[] d) {
    return new int[]{d[1], -d[0]};
}
static int[] add(int[] x, int[] y) {
    return new int[]{x[0] + y[0], x[1] + y[1]};
}
static int[] sub(int[] x, int[] y) {
    return new int[]{x[0] - y[0], x[1] - y[1]};
}
```
It maps it's input onto a spiralthe snaking implementation didn't work, leaving characters out if possible. It's rather simple so could probably be improved and I forgot to add checking for characters in the backwards-right direction(update: I added it an it produced incorrect results), so I could probably shave off one or two characters but I doubt it's getting on a 22x22.
Edit:
Removed 6 spaces in places they didn't need to be.
Saved 13 bytes by replacing a check on array indices with a try-catch.
Shaved off 12 bytes by moving the board size into an `int`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2316 bytes, score 3
```
1111111111111111111111111111111,11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,111111111111111111111111111111111111111111111111,11111111111111111111,11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,1111111111111111111,11111111111111111111111111111111111111111111111,111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,1111111111111,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111D§ịØJv
```
[Try it online!](https://tio.run/##y0rNyan8/98QP9AxHJ5AZ5g4S2dweE5nNI0MP3fpDBG/64wm1mHhT52h4jSd0VAdZk5yObT84e7uwzO8yv4fbj866eHOGf//R0erp2UqFKvrKKgXleTmgOjU/PwCEB2Tp1VSpB4LZKUV5ecqZJakFpXk5@cUK2TmFuQXlWipxwIA "Jelly – Try It Online")
Board:
```
1,v
D1J
§ịØ
```
Note: this is a (somewhat) trivial solution. Credit to [Lynn](https://codegolf.stackexchange.com/users/3852/lynn) for the [idea](https://codegolf.stackexchange.com/a/165171/41024).
Returns a non-empty list if `s` can be found in `B`, and an empty list if not. The added footer helps clarifying that.
]


[Question]
      [
Consider a one-dimensional sequence of numbers within a fixed range, i.e.
```
[1, 2, 4, 6, 8, 0, 2, 7, 3] in range [0, 10⟩
```
The Ever-Increasing Graph\* \*\* is a line that connects all the points in this sequence left to right, and always goes upwards or stays level. If necessary, the line wraps around from top to bottom and continues going up from there to meet the next point.
The goal of this challenge is to split the sequence in different subsequences that are all nondecreasing, so that when plotted together with a limited vertical axis they will form an Ever-Increasing Graph. This is done by adding an a point to the end of one subsequence and to the beginning of the next subsequence, so that the angle of the line that crosses the top boundary aligns with the line that crosses the bottom boundary, and the two crossing points have the same horizontal coordinate. The example above would give the following output:
```
[1, 2, 4, 6, 8, 10]
[-2, 0, 2, 7, 13]
[-3, 3]
```
And the corresponding graph will look as follows:
[![The Ever-Increasing Graph which should actually be called Ever Nondecreasing Graph](https://i.stack.imgur.com/cby5a.png)](https://i.stack.imgur.com/cby5a.png)
And with the axis extended for a better view:
[![Ever-Increasing Graph which should actually be called Ever Nondecreasing Graph with extended vertical axis.](https://i.stack.imgur.com/OqLqA.png)](https://i.stack.imgur.com/OqLqA.png)
The required output is a list of subsequences that form the parts of the Ever-Increasing Graph. Making a plot is not required but will earn you bonus points ;). The output must clearly separate the subsequences in some way.
**Notes**
* The range will be always have zero as the left (inclusive) boundary, and the right boundary will be some integer N.
* The sequence will never contain values that are not within the range.
* The first subsequence does not have an additional point at the beginning.
* The last subsequence does not have an additional point at the end.
* It is not required to provide the starting indices that would be required to plot the subsequences.
**Test cases**
```
Input: [0, 2, 4, 6, 1, 3, 5, 0], 7
Output: [0, 2, 4, 6, 8], [-1, 1, 3, 5, 7], [-2, 0]
Input: [1, 1, 2, 3, 5, 8, 3, 1], 10
Output: [1, 1, 2, 3, 5, 8, 13],[-2, 3, 11],[-7, 1]
Input: [5, 4, 3, 2, 1], 10
Output: [5, 14],[-5, 4, 13],[-6, 3, 12],[-7, 2, 11],[-8, 1]
Input: [0, 1, 4, 9, 16, 15, 0], 17
Output: [0, 1, 4, 9, 16, 32], [-1, 15, 17], [-2, 0]
```
**Scoring**
This is code-golf, the shortest code in bytes wins.
\*Not actual jargon
\*\*Actually should be called Ever Non-Decreasing Graph, as @ngm pointed out, but that sounds less impressive.

[Answer]
# [**R**](https://www.r-project.org/about.html), 179 158 151 bytes
```
function(s,m){p=1;t=c(which(diff(s)<0),length(s));for(i in t){d=c(s[p]-m,s[(p+1):i],s[i+1]+m);if(p==1)d[1]=s[1];if(p==t[-1])d=head(d,-1);print(d);p=i}}
```
[Try it online!](https://tio.run/##LYrBCsMgEER/xeMuUei2FEqNXyIeisa60BiJlh5Cvj2VUpgZ3gyzHnFUR3xn33jJUOWMWzGkm/HwSewTBI4RKo4nlK8pP1vqBXVcVmDBWTTcQv9WW5yaZbVQBsI7u448kBtm1ByhGEMYLDlTe/yXZhU5DCZNjwBBKkJdVs4NQgfD@35E8EBSdJ2luEhxleL2A8LuEx5f)
**Edit:** Code is now a function and takes input. (Thanks to Giuseppe, user202729 and JayCe for calmly pointing that out)
**Edit:** -21 bytes suggested by Giuseppe.
**Edit:** -7 bytes by removing `d=NULL;`.
[Answer]
# [Python 2](https://docs.python.org/2/), 60 bytes
Input is N, followed by all points as individual arguments. Subsequences in the output are seperated by `0.5`.
```
f=lambda N,k,*l:(k,)+(l and(l[0]+N,.5,k-N)*(l[0]<k)+f(N,*l))
```
[Try it online!](https://tio.run/##XY9BCoMwFET3nmKWif6WRGu1Uq@QC4gLi0hL0iiSTU@fxmBBupv582bgLx/3nG3u/dSa4f0YByjSlJqGaeIZMxjsyEwn@kzRuSR9UjyN/q55NjEVUM69Q4suAVgnCTnhQrgSaoKItiIUPUEKThESBygUCkIZ0EBUOyDjPf9FdRTyOFHGfhEh@bctY3YLYtvfp2XFkz5JpnmFISi8LFwTGsv6sg7bJwiv@C8 "Python 2 – Try It Online")
---
# [Python 2](https://docs.python.org/2/), ~~92~~ ~~77~~ 68 bytes
Subsequences are seperated by `[...]`.
```
l,N=input();r=[];k=0
for a in l:r+=[a+N,r,k-N]*(a<k)+[a];k=a
print r
```
[Try it online!](https://tio.run/##TYxNDoIwEIX3PcWEFT9j0oIIir0CF2hYNIihgRTSYKKnr20h0d2bee/71s82Ljq3/fIYeBRFdsaWK72@tjhpDBddM3FKnosBCUrDfDMZFzJr0eB0ars0lvcpyYT0O0lWo/QGxjoRIcN76MF709IKhpAjnBEuCDUCDWeFUHQIjBJB/3q3LRBKt3JlRTy74/u3DoEdYBmoIvTsJ2PhfXXBCw8Xq74 "Python 2 – Try It Online")
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), ~~279~~ ~~269~~ 258 bytes
```
import StdEnv
s=snd o unzip
$[]=[]
$l#(a,b)=span(uncurry(<))(zip2[-1:l]l)
=[s a: $(s b)]
?l n#[h:t]= $l
=[h:if(t>[])(?(map((+)n)(flatten t))n)t]
@l n#l= ?l n
=[[e-i*n\\e<-k]\\k<-[a++b++c\\a<-[[]:map(\u=[last u])l]&b<-l&c<-tl(map(\u=[hd u])l)++[[]]]&i<-[0..]]
```
[Try it online!](https://tio.run/##RZDLasMwEEX3@oqBmCDVUkj6BGM1WbSLQndZyrOQH2lEZNlYUiH9@LpKSunycO@5MNPYTru5H9poO@i1cbPpx2EKsA/tq/skXnrXwgDRfZmRZAqlQpLZBdW8ZtKP2tHomjhNZ1oyRlPpVolNYdEyIpUHXUBGPdQMydaCW6hjEVBCZlN6LMyBhmeFjG5pr0dKc@YYPVgdQucgsEQBye7iWQkXP1mqE@bGVVVXihNW1akUSud5nedNVekECovLVhWlstoHiMgsLutS2GVTimDpX3psrxnL8@QgLk2S16sV4rwPegpkAdYkX4Jac7jlcM/hkcOGwx2HBw5rTA0X@7qbUucpwSF9IpjBJdwR@Y/Xmd/m/N2k8z78LN7e55ez071p/A8 "Clean – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~104~~ 82 bytes
```
n=>a=>a.map((e,i)=>e>a[s.push(e),++i]&&s.push(a[r.push(s=[e-n]),i]+n),r=[s=[]])&&r
```
[Try it online!](https://tio.run/##dY5NDsIgEEb3noIVgXTalNb6E0MvQliQSiqmQgPq9RGxXZhoMos3kzcz31U9VRi8me@ldWcdRx4t71Wq6qZmQjQYynvdKxGq@REuRFMoCiMxXnol/AcCF7q0koKRhaXguUgTKSnGPg7OBjfpanIjGcmeElEDagBtAe0AMUAtoA5QLSk9bb5lViebZalZvUMG9s/u8uE2L/yUlgAse8cE7xDr//gC "JavaScript (Node.js) – Try It Online") Port of @ovs's Python answer.
[Answer]
# Haskell, ~~82~~ ~~81~~ 80 bytes
This is a port of [my Clean answer](https://codegolf.stackexchange.com/a/165066/42682).
```
r!n|let f x(r@(a:_):s)|x>a=[x,n+a]:(x-n:r):s|y<-x:r=y:s=foldr f[[last r]]$init r
```
[Try it online!](https://tio.run/##HYhPC8IgHIa/yjvYwZGDraLiR0bXoFtHkRDamGQu1MjBvruNTs@fQYdnZ23OvnCz7SJ6JObPTNO9olDN6aSFTNyttCKWakd@2fN0rBN5MVEQ/WgfHr2UVocIr1RpnFkkv7RxEHh/4i36q0OJMIzfBbLlWHNsOXYcB47mn3uOjUIB1jYgwsXFKv8A "Haskell – Try It Online")
-1, -1 thanks to [Laikoni](https://codegolf.stackexchange.com/users/56433/laikoni)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 20 bytes
```
⁹;+⁴,N¤j.x>ṭḷ
çƝF;Ṫ{
```
[Try it online!](https://tio.run/##y0rNyan8//9R405r7UeNW3T8Di3J0quwe7hz7cMd27kOLz8218364c5V1f///4821FEAIiMdBWMdBVMdBQswwzD2v6EBAA "Jelly – Try It Online")
Subsequences are splitted by `0.5`.
[Answer]
# [Clean](http://clean.cs.ru.nl), 92 bytes
```
import StdEnv
@r n=foldr(\x[r=:[a:_]:s]|x>a=[[x,n+a]:[x-n:r]:s]=[[x:r]:s])[[last r]](init r)
```
[Try it online!](https://tio.run/##JYw9C8IwFAB3f8UbW4zQqqgEIh10ENw6xiCPfkggeZUkSgR/u7HV7e6Ga0yHlOzQPkwHFjUlbe@DC1CH9kjPWeWARD@Y1mWXKJ3gEvlVca/ecY9CyshojorLuCDupj61P@VSGvQBnFKZJj1CnuqA41tABbJksGSwZrBhsGNQ/HTLYKWgLNKn6Q3efFqczunwIrS68V8 "Clean – Try It Online")
The operator argument to `foldr` is a lambda with guard; it is parsed as:
```
\x [r=:[a:_]:s]
    | x > a     = [[x,n+a]:[x-n:r]:s]
    | otherwise = [[x:run]:s]
```
I ported this [to Haskell](https://codegolf.stackexchange.com/a/165069/42682).
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), ~~110~~ ~~109~~ ~~104~~ ~~100~~ 97 bytes
```
import StdEnv
@[x:r]n=let$s=:[x:r]a|x<last a=[a++[n+x]: $s[last a-n]]= $r(a++[x]);$_ a=[a]in$r[x]
```
[Try it online!](https://tio.run/##JY2xCsIwFEV3v@INGZSm0KqoVAMddBDcOoYgj7ZKIHmVJEoEv92odTznHrit6ZGSHbq76cGipqTtbXABmtAd6DGpZaycImH6wLyoRsJX3Bn0AVBIzDJJWVQVMC//MielBDA3/W1RzbbsPJZKE3NfkZqA3wMBNciSw5zDksOKw4ZDMeKaw0JBWaR3ezF49Sk/ntL@SWh16z8 "Clean – Try It Online")
*-1 byte thanks to [Keelan](https://codegolf.stackexchange.com/users/42682/keelan)*
[Answer]
# [Haskell](https://www.haskell.org/), 82 bytes
```
(x:r)#n|let b@(a:_)%s@(x:r)|x<a=(n+x:b):[a-n]%s|c<-x:b=c%r;a%_=[a]=reverse<$>[x]%r
```
[Try it online!](https://tio.run/##ZY/taoMwFIb/exUH2oCyCCa21WVm9AbGLiCEkpbAymyQaIcwd@0uiXP98tfxnOc958mHaj91XY9j3DObLMxQ6w7221ixXYLabegOfaV4bJ56tk@YUKmRqB0OVer@@QHZF4V2XCjJrf7SttXV8lX0EtnxpI4GOJxU8waNPZoOlhCB@wSIDAPFsMKwwUAw5BjWGDIJCygCgkGQMKHzsAwF8QjJZmYdduQBuxtlIe6mz67wV@YDZLogo@g7jd7PXXPu2K1QKV0@JVdmRehQv@ESeRQkucQB86bE14X3ukQcRla@P4lP/Gbi6R9P52x5m71/UE7/Nf3aa8X0Z/wF "Haskell – Try It Online") Port of my [Clean answer](https://codegolf.stackexchange.com/a/165061/56433).
---
### Alternative, also 82 bytes
```
(x:r)#n|let a%s@(x:r)|x<last a=(a++[n+x]):[last a-n]%s|c<-a++[x]=c%r;a%_=[a]=[x]%r
```
[Try it online!](https://tio.run/##ZY/rasMwDIX/5ykEnaElMkRO22RZDXuBsQcwZphSaFlqQpJCYNmzZ74s62X@Jel8Rzo@mu7zUNfTtByqdrWwY33owbDuNfTjsKtN5wZyadJU2XTQq0rFEbeadeN@x70yaLln7YthH1IZLV3P2ulsThYknE3zBk17sj08QQLuKVAZgkBYI2wRCCFH2CBkGhZQBARBUVDELJahII9QNjObsCMP2IOUBbtTn13hr8wHKF7QSfLFk/dL31z66j5QqZ2f002yIkyE33C1/A9IucaA@aTk68LnulocRms/j8Ejv428@OXF7C3vvY8fysVfTL/2NiL/nn4A "Haskell – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 98 bytes
```
a=>m=>(r=[],b=[],a.map((e,i)=>e<a[--i]?(b[p](m+e),r[p](b),b=[a[i]-m,e]):b[p='push'](e)),r[p](b),r)
```
[Try it online!](https://tio.run/##dc7JDoIwEAbgu0/RGzNxSiiIe/FBmh4KNohhC6ivj7TRmBi9TP5kvlmu5mHGYqj6G2@7s51KORmZNTKDQSpNuSsmbEwPYKlCmdmjUZxX@gS56jU0S4s0uJSj00ZVmjdkNe7nvgz6@3gJNFj8qAGnomvHrrZh3ZVQgoqIxcRWxNbEBLGEWEos0ggbxMPiCwtv4jfb@iBmLKIfOvV7Ez/wF0V@5ex2c3A/vM4Ld396Ag "JavaScript (Node.js) – Try It Online") This is quite a bit longer than the other JS answer, but it uses a different approach.
## Ungolfed and simplified explanation
```
g=(a,m)=>{
    // r is the final array of arrays to return.
    // b is the current subset of only ascending numbers.
    r=[],b=[];
    a.map((e,i)=>{
        if(e<a[i-1]){
            // if the current value is less than the previous one,
            // then we're descending, so start a new array b.
            // add the proper value to b to match slopes with the next
            b.push(m+e);
            // add r to b, and restart b with the starter value and the current value in a
            r.push(b);
            b=[a[i-1]-m,e];
        } else{
            // otherwise, we're ascending, so just addd to to b.
            b.push(e);
        }
    });
    r.push(b); // add the final b to r, and return r
    return r;
}
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 48 bytes, arrays separated by `,,`
```
s=>n=>s.map(r=t=>(t<r?[t+n,,r-n,,]:``)+(r=t))+``
```
[Try it online!](https://tio.run/##fc5NCsIwEAXgvaeYZUKnJWmt/6m7XqIUUmoRpSYlCV4/JkE3IsIwPJiP4d2H52BHc1tcrvRl8q3wVjRKNLZ4DAsxwomGuJM5dy5TiCYPqz9ISbN4ozST0o9aWT1PxayvpCUdQygR1ggbBI5QIdQIrKdkS@lx9YV5MuWH7VLgAXP2Q9fpb5Wm/ONY@hroPoRY492Axwr@BQ "JavaScript (Node.js) – Try It Online")
# [JavaScript (Node.js)](https://nodejs.org), 50 bytes, arrays separated by `|`
```
s=>n=>s.map(r=t=>(t<r?t+n+`|${r-n},`:``)+(r=t))+``
```
[Try it online!](https://tio.run/##fc5NCsIwEAXgvaeYhYuETEvSWv9Td72ECCm1iFKTkgQ36tljG3QjIsziwXw83qW@1a6x594n2hzbUMngZKll6dJr3RMrvSyJ39qdZ5qpx/RuE/1EtVaKsvFLKVMqNEY707VpZ06kInuOkCHMEOYIAiFHKBD4gZIFpZvJFxbRZB@2jEEMWPAfuoi9ebzsj@OxdaCrIYwz3gvEOCG8AA "JavaScript (Node.js) – Try It Online")
]