# Split a number in every way possible way within a threshold

## Jelly, 11 bytes

```
ŒṖḌfV⁼³ʋƇḶ}
```

Try it online!

-1 byte thanks to Jonathan Allan

-1 more byte thanks to Jonathan Allan

### How it works

```
ŒṖḌfV⁼³ʋƇḶ} - Main link. Takes n on the left and t on the right
ŒṖ - All partitions of the digits of n
Ḍ - Convert the lists of digits to a list of numbers
} - To t:
Ḷ - Yield [0, 1, 2, ..., t-1]
Ƈ - Filter the partitions p, keeping those for which the following is true...
ʋ ...with each partition p on the left and the lowered range on the right:
f - Keep the numbers in the lowered range (i.e. less than t)
V - Concatenate the numbers into a single number
⁼³ - Is that equal to n?
```

## 05AB1E, 9 bytes

Generates all valid partitions and keeps those that join to the input number. This is *really slow* because it generates partitions of up to as many integers as the input number.

```
Ýsã0δÛʒJQ
```

Try it online! Don't try the cases from the challenge, even for the one with threshold 17 this tries to generate roughly \$1.35 \cdot 10^{18839}\$ partitions.

**Commented:**

```
# first input: threshold, second input: number
Ý # inclusive range [0 .. threshold]
s # swap to the input number
ã # take the range to this cartesian power
# this generates all input-tuples of integers in [0 .. threshold]
0δÛ # for each tuple remove leading 0's
ʒ # only keep the partitions
JQ # which are equal to the input if joined into a single string
```

## 05AB1E, 10 bytes

This is more efficient, starting with actual partitions of the number and keeping the valid ones.

```
.œʒà@y*J¹Q
```

Try it online!

**Commented**:

```
# first input: number, second input: threshold
.œ # all string partitions of the first input
ʒ # keep all partitions where
à # the maximum string
@ # is less or equal compared to the second input
y* # multiply this (0 or 1) with each number in the partition
# all strings are converted to integers here, which removes any leading 0's
J # join into single string
¹Q # is this equal to the first input?
```

## Perl 5, 131 bytes

```
sub{($n,$t)[email protected]_;grep{!grep$_>$t,/\d+/g}grep$n==s/,//gr,map$n=~s|.|$_/=2;$_*2%2?"$&,":$&|egr=~s/\b0+\B|00+//gr,0..2**($n=~y///c-1)-1}
```

Try it online!