Add++, 109 bytes
D,g,@@#,BF1_B
D,k,@@#,bR$d@$!Q@BFB
D,f,@,BDdVÑ_€?1€_0b]$+€?dbLRBcB*BZB]GbL1+b]+qG€gd€bLÑ_0b]$+BcB]£k€¦+Ñ=1$ª=
Try it online!
How it works
We define our 3 functions, \$f\$, \$g\$ and \$k\$. \$f\$ is the main function, which transforms the input to the correct output.
\$f(x)\$
First, we convert the input \$x\$ into a list of digits, then take the forward increments. Next, we take the sign of each increment. For increasing subsequences, this yields a subsequence of \$1\$, for equal subsequences, such as \$[4, 4, 4]\$, this yields \$0\$s and for decreasing sections, \$-1\$ is returned. We then take the complement of each of these signs, to turn \$1\$ into a falsey value, and everything else into a truthy value. Next, \$0\$ is prepended to this array, and we take the sign of each element again. This yields an array, \$A\$, of \$0\$ and \$1\$, with the first element always being \$0\$.
We then yield the range \$[1, 2, ... length(A)]\$ and remove the elements that correspond to \$0\$ in \$A\$. This leaves us with a second array, \$A'\$. We then push the number of digits in the input, add one and append this number to \$A'\$. We then deduplicate \$A'\$, to yield a new array, \$A''\$.
Next, we use the \$g\$ helper function. As \$g\$ is dyadic (takes 2 arguments), it behaves slightly differently when paired with the each operator, €
. Dyadic functions pop a value from the stack and bind that value as their right argument to create a partial monadic function. This partial function is then mapped over each element in the argument. Here, the bound right argument is the digits of the input and the partial function is mapped over \$A''\$.
\$g(x, y)\$
Let's take a look at just one iteration of \$g(x, y)\$ where \$x := [1, 2, 0, 1, 2]\$ and \$y = 3\$. Note that \$3\$ is the first index in \$A''\$ where the signs from \$A\$ corresponded with \$1\$, rather than \$0\$. In fact, for \$x = 12012\$, we can see that \$A'' = [3, 6]\$. \$3\$ is the only non-zero index in \$A\$, and \$6\$ is the length of \$x\$ plus one.
So, for \$g([1, 2, 0, 1, 2], 3)\$ the following happens: First, we swap the two arguments so that the stack has the digits below the index. We then flatten the array and decrement the index. So far, the stack looks like [1 2 0 1 2 2]
. We then perform the head command. We pop the index from the top f the stack and take that many characters from the stack, starting at the bottom. This yields \$[1, 2]\$, which is then returned by \$g\$.
So, \$g(x, y)\$ is mapped over each element \$y \in A''\$, which returns a series of prefixes of the input of various increasing lengths. This part could get slightly confusing, so we'll work through it with the example input of \$x := 12012\$. After the mapping of \$g\$, the stack currently looks like
[[[1 2] [1 2 0 1 2]]]
We then push an array containing the length of each array in the top element, or in this instance, the array \$[2, 5]\$. This is the same as \$A'' - 1\$, if the \$-\$ operator maps, but it takes more bytes to use this relationship. Next, the forward differences of the lengths is taken, and \$0\$ is prepended, yielding, in this example, \$[0, 3]\$. This new array is then zipped with the results from \$g\$ to create \$B\$ and the starmap operator is run over each pair.
\$k(x, n)\$
The starmap operator uses the function \$k\$ as its argument, and works by taking a dyadic function and a nested array. The array must consist of pairs, such as \$[[1, 2], [3, 4], [5, 6]]\$, and the dyadic function is mapped over each pair, with each element of the pairs being the left and right arguments respectively.
Here, our example nested array is \$[[[1, 2], 0], [[1, 2, 0, 1, 2], 3]]\$ and our function is \$k\$. We'll focus simply on \$k([1, 2, 0, 1, 2], 3)\$ for now.
\$k(x, n)\$ starts, similar to \$g\$, by swapping the two arguments, so that the array is the top of the stack. We then reverse the array and swap the arguments back. Now, \$n = 0\$, we want to leave the array unchanged, so we duplicate the integer and rotate the top three arguments, so that the stack has the format of \$[n, x, n]\$. Next, we return the array if \$n = 0\$. Otherwise, the top element is discarded, and we arrange the stack back to how it was i.e. with the reversed array at the bottom and the integer at the top, or in our example: \$[[2, 1, 0, 1, 2], 3]\$. We then flatten the stack, and take the first \$n\$ elements of \$x\$. These elements are then returned and replace \$x\$ in \$B\$.
For our input, this returns \$[0, 1, 2]\$. (Strictly speaking, it returns\$[2, 1, 0]\$, but order doesn't matter for the rest of the program).
After \$k(x, n)\$ is mapped over each pair \$(x, n) \in B\$, we take the sum of each pair, then check that each element is equal, by asserting that each neighbouring pair are equal, and then asserting that each of those equality tests result in \$1\$ (a truthy value). Finally, this result is returned.
1Just for reference, Martin Ender was the first one to ever get 100k rep. – Erik the Outgolfer – 2016-09-30T15:48:25.710
1Is 12366 a valid 2.0 number? (123|6|6 vs. 1236|6) – Sp3000 – 2016-09-30T16:00:55.760
2@sp3000 That is not a Dennis number. It would be
1236|6
– James – 2016-09-30T16:03:56.673Can I take each digit as it's unary representation with a
,
between them? This is probably stretching it a lot. – Riley – 2016-09-30T16:16:13.320@Riley Yeah, that's definitely stretching it. Unless it's the only possible way to take numeric input in your language, I'm gonna say no, that doesn't count. – James – 2016-09-30T16:40:35.160
I have a solution in sed. I'll just have to do the conversion myself. – Riley – 2016-09-30T16:44:30.097
@Riley Hmm. Somehow that seems more reasonable for a purely regex based language like sed. I guess I don't really have any problem with it (Since it will be a cool solution that probably wouldn't be the shortest anyway) – James – 2016-09-30T17:09:32.257
13Im scared Dennis will destroy all of us in this challenge nontheless – downrep_nation – 2016-09-30T17:14:12.003
I'll post both, and no, they are not even close to winning. – Riley – 2016-09-30T17:28:40.860
@downrep_nation Who knows? Now, Jonathan Allan has been constantly outgolfing Dennis in Jelly. – Erik the Outgolfer – 2016-10-06T07:52:41.800
Some say that TheLegend12012 was the first PPCG user ever... born from Jelly... (that sounds weird, also resurrecting old memes >_>) – HyperNeutrino – 2017-03-25T02:14:36.760
Are you sure you mean "subsequence", not "substring"? (
135
is a subsequence of12345
.) – None – 2017-04-25T18:17:32.923