text:
Self-summed numbers
Convert a number to a sum of digits
Not any sum: we need the shortest sum
Not any digits: you can use only digits of the number
Example
You will be given as input an integer n>0
Let's say n=27. You have to express 27 as a sum, using only the digits [2,7], in the shortest way possible. You don't have to use all the digits of the given number!
So 27=2+2+2+7+7+7. We then take those digits and count them: [2,2,2,7,7,7].
Final answer for n=27 is 6
One more example for n=195 in order to get the shortest sum we have to use the following digits:
[5,5,5,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9] and the answer is 23
The challenge
Given an integer n>0, output the minimum number of digits (contained in the number) that sum up to this number
Test Cases
Input->Output
1->1
2->1
10->10
58->8
874->110
1259->142
12347->1765
123456->20576
3456789->384088

This is code-golf.Shortest answer in bytes wins!

Are there any numbers that cannot sum to themselves/will they be input?

@Stephen They all can!

@Stephen Because every number can be expressed as d_0 + 10d_1 + 100 d_2, etc...

Can we take the input as string, char-array or integer-array?

@KevinCruijssen String is ok. char-array or integer-array are not.

How did you pick [5,5,5,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9] over [5,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9], is either correct?

@MagicOctopusUrn Yes, they are both correct. We are only interested in the minimum number of digits.

Husk, 12 bytes
Lḟo=⁰ΣṁΠḣ∞d⁰

Handles two-digit numbers pretty fast.
Try it online!
Explanation
Lḟo=⁰ΣṁΠḣ∞d⁰  Input is n, say n = 13.
          d⁰  Digits of n: [1,3]
         ∞    Repeat infinitely: [[1,3],[1,3],[1,3],[1,3]...
        ḣ     Prefixes: [[],[[1,3]],[[1,3],[1,3]],[[1,3],[1,3],[1,3]],...
      ṁ       Map and concatenate
       Π      Cartesian product: [[],[1],[3],[1,1],[3,1],[1,3],[3,3],[1,1,1],[3,1,1],...
 ḟo           Find the first element
     Σ        whose sum
   =⁰         equals n: [3,3,3,3,1]
L             Return its length: 5

R, 78 bytes
function(n){while(all(F-n)){F=outer(F,n%/%10^(0:nchar(n))%%10,"+")
T=T+1}
T-1}

Try it online! (golfed version)
Pure brute force algorithm, so it doesn't actually solve all the test cases, and I think it tried to allocate 40,000 GB for the last test case...
T in R defaults to 1 so we get an off-by-one error which we correct at the return step, but we also get F which defaults to 0 which pays off.
ungolfed explanation:
function(n){
 d <- n%/%10^(0:nchar(n))%%10   # digit list with a 0 appended at end
 d <- unique(d[d>0])            # filter zeros (not technically necessary)
                                # and get unique digits
 x <- 0                         # storage for sums
 i <- 0                         # counter for number of sums done
 while(!any(x==n)){             # until we find a combination
  x <- outer(x,d,"+")           # take all sums of x and d, store as x
  i <- i + 1}                   # increment counter
i}                              # return counter

Try it online! (less golfy version)

Python 2, 168 155 144 bytes
It isn't the shortest it could be, but it's best-first and not real bad, runtime wise.
n=input()
g=sorted(set(n)-{0})[::-1]
def h(k):
 if k<0:return
 if`k`in g:return 1
 for d in g:
  f=h(k-int(d))
  if f:return 1+f
print h(int(n))

The filter(None... is to remove 0 as a digit, which I learned I could do while making this.
The biggest problem is python stack frames, which realistically don't allow me to run this on the largest inputs. So, it is not a valid solution, really, I played around with increasing the recursion limit which just led to seg-faults. This has to either be done with a loop and a stack or with a lot more cleverness to work in python.
edit: Thanks to caird and Chas Brown for 13 bytes!

You can use input and require the input to be surrounded with quotes.

It's perfectly acceptable to fail due to physical limitations, so long as it succeeds in theory, which this does.

Save 9 bytes by replacing filter(None,sorted(map(int,set(n)))[::-1]) with sorted(set(map(int,n))-{0})[::-1] (although the None thing is pretty nice to know about).

@ChasBrown In most cases you can use filter(len,...) for lists and strings and filter(abs,...) for integers and floats.

Pyth, 12 bytes
lef!-TsM`Q./

Try it online!
Unfortunately it memory errors on inputs as large as 58.
Explanation
lef!-TsM`Q./
          ./    All lists of integers that sum to [the input]
  f             Filter for:
    -TsM`Q           Remove all occurrences of the digits in the input
   !                 Check if falsey (i.e. an empty list)
le              Length of the last occurrence, which is the shortest because all the
                filtered partitions share the same digit pool

would you mind adding an explanation?

@Jonah Explanation added.

Thanks.  Interesting that Pyth has a primitive that essentially solves the problem in ./

12-byte alternative: lef<.{TjQ;./ (filter - proper subset - of input's digits)

Mathematica, 78 bytes
(t=1;While[(s=IntegerPartitions[x=#,t,IntegerDigits@x])=={},t++];Tr[1^#&@@s])&

finds last test case in 5 sec

A little bit shorter: Length@IntegerPartitions[#, All, Sort@DeleteCases[0]@IntegerDigits@#,     1][[1]] &

JavaScript (ES6), 82 bytes

f=(n,l=0,a=n,[c,...b]=a)=>n?1/c?Math.min(!+c|+c>n?1/0:f(n-c,l+1,a),f(n,l,b)):1/0:l
<input type=number oninput=o.textContent=f(this.value)><pre id=o>

Takes input as a string.

Can you explain why you are using 1/0?

@Zacharý I want the shortest sum, i.e. the minimum number of digits. Attempts which lead to an invalid solution mustn't count, so to exclude them, they score Infinity, which doesn't affect the minimum.

Oh, didn't realize it's recursive.

@Zacharý The f= at the beginning is a big clue, since you don't need it for nonrecursive lambdas.

Ruby, 70 bytes
->n{w,s=n.digits,0;s+=1while !w.product(*[w]*s).find{|x|x.sum==n};s+1}

Very slow, try all the possible combinations increasing the size until we get to a solution.
Thanks Dennis for Ruby 2.4 on TIO.
Try it online!

Jelly, 23 bytes
D;0ṗµḟ€0
ÇS€=µT
Çị1ĿL€Ṃ

Try it online!
This is so inefficient, that it does not run for the test cases after the third one on TIO due to a time limit >_<
Any golfing tips are welcome!

Haskell, 91 bytes
f n=[read[c]|c<-show n,c>'0']#n!!0
s#n|n>0,x:m<-(s#).(n-)=<<s=[1+minimum(x:m)]|1<3=[0|n==0]

Try it online! Example usage: f 58 yields 8. Quick for two-digit numbers, horrendously slow for larger inputs.
The function f converts the input number n into a list of digits while filtering out zeros. Then this list and n itself are handed to the (#) function, which returns a singleton list. !!0 returns the element of this singleton list.
(#) uses singleton and empty lists as option type. Given an input of n=58 and s=[5,8], the idea is to subtract all digits in s from n, then recursively apply (#) and check which digit resulted in the minimum number of steps and return one plus this minimum as result. The first part is computed by (s#).(n-)=<<s, which is the same as concat(map(s#)(map(n-)s)). So in our example first [58-5,58-8] is computed, followed by [[5,8]#53,[5,8]#50] which results in [[7],[7]] or [7,7] after concat. The result is matched on the pattern x:m to make sure the list has at least one element (minimum fails otherwise), then the singleton list of 1 plus the minimum of the result is retuned. If n was smaller zero or the recursive call returned an empty list, we are in a failing branch of the search and an empty list is returned. If n==0 the branch was succeeding and [0] is returned.

Haskell, 101 bytes
f n=[d|d<-[9,8..1],show d!!0`elem`show n]#n!!0
s@(d:r)#n|n>=d,[x]<-s#(n-d)=[x+1]|1<3=r#n
s#n=[0|n==0]

Try it online! A way more efficient approach, checks all test cases in under one second.
This time, the list of digits of the input is computed to be in descending order, which allows (#) to try to use the largest digit as often as possible, then the second largest, and so until a solution is found. The first solution found this way is also guaranteed to be the smallest one.

Python 2, 183 176 172 166 161 bytes
def f(n,D=0,p=0,b=0):
	D=D or set(map(int,`n`))-{0}
	d=min(D);c=0;D=D-{d}
	q=[p+n/d,b][n%d>0]
	while c<min(D or{0}):q=b=f(n-c*d,D,p+c,b);c+=1
	return[q,b][q>b>0]

Try it online!
Longer than the other Python answer, but performs all test cases combined plus 987654321 in under a second on TIO.
Takes advantage of the fact that if d1<d2 are digits, then there need be at most d2-1 d1's in the sum (since d2 instances of d1 can be replaced with d1 instances of d2 for a shorter sum). Thus, sorting the digits in ascending order, there are "only" at most 9! = 362880 possible sums to consider; and a maximum recursion depth of 9 (regardless of the value of n).

Husk, 13 bytes
Pretty inefficient
VVo=⁰ΣMṖNṘ⁰d⁰

Try it online!


text:
Cooking with Code
You're a chef and you love cooking with your spices, but recently you've taken a liking to organizing your spices based on how often you use them. But you have no time to be writing down when you used your spice last. Simply, you swap and move spices around, and this seems to do the trick.
But of course you're a chef and that means you have some cooks with you. You
decide to tell them the simple rules of engagement with your spices.

If you recently used a spice, move it up one in the spice rack
If you didn't use any spices at all, e.g. [] empty movement list,
then the spice list is not affected.
You may put any spice into my spice holder, but if you use it, make
sure to move it.
The list can contain anything. But because these are spices we are
working with. It is preferred that you use names of spices.
Spices should be unique. Too many of the same spices spoil the
broth... or however that saying goes

Normal code-golf rules apply.
Example of Oregano being used again and again.
pepper  pepper  pepper  pepper  oregano
paprika paprika paprika oregano pepper
salt    salt    oregano paprika paprika
cumin   oregano salt    salt    salt
oregano cumin   cumin   cumin   cumin

Task
Input a list of spices, and a list of what spices got used, then output the final list.
Example
Input
[pepper, paprika, salt, cumin, oregano], [oregano, cumin, cumin, salt, salt, salt]

Output
[salt, pepper, paprika, cumin, oregano]

How this looks
pepper  pepper  pepper  pepper  pepper  pepper  salt
paprika paprika paprika paprika paprika salt    pepper
salt    salt    salt    cumin   salt    paprika paprika
cumin   oregano cumin   salt    cumin   cumin   cumin
oregano cumin   oregano oregano oregano oregano oregano

Input
[pepper, paprika, salt, cumin, oregano], [salt, salt, salt, salt, salt, salt, salt, salt, salt, salt, salt, salt, oregano]

Output
[salt, pepper, paprika, oregano, cumin]

Is items in list of spices unique?

Yes, they will be unique

I got pretty far doing this in Chef but eventually it got too tiring! I'll give someone 50 bounty if they can do it.

Here's a gist of getting the input into the mixing bowls. The rest will be very difficult, but doable for the right person!

@tisaconundrum Can I move the recently used spices to the right, rather than to the left?

@geokavel Challenge accepted

Husk, 15 14 bytes
Fλṁ↔`C⁰tMo→=¢⁰

Inputs are lists of strings (it also works on other kinds of lists).
Try it online!
-1 byte thanks to H.PWiz
Explanation
Fλṁ↔`C⁰tMo→=¢⁰  Implicit inputs (two lists).
F               Fold second input using the first as initial value
 λ              with this anonymous function:
                 Arguments x (list of spices) and s (used spice).
                 For example, x=["a","b","c","d"] and s="c".
            ¢⁰   Repeat x infinitely: ["a","b","c","d","a","b","c","d"..
        M        For each item,
           =     test equality to s: [0,0,1,0,0,0,1,0..
         o→      and increment: [1,1,2,1,1,1,2,1..
       t         Drop first element: [1,2,1,1,1,2,1..
    `C⁰          Cut x to these lengths: [["a"],["b","c"],["d"]]
  ṁ↔             Reverse each slice and concatenate: ["a","c","b","d"]

I have to repeat x infinitely, since otherwise the list would lose its last element when we use the topmost spice.
It would be enough to add a trailing 1, but repetition takes fewer bytes.
A better way would be to rotate the list instead of dropping its first element, but Husk has no built-in for that.

Σm is ṁ for one byte.

Haskell, 48 bytes
foldl(?) is an anonymous function taking two list arguments and returning a list, with all elements of the same (Eq-comparable) type.
Use as foldl(?)["pepper", "paprika", "salt", "cumin", "oregano"]["oregano", "cumin", "cumin", "salt", "salt", "salt"].
foldl(?)
(x:y:r)?n|y==n=y:x:r|s<-y:r=x:s?n
s?n=s

Try it online!

foldl(?) s m starts with the (spice rack) list s and combines it with each element (spice) from m in order, using the operator ?.
s?n uses the spice n from the spice rack s and returns the resulting spice rack.

If s has at least two elements, ? checks whether the second one is equal to n, and if so switches the first two elements. If not equal, ? keeps the first element fixed and recurses on the rest.
If s has at most one element, ? returns it unchanged.

Chef, 875 843 bytes
S.

Ingredients.
1 g T
0 g Z
J
I

Method.
Put Z into mixing bowl.Take I from refrigerator.B I.Put I into mixing bowl.Take I from refrigerator.B until bed.Take I from refrigerator.V I.Put Z into 2nd mixing bowl.N T.Fold J into mixing bowl.Put J into mixing bowl.Remove I.Fold T into mixing bowl.Put J into 2nd mixing bowl.N until ned.Fold T into mixing bowl.Put T into mixing bowl.Fold J into 2nd mixing bowl.Put J into mixing bowl.C T.Stir for 1 minute.Put Z into mixing bowl.Fold T into mixing bowl.C until ced.Fold T into 2nd mixing bowl.G T.Put T into mixing bowl.Fold T into 2nd mixing bowl.G until ged.Put I into mixing bowl.Fold T into mixing bowl.Take I from refrigerator.V until ved.Fold T into mixing bowl.L T.Put T into 2nd mixing bowl.Fold T into mixing bowl.L until led.Pour contents of 2nd mixing bowl into baking dish.

Serves 1.

-32 bytes thanks to Jonathan Allan by removing the where I wouldn't think it will work.
Chef has no string types, so the ingredients are positive integers. 0 is used to separate the starting list from used ingredients and to end the used ingredients list. See the TIO link for an example.
Pseudocode explaination:
A, B: stack
T, J, IN: int
T = 1
A.push(0) // used as the marker for the bottom of the stack
IN = input() // input the first list
while(IN):
    A.push(IN)
    IN = input()
IN = input() // for each used ingredient
while(IN):
    B.push(0)
    while(T): // move all ingredients up to and including the one we are moving right now to the second stack
        T = A.peek() - IN
        B.push(A.pop())
    A.push(B.pop())
    if(A.peekUnderTop() != 0):
        A.swapTopTwoItems()
    T = B.pop() // move the ingredients from the second stack back to the first
    while(T):
        A.push(T)
        T = B.pop()
    T = IN // to make it non-zero for next iteration
    IN = input(0
print(A.inverted())

Try it online!

Awesome! Has this language been on TIO all along?

By removing some redundant words you can save 32 bytes

@geokavel it got added yesterday.

@Jon Is it one of the existing interpreters or a newly created one?

@geokavel It is the one linked to by the word Chef at the top of the TIO page.

@Jon That would be the Perl one, but I could never get Serves to work on there.

@geokavel Did you pour the contents of the mixing bowl into the baking dish before serving?

@geokavel No, only recently.

Oh, I just forgot the line separator.

@NieDzejkob Did you pour the contents of the mixing bowl into the baking dish before serving? that completely sounds like a comment that would go on the cooking SE and not here :P lol (also a very strange question for cooking if you ask me :P)

JavaScript, 61 bytes
a=>b=>b.map(v=>(p=a.indexOf(v))&&a.splice(p-1,2,a[p],a[p-1]))

Input format:

f(list_of_spices)(list_of_what_spices_got_used)
two list are array of string

Output:

list_of_spices is modified in-place.

f=
a=>b=>b.map(v=>(p=a.indexOf(v))&&a.splice(p-1,2,a[p],a[p-1]))

a = ['pepper', 'paprika', 'salt', 'cumin', 'oregano'];
b = ['salt', 'salt', 'salt', 'salt', 'salt', 'salt', 'salt', 'salt', 'salt', 'salt', 'salt', 'salt', 'oregano'];
f(a)(b);
document.write(JSON.stringify(a))

Python 2, 72 71 69 bytes
New answer, in the spirit of my original attempt.
r,u=input()
for x in u:i=r.index(x);r.insert(i/~i+i,r.pop(i))
print r

Try it online!
Other solution:
Python 2, 69 bytes
r,u=input()
for x in u:i=r.index(x)-1;r[i:i+2]=r[i:i+2][::-1]
print r

Try it online!

print(r) -> print r?

69 bytes

Python 2, 80 bytes
def g(r,q):
 for s in q:
  i=r.index(s)
  if i:r[i-1],r[i]=r[i],r[i-1]
 return r

Try it online!

Some savings: Use tabs to indent the inner block, and assign to r[i-1:i+1].

Replacing return by print can save another byte.

Java 8, 87 86 76 bytes
a->b->b.forEach(x->{int i=a.indexOf(x);a.set(i,a.set(i>0?i-1:i,a.get(i)));})

Takes two inputs as ArrayList<String> and modifies the first List instead of returning a new one to save bytes.
-10 bytes thanks to @Nevay.
Explanation:
Try it here.
a->b->{                  // Method with two ArrayList<String> parameters and no return-type
  b.forEach(x->{         //  Loop over the second input-List
    int i=a.indexOf(x);  //   Get the index of the current item in the first input-List
    a.set(i,a.set(       //    Swap items:
      i>0?               //     If the current item is not the top item yet:
       i-1               //      Use the item above it
      :                  //     Else:
       i,                //      Use itself
         a.get(i)));     //     And swap it with the current item
  })                     //  End of loop
                         // End of method (implicit / single-line body)

77 bytes: a->b->b.forEach(x->{int i=a.indexOf(x);a.set(i,a.set(i>0?i-1:i,a.get(i)));});

Java is getting revenge for all the people who made fun of it.

C#, 125 117 81 79 bytes
(c,n)=>{foreach(var i in n){var j=c.IndexOf(i);if(j!=0){c[j]=c[--j];c[j]=i;}}};

Try it on .NET Fiddle
golfed off 36 bytes thanks to raznagul

The answer as it is would be 117 bytes as you are missing the namespace for Array.IndexOf. But there are several ways to make the answer shorter: 1. Use a foreach-loop instead of the for-loop. 2. If c is a List<string> instead of string[] you can directly use c.IndexOf. 3. As c is modified in place you don't need to return it.

05AB1E, 20 18 bytes
vDyk>Ig‚£`U`2(@)X«

Try it online!
Explanation
v                    # for each used spice
 D                   # duplicate current spice order
  yk                 # get the index of the current spice
    >                # increment
     Ig‚             # pair with the number of unique spices
        £            # split the spice list into pieces of these sizes
         `           # split as 2 separate lists to stack
          U          # store the list of spices below the current one in X
           `         # push the current spice and all above separately to stack
            2(@      # swap the second item to the top of the stack
               )     # wrap in a list
                X«   # append the rest of the spices

It's better to modify one list instead of creating a second one ;)

Mathematica, 52 bytes
but it is my first post here so please be kind if counted incorrectly :)
Keys@Sort@Merge[{PositionIndex@#,-Counts@#2},Total]&

And an example:
Keys@Sort@Merge[{PositionIndex@#, -Counts@#2}, Total] &[
    {pepper, paprika, salt, cumin, oregano}
  , {oregano, cumin, cumin, salt, salt, salt}
]

{salt, pepper, paprika, cumin, oregano}

I'm not a Mathematica expert, but you could probably remove some spaces to save some bytes.

@pajonk already counted without them but I should've removed them here too, thanks.

05AB1E, 16 bytes
vÐyk©DĀ-DUè®ǝyXǝ

Try it online!

CJam, 18 bytes
l~{a\_@#__g-e\}%~`

Try it online!

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Count the Palindromes
Given a number n, calculate the amount of bases in the range of [2, n) in which b(n) is a Palindrome.
Example
n = 8 has the base conversions:
2 = 1000
3 = 22
4 = 20
5 = 13
6 = 12
7 = 11

Of which 2 of them, 3 = 22 and 7 = 11 are palindromes. So return 2.
Clarifications

For the sake of convenience, Your answer only needs to be correct for inputs 3 - 36 inclusive, as few languages can handle base conversion of >36.
A single digit number is considered a palindrome.
This is sequence A135551 on OEIS

Test Cases
3   -> 1
4   -> 1
5   -> 2
6   -> 1
7   -> 2
8   -> 2
9   -> 2
10  -> 3
11  -> 1
12  -> 2
13  -> 2
14  -> 2
15  -> 3
16  -> 3
17  -> 3
18  -> 3
19  -> 1
20  -> 3
21  -> 4
22  -> 2
23  -> 2
24  -> 4
25  -> 2
26  -> 4
27  -> 3
28  -> 4
29  -> 2
30  -> 3
31  -> 3
32  -> 3
33  -> 3
34  -> 3
35  -> 2
36  -> 5

Finally

Standard Loopholes Apply.
This is code-golf, so fewest bytes wins.
Have Fun!

Did you mean to write "[2, n)", if so, what does the difference in braces mean?

@StanStrum Set notion as described in ISO_31-11, Means 2 (inclusive) through n (exclusive)

I think this might be a dupe of All your base palindromic belong to us?

"A single digit number is considered a palindrome." But this won't happen anyway.

@DomHastings I do not think so, as the sequences A126071 and A135551 differ.

@JonathanFrech actually I think Dom is right - once the sequences are aligned (one starts at index 0 the other at index 1), A126071(n) = A135551(n) + 1. This is evident from the facts that (a) n in Unary is 00...0 [palindromic]; (b) for n>1, n in base n is 10 [not palindromic]; and (c) n in base n+1 is 11 (or 1 for n=1) [palindromic]. Also it even states in the formula section of A135551 "a(n) = A126071(n) - 1".

@JonathanAllan Although the sequences are similar, the challenges themselves do also differ in that one requests the other sequence up to n, where as this only requests n. Answers are completely non-transferable between the two.

While it is true the other asks for up to n, that does not make them non-transferable. The second line of the Jelly submission there, for example, is just calling "link 1" for each number in turn (the only reason it's so much longer than my submission here is that the language has evolved).

@OlivierGrégoire it's a palindrome in n-1 :P

FYI: My latest submission in Pyth shows the ease of porting.

I have voted to reopen this question, because in my honest opinion the challenges (and tasks) are different enough, and porting the answers there might not be the best option (in some languages, at least).

@Mr.Xcoder, if wrapping something in a loop from 1 to n is not sufficiently trivial a change to be a dupe, what is sufficiently trivial?

@PeterTaylor Here are the reasons I think it is not a duplicate. Feel free to disagree, but that won't change my opinion.

@Mr.Xcoder, the number of answers an earlier challenge received is nothing to do with whether it's a dupe or not; "the challenge there is quite old (and many languages have evolved since then, other languages were designed in the mean time" is an argument for keeping it open in spite of being a dupe which was also made in this case to which see also this. If you think an obvious dupe should be reopened in spite of being an obvious dupe, take it to meta first.

@PeterTaylor Feel free to hammer it again, I don't really have a strong opinion right now. You are probably right.

Jelly, 6 bytes
bḊŒḂ€S

A monadic link taking and returning numbers
Try it online!
How?
bḊŒḂ€S - Link: number, n
 Ḋ     - dequeue (with implicit range(n) as input) -> [2,3,4,...,n]
b      - convert to base  -> [nb2, nb3, nb4, ..., nbn] (note: nbn is [1,0])
  ŒḂ€  - isPalindrome? for €ach  -> list of 1s and 0s
     S - sum -> number that are palindomes

05AB1E,  10  8 bytes
-2 bytes thanks to Emigna (use "bifurcation" instruction Â to replace duplicate and reverse DR & increment the loop to avoid needing to close it.)
G¹N>вÂQO

Try it online!
How?
G¹N>вÂQO
G        - for N in range(1, input()+1):
 ¹       -   1st input
  N      -   N (the loop variable)
   >     -   increment
    в    -   base conversion
     Â   -   push reverse
      Q  -   equal?
       O -   sum
         - print top of stack

You can replace DR with Â.

Also, if we know that n can't be a palindrome in base n you could do G¹N>вÂQO.

We know it's not a palindrome in base n, but it's always a palindrome in base 1, so unless there is a loop for [2,n) or [2,n]... EDIT oh wait you increment, but then don't close the loop before summing, how's that work??

Gloops for [1,n), as we incremented N it goes from [2,n]

...but why is no } needed before O?

Because we only have the bools we wish to sum on the stack. No residuals. So we can sum each loop iteration. When we get to O, the only things on the stack are our sum so far and the value we wish to add to the sum from this iteration.

Someone can explains me what bifurcated means, and why it means reverse in 05AB1E?

J, 30 bytes
[:+/i.&.(-&2)(-:|.)@(#.inv)"0]

Try it online!
Straightforward solution featuring a lot of parentheses.
Explanation
[: +/ i.&.(-&2) (-:|.)@(#.inv)"0 ]
                                 ]  Right argument, n
      i.&.(-&2)                     Range [2,n)
           -&2                        Subtract 2
      i.                              Create range from n-2
        &.                            Undo subtraction (add 2)
                              "0    For each value in the range
                       (#.inv)      Convert to that base *
                (-:|.)              Palindrome check
                   |.                 Reversed
                 -:                   Matches self (= is rank 0)
   +/                               Sum (i.e. count palindromes)

*#.inv is used since #: expects you to specify the number of digits in the base (it doesn't treat a single argument the way you might expect).

nice J.  I like the i.&.(-&2) trick.

@Jonah thanks, it's not mine though -- saw it on the Project Euler forums (guess some people like to obfuscate -- or perhaps even golf -- their answers)

Python 2, 90 bytes
lambda n:sum(h(n,i)==h(n,i)[::-1]for i in range(2,n))
h=lambda v,b:v and[v%b]+h(v/b,b)or[]

An unnamed function taking n that counts the palindromes, which utilises the helper function h which performs the base conversions.
Try it online!

Mathematica, 57 bytes
Tr@Boole@Table[PalindromeQ@IntegerDigits[#,i],{i,2,#-1}]&

Ruby, 47 bytes
->n{(2...n).count{|i|(s=n.to_s(i))==s.reverse}}

Try it online!

Pyth,  10  9 bytes
Port of irtosiast's submission to "All your base palindromic belong to us".
-1 byte thanks to FryAmTheEggman - use the filter alias # to replace f and do away with the T (which seems also to have been available back then too).
lt_I#jLQS

Try it online!

I don't know if this existed for the previous question, but you can change f_IT to _I#.

Looks like it may well have done.

Pyth, 9 bytes
lf_IjQTtS

Test it here!
Pyth, 9 bytes
sm_IjQdtS

Try it here!

How?

sm_IjQdtS  - Full program with implicit input (Q at the end)

tS - All the integers from 2 to the input (inclusive). I chose inclusive because it is golfier and any number n converted to base n is 10.

m - Map over the above with a variable d.

jQd - Convert the input to base d (the current number in the range) as a list.

_I - The best part of this program: Is invariant under reverse? – This checks if the list is palindromic.

s - Sum, which acts like "count the number of truthy results" in this case.

Pyke, 10 bytes
tFOAbD_q)s

Try it here!
t          -   input - 1
 FOAbD_q)  -  for i in ^:
  O        -   ^ + 2
   Ab      -    base(input, ^)
     D_q   -     ^ == reversed(^)
         s - sum(^)

Also 10 bytes: StFAbD_q)s (porting my Pyth solution)

RProgN 2, 18 bytes
x=x1-2R³x\Br³]ier+

This is essentially what I used as a reference implementaiton.
Explained
x=x1-2R³x\Br³]ier+
x=                  # Associate 'x' with the implicit input.
  x1-               # Get x - 1
     2R             # Get all numbers in the range 2 through x - 1
           r        # Replace each element by the function...
       ³x\B         # Convert x to base i.
                r   # Replace each element by another function...
            ³]ie    # Duplicate, Inverse, Equals. Checks if it's a palindrome.
                 +  # The sum of. Which counts how many are palindromes.

Try it online!

Python 2, 187 bytes
def P(n):
 p=0
 for b in range(2,n):
	M=0
	while n>=b**M:M+=1
	N,I,B=n,M-1,[]
	while N:
	 for f in range(b)[::-1]:
		if f*b**I<=N:N-=f*b**I;B+=[f];I-=1;break
	p+=0>(B[::-1]==B)*I
 print p

Try it online!
A bit on the lengthy side, as there is no built-in used for changing base.

Haskell, 67 bytes
0#b=[]
x#b=mod x b:div x b#b
f n=sum[1|b<-[2..n],n#b==reverse(n#b)]

Try it online! Use by calling f. Works with arbitrary high bases.

JavaScript (ES6), 77 71 70 68 67 bytes
n=>(g=b=>b<n&&([...s=n.toString(b)].reverse().join``==s)+g(++b))(2)

(Golfed from 77 down to 68 while waiting for the challenge to be reopened)

Test it

f=
n=>(g=b=>b<n&&([...s=n.toString(b)].reverse().join``==s)+g(++b))(2)
o.innerText=[...Array(34)].map(_=>(""+x).padStart(2)+": "+f(x++),x=3).join`\n`
<pre id=o>

Japt -x, 9 8 bytes
ò2@sX êS

[Test it]https://ethproductions.github.io/japt/?v=1.4.5&code=8jJAc1gg6lM=&input=MzYKLXg=)

Explanation
             :Implicit input of integer U.
ò2           :Range [2,U]
  @          :Map each X
   sX        :  Convert U to a base-X string
      êS     :  Is it a palindrome?
             :Implicitly reduce by addition and output

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
The Binary Binary Expansion

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term:
25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1
The choice of 0 and 1 is... not very binary. We shall perform the true binary expansion by expanding with powers of 2, but with a coefficient of 1 or -1 instead:
25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1
Now this looks binary.
Given any positive number, it should be trivial to see that:

Every odd number has infinitely many true binary expansions
Every even number has no true binary expansions

Hence, for a true binary expansion to be well-defined, we require the expansion to be the least, i.e with the shortest length.

Given any positive, odd integer n,  return its true binary expansion, from the most significant digit to the least significant digit (or in reversed order).
Rules:

As this is code-golf, you should aim to do this in the shortest byte count possible. Builtins are allowed.
Any output that can represent and list the coefficients is acceptable: an array, a string of coefficients with separators, etc...
Standard golfing loopholes apply.
Your program should work for values within your language's standard integer size.

Test Cases
25 -> [1,1,1,-1,-1]
47 -> [1,1,-1,1,1,1]
1 -> [1]
3 -> [1,1]
1234567 -> [1,1,-1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,1,1]

Related but quite different.

Simple algorithm: Convert to base 2, replace 0's with -1's, put the LSD at the front.

Voile: I wasn't explaining the downvotes, I was just outlining an algorithm for people who have base-conversion commands in their language.

Since you're so keen on being truly binary, can we return the value as packed bits with the usual place-value but the new interpretation of the two states?  i.e. electrically it's just high or low voltage (or whatever), and it's not my fault if standard debuggers print 0 instead of -1 for the low-voltage state.  The caller receiving the bits knows what they mean.  (It's still a non-trivial bit-manipulation exercise, since a rotate right only works if it has 32 significant bits.  e.g. a 5-bit number needs a rotate width of 5.)

Does the output need to include separators? Is 111-1-1 a valid output for 25?

@Oliver No separators is also fine, since that list is readable (only -1 can start with the minus sign).

@PeterCordes Sure if your language cannot represent the concept of -1 easily. For regular languages, however, as -1 is just a number like 0 or any other numbers, there is no particular reasons why one should avoid -1.

@Voile: I want to write a bit-manipulation answer (in x86 assembly machine code: bsf ecx, edi / shr edi,1 / bts edi, ecx are 2 and 3 byte instructions), not an answer with a loop that turns bits into string digits or array elements one at a time.  In the latter case, the answer is more boring, and the best way to handle the n-bit rotate is by storing a leading 1 and then looping over the bits in x >> 1.

i.e. I want to return an answer in "true binary", not a string or array representation of it.  I know this is basically asking for a loophole that changes the problem for other languages, too, so I get why you're reluctant to allow it.  I wish that you'd allowed that in the first place.

@JosiahWinslow, I can see why your algorithm works easily enough by subtracting the two representations and seeing that the result is 0, but is there a succinct proof of it?

@Jonah: Even though an n-bit rotation works, for understanding why it works, it's probably best to think of it as a right-shift that shifts in a copy of the high bit (like a 2's complement arithmetic shift but for limited width).  Then remember that 1000 - 1 is 0111 (in normal base2 binary).  Transforming from normal binary to "true binary" will require more set bits at the front, to compensate for unset bits meaning subtract their place-value rather than 0.  (This isn't a proof, but for me it's an "ok, that makes sense", and maybe could be cleaned up into a proof.)

Japt, 6 bytes
¤é r0J

Try it online!
Explanation:
¤é r0J  // Test input:                  25
¤       // Binary the input:            11001
 é      // Rotate 1 chars to the right: 11100
   r0J  // Replace 0s with -1:          111-1-1

Ah, the rotation; that's why it wasn't working for me.

Rotate??? dagnabbit.

JavaScript (ES6), 35 34 bytes
f=n=>n?[...f(n>>=1),!n|n%2||-1]:[]

Test snippet

let f=n=>n?[...f(n>>=1),!n|n%2||-1]:[];

[25, 47, 1, 3, 1234567].map(x => console.log(x + ":", JSON.stringify(f(x))))

Pyth,  12  11 bytes
|R_1.>jQ2 1

Try it here!

How?

|R_1.>jQ2 1   Full program.

      jQ2      Convert input to a binary list.
     .>   1    Cyclically rotate the list above by 1 place to the right.
|R_1           Substitute 0 with -1.
               Implicitly output.

First off, we notice that the task is just "substitute the 0s in the binary writing with -1s and shift to the right by 1 place." — That's exactly what we should do! The binary conversion gives us a list of 0s and 1s. All we should do here is to find a golfy way to convert 0 to -1. The bitwise operator | (bitwise OR) is our friend. The map over the binary representation shifted with | and -1. If the current number is 0, it gets converted to -1.

I don't think there's a better way. ;)

@JosiahWinslow I do... Trying to find it

Hm? The algorithm seems optimal, maybe that's because I don't know Pyth.

@JosiahWinslow Found the better way. Syntactical better way, not algorithmic better way.

@Mr.Xcoder And now there really isn't any at least to me.

Perl 6
String version, 31 bytes
1~(*+>1).base(2).subst(0,-1,:g)

Try it online!
List version, 36 bytes
{map * *2-1,1,|($_+>1).base(2).comb}

Try it online!

Perl 6, 72 bytes
There is surely a better way, but this is what I have...

->$a {grep {$a==[+] @^a.reverse Z+< ^∞},[X] (1,-1)xx $a.base(2).chars}

Try it online!
Explanation: It's a function that takes one argument (->$a). We first get the number of coefficients needed ($a.base(2).chars = number of characters in base 2 representation), then make a Cartesian product (X) of that many pairs (1,-1). (The [X] means: reduce the following list with X.) So we get a list of all possible combinations of 1s and -1s. Then we filter (grep) only the lists which encode the given number $a. There is only one, so we get a list of one list with the coefficients.
The grep block does this: takes its argument as a list (@^a), reverses it and zips it with an infinite list 0,1,2,... using the "left bit shift" operator +<. Zipping stops as soon as the shorter list is depleted (good for us!) We then sum all the results and compare it with the given number. We had to use .reverse because the OP demands that the coefficients be in the order from most significant to least significant.

R, 90 88 46 bytes
function(n)c((n%/%2^(0:log2(n))%%2)[-1],1)*2-1

Try it online!
Implements Oliver's algorithm, but returns the digits in reverse order. Since we are guaranteed that n is never even, the least significant bit (the first) is always 1, so we remove it and append a 1 to the end to simulate rotation in R. Thanks to Shaggy for getting me to fix my math.
Simply putting rev( ) around the function calls in the footer should return the values in the same order.
original answer, 88 bytes:
function(n,b=2^(0:log2(n)))(m=t(t(expand.grid(rep(list(c(-1,1)),sum(b|1))))))[m%*%b==n,]

Anonymous function; returns the values in reverse order with column names attached.
Try it online!
Explanation:
function(n){
 b <- 2^(0:log2(n))         # powers of 2 less than n
 m <- expand.grid(rep(list(c(-1,1)),sum(b|1))) # all combinations of -1,1 at each position in b, as data frame
 m <- t(t(m))               # convert to matrix
 idx <- m%*%b==n            # rows where the matrix product is `n`
 m[idx,]                    # return those rows
}

I wouldn't consider that output to be valid; suggest asking the challenge author for confirmation.

@Shaggy reversed order is explicitly allowed: from the most significant digit to the least significant digit (or in reversed order). hence this should be perfectly acceptable.

Reversed order, not reversed signs. Meaning valid output for 25, for example, would be [1,1,1,-1,-1] or [-1,-1,1,1,1].

@Shaggy ah, you're right, I just did the math wrong! should be 2*bits - 1 instead of 1-2*bits. Thank you.

05AB1E, 6 5 bytes
bÁ0®:

Try it online!

D< can be ® (® is default -1).

@EriktheOutgolfer Thanks! Didn't realize that.

Jelly, 5 bytes
Bṙ-o-

Try it online!

J, 11 bytes
1-~2*_1|.#:

Try it online!
Thanks to @JosiahWinslow for the algorithm.
Any thoughts on making the conversion shorter? My thoughts are to using !.-fit (nvm, it just changes the tolerance of the conversion).
Using {-take is longer by 1 character.
_1 1{~_1|.#:

Perl 5, 30 bytes
29 bytes code, 1 byte for -p switch.
$_=sprintf'1%b',$_/2;s/0/-1/g

Try it online!

Java 8, 101 bytes
n->{String s=n.toString(n,2);return(s.charAt(s.length()-1)+s.replaceAll(".$","")).replace("0","-1");}

Port of @Oliver's Japt answer, with a few more bytes.. ;)
Can definitely be golfed by using an mathematical approach instead of this String approach.
Explanation:
Try it here.
n->{                             // Method with Integer parameter and String return-type
  String s=n.toString(n,2);      //  Convert the Integer to a binary String
  return(s.charAt(s.length()-1)  //  Get the last character of the binary String
    +s.replaceAll(".$","")       //   + everything except the last character
   ).replace("0","-1");          //  Then replace all zeroes with -1, and return the result
}                                // End of method

Ruby, 44 37 33 32 bytes
->n{("1%b"%n).chop.gsub ?0,"-1"}

Try it online!

Golfscript, 14 13 14 bytes
-1 byte because I forgot % existed.
+1 byte because I also forgot input is a string.
~2base{.+(}%)\

If you're going to assume that the input comes as an integer, you should wrap the code in {} to make it a block. Full programs can only get input as strings.

Um...what? I meant, the number is being pushed as an integer, instead of a string containing a number.

In that case your answer is not a full program, and so must be a "function", or in the case of GolfScript a block. Therefore it's {2base{.+(}%\} for 15 bytes. Similarly your CJam answer.

This is a full program. Input in Golfscript are implicitly pushed onto the stack at the beginning of the program, and input in CJam is specified before execution and accessed with the q command.

I do have some familiarity with GolfScript. (And CJam). If you want to claim that it's a full program you need to prefix it with ~.

That I'd specified (I wasn't sure; I hadn't messed with GolfScript in a while, and I used the online interpreter). Will add now.

CJam, 12 bytes
A port of my Golfscript answer.
qi2b{_+(}%)\


text:
How many partitions do I have?
The partition number of a positive integer is defined as the number of ways it can be expressed as a sum of positive integers. In other words, the number of integer partitions it has. For example, the number 4 has the following partitons:

[[1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2], [4]]

Hence, it has 5 partitions.
This is OEIS A000041.

Task
Given a positive integer N determine its partition number.

All standard rules apply.

The input and output may be handled through any reasonable mean.

This is code-golf, so the shortest code in bytes wins.

Test Cases

Input | Output

1  |  1
2  |  2
3  |  3
4  |  5
5  |  7
6  |  11
7  |  15
8  |  22
9  |  30
10 |  42

I'm almost positive this is a duplicate...

@DJMcMayhem Umm, ok. Let me know if you find a duplicate. Sorry, I'm new to all this!

@DJMcMayhem maybe this question you asked since it's a short step from "generating" to "counting" but you don't necessarily have to generate all the partitions to count them...

this one is a dupe, EXCEPT that is a popcon(?) and closed as too broad. IMHO this is WAY better written and should be keep open, while the old one should be (reopened and) closed as dupe

@Rod, it's a bad pop-con, but switching the close reason to dupe wouldn't be an improvement. The performance requirement there would be an obstacle to porting some answers (no-one's going to generate the 24061467864032622473692149727991 partitions of 1000 in a couple of minutes); and the Hardy-Ramanujan-Rademacher implementation is not exactly golfed... However, it may be worth opening a discussion in meta about what to do with this question and that one.

There's also this in the sandbox.

Pyth, 3 bytes
l./

Try it here! or Try a test Suite.
The answer took much longer to format than writing the code itself :P.

How?
Pyth is the right tool for the job.

l./   Full program with implicit input.

 ./   Integer partitions. Return all sorted lists of positive integers that add to the input.
l     Length.
      Implicitly output the result.

Mathematica, 11 bytes
PartitionsP

Explanation
¯\_(ツ)_/¯

Emojicode 0.5, 204 201 bytes
➡⬅11s 0k⏩0t➖kr ti⏩1 tt i 0➕r i➕s✖rk➗s

Try it online!
-3 bytes by using "less than or equal to 1" instead of "less than 2" because the "less than" emoji has a quite long UTF-8 encoding. Also made t a frozen to silence a warning without affecting the byte count.
Extends the  (integer) class with a method named . You can write a simple program that takes a number from the input, calls  on the number and prints the result like this:

 strPlease enter a number
 numstr 10
  num 10

  Learn what a number is, you moron!

This part could be golfed a lot by omitting the messages and error handling, but it's not included in the score, so I prefer to show more features of Emojicode instead, while improving readability along the way.
Ungolfed

 ➡
  ◀2
   1

  sum 0
  k⏩0
   nmk➖k
   sig nmk
   i⏩1 nmk
    nmk i 0
     ➕sig i

   ➕sum✖sigk

  ➗sum

Explanation
Note: a lot of emoji choice doesn't make much sense in emojicode 0.5. It's 0.x, after all. 0.6 will fix this.
Emojicode is an object-oriented programming language featuring generics, protocols, optionals and closures, but this program uses no closures and all generics and protocols can be considered implicit, while the only optional appears in the I/O stub.
The program operates on only a few types:  is the integer type,  is the string type and ⏩ is the range type. A few booleans () appear too, but they are only used in conditions. Booleans can take a value of  or , which correspond to true and false, respectively.
There are currently no operators in Emojicode, so addition, comparsions and other operations that are normally operators are implemented as functions, effectively making the expressions use prefix notation. Operators are also planned in 0.6.
Let's tackle the test program first.

This is the  block, which can be compared to main from other languages.
 ...

Grapes and watermelons declare code blocks in emojicode.
strPlease enter a number

This declares a "frozen" named str and sets it value to a new string created using the initializer (constructor) , which takes a prompt as a string and then inputs a line from the user. Why use a frozen instead of a variable? It won't change, so a variable would emit a warning.
numstr 10

Let's break it down. str 10 calls the  method on the str frozen with the argument 10. By convention, methods named with the name of a type convert the object to that type. 10 is the base to use for integer conversion. This method returns an optional, . Optionals can contain a value of the base type or nothingness, ⚡. When the string doesn't contain a number, ⚡ is returned. To use the value, one has to unwrap the optional using , which raises a runtime error if the value is ⚡. Therefore, it is good practice to check for nothingness before unwrapping an optional. It is so common, in fact, that Emojicode has a shorthand for that. Normally,  is an "if".  variable expression means: evaluate the expression. If the optional contains nothingness, the condition evaluates to  (false). Otherwise, a frozen named variable is created with the unwrapped value of the optional, and the condition evaluates to , (true). Therefore, in normal usage, the  ...  block following the conditional is entered.
num 10

 is the method the main code adds to  using  that calculates the number of partitions. This calls  on the num frozen we declared in the conditional and converts the result to a string using base 10 by the  method. Then,  prints the result.
 ...

 means "else", so this block is entered when the user did not enter a number correctly.
Learn what a number is, you moron!

Prints the string literal.
Now, let's look at the main program. I'll explain the ungolfed version; the golfed version just had the whitespace removed and variables renamed to single letter names.
 ...

Extend the  class. This is a feature that is not commonly found in programming languages. Instead of creating a new class with  as the superclass,  modifies  directly.
➡ ...

Creates a new method named  that returns a . It returns the number of partitions calculated using the formula a(n) = (1/n) * Sum_{k=0..n-1} sigma(n-k)*a(k)
⬅1
 1

 is similar to this or self from other languages and refers to the object the method was called on. This implementation is recursive, so this is the terminating condition: if the number the method was called on is less than or equal 1, return 1.
sum 0

Create a new variable sum and set it to 0. Implicitly assumes type .
k⏩0

 iterates over anything that implements the ⚪ protocol, while ⏩ is a range literal that happens to implement . A range has a start value, a stop value and a step value, which is assumed to be 1 if start < stop, or -1 otherwise. One can also specify the step value by using the ⏭ to create the range literal. The start value is inclusive, while the stop value is exclusive, so this is equivalent to for k in range(n) or the Sum_{k=0..n-1} in the formula.
nmk➖k

We need to calculate sigma(n - k), or the sum of divisors of n - k in other words, and the argument is needed a few times, so this stores n - k in the variable nmk to save some bytes.
sig nmk
i⏩1 nmk

This sets the sig variable to the argument of sigma and iterates over all numbers from 1 to nmk - 1. I could initialize the variable to 0 and iterate over 1..nmk but doing it this way is shorter.
nmk i 0

 calculates the remainder, or modulus and  checks for equality, so the condition will be  if i is a divider of nmk.
➕sig i

This is an assignment by call, similar to the += -= >>= operator family in some of the inferior, emoji-free languages. This line can be also written as  sig ➕ sig i. Therefore, after the inner loop finishes, sig will contain the sum of divisors of n - k, or sigma(n - k)
➕sum✖sigk

Another assignment by call, so this adds sigma(n - k) * A(k) to the total, just as in the formula.
➗sum

Finally, the sum is divided by n and the quotient is returned. This explanation probably took thrice as much time as writing the code itself...

Python 2, 85 83 bytes
-2 bytes thanks to @notjagan
lambda n:n<1or sum(sum(i*((n-k)%i<1)for i in range(1,n+1))*p(k)for k in range(n))/n

Try it online!
Using recursive formula from OEIS A000041.

83 bytes.

84 bytes. ==0 is equivalent to <1 in this case. EDIT: Use notjagan's approach

@Mr.Xcoder The original code actually had <1 instead of ==0, but the TIO code didn't.

Also 83 bytes.

Python 2, 54 53 bytes
f=lambda n,k=1:1+sum(f(n-j,j)for j in range(k,n/2+1))

Try it online!
How it works
Each partition of n can be represented as a list x = [x1, ⋯, xm] such that x1 + ⋯ + xm = n. This representation becomes unique if we require that x1 ≤ ⋯ ≤ xm.
We define an auxiliary function f(n, k) that counts the partitions with lower bound k, i. e., the lists x such that x1 + ⋯ + xm = n and k ≤ x1 ≤ ⋯ ≤ xm. For input n, the challenge thus asks for the output of f(n, 1).
For positive integers n and k such that k ≤ n, there is at least one partition with lower bound k: the singleton list [n]. If n = k (in particular, if n = 1), this is the only eligible partition. On the other hand, if k > n, there are no solutions at all.
If k < n, we can recursively count the remaining partitions by building them from left to right, as follows. For each j such that k ≤ j ≤ n/2, we can build partitions [x1, ⋯, xm] = [j, y1, ⋯,  ym-1]. We have that x1 + ⋯ + xm = n if and only if y1 + ⋯ + ym-1 = n - j. Furthermore, x1 ≤ ⋯ ≤ xm if and only if j ≤ y1 ≤ ⋯ ≤ ym-1.
Therefore, the partitions x of n that begin with j can be calculated as f(n - j, j), which counts the valid partitions y. By requiring that j ≤ n/2, we assure that j ≤ n - j, so there is at least one y. We can thus count all partitions of n by summing 1 (for [n]) and f(n - j, j) for all valid values of j.
The code is a straightforward implementation of the mathematical function f. In addition, it makes k default to 1, so f(n) computes the value of f(n, 1) for input n.

Oh wow, this is incredible! Can you add an explanation on how this works?

I've edited my answer. If anything is unclear, please let me know.

Pari/GP, 8 bytes
numbpart

Try it online!

Retina, 34 bytes
.+
$*
+%1`\B
;$'¶$`,
,

%O`1+
@`.+

Try it online!
Explanation
.+
$*

Convert the input to unary.
+%1`\B
;$'¶$`,

This computes all 2n-1 partitions of the unary digit list. We do this by repeatedly (+) matching the first (1) non-word boundary (\B, i.e. a position between two 1s) in each line (%) and replacing it with ;, everything after it ($'), a linefeed (¶), everything in front of it ($`) and ,. Example:
1;1,111

Becomes
      vv
1;1,1;11
1;1,1,11
^^^^^

Where v marks the result of $' and ^ marks the result $`. This is a common idiom to get the result of two different replacements at once (we basically insert both the ; and the , replacement, as well as the missing "halves" of the string to complete two full substitutions).
We will treat ; as actual partitions and , just as placeholders that prevent subsequent \B from matching there. So next...
,

... we remove those commas. That gives us all the partitions. For example for input 4 we get:
1;1;1;1
1;1;11
1;11;1
1;111
11;1;1
11;11
111;1
1111

We don't care about the order though:
%O`1+

This sorts the runs of 1s in each line so we get unordered partitions.
@`.+

Finally, we count the unique (@) matches of .+, i.e. how many distinct lines/partitions we've obtained. I added this @ option ages ago, then completely forgot about it and only recently rediscovered it. In this case, it saves a byte over first deduplication the lines with D`.

Python 2, 89 bytes
-9 bytes by Mr.Xcoder
-1 byte by notjagan
lambda n:len(p(n))
p=lambda n,I=1:{(n,)}|{y+(x,)for x in range(I,n/2+1)for y in p(n-x,x)}

Try it online!

90 bytes

@Mr.Xcoder Don't even know, why I didn't use lambda D:

Hehe, ¯\_(ツ)_/¯ - BTW, if you wanted to keep it a full function, you wouldn't need the variable, 94 bytes

@Mr.Xcoder Yeah.. I'm feeling rusty after some time being away from codegolf :c

-1 byte.

J, 37 35 bytes
0{]1&((#.]*>:@#.~/.~&.q:@#\%#),])1:

Try it online!
Explanation
0{]1&((#.]*>:@#.~/.~&.q:@#\%#),])1:  Input: n
                                 1:  Constant 1
  ]                                  Get n
   1&(                          )    Repeat n times on x = [1]
                          \            For each prefix
                         #               Length
                      q:@                Prime factors
                 /.~&                    Group equal factors
              #.~                        Compute p+p^2+...+p^k for each group
           >:@                           Increment
                    &.q:                 Product
                           %           Divide
                            #          Length
         ]                             Get x
          *                            Times
   1   #.                              Sum
                              ,        Joim
                               ]       Get x
                                       Set this as next value of x
0{                                   Select value at index 0

I'm dumbstruck and dumbfounded, mind posting an explanation?

@cole This is an iterative approach that starts with the solution for p(0) = 1, and builds the next using the formula p(n) = sum(sigma(n-k) * p(k) for k = 0 to n-1) / n. I'll add an explanation of the code later when I believe it can't be significantly shortened.

Octave, 18 bytes
partcnt(input(''))

Uses the built-in function partcnt.
Can't get it right by using an anonymous function using @, some help would be appreciated.

Regex  (RME / Perl / PCRE2 v10.35+), 13 12 bytes
((\1|^)x*)+$

Try it on replit.com - RegexMathEngine
Try it online! - Perl v5.28.2 / Attempt This Online! - Perl v5.36+
Attempt This Online! - PCRE2 v10.40+
Takes its input in unary, as the length of a string of xs. Returns its output as the number of ways the regex can match. (The rabbit emoji indicates this output method.)
This simply enumerates all the partitions. In order to count unordered partitions, it enforces that partitions occur in strictly nondecreasing order. This is accomplished by starting with an arbitrary-sized partition on the first iteration, and adding an arbitrary nonnegative integer to the partition size on each iteration. At the end, $ asserts that the cumulative sum is equal to the input number.
                    # tail = N = input number; no need to anchor, because the
                    # following loop is forced to do at least one iteration,
                    # and its first iteration has an anchor.
(                   # \1 = sum of the following:
    (
        \1          # Previous value of \1, if set
    |           # or
        ^           # 0, if this is the first iteration
    )
    x*              # Any arbitrary nonnegative integer
)+                  # Iterate the above any positive number of times
$                   # Assert tail == 0

Alternative 12 bytes:
(\1x*|^x*)+$

Try it online! - Perl v5.28.2 / Attempt This Online! - Perl v5.36+
Try it online! - PCRE2 v10.40+
Regex  (Raku:P5), 13 bytes
^(\1x*|^x+)*$

Try it online!
^                   # tail = N = input number
(                   # \1
    # If on an iteration after the first:
    \1x*            # \1 += {any arbitrary nonnegative integer}; tail -= \1
|
    ^               # Anchor to start, to assert this is the first iteration.
    x+              # \1 = {any arbitrary positive integer}; tail -= \1
)*
$                   # Assert tail == 0

Raku's Perl 5 compatibility mode is rather inaccurate, and prevents the 12 byte regex from working, apparently because there is nothing preventing a zero-width match from looping infinitely.
Regex  (RME / Perl / PCRE), 29 20 bytes
((?=(\3|^))(\2x*))+$

Try it on replit.com - RegexMathEngine
Try it online! - Perl v5.28.2 / Attempt This Online! - Perl v5.36+
Try it online! - PCRE1
Try it online! - PCRE2 v10.33 / Attempt This Online! - PCRE2 v10.40+
PCRE1, and PCRE2 up to v10.34, automatically makes any capture group atomic if it contains a nested backreference. To work around this, the capture is copied between \2 and \3 using only forward-declared backreferences.
This would also make the regex compatible with Pythonregex and Ruby, but they have no way of doing  output without source code modifications.
                      # tail = N = input number; no need to anchor, because the
                      # following loop is forced to do at least one iteration,
                      # and its first iteration has an anchor.
(
    (?=
        (             # \2 = the following:
            \3        # Previous value of \3, if \3 is set
        |         # or
            ^         # 0, if on the first iteration
        )
    )
    (                 # \3 = the following, which is also subtracted from tail:
        \2x*          # \2 plus any arbitrary nonnegative integer
    )
)+                    # Iterate the above as many times as possible, minimum 1
$                     # Assert tail == 0

Perl, 37 36 bytes (full program)
1x<>~~/((\1|^).*)+$(??{++$i})/;say$i

Try it online!
Alternative 36 bytes:
1x<>~~/((\1|^).*)+$(??{++$\})/;print

Try it online!
Perl -p, 33 32 bytes (full program)
1x$_~~/((\1|^).*)+$(??{++$\})/}{

Try it online!
Can only take one input (followed by EOF) per run. See Fibonacci function or sequence for an explanation.
Raku, 29 bytesSBCS (anonymous function)
{+m:ex:P5/^(\1.*|^.+)*$/}o¹x*

Try it online!

JavaScript, 125 121 bytes
n=>(z=(a,b)=>[...Array(a)].map(b))(++n**n,(_,a)=>z[F=z(n,_=>a%(a/=n,n)|0).sort().join`+`]=b+=eval(F)==n-1&!z[F],b=0)|b||1

Try it online!
Warning: time and space complexity is exponential. Works very slow for large numbers.

JavaScript ES7, 69 Bytes
n=>(f=(i,s)=>i?[for(c of Array(1+n))f(i-1,s,s-=i)]:c+=!s)(n,n,c=0)&&c

Try it online!
JavaScript ES6, 71 Bytes
n=>(f=(i,s)=>i?[...Array(1+n)].map(_=>f(i-1,s,s-=i)):c+=!s)(n,n,c=0)&&c

Try it online!
Time complexity O(n^n), so be careful (an obvious delay appears on my computer for F(6))

Desmos, 64 bytes
p(n)=1+∑_{i=1}^{n^n}0^{(n-∑_{j=1}^njmod(floor(ni/n^j),n))^2}

Try it on Desmos!
This is O(n^(n+1))
How it works
The value of i in base n encodes a partition by counting the multiplicity of each part.
For n=8, i=81 encodes [mod(81,8), mod(81//8,8), mod(81//8^2,8), ...] = [1,2,1], so that's 1 one, 2 twos, and 1 three, which gives the partition 1 + 2 + 2 + 3
mod(floor(ni/n^j),n) is the number of parts of size j.
∑_{j=1}^njmod(floor(ni/n^j),n) is the sum of the parts
0^{(n-sum)^2} is an indicator for if i encodes a partition of n: it is 1 if the sum is n, otherwise 0
Summing 0^{(n-sum)^2} over all valid i gives the number of partitions, excluding the n-ones partition 1+1+1....+1 because i=n encodes one 2, not n 1s, so we add 1 to the count.
DesModder Text Mode Beta 1, 73 bytes
p(n)=1+sum i=(1...n^n)({n=sum j=(1...n)(j*mod(floor(n*i/n^j),n)),else:0})

DesModder Text Mode avoids the pains of golfing Desmos LaTeX, but it's still a bit buggy, and the syntax is in flux. So some more development might end up with the following syntax for 64 bytes:
p(n)=1+sum(i=1...n^n,{n=sum(j=1...n,j*mod(floor(n*i/n^j),n)),0})

Yo nice answer! I still have no idea what is going on even after reading the explanation lol

ooh this text mode thingy seems cool

Jelly, 13 bytes
JÆsæ.:L;
1Ç¡Ḣ

Try it online!
Takes 5 seconds to solve n = 1000 on TIO.

Jelly, 3 bytes
The Œṗ atom has recently been added, and it means "Integer partitions".
ŒṗL

Try it online!

ŒṗL   - Full program.

Œṗ    - Integer partitions.
  L   - Length.
      - Output implicitly.

Pyt, 2 bytes
←ᵱ

Try it online!
Explanation:
←          Get input
 ᵱ         Number of partitions

The ← can be removed as it is implicit for 1 byte,

05AB1E, 3 bytes
Åœg

Try it online or verify all test cases.
Explanation:
Åœ   # Get all lists of positive integers that sum to the (implicit) input
  g  # Pop and push the length to get the amount lists
     # (which is output implicitly as result)

Vyxal l, 1 byte
Ṅ

Try it Online!
Vyxal, 2 bytes
ṄL

Try it Online!

Jelly, 5 bytes
ŻṗḋRċ

Try it online!
Non-builtin solution using Henry Bottomley's comment at the top of the OEIS page. Although this obviously doesn't beat the builtin, I wouldn't be surprised if the same approach might be the shortest in some other array languages.
 ṗ       Generate every combination of n elements with replacement from
Ż        [0 .. n],
  ḋ      dot product each with
   R     [1 .. n],
    ċ    and count the occurrences of n.

This can also be thought of as encoding each unordered partition as an ordered list of the multiplicity of each integer.

Java 8 (229 bytes)
import java.util.function.*;class A{static int j=0;static BiConsumer<Integer,Integer>f=(n,m)->{if(n==0)j++;else for(int i=Math.min(m,n);i>=1;i--)A.f.accept(n-i,i);};static Function<Integer,Integer>g=n->{f.accept(n,n);return j;};}

Ungolfed:
import java.util.function.*;

class A {
    static int j = 0;
    static BiConsumer<Integer, Integer> f = (n, m) -> {
        if (n == 0)
            j++;
        else
            for (int i = Math.min(m, n); i >= 1; i--)
                A.f.accept(n - i, i);
    };
    static Function<Integer, Integer> g = n -> {
        f.accept(n, n);
        return j;
    };
}


text:
Approximate the Score of a 2048 Game
A game of 2048 goes like this:

Every move you get another piece - either 2 90% of the time, or 4 10% of the time
for each 2 equal pieces combined you get a piece of the sum of the two and the sum gets added to your score

Your task
given a board of a 4x4 game, give the average score of what A game like that would result in.
To calculate it, go the other way around of the game. For example, if there's an 8 piece, it's made from 4s. The average score of a 4 piece is 4*90% (90% of the time it's made from combining two 2 pieces together and it the other 10% a 4 isn't made, but ) = 3.6. As to make an 8 you need two 4s, and then you need to combine them to an 8, the result is 3.6*2 + 8 = 15.2.
In pseudocode a calculation for one number could be this:
function value (x) {
  if (x > 4) return value(x / 2) * 2 + x
  else if (x == 4) return 4*90%
  else return 0
}

but you're free to choose any approach as long as it works the same.
Clarifications

The input board will always be from a 4x4 board.
You can take in the board as an array of the 16 values, as 16 different inputs or even a 2D array if that somehow helps you.
The input numbers will always be zero or 2 to the power of a positive integer.
You can discard any errors due to floating point operations (but theoretically the program must implement a correct algorithm).
This is code-golf, the shortest code wins!

Test-cases
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -> 0
[2,4,2,4,4,2,4,2,2,4,2,4,4,2,4,2] -> 28.8
[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4] -> 57.6
[0,0,0,4,0,0,0,8,0,0,0,16,2,2,0,2048] -> 20340.4
[2,16,2048,4096,4,32,1024,8192,8,64,512,16384,16,128,256,32768] -> 845465.2
[8,8,4,4,0,0,0,0,0,0,2,2,2048,65536] -> 996799.2

@LuisMendo 90% of the time a given 4 gets made from combining two 2 pieces, while 10% of the time they appear as one and give no score

@LuisMendo A 4 piece isn't always made from combining two 2's, as 10% of the time when a piece spawns in after a move, it starts as a 4

Out of 9 spawned 2's one can only create 4.5 4's, not 9. Shouldn't the average score of a 4 piece be 9/11 * 4 = 3.2727... ?

@ovs Even if my math is wrong, the challenge will stay this way. Trying to figure what you mean (and now even why I thought my method was correct)

if 20 new pieces spawn, 2 4's and 18 2's. We can create additional 9 4's by merging the 2's. We now have 11 4's with a total score of 36 and an average score of 36/11 = 3.2727...

@ovs ah, I guess you're right :/

Python 3, 51 48 bytes
 -3 bytes thanks to Mr. Xcoder!
lambda b:sum(n*max(0,len(bin(n))-4.1)for n in b)

Try it online!

48 bytes. n.bit_length() means len(bin(n))-2, which we can compress into len(bin(n))-4.1

@Mr.Xcoder Nice. I was sure there was some easier way to do number of bits but I blanked for some reason.

C# (.NET Core), 101 100 bytes
n=>{double k=0,l=0;for(int i=0,j;i<n.Length;l+=k,++i)for(j=4;j<=n[i];j*=2)k=j>4?k*2+j:3.6;return l;}

Try it online!
Lambda function. Takes in an array for the board, and returns a double for the score

APL (Dyalog Extended), 18 bytes
+/{⍵×0⌈2.1-⍨≢⊤⍵}¨⎕

Try it online! or Verify all test cases
Full program submission.
Port of the Python answer.
Explanation
+/{⍵×0⌈2.1-⍨≢⊤⍵}¨⎕
                ¨⎕ to each element of the input:
              ⊤⍵   convert to base 2 digits
       2.1-⍨≢      length - 2.1
     0⌈            maximum with 0
   ⍵×              times the element
+/                 sum the resulting array

JavaScript (V8), 58 bytes
b=>b.reduce((a,n)=>a+(z=x=>x>4?z(x/2)*2+x:x-4?0:3.6)(n),0)


text:
Go away! No-1's Here!
I was playing around with some numbers and found a sequence that, of course, is on OEIS. It is A005823: Numbers whose ternary expansion contains no 1's. It goes:

a(2n) = 3*a(n)+2
a(2n+1) = 3*a(n+1)
a(1) = 0
a = 0,2,6,8,18,20,24,26,54....

I wrote a CJam program that generates the first n of these numbers by converting the index to binary, replacing the 1's with 2's, and converting from ternary to decimal.
I also noticed that any even number can be obtained by taking the sum of two numbers in the sequence (sometimes the number with itself).
The Challenge:
Given any non-negative even number as input, output the indices of two numbers in the sequence that sum to it. (Note that sometimes multiple pairs are possible.)
The Rules:

Specify if you're using 0- or 1-indexing.
If you're outputting as a string, put a delimiter between the two indices.
You are allowed to output as a complex number.
If you so desire, you can output every valid pair.
Code Golf: shortest answer wins

Test Cases
I use 0-indexing. Here I list every possible output for each input, but you only need to output one.

0:      [0 0]
2:      [1 0]
4:      [1 1]
6:      [2 0]
8:      [2 1]   [3 0]
10:     [3 1]
12:     [2 2]
14:     [3 2]
16:     [3 3]
18:     [4 0]
30:     [6 2]
32:     [6 3]   [7 2]
46:     [7 5]
50:     [7 6]
120:    [10 10]
338:    [19 18]
428:    [30 23] [31 22]
712:    [33 27] [35 25] [41 19] [43 17] [49 11] [51 9]  [57 3]  [59 1]
1016:   [38 37] [39 36] Thanks to @Luis Mendo for test case help.
Related: Is it within the Cantor set?

May we output a complex number of the two values? May we provide two functions, one giving each value?

May we output all possible values, or is that going beyond the challenge?

@cole Yeah, that's ok.

It seems that Mr Sloane really likes his number sequences. "There's a sequence for that" (TM)

Since there are several solutions for some inputs, it would be nice to include all the solutions in the test cases. This program shows all solution pairs for each test case, in the same format as in the challenge text (0-based, each pair sorted increasingly)

Thanks @LuisMendo. 712 is really special, huh?

Husk, 21 14 13 bytes
-7 bytes, thanks to @Neil's JS answer
-1 byte inspired by betaveros's Parradoc answer
Uses 0-indexing
mḋTmMo±>ḋ2B3½

Try it online!
Explanation
            ½    Half the input
          B3     Convert to Base 3
   m             Map over the list
    Mo±>ḋ2       Function such that: 0 -> [0,0], 1 -> [0,1], 2 -> [1,1]
        ḋ2       Binary 2, [1,0]
    M            For each in that list
     o±>         check if the argument is greater than it
  T              Transpose
mḋ               Convert each from binary

Previous 21 byte Solution
First time I've seen a use for ».
mḋT»o%2+ȯ?´eḋε%3`-0B3

Try it online!
Longer, as I was dealing with carries

JavaScript (ES6), 75 71 bytes

f=
n=>[1,0].map(i=>parseInt((n/2).toString(3).replace(/./g,c=>+c+i>>1),2))
<input type=number min=0 step=2 oninput=o.textContent=this.value%2?``:f(this.value)><pre id=o>

Explanation: Dividing input and the elements of A005823 by 2 doesn't alter the problem, however it makes the solution simpler as the ternary representations now only use 0s and 1s and therefore there is no carrying to consider. It also saves a step when converting from the element to its index (each element's ternary is twice the binary of its index). Examples:
                 A005823
                  halved
            n in  values A005823
   n n/2  base 3  base 3 indices
   0   0       0   0   0   0   0
   2   1       1   1   0   1   0
   4   2       2   1   1   1   1
   6   3      10  10   0   2   0
   8   4      11  11   0   3   0
  10   5      12  11   1   3   1
  12   6      20  10  10   2   2
  14   7      21  11  10   3   2
  16   8      22  11  11   3   3
  18   9     100 100   0   4   0
  30  15     120 110  10   6   2
  32  16     121 111  10   7   2
  46  23     212 111 101   7   5
  50  25     221 111 110   7   6

Jelly, 26, 22, 21 bytes
ḶBḤḅ3
ÇŒcS=¥Ðf⁸ḢiÐ€ÇT

Try it online!
One byte saved thanks to @JonathanAllan!
Explanation:
                # Helper link: A005823 to *N* terms
Ḷ               # Lowered range(N)
 B              # Converted to binary
  Ḥ             # Double each digit
   ḅ3           # Converted from base 3 to decimal
                # Main link
Ç               # Last link
 Œc             # All combinations of 2 items (with replacement)
      Ðf        # Remove every combination where this isn't true:
   S=¥          #   The sum of the two items is equal to N
        ⁸Ḣ      # Take the first combination left
          i     # Index of
           Ð€   # Each element of the combination
             Ç  # In the sequence
              T # Return the truthy indices

@JonathanAllan Oh, nice to know about Œc. And yeah, Dennis explained the problem with S=¥ to me.

Looks like you need to add edge-case handling for zero by the way :(

Looks like this is 1-based; perhaps it would be worth stating it in the answer

20 bytes

J, 35 32 bytes
($#:I.@,)@(=[:+/~3#.+:@#:@i.@>:)

Try it online!
0-indexed and input is given monadically. Returns all possible summations to the value (it treats a b and b a as different possible summations).
Converting from a boolean matrix to indices takes a lot of code...
I'd like to also remove the fork on the left so I don't have to use as many parentheses and @-ats, but I can't figure out a good way to do it (my alternate approach doesn't save any bytes).
Explanation
For purposes of explaining and ungolfing, consider the following components of the main function
valid_nums      =. = [: +/~ 3 #. +:@#:@i.@>:
indices_of_ones =. $ #: I.@,

valid_nums yields a boolean matrix where the indices are the indices of the summed sequence values. If there's a one at those indices, it means that the two numbers sum to the input value.
indices_of_ones is a J idiom for giving the coordinates of the ones in an arbitrary rank boolean matrix
The main function is composed quite simply as
indices_of_ones@valid_nums

valid_nums
= [: +/~ 3 #. +:@#:@i.@>:  Input is n
                 #:@i.@>:  Binary numbers in range [0,n]
              +:           Doubled
         3 #.              Interpreted as ternary
     +/~                   Addition table with self (sum all possible pairs)
=                          Equate to n

indices_of_ones
$ #: I.@,
        ,  Ravel matrix into a single list
     I.    Find the indices of ones in that list
  #:       Convert to the base given by
$          The shape of the matrix

,-ravel works in this case by joining each row to the next.
   i.3 3
0 1 2
3 4 5
6 7 8
   , i.3 3
0 1 2 3 4 5 6 7 8

We can see that if this were a boolean matrix, the coordinates of ones can be found by interpreting the indices of the raveled matrix as numbers in the base of the shape of that matrix using as many prepositional phrases as possible to help confuse the poor reader.

your redundant outputs are ok.

Python 2, 51 bytes
f=lambda n:[n and(n/2%3>r)+2*f(n/3)[r]for r in 0,1]

Try it online!
The task can be done like this:

Halve the input
Convert to ternary list
Split that into two binary lists that sum elementwise to it
Convert those lists from binary

We can do the splitting in (3) by converting 0->0,1->1,2->1 for one list and 0->0,1->0,2->1 for the other. That is, by checking is the value is above a threshold of 0 or 1.
The two values can be found by respective recursive functions:
p=lambda n:n and(n/2%3>0)+2*p(n/3)
q=lambda n:n and(n/2%3>1)+2*q(n/3)

The function f combines the two of these in a list comprehension. This makes it inefficient due to exponential branching.
If complex numbers could be output, we could save 10 bytes with:
f=lambda n:n and(n%6>1)+n%6/4*1j+2*f(n/3)

I guess complex numbers are ok.

MATL, 22 21 19 17 bytes
tQ:qBEI_ZA&+=R&fh

Output is 1-based. The program produces all solution pairs. Try it online! Or verify all test cases.
Explanation
t      % Implicit input: n. Duplicate
Q:q    % Range [0 1 ... n]
B      % Convert to binary. Gives a matrix where each row corresponds to a number
E      % Multiply each entry by 2
I_ZA   % Convert each row from ternary to a number
&+     % Matrix of all pair-wise additions
=      % Does each entry equal n?
R      % Upper triangular matrix
&f     % Push row and column indices of nonzero entries
h      % Concatenate horizontally. Implicit didsplay

OP said that producing all solutions was OK in the comments

@H.PWiz Thanks! I hadn't seen that

Paradoc (v0.2.10), 11 bytes (CP-1252)
½3B2>_B™2Bv

Try it online!
Algorithmically it's very much just like Neil's ES6 answer. On a lower level, also strikingly similar to H.PWiz's Husk answer. I am amused that we got to use all three overloadings of B.
Takes an integer on the stack, leaves a list of two integers on the stack.
Explanation:
½           .. Halve input
 3B         .. Convert to ternary
   2        .. 2, which will get implicitly coerced to [0,1]
    >_      .. Greater than, as a block
      B     .. "Bimap": take the block and map it over the Cartesian
            .. product of the last two lists to get a matrix
       ™    .. Transpose
        2Bv .. Convert each row from binary

Pyth, 37 bytes
0-indexed
Certainly not golfed as well as it could be.
KUQJmi:.Bd\1\23KhfqQ+@JeT@JhTsmm,dkKK

Try it online!

34 bytes: hfqQ+@Jmi:.Bd\1\23QeT@JhTsmm,dkUQU. Can most definitely be golfed

33 bytes: hfqQ+@Jmi:.Bd\1\23QeT@JhTsmm,dkUQ

Pyth, 29 bytes
This one returns all possible pairs of indices.
fqQ+@Kmi:.Bd\1\23QhT@KeT.cUQ2

Try it here.
Pyth, 30 bytes
hfqQ+@Kmi:.Bd\1\23QhT@KeT.cUQ2

Try it here.
This returns the pairs of indices as [LowerIndex, HigherIndex].

How does this work?
hfqQ+@Kmi:.Bd\1\23QhT@KeT.cUQ2   Full Program. Q means input throughout the whole explanation.

       m          Q               Map over the range [0, Q) with a variable d.
          .Bd                     Convert to binary.
         :   \1\2                 Replace 1 with 2.
        i        3                Convert it from base 3 to integer.
      K                           Assign the mapped range to a variable K.
                         .cUQ2    All possible two-element combinations of the range [0...Q).
    +@             hT@KeT         Sum of the integers on positions in K of the two-element
                                  combination.
 fqQ                              Filter those that equal the input.
h                                 Optional: Head. Take the first element.
                                  Print the result, implicitly.

JavaScript, 120 101 bytes
n=>[(A=[...Array(n+1)].map(Z=(a,b=a)=>b&&3*Z(b/2|0)+b%2*2))[F='findIndex'](a=>z=~A[F](b=>a+b==n)),~z]

Try it online!
0-indexed.
It returns the pair of indices where one index is the smallest possible (for example in the case of 428 it returns 22,31).

Python 3, 122 120 bytes
-2 bytes thanks to Mr. Xcoder!
0-indexed
def f(a):r=range(a);s=[int(bin(x)[2:].replace(*'12'),3)for x in r];return[(i,j)for i in r for j in r if s[i]+s[j]==a][0]

Ungolfed:
def f(a):
    r=range(a)
    s=[int(bin(x)[2:].replace(*'12'),3)for x in r]
    return[(i,j)for i in r for j in r if s[i]+s[j]==a][0]

Try it online!

Hope you do not mind. I added a TiO link.

Mathematica, 94 bytes
(w=#;Position[s,#]&/@#&@@(k=Select)[Tuples[s=k[Range@w,DigitCount[#,3,1]==0&],{2}],Tr@#==w&])&

1-indexed

Brain-Flak, 220 166 bytes
-54 bytes by looking up the modulo function on the wiki, allowing some structural changes
({()<({}[()()])>}{}){({}(<>))<>(()()())({()<(({})){({}[()])<>}{}>}{}<><([{}()]{})>[()])}([]){{}<>(({}){})<>(({}){}{()<({}[()]){<>({}())<>(<{}>)}>}{})([][()])}({}{}<>)

Try it online!
0-indexed.
Explanation
Like many of the other solutions, this computes the ternary expansion of n/2 and converts that to two binary numbers.
Step 1: Divide input by 2
({()<({}[()()])>}{})

 {              }     until number becomes zero:
     ({}[()()])       subtract two
( ()<          > {})  push number of iterations

Step 2: compute ternary expansion
{({}(<>))<>(()()())({()<(({})){({}[()])<>}{}>}{}<><([{}()]{})>[()])}

 ({}(<>))<>         {   (({})){({}[()])<>}{} }{}<> ([{}()]{})         modulo (from wiki)
           (()()())                                                   use 3 as base
                     ()<                    >                         evaluate as 1 every time the 3 rolls over
                   (                              <          >[()])   push number of rollovers (function is now division with remainder)
{                                                                  }  repeat until quotient is zero, leaving all remainders on stack

Step 3: Convert to solution
([]){{}<>(({}){})<>(({}){}{()<({}[()]){<>({}())<>(<{}>)}>}{})([][()])}({}{}<>)

([]){{}                                                      ([][()])}           repeat while stack height > 1:
                                                                                (loop happens once when initial stack height is 1, but that's fine)
       <>(({}){})                                                                double smaller output number
                 <>(({}){}                                  )                    double larger output number
                          {                              }{}                     if digit in ternary expansion is nonzero:
                           ()<                          >                        add 1 to larger output number
                              ({}[()]){                }                         if digit is 2:
                                       <>({}())<>(<{}>)                          add 1 to smaller output number

JavaScript (ES6), 70 72 bytes
n=>[6,4].map(x=>parseInt((n/2).toString(3).replace(/./g,d=>x>>d&1),2)) // thanks @Neil
n=>[0,1].map(x=>parseInt((n/2).toString(3).replace(/1|2/g,d=>~-d||x),2))

(0-indexed, and apparently nearly the same solution as @Neil even if I hadn't seen his answer)
I started off with getting the index back from a number using the reverse of the process: stringify with base 3, replace every 2 with 1, parse with base 2.
To get two numbers, and that for every even one, we just half the input - but now, also 1 digits can occur. So we replace it with a 0 in the one number and a 2 in the other number, which does not change the sum of the two, before the replace-and-parse step. Here is what I came up with (doing the two replacements, 1 -> 0-or-2 and 2 -> 1 in one step):
n=>["001","011"].map(x=>parseInt((n/2).toString(3).replace(/./g,d=>x[d]),2))

Of course the two replacement maps (strings) differ only in one index, so we should be able to shorten the array literal by only replacing 1 and 2 with d == 2 ? 1 : x. Or d-1 || x. Where -1 does the same as the two unary operators - but they look scarier :-)
Trying to avoid the array literal and the parenthesis around n/2 I also came up with
n=>Array.from(parseInt,(h=n/2,i)=>parseInt(h.toString(3).replace(/1|2/g,d=>~-d||i),2))

but it did not turn out fruitful.

I started with the ["001","011"] version too (well my variable names were different)

I think .replace(/./g,d=>d>>1|x) saves 2 bytes.

@Neil Unfortunately that doesn't work for d="0" and x=1 - the digit should stay 0

Yeah, I just worked that out after trying a few more test cases. (And I have since come up with another variant, but that's going in my answer, I'm afraid.)

@Neil but you were up to something... Bit patterns, how obvious in hindsight!

Oh very nice, and I thought I was being clever to beat your previous version...

Pyth, 22 bytes
J.m}1jb3hQxLJhfqsTQ^J2

Try it online: Demonstration
Explanation:
J.m}1jb3hQxLJhfqsTQ^J2
        hQ                input + 1
 .m                       find all values of [0, 1, 2, ..., input], where
     jb3                     value converted to base 3
   }1                        check if it contains the digit 1
                          this boolean ^ is false
J                         store this list in variable J

                   ^J2    every pair of J
              f           filter for pairs with
                sT           sum of pair
               q             equal
                  Q          the input
             h            take the first of these pairs
          xLJ             and find the corresponding indices of J


text:
Wicka-wub a string
Inspired by this.
Given a string as input consisting of only upper and lowercase alphabet characters, wicka-wub it.
How do I wicka-wub a string?
The example text used is "DJMcMayhem".
Split the string before each capital letter, so you get ["D", "J", "Mc", "Mayhem"].
Next, take the two halves of the list as sublists. This gives us [["D", "J"],["Mc", "Mayhem"]]. If the list is an odd length (i.e. 3), the first sublist will contain the middle substring (i.e. [[a,b], [c]]).
Create a list of wickas and wubs.  The number of wickas should be as many as the length of the first part of the input list (i.e. ["D", "J"] -> ["wicka", "wicka"]), and the number of wubs should be as many as the length of the second part of the input list.  In our case, this gives ["wicka", "wicka", "wub", "wub"].
Now join the sublists of the input list into single strings and flatten.
We currently have ["DJ", "McMayhem"] and ["wicka", "wicka", "wub", "wub"].
Join the wicka/wub list with -s: wicka-wicka-wub-wub.  Prepend a -.  If there is more than one capital letter in the input, append another -.
Now we have  ["DJ", "McMayhem"] and "-wicka-wicka-wub-wub-".
Append the wicka-wub string to the end of the first item in the input list, to get ["DJ-wicka-wicka-wub-wub-","McMayhem"].
Lastly, repeat the characters in the second part of the string by their 0-indexed value in the original input string. In our example, that means the first M would be repeated twice, then the c three times, and the next M four times.   Join the list, so the second part (the part you just repeated letters in) is appended to the first part ("DJ-wicka-wicka-wub-wub-").
Final result of input:
"DJ-wicka-wicka-wub-wub-MMcccMMMMaaaaayyyyyyhhhhhhheeeeeeeemmmmmmmmm"

Total process:
["D", "J", "Mc", "Mayhem"] =>
[["D", "J"], ["Mc", "Mayhem"]] =>
["DJ", "McMayhem"] and ["wicka", "wicka", "wub", "wub"] =>
["DJ", "McMayhem"] and "-wicka-wicka-wub-wub-" =>
["DJ-wicka-wicka-wub-wub-", "McMayhem"] =>
"DJ-wicka-wicka-wub-wub-MMcccMMMMaaaaayyyyyyhhhhhhheeeeeeeemmmmmmmmm"

Your task
Your task is, given a string that consists of only upper and lowercase alphabet characters, output the wicka-wubbed version of that string.
A few rules

The input may consist entirely of lowercase letters, or entirely of uppercase letters, or any number of each, but no other characters.
If the input consists of entirely lowercase letters the correct output should simply be the final stage (the string with the characters repeated according to their 0-indexed position). There should be no wicka or wub in that case.
Standard rules apply, full programs or functions, up to you.
This is a code-golf so shortest code wins.

GoodLuck-wicka-wicka-wub-GGGGGGGGooooooooollllllllllfffffffffffeeeeeeeeeeerrrrrrrrrrrrrssssssssssssss
Test cases
input => output

DJMcMayhem => DJ-wicka-wicka-wub-wub-MMcccMMMMaaaaayyyyyyhhhhhhheeeeeeeemmmmmmmmm
PPCG => PP-wicka-wicka-wub-wub-CCGGG
foobarbaz => fooooobbbbaaaaarrrrrrbbbbbbbaaaaaaaazzzzzzzzz
FooBarBaz => FooBar-wicka-wicka-wub-BBBBBBaaaaaaazzzzzzzz
HelloWorld => Hello-wicka-wub-WWWWWoooooorrrrrrrllllllllddddddddd
Test => Test-wicka
UPPER => UPP-wicka-wicka-wicka-wub-wub-EEERRRR
fooBarBaz => fooBar-wicka-wicka-wub-BBBBBBaaaaaaazzzzzzzz

Sandbox

Can you add a test with 5 uppercase letters?

This is an ungolfed reference implementation in Python

The formatting at the top hurts my eyes. Can you clean it up a bit?

@Riker it doesn't hurt my eyes, so I don't know how to clean it up as to not to. Feel free to edit, however.

Can I use "Wubba Lubba Dub Dub" instead? Doesn't save me bytes though :P.

@MagicOctopusUrn No, I'm afraid you can't :(

Doesn't splitting 'foobarbaz' before each uppercase letter return the string unchanged, e.g. ['foobarbaz'].  This list has an odd length and the two halves would be: [['foobarbaz'], []].  So, shouldn't the answer be 'foobarbaz-wicka'? (There aren't any test cases that start with a lower case letter and have an uppercase letter later in the string.)

@RootTwo hang on, I think that got caught in the mass edit. I'll just put that back in.

"the first sublist will contain the odd number (i.e. [[a,b], [c]])" Actually, now the first list contains an even number of items, not odd. ;) I would change this to "the first sublist will contain the middle substring (i.e. [[a,b], [c]])", or something along those lines.

Should foobarbaz simply return foobarbaz? Is there a second part at all?

Also suggested test-case: fooBarBaz

@EriktheOutgolfer please read the second point in the rules

@cairdcoinheringaahing Well it's a bit unclear...you mean that if the input is all-lowercase instead of the standard procedure we just repeat each char the 1-based index of it times?

There seems to be an inconsistency in how the repeated characters are done. In the test case for 'PPCG', the 'C' is at index 2 and is repeated 2x in the output.  For test case 'foobarbaz', the 'f' is at index 0, but is repeated 1x in the output; the first 'b' is at index 3, but is repeated 4x in the output.

Not necessarily a problem of the challenge, but I can't solve this as elegantly as I hoped. There seems to be unnecessary special casing to an otherwise interesting challenge, particularly the no-uppercase strings. It's personally turned me away from solving this cool-looking challenge in three different languages. Maybe something to consider for future challenges.

Perl 5, 142 bytes
130 bytes code + 12 for -F(?=[A-Z]).
This now correctly matches all the test cases provided.
map$a+=y///c,@E=($z=/[A-Z]/)?splice@F,0,@F/2+.5:();print@E,("-wicka"x@E,"-wub"x@F,"-"x!!@F)x$z,map$_ x$a++,$z?map/./g,@F:('',/./g)

Try it online!
Note: TIO includes -l to run all tests at once.

Java 8 (782 bytes)
import com.google.common.collect.*;import java.util.*;import java.util.function.*;public class p{Function<String,String>b=s->{List<String>p=Arrays.asList(s.split("(?=[A-Z])"));if(!s.matches("[^A-Z]*[A-Z].+")){String w="";int i=0;for(char c:String.join("",s).toCharArray()){w+=String.join("",Collections.nCopies(i,Character.toString(c)));i++;}return w;}String h="-";List<List<String>>k;if(p.size()!=1){k=Lists.partition(p,2);String w=String.join("",k.get(0))+h+String.join(h,Collections.nCopies(k.get(0).size(),"wicka"))+h+String.join(h,Collections.nCopies(k.get(1).size(),"wub"))+h;int i=String.join("", k.get(0)).length();for(char c:String.join("",k.get(1)).toCharArray()){w+=String.join("",Collections.nCopies(i,Character.toString(c)));i++;}return w;}return p.get(0)+h+"wicka";};}

Ungolfed:
import com.google.common.collect.*;

import java.util.*;
import java.util.function.*;

public class p {
    Function<String, String> b = s -> {
        List<String> p = Arrays.asList(s.split("(?=[A-Z])"));

        if (!s.matches("[^A-Z]*[A-Z].+")) {
            String w = "";

            int i = 0;

            for (char c : String.join("", s).toCharArray()) {
                w += String.join("", Collections.nCopies(i, Character.toString(c)));

                i++;
            }

            return w;
        }

        String h = "-";

        List<List<String>> k;

        if (p.size() != 1) {
            k = Lists.partition(p, 2);

            String w = String.join("", k.get(0)) + h + String.join(h, Collections.nCopies(k.get(0).size(), "wicka")) + h + String.join(h,    Collections.nCopies(k.get(1).size(), "wub")) + h;

            int i = String.join("", k.get(0)).length();

            for (char c : String.join("", k.get(1)).toCharArray()) {
                w += String.join("", Collections.nCopies(i, Character.toString(c)));

                i++;
            }
            return w;
        }

        return p.get(0) + h + "wicka";
    };
}

Kotlin 1.1 - 494 492 bytes
Submission
typealias S=String
fun Iterable<*>.j(s:S="")=this.joinToString(s)
fun s(s:S):S{var c=0
val m=mutableListOf<S>()
var t=""
s.map{if(it.isUpperCase()){c+=1
if(t!=""){m.add(t)
t=""}}
t+=it}
if(c==0)return e(s,1)
m.add(t)
val p=Math.ceil(m.size/2.0).toInt()
val f=m.subList(0,p)
val z=m.subList(p,m.size)
val w=List(f.size,{"wicka"})
val u=List(z.size,{"wub"})
val x=f.j()
var v="-"+(w+u).j("-")
if(c>1)v+="-"
return x+v+e(z.j(),x.length)}
fun e(s:S,o:Int)=s.mapIndexed{c,i->List(c+o,{i}).j()}.j()

Test
typealias S=String
fun Iterable<*>.j(s:S="")=this.joinToString(s)
fun s(s:S):S{var c = 0
val m=mutableListOf<S>()
var t=""
s.map{if(it.isUpperCase()){c+=1
if(t!=""){m.add(t)
t=""}}
t+=it}
if(c==0)return e(s,1)
m.add(t)
val p=Math.ceil(m.size/2.0).toInt()
val f=m.subList(0,p)
val z=m.subList(p,m.size)
val w=List(f.size,{"wicka"})
val u=List(z.size,{"wub"})
val x=f.j()
var v="-"+(w+u).j("-")
if(c>1)v+="-"
return x+v+e(z.j(),x.length)}
fun e(s:S,o:Int)=s.mapIndexed{c,i->List(c+o,{i}).j()}.j()

data class TestData(val input: String, val output: String)

fun main(args: Array<String>) {
    val tests = listOf(
            TestData("DJMcMayhem", "DJ-wicka-wicka-wub-wub-MMcccMMMMaaaaayyyyyyhhhhhhheeeeeeeemmmmmmmmm"),
            TestData("PPCG", "PP-wicka-wicka-wub-wub-CCGGG"),
            TestData("foobarbaz", "fooooobbbbaaaaarrrrrrbbbbbbbaaaaaaaazzzzzzzzz"),
            TestData("FooBarBaz", "FooBar-wicka-wicka-wub-BBBBBBaaaaaaazzzzzzzz"),
            TestData("HelloWorld", "Hello-wicka-wub-WWWWWoooooorrrrrrrllllllllddddddddd"),
            TestData("Test", "Test-wicka"),
            TestData("UPPER", "UPP-wicka-wicka-wicka-wub-wub-EEERRRR"),
            TestData("fooBarBaz", "fooBar-wicka-wicka-wub-BBBBBBaaaaaaazzzzzzzz")
    )

    for (test in tests) {
        var out = s(test.input)
        if (out != test.output) {
            System.err.println("TEST FAILED")
            System.err.println("IN  " + test.input)
            System.err.println("EXP " + test.output)
            System.err.println("OUT " + out)
            return
        }
    }
    println("Test Passed")
}

Running
Works on KotlinLang, but not on TryItOnline as 1.1 is not supported
Ran through my compressor, saved 2 bytes

Vyxal Ṫ, 64 bytes
ꜝ[`(?=[A-Z])`ṡḢ:₅½⌈:‟ẎDƛ`≤ȧka-`;∑$∑‹p^ȯ:ƛ‛≤¶;‹∑∇∑f:ẏ∇∇∑L+*÷|ėvΠ÷

Try it Online!
Since the stack manipulation is quite complex, I've added a representation of the stack after each step.
ꜝ[             # If any letters are uppercase (example input: DJMcMayhem
  `(?=[A-Z])`ṡ # Split before uppercase letters
               # [['','D','J','Mc','Mayhem']]

Ḣ                  # Lop off the first value
                   # [['D','J','Mc','Mayhem']]
 :₅½⌈              # Duplicate and push ceil(length/2)
                   # [['D','J','Mc','Mayhem'],['D','J','Mc','Mayhem'],2]
     :‟Ẏ           # Push a copy on the bottom and slice from the start
                   # [2,['D','J','Mc','Mayhem'],['D','J']]
        Dƛ`≤ȧka-`; # Triplicate and fill one copy with 'wicka-'
                   # [2,['D','J','Mc','Mayhem'],['D','J'],['D','J'],['wicka-','wicka-']]

∑$∑             # Sum these and sum the pair under that
                # [2,['D','J','Mc','Mayhem'],['D','J'],'wicka-wicka-','DJ']
   ‹p           # Add a hyphen and prepend
                # [2,['D','J','Mc','Mayhem'],['D','J'],'DJ-wicka-wicka-']
     ^ȯ         # Reverse the stack and slice
                # ['DJ-wicka-wicka-',['D','J'],['Mc','Mayhem']]
       :ƛ‛≤¶;‹∑ # Duplicate, fill a copy with 'wub-' and sum that
                # ['DJ-wicka-wicka-',['D','J'],['Mc','Mayhem'],'wub-wub-']

∇∑f          # Shift and turn the full second half into a list of characters
             # ['DJ-wicka-wicka-','wub-wub-',['D','J'],['M','c','M','a','y','h','e','m']]
   :ẏ        # Duplicate and make a range of 0...length
             # ['DJ-wicka-wicka-','wub-wub-',['D','J'],['M','c','M','a','y','h','e','m'],[0,1,2,3,4,5,6,7]]
     ∇∇∑L+   # Get the full length of the first half and add it to each item of this range
             # ['DJ-wicka-wicka-','wub-wub-',['M','c','M','a','y','h','e','m'],[2,3,4,5,6,7,8,9]]
          *÷ # Multiply (repeat) (vectorising) and iterate out over the stack
             # ['DJ-wicka-wicka-','wub-wub-','MM','ccc','MMMM','aaaaa','yyyyyy','hhhhhhh','eeeeeeee','mmmmmmmmm']
             # Then the Ṫ flag smash-prints this.

|     # Else...
 ė    # Enumerate (zip with range to length)
  vΠ  # Reduce each by multiplication
    ÷ # Iterate (push each to the stack)
      # Then the Ṫ flag smash-prints this.

Python 3, 234 281 270 248 246 bytes
s,j=input(),"".join;f=lambda l,n:j(c*i for i,c in enumerate(j(l),n));import re;u=re.split("([A-Z])",s);l=len(u)
m=[j(u[i:i+2])for i in range(1,l,2)];i=-~l//4;d=j(m[:i]);print((j([d+"-wicka"*i+"-wub"*(l//2-i)+"-",f(m[i:],len(d))]),f(u[0],1))[l<2])

Try it online!
Added 47 bytes, thanks to Mr. Xcoder ;)
Saved 11 bytes thanks to Jonathan Frech
Saved 22 bytes thanks to Halvard Hummel
Saved 2 more bytes thanks to Mr. Xcoder

Fails for foobar.

@Mr.Xcoder Fixed!

Added 47 bytes, thanks to Mr. Xcoder ;) >_>

Possible 270 bytes.

248 bytes

246 bytes


text:
Boolean Rectangles
Inspired by Braille graphics
Given a Boolean matrix (i.e., consisting of only 1s and 0s), output an ASCII-art-style Unicode representation of the closed-polygon shape created by the 1s in the matrix, using the Unicode drawing characters ┌ ─ ┐ │ └ ┘ (code points 0x250c, 0x2500, 0x2510, 0x2502, 0x2514, and 0x2518, respectively, separated by spaces). Replace the 0s with spaces, so you're left with just the line drawing. Output or return that drawing.
You won't have to handle invalid or ambiguous input - there will be only one unambiguous path of 1s through the matrix. In other words, every 1 has exactly two cardinal neighbors that are 1s, and two that are 0s or out of bounds. Additionally, since the shape is a closed-polygon, this guarantees that the path is cyclical.
Examples:
[[1,1,1]
 [1,0,1]
 [1,1,1]]

┌─┐
│ │
└─┘

[[0,1,1,1,1,0],
 [1,1,0,0,1,1],
 [1,0,0,0,0,1],
 [1,1,1,1,1,1]]

 ┌──┐
┌┘  └┐
│    │
└────┘

[[1,1,1,0,0]
 [1,0,1,1,1]
 [1,0,0,0,1]
 [1,1,0,1,1]
 [0,1,1,1,0]]

┌─┐
│ └─┐
│   │
└┐ ┌┘
 └─┘

[[1,1,1,0]
 [1,0,1,1]
 [1,1,0,1]
 [0,1,1,1]]

┌─┐
│ └┐
└┐ │
 └─┘

Leading or trailing newlines or whitespace are all optional, so long as the characters themselves line up correctly.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
If possible, please include a link to an online testing environment so other people can try out your code!
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

What are the codepoints for the relevant drawing characters?

@PeterTaylor Good point. Added.

I believe this is a dupe since my Jelly solution works with this input TIO. It could probably be shortened since there will only be one path here instead of multiple like in the other.

@miles Dagnabbit. I thought this was a duplicate, but 48+ hours in the Sandbox and several searches by me didn't find one.

@AdmBorkBork The usual tip: after you type the title, a list with possible duplicates goes below the title. You can check there, although the titles in this case were quite different.

Javascript (ES6), 125 bytes
a=>a.map((r,i)=>r.map((c,j)=>c&&"─ ┌└  ┐┘ |"[!(a[i-1]||0)[j]+!(a[i+1]||0)[j]*2+!r[j-1]*4+!r[j+1]*8-3]||" ").join``).join`
`

Example code snippet:

f=
a=>a.map((r,i)=>r.map((c,j)=>c&&"─ ┌└  ┐┘ |"[!(a[i-1]||0)[j]+!(a[i+1]||0)[j]*2+!r[j-1]*4+!r[j+1]*8-3]||" ").join``).join`
`
o.innerText=f([[1,1,1,0,0],
[1,0,1,1,1],
[1,0,0,0,1],
[1,1,0,1,1],
[0,1,1,1,0]])
<pre id=o>