title: Long period primes

text:
# Question
Title: Long period primes
A long period prime is a prime number \\$p\\$ such that decimal expansion of \\$1/p\\$ has period of length \\$(p-1)\\$. Your task is to output this number sequence. For purposes of this challenge we will consider only odd primes.

Period of a decimal expansion of a rational number is the smallest period \\$k\\$ that makes the decimal representation periodic (repeating at regular intervals \\$k\\$).

This is A001913, or A006883 without leading \\$2\\$.

## Examples

\\$\frac{1}{3}=0.33333\ldots\\$, so the period is \\$1\\$ (although the number is also 2-periodic, 3-periodic etc., but we take the minimum). \\$3-1=2\neq1\\$, so \\$3\\$ won't appear in our sequence.

\\$\frac{1}{7}=0.14285714\ldots\\$ \- the period is \\$6 = 7-1\\$.

## Rules

This is a standard challenge, so please comply with the defaults.

With floating point errors, let's stick to the highest voted decisive answer here on meta, so I'll allow them.

## Test cases

First 10 entries:

```
7, 17, 19, 23, 29, 47, 59, 61, 97, 109

```

For more visit: A001913's b-file.

---

*Inspired by recent Numberphile video.*

# Answer
> 7 votes
# x86-64 machine code, 27 bytes

```
31 F6 FF C6 89 F1 6A 0A 58 99 F7 FE 6B C2 0A FF CA E0 F6 E2 ED FF CF 75 E9 96 C3

```

Try it online!

Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes a number \\$n\\$ in EDI and returns the 1-indexed \\$n\\$th long-period prime in EAX.

In assembly:

```
f:
    xor esi, esi        # Set ESI to 0.
nextm:
    inc esi             # Add 1 to ESI to get the next number (m) to test.
    mov ecx, esi        # Set ECX to m.
    push 10             # Push 10 onto the stack
    pop rax             #  and pop it into RAX.
l:
    cdq                 # Sign-extend, setting up for the next instruction.
    idiv esi            # Divide by m, putting the quotient in EAX and the remainder in EDX.
    imul eax, edx, 10   # Set EAX to EDX×10.
    dec edx             # Subtract 1 from EDX.
    loopnz l            # Subtract 1 from ECX, and repeat if both are nonzero.
    loop nextm          # Subtract 1 from ECX, and jump if the result is nonzero.
                        #   This point will be reached iff 1 is first obtained
                        #   after exactly m-1 iterations of ×10 and mod m.
    dec edi             # Subtract 1 from EDI, counting down from n.
    jnz nextm           # Jump if it is nonzero.
    xchg esi, eax       # Exchange the final value of m from ESI into EAX.
    ret                 # Return.

```

# Answer
> 5 votes
# Python 3, ~~73~~ 64 bytes

~~The usual Wilson's theorem based prime generation combined with computing the multiplicative order.~~ Now porting tsh's answer, you don't actually need to check for primality if the multiplicative order is right.

```
k=3
while j:=1:
 while 10**j%k>1<k>j:j+=1
 j==k-1==print(k);k+=1

```

Try it online!

# Answer
> 5 votes
# JavaScript + `alert`, 57 bytes

```
for(i=2n;++i;j-i||alert(i))for(j=1n;j<=i&10n**j++%i!=1;);

```

Try it online!

# Answer
> 4 votes
# Husk, 15 bytes

```
tfλ=←⁰LUm%⁰İ⁰)N

```

Try it online!

For each natural number (`N`), get the series of powers-of-10 (`İ⁰`) modulo that number (`m%⁰`); now select those (`fλ)`) for which the length (`L`) of the longest prefix of unique elements (`U`) is equal to (`=`) that number minus one (`←⁰`). This annoyingly includes 2 at the start, so we need to take the tail (`t`).

# Answer
> 4 votes
# Jelly,  ~~12~~  11 bytes

```
ṖȯfƑ⁵*Ɱ%Ɗµ#

```

A full program that accepts an integer, `n`, from STDIN and prints the Jelly representation\* of a list of the first `n` numbers which have a primitive root of \\$10\\$.

**Try it online!**

* the Jelly representation of a list with a single element is just that element.

### How?

```
ṖȯfƑ⁵*Ɱ%Ɗµ# - Main Link: no arguments
         µ# - implicitly takes input - call this N
         µ# - collect the first N values of K (in [0,1,2,...]) for which:
Ṗ           -   pop -> [1,2,...,K-1]
 ȯ          -   logical OR with K (so we get K when K is 0 or 1, rather than [])
                (let's call this list of integers (or 0 or 1) P)
        Ɗ   -   last three links as a monad - f(K):
    ⁵       -     10
      Ɱ     -     map across (implicit [1,2,...,K]) with:
     *      -       exponentiation
       %    -     modulo K (vectorises)
                (let's call this list of integers M)
   Ƒ        -   is P invariant under?:
  f         -     P filter keep M
            - implicit print

```

---

A couple of other 11 byters:

```
⁵*Ɱ%i1=ṖṪµ#
⁵*Ɱ%=1Ḅ⁼2µ#

```

# Answer
> 3 votes
# Vyxal, 11 bytes

```
Þp'ɾ↵$%1ḟ⇧=

```

Try it Online!

Port of Kevin Cruijssen's answer.

```
Þp'         # Filter the infinite list of primes by...
   ɾ        # 1...n
    ↵       # 10 to the power of each of those
     $%     # Modulo n
       1ḟ   # Find the first index of a 1
         ⇧= # Is it + 2 equal to n?

```

See, when I saw something about "powers of 10 modulo n" I thought it meant you could get something with an equivalent cycle in that way. I didn't realise it was so simple...

# Answer
> 3 votes
# Factor \+ `lists.lazy math.primes.lists project-euler.026`, ~~57~~ 52 bytes

```
[ lprimes [ dup -1 ^ period-length - 1 = ] lfilter ]

```

Try it online!

Believe it or not, Factor includes solutions to the first 200 or so Project Euler problems and exposes them the same way as any other vocabulary. Many of these vocabularies provide useful words, such as `project-euler.026` which provides the `period-length` word.

## Explanation

It's a quotation that outputs the infinite lazy sequence of long period primes.

* `lprimes` An infinite lazy list of primes.
* `[ ... ] lfilter` Select only those whose...
* `dup -1 ^ period-length - 1 =` ...reciprocals have a period length one less.

# Answer
> 3 votes
# 05AB1E, 12 bytes

```
∞ʒ©L.Δ°®%}®α

```

Port of *@tsh*'s JavaScript answer, and also outputs the infinite sequence.

Try it online.

**Explanation:**

```
∞          # Push an infinite positive list: [1,2,3,...]
 ʒ         # Filter it by:
  ©        #  Store the current value in variable `®` (without popping)
   L       #  Pop and push a list in the range [1,®]
    .Δ     #  Find the first value in this list which is truthy for:
      °    #   Push 10 to the power the value
       ®%  #   Modulo-`®`
           #   (Note: only 1 is truthy in 05AB1E)
     }     #  After we've found our result (or not, resulting in -1)
      ®α   #  Take the absolute difference with `®`
           #  (and again, only 1 is truthy in 05AB1E)
           # (after which the infinite list is output implicitly)

```

# Answer
> 3 votes
# Ruby, 47 bytes

```
7.step{|x|x-1==(1..x).find{|c|10**c%x<2}&&p(x)}

```

Try it online!

# Answer
> 3 votes
# , ~~53~~ 51 bytes

```
repeat if(T==match(1,10^(1:(T=T+1))%%T,0))cat(T,"")

```

Try it at rdrr.io (but see below...)

Similar approach to this: for each integer `T`, check whether the first `1` in the list of powers-of-10 modulo `T` occurs at the `T-1`-th position (meaning that the period of the decimal expansion is `T-1`).

Unfortunately, this approach suffers (quite badly) from inaccuracies as soon as the powers-of-10 exceed 's floating-point precision: so, it only manages to output `7 17 19 23` before generating a large number of `probable complete loss of accuracy in modulus` warnings.

---

# , 65 bytes

```
repeat{y=T=T+1;z=1;while(y&(z=(z*10)%%T)-1)y=y-1;cat(T[y==2],"")}

```

Try it online!

Alternative approach unaffected by floating-point inaccuracies (at least until very large values...); outputs a whitespace-separated list of all long-period-primes.

# Answer
> 2 votes
# Wolfram Language (Mathematica), 52 bytes

```
If[10~MultiplicativeOrder~k==k-1,Print@k]~Do~{k,∞}

```

Try it online!

-15 bytes from @ovs

# Answer
> 2 votes
# Javascript + `alert`, 54 53 bytes

```
for(n=3;i=n++;i||alert(n))for(x=1;i*(x=x*10%n)>i--;);
```

# Answer
> 1 votes
# C (gcc), ~~73~~ ~~72~~ 71 bytes

```
k,j,i;f(n){for(j=k=2;n-=j==k++-1;)for(i=10,j=0;j++<k&i%k>1;)i*=10;--k;}

```

Try it online!

Returns the \\$1\\$-based \\$n^\text{th}\\$ long period prime.

# Answer
> 1 votes
# Charcoal, 29 bytes

```
≔¹θＦＮ«≦⊕θＷ›⊖θ⊕⌕﹪Ｘχ…¹θθ¹≦⊕θ⟦Ｉθ

```

Try it online! Link is to verbose version of code. Outputs the first `n` long period primes. Explanation: Based on @tsh's answer.

```
≔¹θ

```

Start at `2` (because we increment this almost immediately). (Any number below `7` would work.)

```
ＦＮ«

```

Loop `n` times.

```
≦⊕θ

```

Increment the number under test.

```
Ｗ›⊖θ⊕⌕﹪Ｘχ…¹θθ¹

```

While the number's period is not equal to one less than it...

```
≦⊕θ

```

... increment the number under test.

```
⟦Ｉθ

```

Output the next long period prime.

# Answer
> 1 votes
# Zsh, 54 bytes

```
for ((;++n;))(r=9;for ((;r%n;))r+=9
((n+~$#r))||<<<$n)
```

Attempt This Online!

Uses the fact that the repeating decimal period of \\$ n \\$ is the minimum integer \\$ i \\$ such that \\$ n \\$ divides \\$ r = 10^i - 1 = \operatorname{rep}(9, i)\\$.

Prints the sequence infinitely, but can only manage the first 3 terms before Zsh's floating point numbers implode.

We have to be careful with how and where we use `$r` to ensure it stays a string, so that `r+=9` literally appends instead of adds 9.

# Answer
> 1 votes
# Sidef, 39 bytes

```
{10.is_primitive_root(_)&&.say}<<2..Inf

```

---
Tags: code-golf, sequence, primes
---


title: Implement the Torian

text:
# Question
Title: Implement the Torian
The Torian, \\$x!x\\$, of a non-negative integer \\$x\\$ can be recursively defined as

$$ x!0 = x \\ x!n = \prod^x\_{i=1} i!(n-1) = 1!(n-1) \times 2!(n-1) \times \cdots \times x!(n-1) $$

The Torian is then equal to \\$x!x\\$ for a given \\$x\\$. This sequence begins \\$0, 1, 2, 24, 331776, ...\\$ for \\$x = 0, 1, 2, 3, 4, ...\\$

Alternatively, you can consider the binary function \\$!\\$ to be instead \\$f(x, y)\\$. We then have \\$f(x, 0) = x\\$ and \\$f(x, y) = f(1, y-1) \times f(2, y-1) \times \cdots \times f(x, y-1)\\$. You should then calculate \\$f(x, x)\\$.

You are to take a non-negative integer \\$x\\$ and output \\$x!x\\$. You may take input and output in any convenient method, and you don't have to worry about outputs exceeding your language's integer limit. This is , so the shortest code in bytes wins

### Test cases

```
x x!x
0  0
1  1
2  2
3  24
4  331776
5  2524286414780230533120
6  18356962141505758798331790171539976807981714702571497465907439808868887035904000000
7  5101262518548258728945891181868950955955001607224762539748030927274644810006571505387259191811206793959788670295182572066866010362135771367947051132012526915711202702574141007954099155897521232723988907041528666295915651551212054155426312621842773666145180823822511666294137239768053841920000000000000000000000000000

```

And here is a reference program that produces output for \\$0!0\\$ to \\$11!11\\$

# Answer
> 14 votes
# Jelly, 6 bytes

```
R×\⁸¡Ṫ

```

Try it online!

# APL (Dyalog Unicode), 10 bytes

```
{⊃⌽×\⍣⍵⍳⍵}

```

Try it online!

The main trick is to observe how the computation of `x!y` progresses as `y` increases.

```
1!0=1    2!0=2        3!0=3            4!0=4                ...
1!1=1    2!1=1*2      3!1=1*2*3        4!1=1*2*3*4          ...
1!2=1!1  2!2=1!1*2!1  3!2=1!1*2!1*3!1  4!2=1!1*2!1*3!1*4!1  ...
1!3=1!2  2!3=1!2*2!2  3!3=1!2*2!2*3!2  4!3=1!2*2!2*3!2*4!2  ...
...

```

Basically going to the next row is just a matter of product scan on the previous row. Therefore, to get the value of `x!x`, we can just run product scan on the range `1..x` `x` times, and extract the last element.

One caveat of this approach is that the 0 case must be checked separately. In Jelly, popping from an empty array gives 0. In APL,  of the empty vector is 0 (`⊢/` does not work in place of `⊃⌽`).

I have 16-byte J and 14-byte ngn/k answers using the same algorithm. Can you find them? (ngn/k code includes converting 0N to 0)

# Answer
> 12 votes
# Jelly, 4 bytes

```
R¡FP

```

Try it online!

```
       (Starting from [n],)
R      Recursively replace each x with [1..x]
 ¡     n times
  F    Flatten
   P   Product

```

For example  for the input `4` yields

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

```

and the product of all numbers in that nested list is 331776.

# Answer
> 9 votes
# Haskell, 43 bytes

```
f x=x!x
x!0=x
x!n=product$map(!(n-1))[1..x]

```

Try it online!

+8 bytes due to the problem needing a function that only takes a single argument. Thanks to @Lynn for pointing that out

Thanks to OVS for pointing out map is shorter than a list comprehension and taking 1 byte off.

My first time ever submitting a haskell answer. I am a beginner so do point out places where I can shorten my code :)

---

# Haskell, 39 bytes

```
f x=x!x
x!0=x
0!_=1
x!n=x!(n-1)*(x-1)!n

```

Try it online!

Thanks to @Alwin for suggesting this version.

# Answer
> 8 votes
# Python 3 48 bytes

```
f=lambda x,y:f(x,y-1)*f(x-1,y)if x*y else(y>0)+x

```

TIO

# 55 bytes

if a more conventional input is required. I don't know how to initialize the default 2nd argument to equal the first, so I've rewritten everything as t=x-y without much more thought.

```
f=lambda x,t=0:f(x,t+1)*f(x-1,t-1)if(x-t)*x else(x>t)+x

```

Thanks to Arnauld for saving 3 bytes

# Answer
> 5 votes
# Factor, ~~53 45~~ 41 bytes

```
[ dup [1,b] [ cum-product ] repeat last ]

```

Try it online!

A port of @Bubbler's answers; take the product scan (cumulative product) of `1..x` `x` times and then return the last element.

# Answer
> 5 votes
# Wolfram Language (Mathematica), 27 bytes

```
1##&@@#&//@Nest[Range,#,#]&

```

Try it online!

Port of Lynn's solution.

---

### Wolfram Language (Mathematica), 33 bytes

```
Nest[f1##&@@f~Array~#&,D,#]@#&

```

Try it online!

Builds \\$x!0...x!x\\$:

```
                        D           x => x!0
     f1##&@@f~Array~#&             (x => x!n) => (x => x!(n+1))
Nest[                  , ,#]        x => x!#
                            @#      #!#

```

# Answer
> 5 votes
# JavaScript (Node.js), 43 bytes

Expects and returns a BigInt.

```
f=(x,n=x,g=_=>x?f(x--,~-n)*g():1n)=>n?g():x

```

Try it online!

This actually simplifies down to ...

# JavaScript (Node.js), 37 bytes

```
f=(x,n=x)=>n?x?f(x,~-n)*f(~-x,n):1n:x

```

Try it online!

... which is essentially the same as Alwin's answer.

# Answer
> 5 votes
# Haskell, 41 bytes

```
f n=product$iterate(>>= \x->[1..x])[n]!!n

```

Try it online!

Same idea as my Jelly answer: starting from `[n]`, repeatedly replace each `x` by `1..x`, `n` times, then take the product.

```
  [4]
→ [1,2,3,4]
→ [1,1,2,1,2,3,1,2,3,4]
→ [1,1,1,2,1,1,2,1,2,3,1,1,2,1,2,3,1,2,3,4]
→ [1,1,1,1,2,1,1,1,2,1,1,2,1,2,3,1,1,1,2,1,1,2,1,2,3,1,1,2,1,2,3,1,2,3,4]
→ product: 331776

```

# Answer
> 5 votes
# K (oK), ~~13 12~~ 14 bytes

Saved 1 byte thanks to ngn

Fixed thanks to Razetime

```
{*|0,x*\/1+!x}

```

Try it online!

```
{*|0,x*\/1+!x}
           !x  Range [0..x-1]
         1+    Increment range
     x  /      Repeat x times:
      *\       Get the cumulative products of the list
               When this is done y times, we get [1!y, 2!y...x!y]
   0,          Prepend a 0 in case x is 0
 *|            Get the last number (x!y) by reversing and getting the head

```

# Answer
> 4 votes
# JavaScript (ES6), 46 bytes

```
x=>(g=p=>x>1n?x--**p*g(p*y++/i++):x)(i=1n,y=x)

```

Try it online!

Use

$$ f\left(n\right) = \prod\_{i=1}^n i^{{2n-i-1}\choose{n-1}} $$

with exception

$$ f\left(0\right) = 0 $$

# Answer
> 4 votes
# , 46 bytes

```
x=scan();i=1:x;prod(i^choose(2*x-i-1,x-1))*!!x

```

Try it online!

Using formula from tsh's answer (presumably adapted from OEIS page).

---

Straightforward recursion:

### , 50 bytes

```
f=function(x,n=x)"if"(n,prod(sapply(1:x,f,n-1)),x)

```

Try it online!

# Answer
> 3 votes
# Vyxal, 9 bytes

```
[ɾ?(⁽*r)t

```

Try it Online!

-1 thanks to @AUsername

# Answer
> 3 votes
# Julia 0.7, ~~32~~ 29 bytes

-3 bytes by MarcMush.

```
<(x,n=x)=n>0?prod(1:x.<n-1):x

```

Try it online!

Or if we are allowed to take the input as it appears in Torian notation itself (essentially twice), then it becomes:

# Julia 0.7, 24 bytes

```
x<n=n>0?prod(1:x.<n-1):x

```

Try it online!

# Answer
> 2 votes
# Jelly, 9 bytes

```
’ß¥ⱮPðṛḷ?

```

Try It Online!

-1 byte thanks to caird coinherinaahing

This is a singular dyadic link. The challenge requires taking one input; however, a single dyadic chain within a monadic link will have the argument supplied to both sides so this works just fine.

```
’ß¥ⱮPðṛḷ?    Dyadic Chain
        ?    If
       ḷ     The left argument is truthy
-----ð       Evaluate on the left argument (this is a variadic chain, and its arity changes between runtimes)
   Ɱ         For each in range on the right argument
--¥          Call as dyad:
’            -  Decrement the left argument
 ß           - Recurse (the `¥` is only necessary to make this act as a dyad since it's a variadic actor)
    P        And take the product
      ṛ      Otherwise, just return x

```

# Answer
> 2 votes
# JavaScript, ~~38~~ 36 bytes

~~I still don't understand the challenge but~~ Thanks to Bubbler I understand the challenge a bit better and this port of Alwin's solution seems to work - be sure to `+1` them too.

Only handles inputs up to `4` as anything bigger will result in an output exceeding JavaScript's `MAX_SAFE_INTEGER`

```
f=(x,n=x)=>n?x?f(x,~-n)*f(~-x,n):1:x

```

Try it online!

For just one byte more, though, we can handle larger inputs by using BigInts:

```
f=(x,n=x)=>n?x?f(x,~-n)*f(~-x,n):1n:x

```

Try it online!

# Answer
> 2 votes
# C (gcc), 51 bytes

```
f(n){n=g(n,n);}g(x,n){x=n?x?g(x,n-1)*g(x-1,n):1:x;}

```

Try it online!

Port of Arnauld's JavaScript answer (which may be based on Shaggy's JavaScript answer) which, in turn, is based on Alwin's answer.

# Answer
> 2 votes
# Haskell, 37 bytes

```
h x=iterate(scanl1(*))(1:[1..])!!x!!x

```

Try it online!

Product scan method seems to win over other approaches.

# Answer
> 2 votes
# Python 3, 50 bytes

```
t=lambda x,z=0:x*(x-z)and t(x-1,z-1)*t(x,z+1)or x

```

Using the trick of using parameter z=x-y from @Alwin's answer. Before that, I had the 59 byte version

```
t=lambda x,y=-1:x*(y:=(y,x)[y<0])and t(x-1,y)*t(x,y-1)or x

```

# Answer
> 1 votes
# Charcoal, 22 bytes

```
≔ＥＮ⊕ιθＦθＵＭθΠ…θ⊕λＩ∧Ｌθ⊟θ

```

Try it online! Link is to verbose version of code. Explanation: Port of @Bubbler's answer.

```
≔ＥＮ⊕ιθ

```

Start with a range from `1` to `n`.

```
Ｆθ

```

Repeat `n` times...

```
ＵＭθΠ…θ⊕λ

```

... calculate the cumulative products.

```
Ｉ∧Ｌθ⊟θ

```

Output the last one, unless `n=0`, in which case just output `0`.

# Answer
> 1 votes
# 05AB1E (legacy), 5 bytes

```
FL}˜P

```

Port of *@Lynn*'s Jelly answer, so make sure to upvote him/her as well!

Try it online or verify the first \\$\[0,7\]\\$ test cases.

**Explanation:**

```
F    # Loop the (implicit) input amount of times:
 L   #  Transform each integer `n` into a [1,n] ranged list
     #  (which uses the implicit input in the first iteration)
}˜   # After the loop: flatten the nested lists
  P  # And take the product of all integers
     # (after which the result is output implicitly)

```

Uses the legacy version of 05AB1E, because the new version's `˜` doesn't work on a single integer for input \\$x=0\\$.

# Answer
> 1 votes
# ayr, 8 bytes (2 methods)

Method 1:

```
:*/,~$:`

```

Method 2 (doesn't work for N=0):

```
]/]*\$:~

```

# Explanation

```
:       Non J-style train
   ~$:  1-range on each scalar val
      ` Commute input (pass to both sides)
*/,     Product of all scalars

```

Dyadic `A u$: B` is call `u` on previous iteration `A` times with starting value `B`

```
       ~    1-range of N
   *\$:     Repeatedly foldl with multiplication
  ]         N times
]/          Rightmost argument

```

# Answer
> 1 votes
# Uiua SBCS, 12 bytes

```
⬚0⊢⇌⍥\×:+1⇡.

```

Try it!

Pretty much a port of Bubbler's Jelly/APL answers.

---
Tags: code-golf, math, factorial
---


title: Calculate 6*9 in different bases

text:
# Question
Title: Calculate 6*9 in different bases
Output the following result (which is a result of calculating 6 * 9 in bases from 2 to 36). Make sure letters are uppercase, and the multiplication itself is outputed on every line.

```
6 * 9 = 110110
6 * 9 = 2000
6 * 9 = 312
6 * 9 = 204
6 * 9 = 130
6 * 9 = 105
6 * 9 = 66
6 * 9 = 60
6 * 9 = 54
6 * 9 = 4A
6 * 9 = 46
6 * 9 = 42
6 * 9 = 3C
6 * 9 = 39
6 * 9 = 36
6 * 9 = 33
6 * 9 = 30
6 * 9 = 2G
6 * 9 = 2E
6 * 9 = 2C
6 * 9 = 2A
6 * 9 = 28
6 * 9 = 26
6 * 9 = 24
6 * 9 = 22
6 * 9 = 20
6 * 9 = 1Q
6 * 9 = 1P
6 * 9 = 1O
6 * 9 = 1N
6 * 9 = 1M
6 * 9 = 1L
6 * 9 = 1K
6 * 9 = 1J
6 * 9 = 1I

```

Shortest code wins.

# Answer
# 05AB1E, ~~21~~ 20 bytes

```
36G54N>B"6 * 9 = ÿ",

```

Try it online!
> 1 votes

# Answer
### GolfScript, 39 characters

```
35,{2+'6 * 9 = '54@base{.9>7*+48+}%n+}/

```

Result can be seen here.
> 7 votes

# Answer
## Octave, 49

`for i=2:36printf("6 * 9 = %s\n",dec2base(54,i))end`
> 7 votes

# Answer
# Javascript, ~~57~~ 55 bytes

```
for(i=2;++i<37;)console.log('6 * 9 = '+54..toString(i))

```

Could be shortened to 49 with `alert`, but I don't want to submit anyone to that...
> 6 votes

# Answer
# Ruby (47)

```
2.upto(36){|t|puts"9 * 6 = "+54.to_s(t).upcase}

```

Well, I know that GolfScript solution is better, but hey, at least this is not esoteric...
> 5 votes

# Answer
## Python, 89

```
B=lambda x:x*'.'and B(x/b)+chr(x%b+7*(x%b>9)+48)
b=2
while b<37:print'6 * 9 =',B(54);b+=1

```
> 4 votes

# Answer
**Python 2.7 (~~124~~ 114)**

EDIT: Cut some fluff thanks to @boothby's comment below

I think Python is doing ok considering it has no built-in (that I know of) to do the base conversion so it has to be done in code;

```
for b in range(2,37):print'6 * 9 = '+''.join(chr((54/b**y%b>9)*7+48+54/b**y%b)for y in range(4,-1,-1)).lstrip('0')

```
> 3 votes

# Answer
# Perl 6, 36 bytes

```
say '6 * 9 = ',54.base($_) for 2..36

```
> 2 votes

# Answer
# Mathematica 40

Not in contention (lower case letters used):

```
Print["6*9 = ",54~BaseForm~#]&/@2~Range~36

```
> 1 votes

# Answer
# J - ~~78~~ 70

```
'6 * 9 = ',"1>;/(a.#~48 10 7 26 165#0 1 0 1 0){~<&.>(2+i.35)#.inv&.>54

```

# Haskell - 137

```
let s=['0'..'9']++['A'..'Z'];t _(0,r)=[s!!r];t b(q,r)=(t b$b q)++[s!!r]in mapM_(putStrLn.("6 * 9 = "++).(\b->t b$b 54).flip divMod)[2..36]

```
> 1 votes

# Answer
**Perl**

Had to use the Math::BaseCnv module

35 chars without the `use` statement:

```
map{say"6 * 9 = ",cnv(54,$_)}2..36

```

54 chars with the `use` statement:

```
use Math::BaseCnv;
map{say"6 * 9 = ",cnv(54,$_)}2..36

```

Not sure how you'd score this, so both are included.

The map BLOCK LIST structure was used. List is the range 2 to 36, that was requested. The meat is in the `cnv($NUMBER, $BASE)` function, and the map is an implied loop.
> 1 votes

# Answer
# Julia 0.6, 60 bytes

```
for b=2:36;@printf("6 * 9 = %s\n",uppercase(base(b,54)));end

```

Try it online!

Pretty painless, apart from remembering to use the macro @printf versus printf.

Import Base; not needed ...
> 1 votes

# Answer
## C (166 151)

Got rid of some unnecessary characters and changed some declarations. Assumes that you are running the program with no arguments.

```
p[7],i,l,v,r;main(b){for(r=2;r<37;r++){b++;printf("6 * 9 = ");v=54;while(v>0)l=v%b,p[i++]=l>9?l+55:l+48,v/=b;while(i^0)printf("%c",p[--i]);puts("");}}

```
> 1 votes

# Answer
**CoffeeScript 71**

```
alert ("6 * 9 = "+59.toString(x).toUpperCase()for x in[2..36]).join "\n"

```

Link
> 1 votes

# Answer
## Clojure, 75

`(for[i(range 2 37)](println"6 * 9 ="(.toUpperCase(Integer/toString 54 i))))`
> 1 votes

# Answer
# Python 3, 83 bytes

```
import numpy;print('\n'.join('6 * 9 = '+numpy.base_repr(54,i)for i in range(2,37)))

```
> 1 votes

# Answer
# Dart, 75 bytes

```
for(int x=2;x<37;x++)print("6 * 9 = ${54.toRadixString(x).toUpperCase()}");

```

Dart is a bit verbose when it comes to the stdlib, but hey... at least you can read it :P
> 1 votes

# Answer
## Scala, 71

```
2 to 36 map(i=>println("6 * 9 = "+Integer.toString(54,i).toUpperCase))

```
> 0 votes

# Answer
Common Lisp: 56 characters

```
(do((b 2(1+ b)))((> b 36))(format t"6 * 9 = ~vr~%"b 54))

```
> 0 votes

# Answer
## Sage, 48:

Shame Sage prints in lowercase... I'd only be one over Howard. Or, I guess, wrong and tied with David Carraher.

```
for i in[2..36]:print'6 * 9 =',54.str(i).upper()

```
> 0 votes

# Answer
## Forth, 54

```
: f 54 37 2 do ." 6 * 9 = " dup i base ! . cr loop ; f

```
> 0 votes

# Answer
# ///, 133 bytes

```
/R/6 * 9 = //S/
R/R110110S2000S312S204S130S105S66S60S54S4AS46S42S3CS39S36S33S30S2GS2ES2CS2AS28S26S24S22S20S1QS1PS1OS1NS1MS1LS1KS1JS1I

```

Try it online!
> 0 votes

# Answer
# SpecBAS - 48 bytes

```
1 FOR i=2 TO 36: ?"6 * 9 = ";BASE$(54,i): NEXT i

```

SpecBAS is actually quite competitive for a change :-)
> 0 votes

# Answer
# 8th, ~~65~~ 62 bytes

This is a complete program. Exit after execution

```
( "6 * 9 = " . #54 swap base drop >s s:uc . cr ) 2 36 loop bye

```

**Explanation**

```
(
   "6 * 9 = " .   \ Print the first part of the formula
    #54 swap base \ Enter into the base provided by loop index and
                  \ convert 54 (which is always expressed in base 10)
    drop          \ Get rid of previous base
    >s s:uc       \ Convert number into an upper case string
    . cr          \ Print result and newline
) 2 36 loop       \ Provide base from 2 to 36
bye               \ Quit

```
> 0 votes

# Answer
# Vyxal `rRMj`, 119 bitsv2, 14.875 bytes

```
34ƛ⇧54R`6*9=`ṄðpJ

```

Try it Online!

Bitstring:

```
01001000111011011000001000111100010001001111010001100010011111010011011001011001000000010100011011001000011111011100011

```

so many flags

```
34ƛ⇧54R`6*9=`ṄðpJ
# R flag casts numbers to ranges
# M flag starts implicit ranges at 0
# The r flag reverses the arguments which makes the base conversion easier
34ƛ                # map over the range 0-34
   ⇧               # add 2, giving a range 2-36
    54R            # Convert 54 to base B
       `6*9=`Ṅ     # separate the multiplication by spaces
              ðpJ  # add a space, and append the converted base

# -j flag joins output on newlines

```

Created with the help of Luminespire.
> 0 votes

# Answer
# Julia 1.0, 59 bytes

```
2:36 .|>b->println("6 * 9 = ",uppercase(string(54,base=b)))

```

Try it online!

# Julia 0.6, 46 bytes

```
@.println("6 * 9 = ",uppercase(base(2:36,54)))

```

Try it online!
> 0 votes

---
Tags: code-golf, kolmogorov-complexity
---


title: Sophie Safe primes

text:
# Question
Title: Sophie Safe primes
## Description

Write a program or function that takes in a positive integer \\$n\\$ as input and outputs all Sophie Germain primes that are safe primes less than or equal to \\$n\\$. A prime number \\$p\\$ is a Sophie Germain prime if \\$2p+1\\$ is also a prime. A prime number \\$p\\$ is a safe prime if \\$p=2q+1\\$, where \\$q\\$ is also a prime. The output should be a list of the Sophie Germain primes that are also safe primes, in ascending order only.

## Test Cases

```
[20] => 5, 11
[10000] => 5, 11, 23, 83, 179, 359, 719, 1019, 1439, 2039, 2063, 2459, 2819, 2903, 2963, 3023, 3623, 3779, 3803, 3863, 4919, 5399, 5639, 6899, 6983, 7079, 7643, 7823
[1000] => 5, 11, 23, 83, 179, 359, 719

```

## Task and Criterion

Output primes \\$p\\$ such that both \\$\frac{p-1}{2}\\$ and \\$2p+1\\$ are prime less then, equal to a specific \\$n\\$ given in input. Shortest bytes answer will win, in case if bytes are equated, a tie will occur.

# Answer
> 6 votes
# Japt `-f`, 10 bytes

```
[UUÑÄUz]ej

```

Try it

# Answer
> 5 votes
# Wolfram Language (Mathematica), 46 bytes

```
Select[Range@#,And@@PrimeQ@{#,(#-1)/2,2#+1}&]&

```

Try it online!

# Answer
> 5 votes
# 05AB1E, 10 bytes

```
Lʒx>y2÷)pP

```

Try it online.

**Explanation:**

```
L       # Push a list in the range [1, (implicit) input-integer]
 ʒ      # Filter it by:
  x     #  Double the current value (without popping)
   >    #  And increase it by 1
  y     #  Push the current value again
   2÷   #  Integer-divide it by 2
  )     #  Wrap all three values into a list: [n,2n+1,(n-1)/2]
   p    #  Check for each whether it's a prime number
    P   #  Check if all three are truthy
        # (after which the filtered list is output implicitly as result)

```

# Answer
> 5 votes
# , 71 bytes

```
f=\(n)if(n>4)c(f(n-1),n[all(Map(\(y)sum(!y%%2:y)<2,(n+1)*2^(-1:1)-1))])

```

Attempt This Online!

Heavily inspired by @Dominic van Essen's answer to Imtiaz Germain Primes.

# Answer
> 4 votes
# Vyxal, 10 bytes

```
':d›n‹½WæA

```

Try it Online!

Ports japt. Quite literally get all numbers where n, 2n incremented, and n decremented halved are all prime. Here's a more fun 11 byter

## Vyxal, 11 bytes

```
~æ~≬‹½æ'd›æ

```

Try it Online!

## Explained

```
~æ~≬‹½æ'd›æ
~æ          # keep only from range [1, input] where prime
  ~≬---     # from that, keep where:
   ‹½       #   (n - 1) / 2
     æ      #   is prime
      '     # from that, keep where:
       d›   #   2n + 1
         æ  #   is prime

```

# Answer
> 4 votes
# Java 8, ~~117~~ ~~115~~ 110 bytes

```
i->{for(;i-->5;)if(p(i)+p(i-~i)+p(i/2)<4)System.out.println(i);};int p(int i){for(int k=i;k%--i>0;);return i;}

```

Outputs each Sophie Safe prime on a separated newline in reversed order.
Based on my answer for the Imtiaz Germain Primes challenge.

Try it online.

**Explanation:**

```
i->{                          // Method with integer parameter and no return-type
  for(;i-->5;)                //  Loop `i` in the range (input,5]:
    if(p(i)                   //   If `i` is a prime number
       +p(i-~i)               //   and `2i+1` is a prime number
       +p(i/2)                //   and `i` integer-divided by 2 is a prime number
       <4)                    //   (by checking if all three are 0 or 1)
      System.out.println(i);} //    Print `i` with trailing newline

// Separated method with integer as both parameter and return-type,
// to check whether the given number (≥2) is a prime number (0 or 1)
int p(int i){
  for(int k=i;                //  Set `k` to the given integer `i`
      k%--i>0;);              //  Decrease `i` before every iteration with `--i`
                              //  Keep looping as long as `k` is NOT divisible by `i`
  return i;}                  //  After the loop, return `i`
                              //  (if it's 1 or 0, it means it's a prime number)

```

# Answer
> 3 votes
# JavaScript (ES6), 71 bytes

```
f=p=>p>4?f(p-1)+[[,p+' '][(P=x=>p%--x?P(x):x)(p)*P(p-=~p)*P(p>>=2)]]:''

```

Try it online!

### Commented

```
f = p =>         // recursive function taking a prime candidate p
p > 4 ?          // if p is greater than 4:
  f(p - 1) +     //   do a recursive call with p - 1
  [[, p + ' '][  //   append p followed by a space iff the following
                 //   result is 1:
    ( P = x =>   //     helper recursive function taking x
      p % --x ?  //     decrement x; if x is not a divisor of p:
        P(x)     //       do recursive calls until it is
      :          //     else:
        x        //       return x (smallest proper divisor of p)
    )(p) *       //     first call with p
    P(p -= ~p) * //     second call with 2p + 1
    P(p >>= 2)   //     third call with floor((2p + 1) / 4) which is
                 //     (p - 1) / 2 if p is odd
                 //   the product is 1 iff all calls return 1,
  ]]             //   i.e. all tested numbers are prime
:                // else:
  ''             //   stop

```

# Answer
> 3 votes
# Thunno `+`, \\$ 16 \log\_{256}(96) \approx\\$ 13.17 bytes

```
gzt2*1+s2,ZPsTNP

```

Attempt This Online!

#### Explanation

```
gzt2*1+s2,ZPsTNP  # Implicit input
g                 # Filter [1..input] by the following:          n
 zt               #  Triplicate the number                       n, n, n
   2*1+           #  Multiply by two and add one                 n, n, 2n+1
       s2,        #  Swap and integer divide by two              n, 2n+1, n//2
          ZP      #  Pair the top two items                      n, [2n+1, n//2]
            sT    #  Swap and append to the list                 [2n+1, n//2, n]
              NP  #  Are they all prime?

```

# Answer
> 3 votes
# Raku, 41 bytes

```
{grep {is-prime $_&2*$_+1&$_/2-.5},1..$_}

```

Try it online!

This filters (`grep`s) the numbers from 1 to the input argument to those where the conjunction (`&`) of the number (`$_`), twice that number plus one (`2 * $_ + 1`) and half the number minus one half (`$_ / 2 - .5`) is prime. The conjunction is prime if all of its elements are.

# Answer
> 2 votes
# Excel (ms365), 146 bytes

```
=LET(x,SEQUENCE(A1*2+1),y,MAP(x,LAMBDA(z,SUM(--((z/x)=INT(z/x)))))=2,q,FILTER(x,y),FILTER(q,MAP(q,LAMBDA(p,SUM(--(q=(p-1)/2))*SUM(--(q=2*p+1))))))

```

---

**EDIT:**

Since the above is rather slow (thought should work for all given samples), I was looking for ways to gain more speed. Just for fun, I created my own `LAMBDA()` based function called 'a' within Excel's name-manager based on one of the more simplistic ways to generate prime numbers; the ***Sieve of Eratosthenes***:

```
=LAMBDA(x,y,z,IF(x=MAX(y),SORT(y),a(SMALL(y,z),FILTER(y,MOD(y,x)+(y=x)),z+1)))

```

Now, since we can output all primenumbers, we can call this on the worksheet and do some filtering on the output:

```
=LET(q,a(2,SEQUENCE(A1*2,,2),1),FILTER(q,MAP(q,LAMBDA(p,SUM(--(q=(p-1)/2))*SUM(--(q=2*p+1))))))

```

The combined byte-count == 173, but it is working faster then the original answer of 146 bytes.

This makes me wonder if I, or someone, else can come up with ways to implement other known ways of generating primes and gain more speed.

# Answer
> 2 votes
# , 28 bytes

```
[:I.1*/@p:i.>:@+:^:_1 0 1@,]

```

Attempt This Online!

`i.,]` Integers from 0 to n.
`>:@+:` Function f that computes `i` -\> `1+2*i`.
`f^:_1 0 1` Apply f -1 times (inverse), 0 times, and 1 time and collect results in a 3-row matrix.
`1 p:` For each integer, is it prime?
`*/` Take the product of each column.
`I.` Indices of 1s in the resulting vector.

# Answer
> 2 votes
# Excel, 118 bytes

```
=LET(
    a,SEQUENCE(2*A1+1),
    b,IF(MMULT(N(MOD(a,TOROW(a))=0),a^0)=2,a),
    FILTER(b,1-ISNA(XMATCH(2*b+1,b)*XMATCH((b-1)/2,b)))
)

```

Fails where `A1>3663`.

# Answer
> 2 votes
# Retina 0.8.2, 75 bytes

```
.+
$*

¶11$`$`
4A`
A`^(11+)\1+$
1(1?)
$1
A`^(11+)\1+$
A`^1((11+)\2+)\1$
%`1

```

Try it online! Link is to verbose version of code. Explanation: Based on my Retina answer to Imtiaz Germain Primes.

```
.+
$*

```

Convert to unary.

```

¶11$`$`

```

Generate all numbers of the form `2n+1` up to the input. Due to golfing, the last entry is not odd, so I have to add `2` to each value so that the final odd entry is `2n+1`. (Although, the non-golfy way only goes up to `2n-1` so wouldn't work anyway.)

```
4A`

```

Deleting composite numbers won't work when the number to be tested is `0` or `1` so delete the small numbers manually.

```
A`^(11+)\1+$

```

Delete the remaining non-prime numbers.

```
1(1?)
$1

```

Integer divide by `2`.

```
A`^(11+)\1+$

```

Delete all composite numbers.

```
A`^1((11+)\2+)\1$

```

Delete all numbers that are `1` more than `2` times a composite number.

```
%`1

```

Convert the results to decimal.

# Answer
> 2 votes
# Charcoal, 26 bytes

```
Ｉ⊕⊗Φ…²⊘⊕Ｎ⬤⊖×⊕ιＥ³Ｘ²λ⬤…²λ﹪λν

```

Try it online! Link is to verbose version of code. Explanation:

```
    …                       Range from
     ²                      Literal integer `2 to
        Ｎ                   Input integer
       ⊕                    Incremented
      ⊘                     Halved
   Φ                        Filtered where
               ³            Literal integer `3`
              Ｅ             Map over implicit range
                 ²          Literal integer `2`
                Ｘ           Raised to power
                  λ         Inner value
           ×                Vectorised multiply by
             ι              Outer value
            ⊕               Incremented
          ⊖                 Vectorised decrement
         ⬤                  All values satisfy
                    …       Range from
                     ²      Literal integer `2`
                      λ     To inner value
                   ⬤        All values satisfy
                        λ   Inner value
                       ﹪    Modulo i.e. is not a multiple of
                         ν  Innermost value
  ⊗                         Vectorised double
 ⊕                          Vectorised increment
Ｉ                           Cast to string
                            Implicitly print

```

# Answer
> 2 votes
# Factor \+ `math.primes`, 63 bytes

```
[ primes-upto [ dup 2/ swap 2 * 1 + [ prime? ] both? ] filter ]

```

Try it online!

* `primes-upto` get a list of primes up to the input
* `[ ... ] filter` select \\$p\\$ where...
* `dup 2/` \\$\lfloor{p/2}\rfloor\\$
* `swap 2 * 1 +` and \\$2p+1\\$
* `[ prime? ] both?` are both prime

# Answer
> 2 votes
# Arturo, 45 bytes

```
$=>[select..1&'n[every?@[1+n*2n/2n]=>prime?]]

```

Try it

```
$=>[                   ; a function
    select..1&'n[      ; select numbers from 1 to <input>, assign current elt to n
        every?         ; is every element in the block...
        @[1+n*2n/2n]   ; ... [n/2, n, n*2+1]     (where / is integer division)
        =>prime?       ; prime?
    ]                  ; end select
]                      ; end function

```

# Answer
> 1 votes
# Jelly, 16 bytes

```
ÆRḤ‘$ÆP$Ƈ’H$ÆP$Ƈ

```

Try it online!

```
ÆR - list of prime numbers up to the input
Ḥ‘ - 2x+1
$ÆP$Ƈ - evaluates as primes
’H - (x-1)/2
$ÆP$Ƈ - evaluates as primes (again)

```

# Answer
> 0 votes
# SageMath, 76 bytes

Run it on SageMathCell!

```
g=lambda n:[x for x in[1..n-1]if all(is_prime(y)for y in[x,(x-1)//2,2*x+1])]

```

# Answer
> 0 votes
# Uiua, 63 Bytes

```
▽⍥×3∩∩∵(¬∊0↘2◿⇡.)⌊÷2:+1×2⍥.4↘3+1⇡

```

Try It

```
▽⍥×3∩∩∵(¬∊0↘2◿⇡.)⌊÷2:+1×2⍥.4↘3+1⇡
                                +1⇡ # generate all numbers from [1, n]
                             ↘3 # drop first three since the prime number function will flag 3 (it returns true for 1)
                          ⍥.4 # make four copies, 3 for checking 2p+1, p, and floor(p/2),
                              # one extra so that we can use a double both (∩) later
                      +1×2 # calculate 2p+1
                  ⌊÷2: # calculate floor(p/2)
     ∩∩∵(¬∊0↘2◿⇡.) # apply prime number function to the top four stack elements
                . # copy so we can divide by the number later
               ⇡ # generate numbers [0, x] where x is the number we are checking
              ◿ # calculate mod, to see if it evenly divides
            ↘2 # drop first two so we discard mod by 0 and 1
          ∊0 # check if there is remainder of 0
         ¬ # if there exists no divisors which yield a remainder of zero, it is prime
 ⍥×3 # use multiplication to and conditions together: prime(floor(p/2)) & prime(2p+1) & prime(p) & prime(p)
▽ # only keep numbers that matched condition

```

---
Tags: code-golf, number-theory, primes
---


title: Crossing a Lily Pond

text:
# Question
Title: Crossing a Lily Pond
## The Narrative

You are a frog who is at the edge of a pond with waterlilies. You would like to cross the pond without getting wet, so you plan to jump from lily to lily. There is, however, one problem: you are a rare species of frog which can only jump one specific distance, and so you might not be able to cross the pond no matter what you do.

## The Objective

Determine if the frog can cross the pond without getting wet.
**Your program should take two inputs:**

* A string or list of lily-y/watery values to represent the lilies in the pond
* A positive integer which tells how far the frog jumps

**Your program should output a truthy/falsy value to indicate whether the pond is crossable**

The frog can start any distance behind the edge of the pond, but may not start on a lily or in the water. Additionally, the frog may finish any distance beyond the far edge of the pond, but not on a lily or in the water. Note that the frog cannot move at any interval other than that which is specified in the input (i.e. With a jumping distance of `3`, the pond `001100` is not crossable, even though it appears that the frog could walk from the first waterlily to the second)
Examples:

```
(lily=1, water=0)

Inputs: "001101001111001", "3"
Output: "Yes"

Inputs: "101001", "2"
Output: "No"

Inputs: "010000001", "7"
Output: "Yes"

Inputs: "00000", "6"
Output: "Yes"

Inputs: "00000", "5"
Output: "No"

Inputs: "00100100", "4"
Output: "No"

Inputs: "001100", "3"
Output: "No"

Inputs: "", "1"
Output: "Yes"

(note that output does not have to be "Yes" or "No", but any truthy/falsy values)

```

This is , so the shortest code in bytes wins.

# Answer
> 11 votes
# Jelly, 5 bytes

```
T%QL<

```

Try it online!

*Look ma, no Unicode!*

Takes a list of 0 for lilies and 1 for water on the left, and the stride on the right.

```
   L     The number of
  Q      unique
T        indices of water
 %       modulo the stride
    <    is less than the stride.

```

The frog must traverse every index with some chosen residue modulo the stride; this checks if there's any residue which does not at any point correspond to water.

# Jelly, 6 bytes

```
s×ƒR}Ẹ

```

Try it online!

Takes a list of 1 for lilies and 0 for water on the left, and the stride on the right. (Without having to handle strides longer than the pond itself, could just be `sPẸ`.)

```
s         Split the pond into stride-sized slices.
  ƒ       Reduce the list of slices by
 ×        vectorizing multiplication
   R}     starting with [1..stride] (all-truthy and the appropriate length).
     Ẹ    Is any value truthy?

```

# Answer
> 16 votes
# BitCycle, 329 bytes

BitCycle is certainly not an easy language to solve this in, despite the fact that its only form of data (streams of bits), easily represents the pattern of the lilypond in this challenge.

None of the mathematical solutions used in the other answers here would be at all easy to implement in BitCycle, so the basic algorithm for this program is as follows: given the jump length `N` and the pond string `P`, take every `N`th bit of `P`, AND those bits together to determine if this pond is crossable, and repeat this for every possible starting distance from the pond, ORing the results from each variation together to determine if any are crossable.

This program takes the bitstring representing the lilypond as its first input (with 1s as lilies and 0s as water), and the jump length in unary (bitcycles normal way of representing integers) as the second input.

```
v      <
   v       ~^  v  <  <>  v F>\^Hv
  Gv            E^   ^~   + > + !
1>Gv>v  ^=~      >    ^v+vF^  H>/
  ?B^>   ^    Cv^\=/^^v~ v
  v ~ ^   >    D  ^   >
   ?~     v~^^<v~D/Bvv   <
  0AG\ ^^= ~>  \^^  < >
  B      ^ >^ ~<?~    =
>  B^ >1B^  v /v~<0C^E^
 ^   ~~   Gv0C>D>    E^
  ^        < ^~    ~
      Bv
       >      ~

```

## More in-depth explanation

*(will come later, when I feel like digging through this code to figure out how each piece of it works again)*

Try it online! or Dlosc's online visualizer (To test inputs on TIO, they must be put into the arguments section, rather than the input section.)

# Answer
> 7 votes
# , 64 bytes

```
function(x,y)length(table(which(strsplit(x,'')[[1]]=='0')%%y))<y

```

Try it online!

If allowed to take a boolean list instead:

# , 42 bytes

```
function(x,y)length(table(which(!x)%%y))<y

```

Try it online!

Can cut that down to 41 if I can flip the lily-y and watery states, losing the ! in the process.

1 byte reduced because `table` is one byte shorter than `unique`.

Basic idea: look at values mod the jump length, any residue that has a 0 is not a residue you can completely jump across, if not all of them have 0 then you can jump across. Some residues may be empty (and thus fine), e.g. if you have 6 pads and can jump across 7 then there are no pads at 0 mod 7 and you can jump straight across the pond.

This is equivalent to the solutions of https://codegolf.stackexchange.com/users/73593/matteo-c.

# Answer
> 5 votes
# Python, ~~62~~ ~~47~~ 46 bytes

*thanks to @Unrelated String for the idea of alternative input format*

*-1 byte thanks to @dingledooper*

```
f=lambda p,n:0in(0in p[i::n]for i in range(n))
```

Attempt This Online!

# C (gcc), ~~118~~ 110 bytes

*-8 bytes thanks to @ceilingcat*

```
d,i,j,n,l,c;main(c,v)char**v;{for(n=atoi(v++[2]);c=i<n;d+=c)for(j=i++;j<strlen(*v);j+=n)c&=j[*v]-48;return d;}

```

Try it online!

# Haskell, ~~50~~ 48 bytes

*-2 bytes thanks to @Unrelated String*

```
p#n=any(\i->all(p!!)[i,i+n..length p-1])[0..n-1]

```

Try it online!

All the solutions do basically the same thing.

# Answer
> 5 votes
# Vyxal `r`, 6 bytes

```
T%UL⁰>

```

Try it Online!

Port of Jelly answer.

## How?

```
T%UL⁰>
T      # Truthy (water) indices of the (implicit) first input
 %     # Modulo each by the (implicit) second input (the stride)
  U    # Uniquify
   L   # Length
    ⁰> # Is the second input (the stride) greater than this?

```

# Answer
> 5 votes
# , ~~37~~ ~~36~~ 34 bytes

*Edit: -2 bytes thanks to Giuseppe*

```
function(x,y)(y:0)[1:y*-!c(x,1:y)]

```

Try it online!

Outputs zero for falsy, and a vector with non-zero first element (which is truthy in ) for truthy.

(test setup stolen from Cong Chen's R answer...)

# Answer
> 5 votes
# Java (JDK), 67 bytes

```
(j,l,s)->{int r=1<<j;for(l|=--r>>s%j<<s;l>0;l>>=j)r&=l;return r>0;}

```

Try it online!

Takes input as three `int`s: the jump size, the lily pond as an integer and the size of the pond

## Explanations

```
(j,l,s)->{                     // 3 parameters: jump size, lilies positions, pond size
 int r=(1<<j)-1;               // Result. By default all entries are crossable
 for(
   l|=r>>s%j<<s;               // Ensure the banks of the pond are jumpables.
   l>0;                        // Stop when all jumps are done
   l>>=j)                      // Prepare the next jump
  r&=l;                        // Do all tests for the n-th jump at once.
 return r>0;                   // Return whether any jump line fully succeeded.
}

```

# Credits

# Answer
> 5 votes
# Desmos, ~~85~~ 62 bytes

```
f(l,s)=max(0,sign(s-mod([1...l.length][l=0],s).unique.length))

```

*-23 bytes thanks to Aiden Chow*

Try it on Desmos!

# Answer
> 4 votes
# C(GCC), ~~105~~ 99 bytes

*-6 bytes thanks to @ceilingcat*, but I want to keep the inside while

```
j(a,b)char*a;{char*c=a,*d=a,m=1,o=0;for(;c-a<b;o|=m++,d=c++)while(*++d)m&=*d-48||(d-c)%b;return o;}

```

Try it online The idea is to try all possible starting points and then go through the whole string and do something only when on a place the frog lands. If frog's jumping power would be limited to 32 max, it would be possible to golf more (88 bytes), like:

```
j(a,b)char*a;{char*d=a;unsigned m=(1<<b)-1;while(*++d)m&=-1u^49-*d<<(d-a)%b;return !!m;}

```

Try it online Here I would simply have a bitflag for each possible start, and use !! to normalize the result.

# Answer
> 4 votes
# 05AB1E, 5 bytes

```
ι€ßĀà

```

First input is the jump-distance, second the string of water/lilies with `0`/`1` similar as the challenge description.

Try it online or verify all test cases.

5 instead of 6 bytes by taking advantage of a bug in 05AB1E that causes `Ā` to be truthy for empty strings `""`. The 6 byter without bug-abuse would have been `ι€ß_ß_`. (It could have been 4 bytes `ι€ßà` if the length of water/lilies string was \\$\geq\\$ the jump-distance, which isn't the case for test case `6,"00000"`.)

**Explanation:**

```
ι      # Uninterleave the (implicit) second input-string to the (implicit)
       # first input-integer amount of parts
 €ß    # Get the minimum of each part
   Ā   # Transform empty strings to 1s with a bugged Python-style truthify
    à  # Get the maximum of this list
       # (which is output implicitly as result)

```

# Answer
> 4 votes
# HBL, 19 bytes

```
?('?,)1(1,)('?.(2.,
+(*(),(<2(*-(0,)).

```

Takes two arguments: a list of 1s and 0s, and an integer. Returns 0 for falsey and a nonzero integer for truthy. Try it at HBL online!

### Explanation

The first line is a recursive helper function that takes the number as its first argument and a partial list as its second argument:

```
?('?,)1(1,)('?.(2.,
?                    If
    ,                 the second argument
 ('? )                is empty, then:
      1                Return 1 (we've reached the other side of the pond)
                     Else, if
       (1 )           the first item in
         ,            the second argument
                      is truthy (nonzero), then:
           ('?         Recur
              .        with same first argument
                       and second argument equal to
               (2       drop
                 .      (first argument) many items
                  ,     from the front of second argument
                     Else, return the falsey value from the last test (0)

```

The result will be 1 if the pond can be crossed by starting with the first lily, 0 otherwise.

Then the main function trims off between 0 and N-1 elements from the start of the list, applies the helper function to each trimmed list, and sums the results:

```
+(*(),(<2(*-(0,)).
              ,     Second argument (jump distance)
            (0 )    Inclusive range from 1 to that number
         (*     )   Map
           -         decrement
        2           Drop that many
      (<             for each of those numbers
                 .   from first argument (list of lily pads)
 (*                 For each of those lists
   ()                call the helper function
     ,               with main function's second argument as first argument
                     and the trimmed list as second argument
+                   Sum

```

# Answer
> 4 votes
# Minecraft Command Blocks, 403 bytes

The commands in the command blocks from left to right:

```
scoreboard objectives add o dummy
execute store result score d o run data get storage a d
data modify storage a c set from storage a b[0]
execute if data storage a {c:0} run scoreboard players add c o 1
execute if data storage a {c:1} run scoreboard players reset c
data remove storage a b[0]
execute if score c o = d o run say 0
setblock 0 0 0 air
execute unless data storage a b[0] run say 1
setblock 0 0 0 air

```

Input is given with the command `/data merge storage a {d:2,b:[0,1,0,1...]}` where `d` is the frog's jump length and `b` is an array representing the lily pads.

## Explanation

When the lever is pressed, the repeating command block (purple) executes every gametick, with the chain command blocks (green) executing after it in sequence. The third-last and last command blocks are conditional, which means they will only execute if the previous command block was successful.

```
scoreboard objectives add o dummy                                   Create scoreboard objective to store variables in
execute store result score d o run data get storage a d             Store the jump distance in d
data modify storage a c set from storage a b[0]                     Get the first value of the lily pad array
execute if data storage a {c:0} run scoreboard players add c o 1    If the value is zero increment the jump counter by 1
execute if data storage a {c:1} run scoreboard players reset c      If the value is one reset the jump counter
data remove storage a b[0]                                          Delete the first value of the array
execute if score c o = d o run say 0                                If the jump counter is equal to the jump distance print 0 (fail)
setblock 0 0 0 air                                                  (conditional) Delete the lever to stop the loop
execute unless data storage a b[0] run say 1                        If the array is empty print 1 (success)
setblock 0 0 0 air                                                  (conditional) Delete the lever to stop the loop

```

# Answer
> 4 votes
# Pip `-xp`, 9 bytes

```
$|$&*aUWb

```

Attempt This Online! Or, verify all test cases.

### Explanation

```
$|$&*aUWb
     a     First command-line input (list of 1s and 0s)
      UW   Unweave into this many strands:
        b  Second command-line input (jump distance)
  $&*      Fold each of those strands on logical AND
$|         Fold the list of results on logical OR

```

That is, there must be at least one strand which contains only 1s.

# Answer
> 3 votes
# JavaScript (ES6), 52 bytes

Expects `(distance)(string)`.

```
(n,k=n)=>g=s=>k--&&[...s].every((x,i)=>i%n|x)|g(1+s)

```

Try it online!

# Answer
> 3 votes
# Factor, 52 bytes

```
[| s n | n 1 s indices [ n mod ] map cardinality > ]

```

Try it online!

Port of Unrelated String's first Jelly answer.

```
               ! s = { 1 1 0 0 1 0 1 1 0 0 0 0 1 1 0 }, n = 3
n              ! 3
1              ! 3 1
s              ! 3 1 { 1 1 0 0 1 0 1 1 0 0 0 0 1 1 0 }
indices        ! 3 V{ 0 1 4 6 7 12 13 }
[ n mod ] map  ! 3 V{ 0 1 1 0 1 0 1 }
cardinality    ! 3 2
>              ! t

```

# Answer
> 3 votes
# , 19 16 bytes

```
[>#@~.@(|[:I.-.)

```

Try it online!

*-3 taking the approach from Unrelated String's jelly answer*

## original answer , 19 bytes

```
+./@((|#\)*//.]),&1

```

Try it online!

Consider `3 f 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1`:

* `,&1` Append a 1:

```
0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1

```
* `(|#\)` Label each 1..n and then mod by 3:

```
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 2 0 1 2 0 1 2 0 1  2  0  1  2  0  1   <-- mod 3

```
* `*//.]` Use the last row to group the original input, and take the product of each group:

```
0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1
1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1   <-- mod 3

0 1 0 1 0 1│0 0 0 1 0│1 1 1 1 1
     ^          ^         ^
  1-group    2-group    0-group

     0     │    0    │    1
     ^          ^         ^
  1-group    2-group    0-group
  product    product    product

```
* `+./@` Is there a 1 among them? That indicates a valid path.

```
1

```

# Answer
> 3 votes
# Retina, 48 bytes

```
~(L$`.+$
*
C`\B
.+
^(^.{0,$&}1|$&*.1)$*.{0,$&}\n

```

Try it online! Takes pond and jump size on separate lines but link is to test suite that splits on comma for convenience. Explanation:

```
~(

```

After running the rest of the program, treat the result as its own Retina program, and execute that on the original input.

```
L$`.+$
*
C`\B

```

Delete the pond and decrement the jump size.

```
.+
^(^.{0,$&}1|$&*.1)$*.{0,$&}\n

```

Replace the decremented jump size with a regular expression that matches crossable ponds. Example: If the jump size is `7`, then the following expression is produced:

```
^(^.{0,6}1|......1)*.{0,6}\n

```

This optionally matches up to six digits and a `1` followed by multiple matches of six digits and a `1`, finishing with up to six digits and the newline that separates the pond from the jump size.

# Answer
> 3 votes
# C++ (clang), 91 bytes

```
[](auto p,int s){int i=s,j,a,r=0;for(;a=i;r|=a)for(j=--i;j<p.size();j+=s)a&=p[j];return r;}

```

Try it online!

input: `lily = -1, water = 0`

### gcc-specific (abusing UB):

# C++ (GCC), 89 bytes

```
int f(auto p,int s){int i=s,j,a,r=0;for(;a=i;r|=a)for(j=--i;j<p.size();j+=s)a&=p[j];s=r;}

```

Attempt This Online!

# Answer
> 2 votes
# Charcoal, 14 bytes

```
Ｎθ¬⌊Ｅθ№✂ηιＬηθ0

```

Try it online! Link is to verbose version of code. Takes the jump size as the first parameter and the pond as the second parameter and outputs a `1` if the pond can be crossed, `0` if not. Explanation: Based on @MatteoC's Python answer.

```
Ｎθ              First input as a number
     θ          First input
    Ｅ           Map over implicit range
      №         Count of
             0  Literal string `0` in
        η       Second input
       ✂        Sliced from
         ι      Current index to
           η    Second input
          Ｌ     Length
            θ   In steps of first input
   ⌊            Take the minimum
  ¬             Logical Not i.e. is zero
                Implicitly print

```

I tried porting @UnrelatedString's Jelly answer but the best I could do was also 14 bytes:

```
Ｎθ‹υ⁻…⁰θ﹪⌕Ａη0θ

```

Try it online! Link is to verbose version of code. Takes the jump size as the first parameter and the pond as the second parameter and outputs a Charcoal boolean, i.e. `1` if the pond can be crossed, nothing if not. Explanation:

```
Ｎθ              First input as a number
   υ            Predefined empty list
  ‹             Is less than
     …          Range from
      ⁰         Literal integer `0` to
       θ        First input
    ⁻           Remove elements from
         ⌕Ａ     Find all occurrences of
            0   Literal string `0`
           η    In second input
        ﹪       Vectorised modulo
             θ  First input

```

# Answer
> 2 votes
# Perl 5 `-pl`, 49 bytes

```
$l=<>-1;$_=/^.{0,$l}(.{$l}1)+.{0,$l}$/||$l>=y///c

```

Try it online!

# Answer
> 2 votes
# Wolfram Language (Mathematica), 44 bytes

```
Length[{}⋃Flatten@#~Position~0~Mod~#2]<#2&

```

Try it online!

# Answer
> 1 votes
# Retina 0.8.2, 62 bytes

```
.+$
$*
^(?=.*¶1(1)*)(?<-1>.)*((?(3)^)1(?=.*¶1(1)*)(?<-3>.)*)*¶

```

Try it online! Takes pond and jump size on separate lines but link is to test suite that splits on comma for convenience. Explanation:

```
.+$
$*

```

Convert the jump size to unary.

```
^(?=.*¶1(1)*)(?<-1>.)*

```

At the start of the pond, match up to (but not including) the jump size number of digits, then...

```
((?(3)^)1(?=.*¶1(1)*)(?<-3>.)*)*¶

```

... repeatedly match a `1` plus up to the jump size number of digits for the last repeat before the end of the pond, except that the condition at the beginning of the repeat means that the maximum number of digits must have been matched on all the previous repetitions.

# Answer
> 1 votes
# Desmos, some bytes

```
t(V)=V.length
R(V)=[sign(t(V)-i+.2)/2+.5fori=[1...t(V)+100]]
X(V)=[1-R(V)[j]+R(V)[j]V[jR(V)[j]+1-R(V)[j]]forj=[1...t(V)+100]]
f(V,z)=∑_{y=1}^z∏_{v=1}^{floor((t(V)-y+z)/z)}[X(V)[y+kz]fork=[0...(t(V)-z+10-y)/z]][v]

```

# Answer
> 1 votes
# Scala, 89 bytes

Golfed version. Try it online!

```
def f(n:Int,p:String)=(0 until n).exists(i=>(i until p.length by n).forall(j=>p(j)=='1'))

```

Ungolfed version. Try it online!

```
object Main {
  def pHash(n: Int, p: String): Boolean = {
    (0 until n).exists(i => (i until p.length by n).forall(j => p(j) == '1'))
  }

  def main(args: Array[String]): Unit = {
    val testCases = List(("001101001111001", 3), ("101001", 2), ("010000001", 7), ("00000", 6), ("00100100", 4))

    for ((p, n) <- testCases) {
      println(pHash(n, p))
    }
  }
}

```

# Answer
> 0 votes
# Uiua SBCS, 6 bytes

```
>⧻◴◿,⊚

```

Try it!

Port of UnrelatedString's Jelly answer.

# Answer
> 0 votes
# JavaScript (Node.js), 49 bytes

```
n=>k=>eval(`/^((.|^|$){${n-1}}(1|$))*$/`).test(k)

```

Try it online!

---
Tags: code-golf, decision-problem
---


title: Deep Search a List

text:
# Question
Title: Deep Search a List
For this challenge, a list is considered valid if and only if it consists entirely of integers and valid lists (recursive definitions \o/). For this challenge, given a valid list and an integer, return a list of all depths at which the integer can be found.

# Example

Let's consider list `[1, [2, [3, [1, 2, 3], 4], 1], 1]` and integer `1`. Then, we can draw out the list like this:

```
Depth 0 1 2 3
Num   1
        2
          3
            1
            2
            3
          4
        1
      1

```

You'll notice that `1` shows up at depths `0, 1, 3`. Thus, your output should be `0, 1, 3` in some reasonable format (order does not matter).

The depth may be either 0- or 1-indexed, but please specify in your submission which one it is.

# Test Cases (0-indexed)

For list `[1,[2,[3,4],5,[6,7],1],[[[[5,2],4,[5,2]]],6],3]`:

```
1 -> [0, 1]
2 -> [1, 4]
3 -> [0, 2]
4 -> [2, 3]
5 -> [1, 4]
6 -> [1, 2]
7 -> [2]

```

For list `[[[[[1],0],1],0],1]`:

```
0 -> 1, 3
1 -> 0, 2, 4

```

For list `[11,22,[33,44]]`:

```
11 -> [0]
22 -> [0]
33 -> [1]
44 -> [1]

```

Return an empty list if the search term does not exist in the list anywhere.

Negative and zero values are valid in the input list and term.

# Answer
> 8 votes
# Haskell, ~~102~~ ~~93~~ ~~80~~ 76 bytes

Thanks Bruce Forte for saving some bytes, and Laikoni for saving some more.

Thanks 4castle for saving 4 bytes.

Haskell has no data type for this kind of list, so I made my own.

This solution is `1-indexed`

```
import Data.List
data T=E Int|L[T]
E n%x=[0|x==n]
L s%x=nub$map(+1).(%x)=<<s

```

Try it online!

First I define (recursively) a data type `T`

`T` has either type `E Int` (single element of type `Int`) or `L[L]` (list of type `T`).

`(%)` is function that takes `2` arguments, on of type `T`, the list through which we are searching, and `x`, the `Int` we are looking for.

Whenever `(%)` finds something that is a single element `E n`, it checks `n` for equality with `x` and returns `0` if True.

When `(%)` is applied to an `L s` (where `s` has type `[T]`) it runs `(%)` on all the elements of `s` and increments the result (as the depth is increasing since we are looking inside `s`), and the concatenates the result.

`nub` then removes the duplicates from the list

NB. `import Data.List` is only for `nub`.

# Answer
> 7 votes
# Mathematica, 25 bytes

```
Tr/@Union[1^Position@##]&

```

(returns 1-indexed output)

# Explanation

```
                         test  {1, {2, {3, {1, 2, 3}, 4}, 1}, 1}
             Position[test,1]  {{1}, {2, 2, 2, 1}, {2, 3}, {3}}
           1^Position[test,1]  {{1}, {1, 1, 1, 1}, {1, 1}, {1}}
    Union[1^Position[test,1]]  {{1}, {1, 1}, {1, 1, 1, 1}}
Tr/@Union[1^Position[test,1]]  {1, 2, 4}

```

# Answer
> 6 votes
# Python 2, 68 bytes

```
f=lambda l,k,d=-1:l>[]and f(l[0],k,d+1)|f(l[1:],k,d)or{d}-{d+(l==k)}

```

Try it online!

# Answer
> 5 votes
# , ~~101~~ ~~95~~ ~~92~~ 100 bytes

```
f=function(L,n,d=0)unique(unlist(Map(function(x)if(n%in%unlist(x))"if"(is.list(x),f(x,n,d+1),d),L)))

```

Try it online!

Recursive solution; it's quite inefficient in bytes, but R `lists` are super annoying to work with.

Basically, takes `L`, and for each element `x` of `L`, (which is either a `list` or an `atomic` vector of one element), checks if `n` is `%in%` `x`, then checks if `x` is a `list`. If it isn't, then `x==n` so we return the depth `d`; otherwise we recursively call `f` on `x`, incrementing `d`.

This, of course, returns a `list`, which we `unlist` and `unique` to ensure the right output (returning a vector of integer depths); returns `NULL` (an empty list) for invalid `n`.

Apparently, `%in%` doesn't search recursively through a `list` like I thought, so I have to `unlist(x)` for +8 bytes :(

# Answer
> 5 votes
# Jelly, ~~11~~ 8 bytes

```
WẎÐĿċ€IT

```

Try it online!

### How it works

```
WẎÐĿċ€IT  Main link. Left argument: A (array). Right argument: n (integer)

W         Wrap; yield [A].
  ÐĿ      Repeatedly apply the link to the left until the results are no longer
          unique. Yield the array of all unique results.
 Ẏ          Concatenate all elements at depth 1 in the array.
          The last array of the array of results is completely flat.
    ċ€    Count the occurrences of n in each intermediate result.
      I   Compute all forward differences.
       T  Truth; yield the array of all indices of non-zero differences.

```

### Example run

For left argument

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

```

`W` first yields the following array.

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

```

`ẎÐĿ` repeatedly concatenates all elements at depth **1**, reducing the depth of the array by **1** in each step. This yields the following array of intermediate results.

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

```

For right argument **1**, `ċ€` counts the occurrences of **1** in each intermediate result.

```
[0, 2, 3, 3, 4]

```

`I` now takes all forward differences.

```
[2, 1, 0, 1]

```

Non-zero differences correspond to steps in which at least one other **1** was added to depth **1**. Thus, a non-zero difference at index **k** indicates the presence of a **1** at depth **k**. `T` finds the indices of all truthy elements, yielding the desired result:

```
[1, 2, 4]

```

# Answer
> 4 votes
# Python 2, 72 bytes

```
f=lambda l,k,d=0:set([d]*(k in l)).union(*[f(x,k,d+1)for x in l if[]<x])

```

Try it online!

# Answer
> 3 votes
# APL (Dyalog), 39 bytes\*

Full program. Prompts for list, then for number. Prints 1-based list to STDOUT.

```
⌊2÷⍨⍸∨⌿⍞⍷⎕FMT⎕JSON⍠'Compact'0⊢⎕

```

Try it online!

prompt for list

yield that (separates `0` and )

`⎕JSON⍠'Compact'0` convert to indented JSON string with newlines

`⎕FMT` convert to matrix (one newline-delimited line per row)

`⍞⍷` prompt for number as string and indicate where it begins in that

`∨⌿` vertical OR reduction (i.e. which columns it begins in)

indices of those beginnings

`2÷⍨` halve that (levels are indented with two spaces)

round down (because first data column is column 3)

---

* In Dyalog Classic, counting  as `⎕U2378` and  as `⎕OPT`.

# Answer
> 2 votes
## JavaScript (ES6), ~~79~~ 68 bytes

```
f=(a,n,r=new Set,d=0)=>a.map(e=>e.map?f(e,n,r,d+1):e-n||r.add(d))&&r

```

Returns a Set. If this is unacceptable, use `&&[...r]` at a cost of 5 bytes.

# Answer
> 2 votes
# PHP, 117 bytes

```
$r;function z($a,&$r,$i=0){foreach($a as $v){is_int($v)?(@in_array($i,$r[$v])?:$r[$v][]=$i):z($v,$r,$i+1);}}z($s,$r);

```

Try it online!

# Answer
> 1 votes
# JavaScript (ES6), ~~73~~ 74 bytes

```
f=(a,n,i=0,o={})=>a.map(e=>e.pop?f(e,n,i+1,o):e-n||o[i]++)&&Object.keys(o)

```

**Explanation:**

```
f=(a,                             //input array
   n,                             //input number to search
   i=0,                           //start at first level
   o={}                           //object to store the finds
  )=>
    a.map(                        //loop through the array
      e => e.pop ?                //is this element an array?
             f(e, n, i+1, o) :    //if so, recurse on it to the next level
             e-n || o[i]++        //otherwise, update o if element equals the number
    ) &&
    Object.keys(o)                //return o's keys

```

**Test cases**

```
f=(a,n,i=0,o={})=>a.map(e=>e.pop?f(e,n,i+1,o):e-n||o[i]++)&&Object.keys(o)

var a = [1,[2,[3,4],5,[6,7],1],[[[[5,2],4,[5,2]]],6],3];
console.log(f(a,1));
console.log(f(a,2));
console.log(f(a,3));
console.log(f(a,4));
console.log(f(a,5));
console.log(f(a,6));
console.log(f(a,7));

console.log('___________');
var a = [[[[[1],0],1],0],1];
console.log(f(a,0));
console.log(f(a,1));

console.log('___________');
var a = [11,22,[33,44]];
console.log(f(a,11)) // [0]
console.log(f(a,22)) // [0]
console.log(f(a,33)) // [1]
console.log(f(a,44)) // [1]
console.log(f(a,55)) // empty set
```

# Answer
> 1 votes
# Python 3, ~~123~~ ~~86~~ 82 bytes

```
def f(a,n,l=[],d=0):
 for e in a:l+=[d]*(e==n);0*e==[]and f(e,n,l,d+1)
 return{*l}

```

Try it online!

-37 bytes thanks to Hyper Neutrino and ovs

-4 bytes thanks to Jonathan Frech

# Answer
> 1 votes
# Jelly,  ~~17~~  16 bytes

```
⁴e®;©ȧ⁸ḟ⁴ẎµÐĿȧ®T’

```

A full program taking two command line arguments the list and an element to check for, and printing the depth or depths (if any) at which the element exists. The results are 1-indexed.

**Try it online!**

### How?

```
⁴e®;©ȧḟ⁴ẎµÐĿȧ®T’ - Main link: list, L
          µÐĿ    - loop, collecting updated values of L, until a fixed point is reached:
⁴                -   4th argument (2nd program input) = the number
 e               -   exists in (the current version of) L?
  ®              -   recall value from the register (initially 0)
   ;             -   concatenate the two
    ©            -   (copy this result to the register)
       ⁴         -   4th argument (2nd program input) again
      ḟ          -   filter out (discard any instances of the number)
     ȧ           -   logical and (non-vectorising)
        Ẏ        -   tighten (flatten the filtered L by one level to create the next L)
             ®   - recall value from the register
            ȧ    - logical and (non-vectorising)
              T  - truthy indexes (1-indexed)
               ’ - decrement (account for the leading zero from the initial register)

```

# Answer
> 1 votes
# Octave, ~~126~~ 122 bytes

```
function n=r(p,t,l)n=[];if nargin<3
l=0;end
for x=p
if iscell(q=x{1})a=r(q,t,l+1);else
a=l*find(q==t);end
n=union(n,a);end

```

Try it online!

For readability, I replaced spaces or `;`'s with line ends where possible. Explanation of ungolfed code:

```
function n=r(p,t,l) % Declare function with list p, integer t and optional recursion depth l
n=[];
if nargin<3
    l=0;            % If l is not given (first iteration), set l to zero (or one for 1-indexing)
end
for x=p             % Loop over list
if iscell(q=x{1})   % If loop variable x is a cell, we must go down one level.
     a=r(q,t,l+1);  % So recurse to l+1.
else
    a=l*find(q==t); % Empty if q~=t (because find(false)==[], and l*[]==[]), else equal to l*1==l.
end
n=union(n,a);       % Append to list of levels, make sure we only get distinct values.
end

```

# Answer
> 1 votes
# APL (Dyalog Classic), ~~31~~ 30 bytes

Function. Left arg  is the needle, right arg  is the haystack.

```
{×≢⍵:(⍳⍺∊⍵),1+⍺∇⊃,/⍵/⍨≢¨⍴¨⍵⋄⍬}

```

Try it online!

# Answer
> 1 votes
# Vyxal, 75 bitsv2, 9.375 bytes

```
w⁽Þf↔ƛ⁰O;¯T

```

Try it Online!

Might be able to shave off a byte here, port of Jelly

# Answer
> 0 votes
# Java, 154 + 19 = 173 bytes

```
import java.util.*;

```

```
Set<Long>f(List l,long n){Set s=new HashSet();if(l.contains(n))s.add(0l);for(Object o:l)if(o instanceof List)for(long d:f((List)o,n))s.add(d+1);return s;}

```

Try It Online

## Ungolfed method

```
Set<Long> f(List l, long n) {
    Set s = new HashSet();
    if (l.contains(n))
        s.add(0l);
    for (Object o : l)
        if (o instanceof List)
            for (long d : f((List) o, n))
                s.add(d + 1);
    return s;
}

```

# Answer
> 0 votes
# ReRegex, 299 bytes

```
#import math
(a[^<>\[\]]*?)\[/$1</(a.*?(_*)<[^<>\[\]]*?)\[/$1_$2</(a.*?(_*)<[^<>\[\]]*?)\]/$1$2>/(a.*?(_*)>[^<>\[\]]*?)\[/$1$2</(a.*?_(_*)>[^<>\[\]]*?)\]/$1$2>/a([^\[\]]*$)/bb$1/^(.*?)b(.*)b(.*?(_*)<[^<]*)\1/$1b$2,d<$4>b$3/^(.*?)b,?(.*)b(.(?!\1))*$/$2/(,|^)([^,<>\[\]]+)([^<>\[\]]*),\2/$1$2$3/#input

```

## With comments

```
#import math
# Count the depths of all braces
(a[^<>\[\]]*?)\[/$1</
(a.*?(_*)<[^<>\[\]]*?)\[/$1_$2</
(a.*?(_*)<[^<>\[\]]*?)\]/$1$2>/
(a.*?(_*)>[^<>\[\]]*?)\[/$1$2</
(a.*?_(_*)>[^<>\[\]]*?)\]/$1$2>/
# Move to step b
a([^\[\]]*$)/bb$1/
# Record all the depths of all instances of the input
^(.*?)b(.*)b(.*?(_*)<[^<]*)\1/$1b$2,d<$4>b$3/
# Move to finalize
^(.*?)b,?(.*)b(.(?!\1))*$/$2/
# Deduplicate
(,|^)([^,<>\[\]]+)([^<>\[\]]*),\2/$1$2$3/
#input

```

Try it online!

# Answer
> 0 votes
# Perl 5 `-a`, 65 bytes

```
$q=<>;s,-?\d+,$q-$&||$k{$`=~y/\[//-$`=~y/]//}++,ge;say for keys%k

```

Try it online!

Result is 1-indexed.

# Answer
> 0 votes
# Ruby, 63 bytes

```
f=->n,a,x=0{a.map{f[n,_1,x+1]rescue n==_1 ?x:p}.flatten-[p]|[]}

```

Attempt This Online!

---
Tags: code-golf, array, ragged-list
---


title: Falsify brief truths

text:
# Question
Title: Falsify brief truths
Find the longest run of true in a list of booleans. Return the same list, with all other trues falsified.

## Input, output

A list; any usual format (e.g., a delimited list as a string).

## Details

True and false can be anything your language typically uses for those values, or the integers 1 and 0. If you use single characters, the list can be a concatenation (e.g., `10001`).

If there's a tie for longest run, keep all tying runs true, and falsify all shorter runs.

## Examples

```
input ↦ output
1,0,1,0,1 ↦ 1,0,1,0,1
1,1,0,1,1,0,1 ↦ 1,1,0,1,1,0,0
1,1,0,1,1,1,0,1,1 ↦ 0,0,0,1,1,1,0,0,0
1,1,1 ↦ 1,1,1
0,0,1 ↦ 0,0,1
0,0 ↦ 0,0
1,1,1,0,0,0,1,1,1,1,0,1,0,0,1,1,0,1,1,1,1,0,0,1,0 ↦ 0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0

```

(directly from https://stackoverflow.com/q/37447114)

# Answer
# Jelly, 8 bytes

```
ṣ0¬¬M¦j0

```

Try it online! or verify all test cases.

### How it works

```
ṣ0¬¬M¦j0  Main link. Argument: A (list of Booleans)

ṣ0        Split at zeroes. This leaves a 2D list of ones.
  ¬       Negate each 1, replacing it with 0.
     ¦    Conditional application:
    M       Yield all maximal indices.
            In lexicographical list comparison, a shorter list of zeroes is less
            than a longer one, so this identifies the longest runs.
   ¬        Negate the items in those lists, changing zeroes back to ones.
      j0  Join, separating by single zeroes.

```
> 19 votes

# Answer
# Haskell, ~~59~~, ~~58~~, ~~55~~, 64 bytes

```
import Data.List
((=<<)=<<(=<<)(<$).(==).maximum.([1<2]:)).group

```

Fun note, this works on any list of values where `falsy < truthy`. So `False/True`, `0/1`, `'f'/'t'`, etc.

### Note:

As several people have pointed out (including `@proud haskeller` and `@nimi`), the previous version failed on a list of all falsy values. The addition of `.([1<2]:)` has fixed this, as suggested by `@proud haskeller`. I'm leaving the explanation the same for now, because I think it still makes sense. If anyone comments, asking for an explanation of the edit, I'll edit.

## Explanation:

I'll first desugar without the `group`, and then add it back. First, I find that words are often easier on the eyes than symbols, so I'll make a few substitutions. (Note that `=<<` is 'classy' so it applies differently for lists and functions. I'm calling `bind` the version of `=<<` for functions.)

```
bind :: (a -> b -> c) -> (b -> a) -> b -> c
bind k f = k =<< f
bind k f = \ r -> k (f r) r

f = ((=<<)=<<(=<<)(<$).(==).maximum)
f = ((bind) concatMap (bind)(<$).equals.maximum)
f = (bind concatMap (bind (<$) . equals . maximum))
f = bind concatMap ((bind (<$)) . equals . maximum))
f = bind concatMap ((\f r -> (<$) (f r) r) . equals . maximum))
f = bind concatMap ((\f r -> (f r) <$ r) . equals . maximum)
f = bind concatMap ((\g r -> (g r) <$ r) . equals . maximum)
f = (\h r -> concatMap (h r) r) ((\g r -> (g r) <$ r) . equals . maximum)
f = \r -> concatMap (((\g r -> (g r) <$ r) . equals . maximum) r) r
f = \r -> concatMap (((\g r -> (g r) <$ r) . equals) (maximum r)) r
f = \r -> concatMap (((\g s -> (g s) <$ s)) (equals (maximum r))) r
f = \r -> concatMap (((\s -> ((equals (maximum r)) s) <$ s))) r
f = \r -> concatMap (\s -> (s == (maximum r)) <$ s) r

f . group = ((=<<)=<<(=<<)(<$).(==).maximum).group
f . group = \r -> concatMap (\s -> (s == (maximum (group r))) <$ s) (group r)

```

The last details are that `x <$ list` replaces every element of the `list` with `x` and `group list` splits the `list` up into chunks of equal elements. So `group [1, 1, 2, 3, 3, 3] == [[1, 1], [2], [3, 3, 3]]`.

To sum it all up, the function splits the list of values into groups of only true and groups of only false. Then for each group, replace each element with the result of the statement `this is the biggest group` (the largest group of `true`'s will be the biggest) and concatenate the groups.

Four bytes saved by `@Zgarb`
> 11 votes

# Answer
# Retina, ~~47~~ ~~43~~ 36

```
0
!
T`p`0`\b(1+)\b(?<=(?=.*1\1).*)|!

```

Try it online! or try all the test cases

Thanks to msh210 for golfing 4 bytes!

Also big thanks to Martin for 7 bytes!

### Explanation:

```
0
!

```

Replace all `0`s with `!`s. This is done to make matching groups of `1`s shorter, as now `1!` and `!1` will have a word boundary (`\b`) between them, which also matches either the start or the end of the string.

```
T`p`0`

```

This is a configuration option saying that after applying the regex after the backtick to the input, in every match translate every printable ascii character into a `0` character.

```
\b(1+)\b(?<=(?=.*1\1).*)|!

```

This regex matches groups of `1`s that are surrounded by zeroes, but do cannot match a `1` followed by itself anywhere in the string. These are the non-maximal groups that will be falsified. In addition, this also matches the `!` characters we added to convert them back into `0`s.
> 6 votes

# Answer
# MATL, 14 bytes

```
Y'yy*X>y=b*wY"

```

**Try it Online!**

Modified version with all test cases

**Explanation**

```
        % Implicitly grab the input as an array
Y'      % Perform run-length encoding of the input. Yields an array of values and an array
        % of run-lengths
yy      % Copy these outputs
*       % Multiply the values (booleans) by the run-lengths. This will zero-out all
        % zero-valued runs so we don't consider them when computing the longest run.
X>      % Compute the longest run of 1's
y       % Copy the run lengths vector
=       % Determine which runs are the same length as the longest run of ones
b*      % Bubble-up the values from the run-length encoding and multiply element-wise
        % With this boolean. This substitutes all 1's that are not in the longest run
        % of ones with 0's
w       % Flip the run-lengths and values on the stack
Y"      % Perform run-length decoding using these substituted values
        % Implicitly display the resulting boolean

```
> 5 votes

# Answer
# Python 2, 62 bytes

```
lambda s:'0'.join(`1-(t+'1'in s)`*len(t)for t in s.split('0'))

```

Test it on Ideone.

### How it works

`s.split('0')` splits the input string **s** into runs of zero or more **1**'s

For each run **t**, we check whether `t+'1'` is a substring of **s**.

* If it is, the run isn't maximal, `t+'1'in s` return **True**, `1-(t+'1'in s)` return **1 - True = 0** and the run is replaced with a run of **0**'s of the same length.
* If it isn't, the run is maximal, `t+'1'in s` return **False**, `1-(t+'1'in s)` return **1 - False = 1** and the run is replaced with a run of **1**'s of the same length, i.e., by itself.

Finally, `'0'.join` restores all removed **0**'s.
> 4 votes

# Answer
# Pyth, ~~26~~ ~~24~~ ~~23~~ 21 bytes

```
M,G&HGJrgMrQ8 9qReSJJ

```

Test suite.

* Uses `1/0` or `true/false` in input.
* Uses `true/false` in output.

### Explanation

```
M,G&HGJrgMrQ8 9qReSJJ

           Q      input
          r 8     run-length encode
        gM        convert each run of 1 to their length
                  for example: [1,1,1,0,1,1] will be
                  converted to [3,3,3,0,2,2]
                  in the run-length encoded version
                  [1,1,1,0,1,1] will be [[3,1],[1,0],[2,1]]
                  [3,3,3,0,2,2] will be [[3,3],[1,0],[2,2]]
                  therefore basically [G,H] becomes [G,H and G]
                  which is what the code below does:
M,G&HG            def g(G,H): return [G,H and G]
       r      9   run-length decode
      J           store to J

               qReSJJ

                R   J   in each element of J
               q eSJ    check if equal to maximum of J

```

### Previous 23-byte

```
M,G&HGJrgMrQ8 9msqdeSJJ

```

Test suite.

* Uses `1/0` or `true/false` in input.
* Uses `1/0` in output.

### Previous 24-byte

```
Jrm,hd&edhdrQ8 9msqdeSJJ

```

Test suite.

* Uses `1/0` or `true/false` in input.
* Uses `1/0` in output.

### Previous 26-byte

```
rm?nhdeS.u&YhNQ0,hd0drQ8 9

```

Test suite.

* Uses `1/0` or `true/false` in input.
* Uses `1/0` in output.
> 3 votes

# Answer
## J, 25 bytes

```
[:(}.=>./)@;0<@(*#);.1@,]

```

This is a monadic verb that takes and returns a 0-1 array. Use it like this:

```
   f =: [:(}.=>./)@;0<@(*#);.1@,]
   f 1 1 0 1 1 1 0 1 1
0 0 0 1 1 1 0 0 0

```

## Explanation

```
[:(}.=>./)@;0<@(*#);.1@,]  Input is y.
            0          ,]  Prepend 0 to y, and
                   ;.1@    cut the result along occurrences of 0,
                           so that each piece begins with a 0.
               (*#)        Multiply each piece element-wise by its length,
             <@            and put it in a box.
                           Without the boxing, the pieces would go in a 0-padded array.
           ;               Join the pieces back together.
                           Now all runs of 1 have been replaced by runs of (1+length of run).
[:(      )@                Apply verb in parentheses:
   }.                        remove the prepended 0,
     =                       form the 0-1 array of equality with
      >./                    the maximum value.

```
> 3 votes

# Answer
## *Mathematica*, ~~46~~ 41

```
1-Join@@Sign[1~Max~#-#]&[#*Tr/@#]&@*Split

```

Works on lists of `0` and `1`. I thought I had done pretty well until I looked at the other answers!

---

*Explanation for 46 character version; I shall update when I cannot improve it further.*

An explanation of this code was requested.
A non-code-golf equivalent (using version 10 operator forms) is:

```
RightComposition[
  Split,
  Map[# Tr@# &],
  # - Max[1, #] &,
  UnitStep,
  Apply[Join]
]

```

This means a function made up of five steps (sub-functions) applied in order from top to bottom.

* `Split`: break up into runs of identical elements: {1,1,0,1,1,0,1} ↦ {{1,1}, {0}, {1,1}, {0,0}}
* `Map[# Tr@# &]`: For each sub-list (`Map`) multiply it (`#`) by its sum (vector trace, `Tr`): {1,1} ↦ {2, 2}
* `# - Max[1, #] &` subtract from every element the maximum value appearing anywhere in the list of lists, or one, whichever is higher. (The one handles the case of all zeros.)
* `UnitStep`: equal to 0 for x \< 0 and 1 for x \>= 0, applied to every element.
* `Apply[Join]`: join the sub-lists into a single list. Could also be done with `Flatten` or `Catenate`, but in short form `Join@@` is more terse.
> 2 votes

# Answer
# Oracle SQL 12.1, ~~137~~ 135 bytes

```
SELECT REPLACE(REPLACE(REPLACE(:1,m,2),1,0),2,m)FROM(SELECT MAX(TRIM(COLUMN_VALUE))m FROM XMLTABLE(('"'||REPLACE(:1,0,'",0,"')||'"')));

```

Un-golfed

```
-- Replace the max value with 2
-- Then replace every 1 with 0
-- Then replace 2 with the max value
SELECT REPLACE(REPLACE(REPLACE(:1,m,2),1,0),2,m)
FROM   ( -- Split on 0 and keep the max value
         SELECT MAX(TRIM(COLUMN_VALUE))m
         FROM XMLTABLE(('"'||REPLACE(:1,'0','",0,"')||'"'))
       );

```

Input use single characters. Ex: '1100111'
> 2 votes

# Answer
# C, 135 129 bytes

**Try Online**

```
m,c,i,d,j;f(int*l,int s){while(i<s)c=l[i++]?c+1:0,m=c>m?c:m;while(j<s)if(l[j++])d=d+1;else if(d<m)while(d)l[j-1-d--]=0;else d=0;}

```

**Ungolfed**

```
m,c,i;
f(int*l,int s)
{
    // obtain max
    while(i<s)
        c = l[i++] ? c+1 : 0,
        m = c>m ? c : m;

    c=0,i=0;

    // remove smaller segments
    while(i<s)
        if(l[i++]) c=c+1;
        else if(c<m) while(c) l[(i-1)-c--]=0;
        else c=0;
}

```
> 2 votes

# Answer
## JavaScript (ES6), 56 bytes

```
s=>s.replace(/1+/g,t=>t.replace(/1/g,+!~s.indexOf(t+1)))

```

Works by checking all runs of 1s and replacing the characters with 0s unless the run is (equally) longest, as measured by searching the string for a longer run of 1s.

Previous 72-byte recursive solution:

```
f=s=>/11/.test(s)?f(s.replace(/1(1*)/g,"0$1")).replace(/0(1+)/g,"1$1"):s

```

Does nothing if there are no runs of 1s (i.e. single 1s at most). Otherwise, subtracts one `1` from each `1` or run thereof, then calls itself recursively on the shorter runs, then adds one `1` back on the (now equally longest) runs. The number of recursive calls is one less than the length of the longest run.
> 1 votes

# Answer
# Julia, 51 bytes

```
s->replace(s,r"1+",t->map(c->c-contains(s,"1"t),t))

```

Try it online!

### How it works

`replace` finds all all runs of one or more **1**'s in the input string **s** via the regex `r"1+"` and calls the lambda `t->map(c->c-contains(s,"1"t),t)` to determine the replacement string.

The lambda maps `c->c-contains(s,"1"t)` over all characters in the run of ones **t**.

* If `"1"t` (concatenation) is a substring of **s**, the run isn't maximal, `contains` returns **true** and `c-contains(s,"1"t)` returns **'1' - true = '0'**, replacing all **1**'s in that run with **0**'s.
* If `"1"t` (concatenation) is not a substring of **s**, the run is maximal, `contains` returns **false** and `c-contains(s,"1"t)` returns **'1' - false = '1'**, leaving the run unmodified.
> 1 votes

# Answer
# Java 8, 205 bytes

This is a lambda expression for a `Function<String,String>`:

```
s->{int x=s.length();for(String t="1",f="0";s.indexOf(t+1)>=0;t+=1){s=s.replaceAll(0+t+0,0+f+0);if(s.indexOf(t+0)==0)s=s.replaceFirst(t,f);if(s.lastIndexOf(0+t)==--x-1)s=s.substring(0,x)+f;f+=0;}return s;}

```

input/output is a `String` where true is represented by 1 and false is represented by 0. There are no delimiter characters separating the values.

code with explanation:

```
inputString -> {
  int x = inputString.length();
  //starting with the truth combination "1",
  //loop until the input string does not contain the combination appended with another "1"
  //with each consecutive loop appending a "1" to the combination
  for( String truthCombo = "1", falseCombo = "0"; inputString.indexOf( truthCombo + 1 ) >= 0; truthCombo += 1 ) {
    //all instances in the input string
    //where the combination has a "0" on either side of it
    //are replaced by "0"'s
    inputString = inputString.replaceAll( 0 + truthCombo + 0, 0 + falseCombo + 0 );
    //if the combination followed by a "0"
    //is found at the beginning of the input string
    //replace it with "0"'s
    if( inputString.indexOf( truthCombo + 0 ) == 0 )
      inputString = inputString.replaceFirst( truthCombo , falseCombo );
    //if the combination preceeded by a "0"
    //is found at the end of the input string
    //replace it with "0"'s
    if( inputString.lastIndexOf( 0 + truthCombo ) == --x - 1 )
      inputString = inputString.substring( 0, x ) + falseCombo;
    falseCombo += 0;
  }
  return inputString;
}

```

see ideone for the test cases
> 1 votes

# Answer
## APL, 22 chars

```
(⊣=⌈/)∊(⊣×+/¨)(~⊂⊣)0,⎕

```

In English (from right to left in blocks):

* prepend 0 to the input
* box starting with each 0
* multiply each box by its sum
* flatten
* 1 if number equal to the max, 0 otherwise
> 1 votes

# Answer
## Clojure, 137 bytes

```
#(let[v(map(juxt first count)(partition-by #{1}%))](mapcat(fn[t](repeat(t 1)(if(=[1(apply max(map(fn[[f c]](if(= 1 f)c 0))v))]t)1 0)))v))

```

First partitions the input into consecutive zeros and ones and maps these into "tuples" of partitions' first element and the count of elements. It then repeats the needed number of zeros or ones, depending if this is the max-length sequence of ones or not.

Less golfed:

```
(def f #(let [v(map(juxt first count)(partition-by #{1}%))
              m(apply max(map(fn[[f c]](if(= 1 f)c 0))v))]
           (mapcat (fn[[f c]](repeat c(if(=[1 m][f c])1 0))) v)))

```
> 1 votes

# Answer
# Vyxal, 99 bitsv2, 12.375 bytes

```
0€‹:ÞG£ƛ¥⁼ß›;0j

```

Try it Online!

Bitstring:

```
001111010110101010011111011100100110010001011001110011110001101100100100110001000010011101000000010

```

port of jelly
> 1 votes

# Answer
# Perl 5, 68 bytes

67, plus 1 for `-pe` instead of `-e`

```
y/0/ /;$_<${[sort@a]}[-1]&&y/1/0/for@a=split/\b/;$_=join"",@a;y; ;0

```

Expects and prints a string (concatenation) of 0s and 1s.
> 0 votes

---
Tags: code-golf, array
---