title: Numbers with distinct decimal digits

text:
# Question
Title: Numbers with distinct decimal digits
Write a program or function that outputs all positive integers with distinct decimal digits (OEIS: A010784)

Examples:

```
1 2 3 4 5 6 7 8 9 10 12 13 ...
96 97 98 102 103 ...
123456789 123456798 ... 9876543120 9876543201 9876543210

```

# Rules

* You can output the list of numbers in any convenient format (string with separators, array, generator, ...)
* The order of the numbers is not important as long as every number appears exactly once
* You can choose if you include zero
* This is the shortest solution wins

# Answer
# Haskell, 37 bytes

```
import Data.List
nub$nub.show<$>[1..]

```

Try it online!

Takes each number, removes duplicate digits from its string representation while preserving order, then removes duplicates from the resulting list.

**41 bytes**

```
[s|s<-show<$>[1..],s==[x|x<-s,y<-s,x==y]]

```

Try it online!

For both solutions, the resulting list is finite, but attempts to read further elements will not terminate. Adding an upper bound would fix this.
> 10 votes

# Answer
# , 14 bytes

```
~.~.@":&>i.!14

```

Attempt This Online! (with 7 instead of 14)

Uses xnor's idea: take unique digits from each number and then take unique results of that.

---

# , 18 bytes

```
I.(=&#=)@":&>i.!14

```

Attempt This Online! (with 7 instead of 14)

14! is the first factorial that exceeds 10^10.

```
I.(=&#=)@":&>i.!14
               !14    large enough number
             i.       all numbers up to that
           &>         for each number,
  (    )@":           stringify and check that,
      =               taking the unique chars
   =&#                keeps the length identical
I.                    output all true indices

```
> 6 votes

# Answer
# 05AB1E, ~~5~~ 4 bytes

```
∞€ÙÙ

```

Outputs an infinite list.

Try it online.

**Explanation:**

```
∞     # Push an infinite list of positive integers: [1,2,3,...]
 €Ù   # Uniquify the digits in each integer
   Ù  # Uniquify this infinite list
      # (after which this 'filtered' infinite list is output implicitly as result)

```
> 5 votes

# Answer
# K (ngn/k), 12 bytes

```
.'??'$!_1e10

```

Try it online! (with 1e3 instead of 1e10)

Uses xnor's idea: take unique digits from each number and then take unique results of that. Because the result is a list of strings, `.'` is necessary to convert them back to numbers.

---

# K (ngn/k), 15 bytes

```
&~'/?:'\$!_1e10

```

Try it online! (with 1e3 instead of 1e10)

```
&~'/?:'\$!_1e10
         !_1e10    0..9999999999
        $          stringify each number
    ?:'\           iterate-collect over "uniquify each string"
                   which gives zeroth (original) and first (uniquified) iterations
 ~'/               1 if the two are equal, 0 otherwise for each item
&                  output nonzero indices

```
> 4 votes

# Answer
# Vyxal, 26 bitsv2, 3.25 bytes

```
Þ∞'Þu

```

Outputs an infinite list.

Try it online.

**Explanation:**

```
Þ∞      # Push an infinite positive list: [1,2,3,...]
  '    '# Filter it by:
   Þu   #  All digits in the integer are unique
        # (after which this filtered infinite list is output implicitly as result)

```
> 3 votes

# Answer
# Python 3, 49 bytes

```
n=1
while 1/n:10**len({*str(n)})>n!=print(n);n+=1

```

Try it online!

Uses my `10**` trick from 2014. Converting the string representation of \\$n\\$ to a set removes duplicates, and we check whether this decreases the length by comparing to \\$10^n\\$, which is bigger than all \\$n\\$-digit number but no \\$(n+1)\\$-digit numbers.

The `1/n` is used to theoretically halt for large enough `n` because doubles become zero around `1e-308` due to finite precision. If the program may just continue to run forever after printing all the numbers, this can be:

**46 bytes**

```
n=0
while[10**len({*str(n)})>n!=print(n)]:n+=1

```

Try it online!
> 3 votes

# Answer
# JavaScript (SpiderMonkey), 43 bytes

```
for(i=99e9;i;)/(.).*\1/.test(--i)||print(i)

```

Try it online! (Linked version prints only up to 3 digits to avoid time out)
> 3 votes

# Answer
# Nekomata, 3 bytes

```
ŇƊů

```

Attempt This Online!

Outputs a list of lists of digits, without leading zeros. Zero is also output in this way (so appears in the output as an empty list).

```
Ň    # nondeterminiatically choose a natural number
 Ɗ   # convert it to a list of decimal digits
  ů  # keep them if they are all unique

```

---

# Nekomata, 4 bytes

```
ŇƊůN

```

Attempt This Online!

Outputs a list of lists of digits, without leading zeros. Zero is not part of the output.
Works as the shorter answer above, but with an additional `N` to reject empty lists.
> 3 votes

# Answer
# Brachylog, 3 bytes

```
ℕ≜≠

```

Try it online!

This is a generator, the output of this predicate unifies with each possible integer in increasing magnitudes. The try it online link has a header to unify the first 100 values.

### Explanation

```
ℕ     A non-negative integer
 ≜    Pick one of them
  ≠   All elements (i.e. digits) must be different

```
> 2 votes

# Answer
# Charcoal, 14 bytes

```
ΦＩ…⁰Ｘχχ¬⊙ι⊖№ιλ

```

Try it online! Link is to verbose version of code but only goes to `9876` because it would be too slow or run out of memory. Explanation:

```
  …             Range from
   ⁰            Literal integer `0`
     χ          Predefined variable 10
    Ｘ           Raised to power
      χ         Predefined variable 10
 Ｉ              Cast to string
Φ               Filtered where
         ι      Current string
       ¬⊙       No character satisfies
           №    Count of
             λ  Current character
            ι   In current string
          ⊖     Is not `1`
                Implicitly print

```
> 2 votes

# Answer
# Retina 0.8.2, 27 bytes

```

9999999999$*¶

$.`
A`(.).*\1

```

Try it online! Link only goes to `9876` because it would be too slow or run out of memory. Explanation:

```

9999999999$*¶

$.`

```

List the numbers up to `9999999999`.

```
A`(.).*\1

```

Delete those with duplicate digits.
> 2 votes

# Answer
# Julia, 45 bytes

```
(r=1:2^34)[allunique.(r.|>x->"$x")].|>println

```

Attempt This Online!

Any number larger than 10^10 is a suitable upper limit for the range; using `2^34` saves a byte (this is reduces to `2^7` in the linked solution).
> 2 votes

# Answer
# Ruby, ~~29~~ 30 bytes

```
p (?0..?9*10).grep_v /(.).*\1/

```

Try it online!
> 2 votes

# Answer
# Ruby, 47 bytes

```
f=->a=[*?1..?9],s=""{a.map{|i|f[a-[i],p(s+i)]}}

```

Try it online!

Link is a demo with only the digits `1..3`

This recursively builds up the number from a pool of available digits. Longer than I had hoped for this approach, but efficient.
> 1 votes

# Answer
# Bash, 34

```
seq -f%.0f 1e10|grep -Ev '(.).*\1'

```

If you have the `jot` command installed, you can save 1 byte by replacing the seq command with `jot 9876543210`.

This is quite slow - I think its been running 2 hours already and is 40% through.

Try it online!
> 1 votes

# Answer
# Jelly, 7 bytes

```
ȷ10Q€ḌQ

```

Try it online!

A niladic link returning the full list of numbers. TIO link only returns values \<1e5 since otherwise it runs out of memory (and would time out if not)

Uses the same methodology as @KevinCruijssen’s 05AB1E answer so upvote that one too!
> 1 votes

---
Tags: code-golf, sequence, permutations
---


title: Magic OEIS formulae (Cops' thread)

text:
# Question
Title: Magic OEIS formulae (Cops' thread)
This is the cops' thread. See the robbers' thread here.

In this cops and robbers challenge, the cops will be tasked with writing an algorithm that computes some function of their choice, while the robbers will try to come up with their algorithm. The catch is, the 'algorithm' must be a *single* closed-form mathematical expression. Remarkably, a function that determines whether a number is prime has been shown to be possible using only Python operators.

## Cops

This is the cops' thread. To compete, first choose any *infinite* OEIS sequence (e.g. A000027). Then, write a single closed-form expression that takes an integer `n`, and provably computes the `n`th term of this sequence. You only need to handle `n` for which the sequence is defined.

In addition, pay attention to the offset of your chosen OEIS sequence. If the offset is `0`, the first term should be evaluated at `n=0`. If the offset is `1`, it should be evaluated at `n=1`.

The specification for the closed-form expression is as such:

* The expression must consist of the following arithmetic/bitwise operators: `**, %, *, /, +, -, <<, >>, &, ^, |` (note that `/` represents floor division). Unary negation `-`, bitwise negation `~`, and parentheses `()` are also allowed.
* The expression may also contain `n`, as well as any positive or negative integer literals. Only decimal (base 10) literals are permitted.
* To avoid ambiguity, the behavior of the expression will explicitly be defined as its result when evaluated as Python 2 code. Take extra note of how Python handles `/` and `%`, especially when used with negative numbers.
* `a**b` may result in a floating-point number, if `b` is negative. Your expression *must not* have this occur.

Once you have chosen an OEIS sequence with an accompanying expression, submit an answer containing the OEIS sequence, and the number of bytes in your expression. It is also recommended to include a brief description of the OEIS sequence itself. Don't reveal your actual expression, as this is what the robbers will try to crack!

The robbers will have one week to crack your submission by trying to figure out your expression. Their expression must be **at most twice** the length of your expression to be considered a crack. This is to ensure that the robber can't crack your submission with an overly long expression.

## Additional Information

* Optionally, you may choose to disallow a subset of the allowed operators. If you do so, mention the restricted set in the body of your submission. Both your expression and the robber's expression must then adhere to this restriction.
* Make sure to specify the offset if you use a different one than on the OEIS.
* If your solution has not been cracked and you find a shorter solution after posting, you may update your byte count accordingly.

## Scoring

If your submission is not cracked within one week of its initial post, you can mark it as *safe* and reveal your solution. After this point, it can no longer be cracked.

Your score is the length of your expression in bytes, with a lower score being better.

## Example Submission

> ### A000225, 6 bytes
>
> > a(n) = 2^n - 1. Sometimes called the Mersenne numbers.
>
> *Solution (keep this hidden until you are cracked or safe!)*:
>
> ```
> 2**n-1
>
> ```

# Answer
# A002193, 82 bytes

Cracked by @loopy walt. The brownie points are still open.

Offset: 1 (that is, \\$f(1) = 1, f(2) = 4, f(3)=1, ...\\$)

The decimal expansion of \\$\sqrt 2\\$.

Six brownie points if your solution can finish for \\$n = 1000\\$ before the end of the universe.

My solution:

> We can approximate \\$\sqrt{2}\\$ using the Pell numbers. To know how much accuracy we need, we need to bound \\$|\sqrt{2} - \frac{p}{10^n}|\\$. According to Carmichael's theorem, 1, 2 and 5 are the only Pell numbers which divide a power of ten, and if \\$\frac{a}{b}\\$ isn't a convergent of \\$x\\$ it's known that \\$|x - \frac{a}{b}| \> \frac{1}{2b^2}\\$, so in particular \\$|\sqrt{2} - \frac{p}{10^n}| \> \min(\frac{1}{2\cdot 10^{2n}}, |\sqrt{2} - \frac{7}{5}|)\\$, but it can be easily calculated that for any \\$n \geq 1\\$, \\$\frac{1}{2\cdot 10^{2n}} \< |\sqrt{2} - \frac{7}{5}|\\$, so \\$|\sqrt{2} - \frac{p}{10^n}| \> \frac{1}{2\cdot 10^{2n}}\\$. This means if we have an approximation with error of at most \\$\frac{1}{2 \cdot 10^{2n}}\\$ the n-th digit must be correct. We will show that \\$|\sqrt{2} - \frac{H\_{4n}}{P\_{4n}}| \leq \frac{1}{2 \cdot 10^{2n}}\\$ for \\$n \geq 1\\$. Since \\$\frac{H\_{4n}}{P\_{4n}}\\$ is a convergent to \\$\sqrt{2}\\$, it's known that \\$|\sqrt{2} - \frac{H\_{4n}}{P\_{4n}}| \leq \frac{1}{P\_{4n} P\_{4n+1}} \leq \frac{1}{P\_{4n}^2}\\$. It can be seen that \\$P\_n \geq \frac{(1+\sqrt{2})^n}3\\$, so \\$\frac{1}{P\_{4n}^2} \leq \frac{9}{(1+\sqrt{2})^{8n}} = \frac{9}{10^{\log\_{10}(1 + \sqrt2)8n}} \leq \frac{9}{10^{3 n}}\\$ and since \\$n \geq 1\\$, \\$\frac{9}{10^{3 n}} \leq \frac{1}{10^{2n}}\\$.
> Now we just need to calculate \\$H\_n\\$ and \\$P\_n\\$. We will use \\$(1 + x)^n \equiv H\_n + x P\_n \pmod {x^2 - 2}\\$. Since \\$H\_n, P\_n \< 3^n\\$, we can use \\$x = 3^n\\$, and \\$(1 + 3^n)^n \equiv H\_n + 3^n P\_n \pmod {9^n - 2}\\$. We actually need to calculate it for \\$4n\\$, so we use \\$(1+81^n)^{4n} \equiv H\_{4n} + 81^{n} P\_{4n} \pmod {6561^n - 2}\\$. Then we can calculate \\$\lfloor \frac{H\_{4n} 10^{n-1}}{P\_{4n}} \rfloor \mod 10 \\$. In code:
> `(1+81**n)**(4*n)%(6561**n-2)%81**n*10**~-n/((1+81**n)**(4*n)%(6561**n-2)/81**n)%10`
> 5 votes

# Answer
# A000796, 105 bytes

Offset: 1 (that is, \\$f(1) = 3, f(2) = 1, ...\\$)

The digits of \\$\pi\\$, in base 10.

Your formula must be provably correct, and can't relay on any unproven assumptions/conjectures. Note that if you approximate \\$\pi\\$, it is possible there are a bunch of \\$9\\$s in that position, and then the \\$n\\$th digit of the approximation could be wrong.

My solution:

> Is has been proven (by Kurt Mahler, I couldn't find the paper online) that for any integers \\$q \geq 2\\$ and \\$p\\$, \\$|\pi - \frac{p}{q}| \geq \frac{1}{q^{42}}\\$. In particular, if \\$\frac{a}{10^{n-1}} \< \pi \< \frac{a+1}{10^{n-1}}\\$, any value \\$r\\$ such that \\$|\pi - r| \leq \frac{1}{10^{42(n-1)+1}}\\$ will be entirely contained within that interval, and so its \\$n\\$-th digit will be correct. To approximate \\$\pi\\$, we can use the asymptotics for the centeral binomial coefficients: \\$\binom{2n}{n} \approx \frac{4^n}{\sqrt{\pi n}}\\$. We can use the nonasymptotic bounds \\$\frac{1}{\sqrt{\pi (n+1)}} \< \binom{2n}{n} 4^{-n} \< \frac{1}{\sqrt{\pi n}}\\$ to derive \\$\frac{16^n}{\binom{2n}{n}^2 (n+1)} \< \pi \< \frac{16^n}{\binom{2n}{n}^2 n}\\$, and it isn't hard to see that the error in any of these bounds is at most \\$\frac{16^n}{\binom{2n}{n}^2} (\frac{1}{n} - \frac{1}{n+1}) = \frac{16^n}{\binom{2n}{n}^2} \frac{1}{n(n+1)}\\$ but as stated earlier \\$\frac{16^n}{\binom{2n}{n}^2 (n+1)} \< \pi\\$ and thus the error is at most \\$\frac{\pi}{n} \< \frac{4}{n}\\$. If we set \\$n = 10^{42 m}\\$ there, where \\$m\\$ is the digit we're trying to calculate, we can see we get enough accuracy. In code:
> `16**10**(42*n)*10**~-n/(((1+4**10**(42*n))**(2*10**(42*n))/4**10**(84*n)%4**10**(42*n))**2*10**(42*n))%10`
> 3 votes

# Answer
# A000120, 50 bytes

Cracked by @Command Master

Offset: 1

Here's one to get started: the Hamming weight of `n`, the number of 1's in the binary representation of `n`. You don't need to handle `n=0`.
> 2 votes

# Answer
# A000005, 242 bytes

Cracked by @l4m2

Offset: 1

The number of divisors of \\$n\\$.
> 2 votes

# Answer
# A000045, 45 bytes

Cracked by xnor

Offset: 0

The Fibonacci numbers. `/` isn't allowed.
> 2 votes

# Answer
# A000244, 23 bytes

Cracked by loopy walt

Compute `3**n`, but `**` is banned. Offset 1, so `n>0`.
> 2 votes

# Answer
# A007953, 93 bytes

Cracked by @Command Master

The `n`th term is the sum of digits of `n` (e.g. `a(1234) = 1+2+3+4 = 10`).

A step up from counting bits. You do not need to handle `n=0`.
> 2 votes

# Answer
# A000012, 6 bytes, cracked in 8 minutes

Offset: Doesn't matter

Every term in the sequence is 1.

Of course, since this would be too trivial without this, **you can only use bit-shifts (which are `>>` and `<<`) and the digit `9`.**

## Intended solution

> Exactly what the cracker posted, `999>>9`.
> 1 votes

# Answer
# A160155, 125 bytes

Offset: 1 (that is, \\$f(1) = 1, f(2) = 1, f(3)=6, ...\\$)

The decimal expansion of the single real root of \\$x^5 - x-1\\$, \\$1.1673...\\$.

Using `&` or `|` is forbidden.
> 1 votes

---
Tags: sequence, code-challenge, restricted-source, cops-and-robbers
---


title: Recursive Steiner Chains

text:
# Question
Title: Recursive Steiner Chains
Steiner Chains are a set of N circles where each circle is tangent to 2 other non-intersecting circles as well as the the previous and next circles of the chain, as seen in the below images:

In this challenge, you will write a program/function that draws Steiner chains recursively, that is, circles of a given chain will be the base circles of another iteration of chains:

# Challenge

Write a program/function that accepts image dimensions and a list of integers denoting the level of circles in each successive iteration of chains, and output an image with the recursive Steiner chains drawn to it.

# Input

Your program/function will accept 2 arguments:

* `s` \- width and height of image
* `ls` \- list of positive integers denoting the number of circles present in each successive iteration of chains, ordered from the top-most chain to the bottom-most chain

# Output

Your program/function will output an image of dimension `s` x `s` displaying the recusive Steiner chain.

* The top level base circle will be as large as the image with a diameter of `s`, centered inside the image
* To make things easy, the 2 base circles of a Steiner chain will be concentric, that is, the centerpoints of the 2 baseline circles will be the same
* Given an outer radius, `R`, and the number of circles in a chain, `N`, the formula for the inner radius `R'` is `R' = (R-R*sin(pi/N))/(sin(pi/N)+1)`
* Circles of the chain as well as the inner base circle will be the outer base circles of the next iteration of chains
* While recursing through the chain circles, the order of the next chain should correspond to the next value in `ls`
* While recursing through the inner circle of a chain, the order should be the same as its parents order (example \[5,2\]):
*
* All chains should end recursion at a depth of the length of `ls`
* The rotation of the chains doesn't matter:
*
* However, the rotations of recursive chains relative to their parents centerpoint should be the same:
*
* All circles should be drawn with an outline or solid fill
* Color choice is left to the implementation, save for loopholes (for example, filling everything with the same color)

# Example Runs

In the following examples, color is determined by `(depth of the recursion)^4`.

You can find source here.

```
chain(600,[5,4,3])

```

```
chain(600,[11,1,1,1,1,1,1])

```

```
chain(600,[5,6,7,8,9])

```

# Answer
> 4 votes
# Javascript ES6, 379 bytes

This solution was used to generate the example runs in the question.

```
f=(s,ls)=>{with(V=document.createElement`canvas`)with(getContext`2d`)with(Math)return(width=height=s,translate(s/=2,s),(S=(o,d=0,n=ls[d],i=(o-o*sin(PI/n))/(sin(PI/n)+1),r=0)=>{fillStyle=`rgba(0,0,0,${pow(d/ls.length,4)})`;beginPath(),arc(0,0,o,-PI,PI),fill();if(d++<ls.length){S(i,d,n);for(;r<n;++r){save();translate(0,(o+i)/2);S((o-i)/2,d);restore();rotate((2*PI)/n);}}})(s),V)}

```

Ungolfed:

```
f=(s,ls)=>{                                        // define function that accepts image dimensions and a list of orders
 with(V=document.createElement`canvas`)            // create canvas to draw on, bring its functions into current scope chain
 with(getContext`2d`)                              // bring graphics functions into current scope chain
 with(Math)return(                                 // bring Math functions into current scope chain
  width=height=s,                                  // set width and height of image
  translate(s/=2,s),                               // center the transform on image
   (S=(o,d=0,                                      // define recursive function that accepts outer radius, depth, and optionally order
       n=ls[d],                                    // default chain order to corresponding order in input list
       i=(o-o*sin(PI/n))/(sin(PI/n)+1),            // calculate inner base circle radius
       r=0)=>{                                     // initialize for loop var
    fillStyle=`rgba(0,0,0,${pow(d/ls.length,4)})`; // fill based on depth
    beginPath(),arc(0,0,o,-PI,PI),fill();          // draw circle
    if(d++<ls.length){                             // if within recursion limit
     S(i,d,n);                                     //   recurse on inner circle
     for(;r<n;++r){                                //   loop through all circles of the chain
      save();                                      //   save transform
      translate(0,(o+i)/2);                        //   translate origin to middle of the 2 base circles
      S((o-i)/2,d);                                //   recurse on chain circle
      restore();                                   //   restore transform
      rotate((2*PI)/n);                            //   rotate transform to next circle in chain
   }}})(s),                                        // begin the recursion
 V)}                                               // return the canvas

```

Note: `f` returns a canvas.

Example run (assumes there's a `<body>` to append to):

```
document.body.appendChild(f(600,[13,7,11,5,3]))

```

Should dump the following image to the page:

# Answer
> 0 votes
@Dendrobium

I was trying to port @Dendrobium's Javascript answer in Python.

\\$\color{red}{\text{But the resolution of my fractal image is terrible.}}\\$

```
from PIL import Image, ImageDraw
import numpy as np
import matplotlib.pyplot as plt

def draw_fractal(s, ls):
    # Create a new image with a white background
    image = Image.new('RGBA', (s, s), color = (0, 0, 0, 0))
    draw = ImageDraw.Draw(image)

    # Begin the recursion
    draw_fractal_recursive(draw, s/2, s/2, s/2, 0, ls, s)

    # Display the image
    plt.imshow(np.array(image))
    plt.show()

def draw_fractal_recursive(draw, x, y, o, depth, ls, s):
    if depth >= len(ls):
        return

    # Chain order to corresponding order in input list
    n = ls[depth]

    # Calculate inner base circle radius
    i = (o-o*np.sin(np.pi/n))/(np.sin(np.pi/n)+1)

    # Fill based on depth
    rgba_color = (0, 0, 0, int(255 * np.power(depth/len(ls), 4)))

    # Draw circle
    draw.ellipse((x-o, y-o, x+o, y+o), fill=rgba_color)

    # Recurse on inner circle
    draw_fractal_recursive(draw, x, y, i, depth+1, ls, s)

    # Loop through all circles of the chain
    for r in range(n):
        # Translate origin to middle of the 2 base circles
        new_x = x + (o+i)/2 * np.cos(2 * np.pi * r / n)
        new_y = y + (o+i)/2 * np.sin(2 * np.pi * r / n)

        # Recurse on chain circle
        draw_fractal_recursive(draw, new_x, new_y, (o-i)/2, depth+1, ls, s)

# Call the function
draw_fractal(600,[13,7,11,5,3])

```

---
Tags: code-golf, graphical-output, fractal, recursion
---


title: Hello world!!! Fibonacci distribution

text:
# Question
Title: Hello world!!! Fibonacci distribution
1. Your program should output exactly: `Hello world!!!` with or without linefeed after.
2. Your program should take no input.
3. Sourcecode character distribution must be correct according to:
    * The number of **numeric characters** (0-9) must be exactly one fibonacci sequence number.
    * The number of **other non-numeric characters** !(0-9) in the sourcecode must be exactly the fibonacci sequence number before the above fibonacci sequence number.

Four examples of valid character distribution in sourcecode:

* 13 numeric, 8 non-numeric characters.
* 34 numeric, 21 non-numeric characters.
* 55 numeric, 34 non-numeric characters.
* 89 numeric, 55 non-numeric characters.

This is code-golf, shortest code in bytes wins! Good luck!

Edit: As this question has constraints on the sourcecode size in combination with being code-golf the accepted answer (if more than one share the equal winning character length) will be the answer with most votes (and least character-count): 2014-03-01.

# Answer
> 23 votes
## Windows Command Prompt - 34, 8, 5 chars, (2 below)

**These ones may or may not be breaking rule 2, but here it is anyway*

```
%~099

```

Name the file:

```
&start call echo Hello world!!!&exit -b .cmd

```

**Now lets corrupt the file-system a little - 2 chars (or less if you want)**

```
A1

```

Name the file (using your preferred unorthodox method):

```
"&start call echo Hello world!!!&exit&.cmd

```

*How does this work:*

Since cmd scripts are invoked with 'cmd.exe /C "%1" %\*' the executed command will be:

```
cmd.exe /C "c:\PATH_TO_THE_SCRIPT\"&start call echo Hello world!!!&exit&.cmd"

```

which will in the following order:

* Fail to execute "c:\PATH\_TO\_THE\_SCRIPT\\"
* Open a new shell printing Hello world!\n
* Exit the original shell

# Answer
> 21 votes
# MySQL, 34

```
x'48656C6C6F20776F726C642121'||'!'

```

This is a MySQL expression that evaluates to `Hello world!!!`, assuming the `sql_mode` setting includes `PIPES_AS_CONCAT`. It contains exactly 21 digits and 13 non-digits.

Whether this qualifies as a valid entry, I leave it to the jury.

**Example**

```
mysql> select x'48656C6C6F20776F726C642121'||'!';
+------------------------------------+
| x'48656C6C6F20776F726C642121'||'!' |
+------------------------------------+
| Hello world!!!                     |
+------------------------------------+
1 row in set (0.00 sec)

```

# Answer
> 16 votes
# C64 BASIC, 55

For fun and nostalgia!

# Answer
> 11 votes
### GolfScript, 55 characters

```
[72 101 108 108 111 32 119 111 114 108 100 33 {.}2*]''+

```

Didn't find a way to have a 34 characters solution, thus I created this one.

# Answer
> 10 votes
# Befunge 98 - 55

```
a"!!!dlrow olleH"ek,@1235813213455891442333776109871597

```

Decided to do it with a newline, since it doesn't cost anything. The numbers are the concatenated values of the Fibonacci sequence.

# Answer
> 8 votes
## Python 34-55

```
print "Hello world%s"%("!"*int(3.141592653589793238462643383279502884197169399375105820))

```

Yes. I waste them digits. What are you gonna do about it?

# Answer
> 7 votes
# Windows PowerShell (probably also Bash), 55

```
curl -L bit.ly/1b9q8ve?1=123581321345589144233377610987

```

You didn't say anything about network access, so here's a dirty solution. I've got a bit.ly URL with few enough letters on the second try. Unfortunately, It's still 21 non-digits, needing 34 digits to be used or wasted.

# Answer
> 7 votes
# C (89 characters)

```
main() {
int i[0000000000000004]={1819043144,1870078063,560229490,2566922529};
puts(i);
}

```

While the above is valid, unfortunately, my efforts to compact it with the following program doesn't meet the spec. I feel like it's worth looking at and maybe someone else can shorten it a bit though (64 characters, 37 numerals, 27 non-numerals). To compile it, you'll have to use clang and with `-fms-extensions`.

```
main(){puts((__int128[]){671944380693508453879479574226248i8});}

```

# Answer
> 6 votes
# sh, 55

```
echo Hello world!!! #1234567890123456789012345678901234

```

# Answer
> 6 votes
# Korn Shell, 21

```
echo $0
#123456789012

```

The script must be called "Hello world!!!" :)

# Answer
> 5 votes
## Python

```
print'092020090920200948656c6c6f20776f726c642121212009200909200920'.decode('hex').strip()

```

digits : 55 non digits: 34

# Answer
> 4 votes
# PHP (55 bytes)

This program uses binary (wow, it's the third time I reuse the same trick). 21 non-numeric characters, 34 numeric characters. No letters, because letters are boring.

## `xxd`

```
0000000: 3c3f 3d7e b79a 9393 90df 8890 8d93 9bde  <?=~............
0000010: dede f53b 2331 3233 3435 3637 3839 3031  ...;#12345678901
0000020: 3233 3435 3637 3839 3031 3233 3435 3637  2345678901234567
0000030: 3839 3031 3233 34                        8901234

```

# Answer
> 4 votes
# Mathematica 55

```
"Hello World!!!"(34+21!)/000000000051090942171709440034

```

Output

```
Hello World!!!

```

# Answer
> 4 votes
# Sclipting (34 characters)

```
丟0000000000긒괡뉆롲닷댠닶롬뉔밈0000000000併0反

```

Unfortunately Sclipting doesn’t use any ASCII characters at all, so I have to pad the program with 21 useless number characters :(

# Answer
> 4 votes
# Bash, 2 chars

Very well, in the unlikely case Robert's answer is not disqualified, here's mine:

```
$0

```

Name the file `echo Hello world!!!` and execute with `sh`.

# Answer
> 3 votes
# Vyxal , 8+13=21 bytes

```
kh6⁽NV33C3ẋ#123456789

```

kh6⁽NV = Hello world

33C = ASCII 33 to !

3ẋ = repeat top of stack three times

(Note that 33C3ẋ is one non numeric less than literal !!! would be)

Try it Online!

# Answer
> 2 votes
## Forth or Ruby, 55

(34 numeric + 21 non-numeric)

## Forth

```
." Hello world!!!" \ 3141592653589793238462643383279502

```

## Ruby

```
puts"Hello world!!!"#3141592653589793238462643383279502

```

Using comments to pad feels dirty, but those are valid answers.

# Answer
> 2 votes
# J (55 characters)

(34 numeric + 21 non-numeric)

```
(72 101 108 108 111 32 119 111 114 108 100{a.), 3#33{a.

```

# Answer
> 1 votes
# APL, 55 bytes

```
14↑'Hello world!!!!!!!11111111111111111111111111111111'

```

# Answer
> 0 votes
# C#, 233 Bytes

233 Characters
144 Numeric
89 Non-Numeric Characters

```
/*I suck at CodeGolf!!!*/new List<int>{0072,00101,000108,000108,000111,0000032,00000119,00000111,0000000000114,0000000000108,00000000000000100,00000000000000033,00000000000000033,00000000000000033}.ForEach(c=>Console.Write((char)c));

```

Outputs:

```
Hello world!!!

```

# Answer
> 0 votes
# Japt, 55 bytes

```
"aaaaaaa1234567890123456789012345678901234"`HÁM WŽld!!!

```

Try it online!

It is basically a simple hello world with some rubbish at the beginning that is ignored but makes the code satisfy the conditions.

# Answer
> 0 votes
# Pxem, Numeric: 34 bytes + Non-numeric: 21 bytes = 55 bytes.

* Filename: `Hello world!!!.pxxxxx1234567890123456789012345678901234`
* Content: empty

The boring answer. The stupid latter part is nothing but a garbage.

Try it online!

# Answer
> 0 votes
# Python 3.11, 34+21=55 bytes

Boring answer, uses comments to store extra junk.

```
print("Hello world!!!")#abcdef12345678901234567890123456

```

# Answer
> -1 votes
## Windows Batch

```
echo Hello World!!!::0123456789012345678901234567890123

```

---
Tags: code-golf, string, restricted-source, hello-world, fibonacci
---


# Question
Title: I reverse the source code, you reverse the input!
*Yet another blatant rip-off of a rip-off of a rip-off. Go upvote those!*

Your task, if you wish to accept it, is to write a program/function that outputs/returns its string input/argument. The tricky part is that if I reverse your source code, the output must be reversed too.

For simplicity, you can assume that the input is always a single line string containing only ASCII letters (a-z), digits (0-9) and spaces.

Should support an input of at least 8 characters long (longer than 8 is not necessary).

Behaviour for empty input is undefined.

## Examples

Let's say your source code is `ABC` and its input is `xyz`. If I write `CBA` instead and run it, the output must be `zyx`.

Let's say your source code is `ABC` and its input is `96`. If I write `CBA` instead and run it, the output must be `69`.

A single leading or trailing white-space is acceptable as long as it is consistent in both normal and reversed outputs.

# Answer
# JavaScript, 32 bytes

```
s=>s//``nioj.)(esrever.]s...[>=s

```

Reversed:

```
s=>[...s].reverse().join``//s>=s

```
> 23 votes

# Answer
# APL (Dyalog Unicode), ~~3~~ 2 bytesSBCS

-1 byte thanks to dzaima

```
⌽⊂

```

Try it online!

enclose the argument to treat it as a singleton: `[1,2,3]``[[1,2,3]]`

reverse (has no effect on singletons): `[[1,2,3]]``[[1,2,3]]`

An enclosed array prints with a leading an a trailing space.

!enilno ti yrT

reverse (has no effect on singletons): `[1,2,3]``[3,2,1]`

enclose: `[3,2,1]``[[3,2,1]]`

An enclosed array prints with a leading an a trailing space.
> 17 votes

# Answer
# Bash, 9 bytes

```
cat # ver

```

Reversed:

```
rev # tac

```

Try it online! !enilno ti yrT
> 17 votes

# Answer
# Keg, ~~3~~ 2 bytes

```
#?

```

Try it online! or !enilno ti yrT

## Explained

```
#? #Implicit cat
?# Reversed input

```

Heh. That's right. Keg can stand up to those 2-byte answers too (and using pure, plain ASCII)!

## Old Program

```
^#?

```

Try it online! Or !enilno ti yrT

Because two can play the 3-byte game. That's why. (did I mention that's 3 bytes of *~~utf8~~ ASCII*?)

```
^#? #Reverse an empty stack, taking implicit input

?#^ #take input

```
> 11 votes

# Answer
# Ruby, 21 bytes

```
->x{x}#}esrever.x{x>-

```

Try it online!

```
->x{x.reverse}#}x{x>-

```

!enilno ti yrT
> 9 votes

# Answer
## Stack Cats `-m`, 4 bytes

```
|>I|

```

Try it online!

Try it reversed!

This works for any inputs that don't contain null bytes.

### Explanation

Wow, I've reached the point where I'm writing these by hand...

The full program is `|>I|I<|`.

```
|   Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
>   Move one stack over to the right (which only contains zeros).
I   Does nothing on zero.
|   Does nothing on zero.
I   Does nothing on zero.
<   Move back to the initial stack.
|   Reverse the input once more.

```

As in the solution to the previous challenge, since the centre command `|` does nothing, so does the entire program.

The reversed program is then `|I>|<I|`.

```
|   Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
I   Move the -1 one stack to the left and turn it into a +1.
>   Move back to the initial stack.
|   Reverse it again, but this time without the EOF marker.
<   Move back to the left.
I   Move the +1 back onto the initial stack and turn it into a -1 again.
|   Reverse the entire stack. We now have the -1 as an EOF marker again at the bottom
    and the rest of the stack has been reversed three times, i.e. one net reversal.

```

Interestingly, if we use this reversing program without `-m` we still get a working solution this time, so the only additional bytes incurred by omitting `-m` are those we get from mirroring the code.

---

## Stack Cats, 7 bytes

```
|I<|>I|

```

Try it online!

Try it reversed!

### Explanation

The reversed version of this program is `|I>|<I|`, the same as above so we can ignore that. But the non-reversed version differs. Since the `<>` now point the other way, the centre command ends up doing nothing, so the program becomes a cat:

```
|   Reverse the entire stack down to the EOF marker -1 (since there are no zeros in the input).
I   Move the -1 one stack to the left and turn it into a +1.
<   Move another stack to the left, which contains only zeros.
|   Does nothing on zero.

```

And thus, `>I|` exactly undo the first half of the program.
> 8 votes

# Answer
# Haskell, 11 bytes

```
id--esrever

```

Try it online! Try it reversed!
> 7 votes

# Answer
# Pyth, 5 3 bytes

`z_k`

-2 bytes by realizing the newline flips around anyways

Explanation:

```
z   # Implicitly print the input
 _k # Implicitly print the reversed empty string

```

Reversed Explanation:

```
k     # Implicitly print the empty string
 _z   # Implicitly print the reversed input

```
> 7 votes

# Answer
# Turing Machine Language, ~~14324~~ ~~14321~~ 13257 bytes

```
0 ( ( l 6;
0 * * l 2;
1 _ _ l 2;
2 _ ( r 3;
3 _ _ r 4;
4 _ _ l 3);
4 * * r 2;
3) _ ) l 5;
3 * * r 3;
5 ( ( * 0;
5 * * l 5;
6 _ _ l 7;
7 _ ] r 8;
8 ) ) l 9;
8 * * r 8;
9 0 @ l c0;
9 1 @ l c1;
9 2 @ l c2;
9 3 @ l c3;
9 4 @ l c4;
9 5 @ l c5;
9 6 @ l c6;
9 7 @ l c7;
9 8 @ l c8;
9 9 @ l c9;
9 a @ l a;
9 A @ l A;
9 b @ l b;
9 B @ l B;
9 c @ l c;
9 C @ l C;
9 d @ l d;
9 D @ l D;
9 e @ l e;
9 E @ l E;
9 f @ l f;
9 F @ l F;
9 g @ l g;
9 G @ l G;
9 h @ l h;
9 H @ l H;
9 i @ l i;
9 I @ l I;
9 j @ l j;
9 J @ l J;
9 k @ l k;
9 K @ l K;
9 l @ l l;
9 L @ l L;
9 m @ l m;
9 M @ l M;
9 n @ l n;
9 N @ l N;
9 o @ l o;
9 O @ l O;
9 p @ l p;
9 P @ l P;
9 q @ l q;
9 Q @ l Q;
9 r @ l r;
9 R @ l R;
9 s @ l s;
9 S @ l S;
9 t @ l t;
9 T @ l T;
9 u @ l u;
9 U @ l U;
9 v @ l v;
9 V @ l V;
9 w @ l w;
9 W @ l W;
9 x @ l x;
9 X @ l X;
9 y @ l y;
9 Y @ l Y;
9 z @ l z;
9 Z @ l Z;
c0 ] ] l c0a;
c0 * * l c0;
c0a _ 0 r @0;
c0a * * l c0a;
@0 @ 0 l nC;
@0 * * r @0;
c1 ] ] l c1a;
c1 * * l c1;
c1a _ 1 r @1;
c1a * * l c1a;
@1 @ 1 l nC;
@1 * * r @1;
c2 ] ] l c2a;
c2 * * l c2;
c2a _ 2 r @2;
c2a * * l c2a;
@2 @ 2 l nC;
@2 * * r @2;
c3 ] ] l c3a;
c3 * * l c3;
c3a _ 3 r @3;
c3a * * l c3a;
@3 @ 3 l nC;
@3 * * r @3;
c4 ] ] l c4a;
c4 * * l c4;
c4a _ 4 r @4;
c4a * * l c4a;
@4 @ 4 l nC;
@4 * * r @4;
c5 ] ] l c5a;
c5 * * l c5;
c5a _ 5 r @5;
c5a * * l c5a;
@5 @ 5 l nC;
@5 * * r @5;
c6 ] ] l c6a;
c6 * * l c6;
c6a _ 6 r @6;
c6a * * l c6a;
@6 @ 6 l nC;
@6 * * r @6;
c7 ] ] l c7a;
c7 * * l c7;
c7a _ 7 r @7;
c7a * * l c7a;
@7 @ 7 l nC;
@7 * * r @7;
c8 ] ] l c8a;
c8 * * l c8;
c8a _ 8 r @8;
c8a * * l c8a;
@8 @ 8 l nC;
@8 * * r @8;
c9 ] ] l c9a;
c9 * * l c9;
c9a _ 9 r @9;
c9a * * l c9a;
@9 @ 9 l nC;
@9 * * r @9;
a ] ] l aa;
a * * l a;
aa _ a r @a;
aa * * l aa;
@a @ a l nC;
@a * * r @a;
A ] ] l Aa;
A * * l A;
Aa _ A r @A;
Aa * * l Aa;
@A @ A l nC;
@A * * r @A;
b ] ] l ba;
b * * l b;
ba _ b r @b;
ba * * l ba;
@b @ b l nC;
@b * * r @b;
B ] ] l Ba;
B * * l B;
Ba _ B r @B;
Ba * * l Ba;
@B @ B l nC;
@B * * r @B;
c ] ] l ca;
c * * l c;
ca _ c r @c;
ca * * l ca;
@c @ c l nC;
@c * * r @c;
C ] ] l Ca;
C * * l C;
Ca _ C r @C;
Ca * * l Ca;
@C @ C l nC;
@C * * r @C;
d ] ] l da;
d * * l d;
da _ d r @d;
da * * l da;
@d @ d l nC;
@d * * r @d;
D ] ] l Da;
D * * l D;
Da _ D r @D;
Da * * l Da;
@D @ D l nC;
@D * * r @D;
e ] ] l ea;
e * * l e;
ea _ e r @e;
ea * * l ea;
@e @ e l nC;
@e * * r @e;
E ] ] l Ea;
E * * l E;
Ea _ E r @E;
Ea * * l Ea;
@E @ E l nC;
@E * * r @E;
f ] ] l fa;
f * * l f;
fa _ f r @f;
fa * * l fa;
@f @ f l nC;
@f * * r @f;
F ] ] l Fa;
F * * l F;
Fa _ F r @F;
Fa * * l Fa;
@F @ F l nC;
@F * * r @F;
g ] ] l ga;
g * * l g;
ga _ g r @g;
ga * * l ga;
@g @ g l nC;
@g * * r @g;
G ] ] l Ga;
G * * l G;
Ga _ G r @G;
Ga * * l Ga;
@G @ G l nC;
@G * * r @G;
h ] ] l ha;
h * * l h;
ha _ h r @h;
ha * * l ha;
@h @ h l nC;
@h * * r @h;
H ] ] l Ha;
H * * l H;
Ha _ H r @H;
Ha * * l Ha;
@H @ H l nC;
@H * * r @H;
i ] ] l ia;
i * * l i;
ia _ i r @i;
ia * * l ia;
@i @ i l nC;
@i * * r @i;
I ] ] l Ia;
I * * l I;
Ia _ I r @I;
Ia * * l Ia;
@I @ I l nC;
@I * * r @I;
j ] ] l ja;
j * * l j;
ja _ j r @j;
ja * * l ja;
@j @ j l nC;
@j * * r @j;
J ] ] l Ja;
J * * l J;
Ja _ J r @J;
Ja * * l Ja;
@J @ J l nC;
@J * * r @J;
k ] ] l ka;
k * * l k;
ka _ k r @k;
ka * * l ka;
@k @ k l nC;
@k * * r @k;
K ] ] l Ka;
K * * l K;
Ka _ K r @K;
Ka * * l Ka;
@K @ K l nC;
@K * * r @K;
l ] ] l la;
l * * l l;
la _ l r @l;
la * * l la;
@l @ l l nC;
@l * * r @l;
L ] ] l La;
L * * l L;
La _ L r @L;
La * * l La;
@L @ L l nC;
@L * * r @L;
m ] ] l ma;
m * * l m;
ma _ m r @m;
ma * * l ma;
@m @ m l nC;
@m * * r @m;
M ] ] l Ma;
M * * l M;
Ma _ M r @M;
Ma * * l Ma;
@M @ M l nC;
@M * * r @M;
n ] ] l na;
n * * l n;
na _ n r @n;
na * * l na;
@n @ n l nC;
@n * * r @n;
N ] ] l Na;
N * * l N;
Na _ N r @N;
Na * * l Na;
@N @ N l nC;
@N * * r @N;
o ] ] l oa;
o * * l o;
oa _ o r @o;
oa * * l oa;
@o @ o l nC;
@o * * r @o;
O ] ] l Oa;
O * * l O;
Oa _ O r @O;
Oa * * l Oa;
@O @ O l nC;
@O * * r @O;
p ] ] l pa;
p * * l p;
pa _ p r @p;
pa * * l pa;
@p @ p l nC;
@p * * r @p;
P ] ] l Pa;
P * * l P;
Pa _ P r @P;
Pa * * l Pa;
@P @ P l nC;
@P * * r @P;
q ] ] l qa;
q * * l q;
qa _ q r @q;
qa * * l qa;
@q @ q l nC;
@q * * r @q;
Q ] ] l Qa;
Q * * l Q;
Qa _ Q r @Q;
Qa * * l Qa;
@Q @ Q l nC;
@Q * * r @Q;
r ] ] l ra;
r * * l r;
ra _ r r @r;
ra * * l ra;
@r @ r l nC;
@r * * r @r;
R ] ] l Ra;
R * * l R;
Ra _ R r @R;
Ra * * l Ra;
@R @ R l nC;
@R * * r @R;
s ] ] l sa;
s * * l s;
sa _ s r @s;
sa * * l sa;
@s @ s l nC;
@s * * r @s;
S ] ] l Sa;
S * * l S;
Sa _ S r @S;
Sa * * l Sa;
@S @ S l nC;
@S * * r @S;
t ] ] l ta;
t * * l t;
ta _ t r @t;
ta * * l ta;
@t @ t l nC;
@t * * r @t;
T ] ] l Ta;
T * * l T;
Ta _ T r @T;
Ta * * l Ta;
@T @ T l nC;
@T * * r @T;
u ] ] l ua;
u * * l u;
ua _ u r @u;
ua * * l ua;
@u @ u l nC;
@u * * r @u;
U ] ] l Ua;
U * * l U;
Ua _ U r @U;
Ua * * l Ua;
@U @ U l nC;
@U * * r @U;
v ] ] l va;
v * * l v;
va _ v r @v;
va * * l va;
@v @ v l nC;
@v * * r @v;
V ] ] l Va;
V * * l V;
Va _ V r @V;
Va * * l Va;
@V @ V l nC;
@V * * r @V;
w ] ] l wa;
w * * l w;
wa _ w r @w;
wa * * l wa;
@w @ w l nC;
@w * * r @w;
W ] ] l Wa;
W * * l W;
Wa _ W r @W;
Wa * * l Wa;
@W @ W l nC;
@W * * r @W;
x ] ] l xa;
x * * l x;
xa _ x r @x;
xa * * l xa;
@x @ x l nC;
@x * * r @x;
X ] ] l Xa;
X * * l X;
Xa _ X r @X;
Xa * * l Xa;
@X @ X l nC;
@X * * r @X;
y ] ] l ya;
y * * l y;
ya _ y r @y;
ya * * l ya;
@y @ y l nC;
@y * * r @y;
Y ] ] l Ya;
Y * * l Y;
Ya _ Y r @Y;
Ya * * l Ya;
@Y @ Y l nC;
@Y * * r @Y;
z ] ] l za;
z * * l z;
za _ z r @z;
za * * l za;
@z @ z l nC;
@z * * r @z;
Z ] ] l Za;
Z * * l Z;
Za _ Z r @Z;
Za * * l Za;
@Z @ Z l nC;
@Z * * r @Z;
Sp ] ] l Sp1;
Sp * * l Sp;
Sp1 _ ~ r @Sp;
Sp1 * * l Sp1;
@Sp @ _ l nC;
@Sp * * r @Sp;
nC _ @ l Sp;
nC 0 0 * 9;
nC 1 1 * 9;
nC 2 2 * 9;
nC 3 3 * 9;
nC 4 4 * 9;
nC 5 5 * 9;
nC 6 6 * 9;
nC 7 7 * 9;
nC 8 8 * 9;
nC 9 9 * 9;
nC - - * 9;
nC a a * 9;
nC A A * 9;
nC b b * 9;
nC B B * 9;
nC c c * 9;
nC C C * 9;
nC d d * 9;
nC D D * 9;
nC e e * 9;
nC E E * 9;
nC f f * 9;
nC F F * 9;
nC g g * 9;
nC G G * 9;
nC h h * 9;
nC H H * 9;
nC i i * 9;
nC I I * 9;
nC j j * 9;
nC J J * 9;
nC k k * 9;
nC K K * 9;
nC l l * 9;
nC L L * 9;
nC m m * 9;
nC M M * 9;
nC n n * 9;
nC N N * 9;
nC o o * 9;
nC O O * 9;
nC p p * 9;
nC P P * 9;
nC q q * 9;
nC Q Q * 9;
nC r r * 9;
nC R R * 9;
nC s s * 9;
nC S S * 9;
nC t t * 9;
nC T T * 9;
nC u u * 9;
nC U U * 9;
nC v v * 9;
nC V V * 9;
nC w w * 9;
nC W W * 9;
nC x x * 9;
nC X X * 9;
nC y y * 9;
nC Y Y * 9;
nC z z * 9;
nC Z Z * 9;
nC ( ( * fC;
fC ] ] l fC1;
fC * * l fC;
fC1 _ [ * cl;
fC1 * * l fC1;
cl [ _ r cl;
cl ] _ r cl;
cl ~ _ r cl;
cl ( _ r clO;
clO ) _ * halt-accept;
clO * _ r clO;
cl ) ) * halt-accept;
cl * * r cl;
;lc r * * lc
;tpecca-tlah * ) ) lc
;Olc r _ * Olc
;tpecca-tlah * _ ) Olc
;Olc r _ ( lc
;lc r _ ~ lc
;lc r _ ] lc
;lc r _ [ lc
;1Cf l * * 1Cf
;lc * [ _ 1Cf
;Cf l * * Cf
;1Cf l ] ] Cf
;Cf * ) ) Cn
;9 * Z Z Cn
;9 * z z Cn
;9 * Y Y Cn
;9 * y y Cn
;9 * X X Cn
;9 * x x Cn
;9 * W W Cn
;9 * w w Cn
;9 * V V Cn
;9 * v v Cn
;9 * U U Cn
;9 * u u Cn
;9 * T T Cn
;9 * t t Cn
;9 * S S Cn
;9 * s s Cn
;9 * R R Cn
;9 * r r Cn
;9 * Q Q Cn
;9 * q q Cn
;9 * P P Cn
;9 * p p Cn
;9 * O O Cn
;9 * o o Cn
;9 * N N Cn
;9 * n n Cn
;9 * M M Cn
;9 * m m Cn
;9 * L L Cn
;9 * l l Cn
;9 * K K Cn
;9 * k k Cn
;9 * J J Cn
;9 * j j Cn
;9 * I I Cn
;9 * i i Cn
;9 * H H Cn
;9 * h h Cn
;9 * G G Cn
;9 * g g Cn
;9 * F F Cn
;9 * f f Cn
;9 * E E Cn
;9 * e e Cn
;9 * D D Cn
;9 * d d Cn
;9 * C C Cn
;9 * c c Cn
;9 * B B Cn
;9 * b b Cn
;9 * A A Cn
;9 * a a Cn
;9 * - - Cn
;9 * 9 9 Cn
;9 * 8 8 Cn
;9 * 7 7 Cn
;9 * 6 6 Cn
;9 * 5 5 Cn
;9 * 4 4 Cn
;9 * 3 3 Cn
;9 * 2 2 Cn
;9 * 1 1 Cn
;9 * 0 0 Cn
;pS l @ _ Cn
;pS@ r * * pS@
;Cn r _ @ pS@
;1pS l * * 1pS
;pS@ r ~ _ 1pS
;pS l * * pS
;1pS l ] ] pS
;Z@ r * * Z@
;Cn r Z @ Z@
;aZ l * * aZ
;Z@ r Z _ aZ
;Z l * * Z
;aZ l ] ] Z
;z@ r * * z@
;Cn r z @ z@
;az l * * az
;z@ r z _ az
;z l * * z
;az l ] ] z
;Y@ r * * Y@
;Cn r Y @ Y@
;aY l * * aY
;Y@ r Y _ aY
;Y l * * Y
;aY l ] ] Y
;y@ r * * y@
;Cn r y @ y@
;ay l * * ay
;y@ r y _ ay
;y l * * y
;ay l ] ] y
;X@ r * * X@
;Cn r X @ X@
;aX l * * aX
;X@ r X _ aX
;X l * * X
;aX l ] ] X
;x@ r * * x@
;Cn r x @ x@
;ax l * * ax
;x@ r x _ ax
;x l * * x
;ax l ] ] x
;W@ r * * W@
;Cn r W @ W@
;aW l * * aW
;W@ r W _ aW
;W l * * W
;aW l ] ] W
;w@ r * * w@
;Cn r w @ w@
;aw l * * aw
;w@ r w _ aw
;w l * * w
;aw l ] ] w
;V@ r * * V@
;Cn r V @ V@
;aV l * * aV
;V@ r V _ aV
;V l * * V
;aV l ] ] V
;v@ r * * v@
;Cn r v @ v@
;av l * * av
;v@ r v _ av
;v l * * v
;av l ] ] v
;U@ r * * U@
;Cn r U @ U@
;aU l * * aU
;U@ r U _ aU
;U l * * U
;aU l ] ] U
;u@ r * * u@
;Cn r u @ u@
;au l * * au
;u@ r u _ au
;u l * * u
;au l ] ] u
;T@ r * * T@
;Cn r T @ T@
;aT l * * aT
;T@ r T _ aT
;T l * * T
;aT l ] ] T
;t@ r * * t@
;Cn r t @ t@
;at l * * at
;t@ r t _ at
;t l * * t
;at l ] ] t
;S@ r * * S@
;Cn r S @ S@
;aS l * * aS
;S@ r S _ aS
;S l * * S
;aS l ] ] S
;s@ r * * s@
;Cn r s @ s@
;as l * * as
;s@ r s _ as
;s l * * s
;as l ] ] s
;R@ r * * R@
;Cn r R @ R@
;aR l * * aR
;R@ r R _ aR
;R l * * R
;aR l ] ] R
;r@ r * * r@
;Cn r r @ r@
;ar l * * ar
;r@ r r _ ar
;r l * * r
;ar l ] ] r
;Q@ r * * Q@
;Cn r Q @ Q@
;aQ l * * aQ
;Q@ r Q _ aQ
;Q l * * Q
;aQ l ] ] Q
;q@ r * * q@
;Cn r q @ q@
;aq l * * aq
;q@ r q _ aq
;q l * * q
;aq l ] ] q
;P@ r * * P@
;Cn r P @ P@
;aP l * * aP
;P@ r P _ aP
;P l * * P
;aP l ] ] P
;p@ r * * p@
;Cn r p @ p@
;ap l * * ap
;p@ r p _ ap
;p l * * p
;ap l ] ] p
;O@ r * * O@
;Cn r O @ O@
;aO l * * aO
;O@ r O _ aO
;O l * * O
;aO l ] ] O
;o@ r * * o@
;Cn r o @ o@
;ao l * * ao
;o@ r o _ ao
;o l * * o
;ao l ] ] o
;N@ r * * N@
;Cn r N @ N@
;aN l * * aN
;N@ r N _ aN
;N l * * N
;aN l ] ] N
;n@ r * * n@
;Cn r n @ n@
;an l * * an
;n@ r n _ an
;n l * * n
;an l ] ] n
;M@ r * * M@
;Cn r M @ M@
;aM l * * aM
;M@ r M _ aM
;M l * * M
;aM l ] ] M
;m@ r * * m@
;Cn r m @ m@
;am l * * am
;m@ r m _ am
;m l * * m
;am l ] ] m
;L@ r * * L@
;Cn r L @ L@
;aL l * * aL
;L@ r L _ aL
;L l * * L
;aL l ] ] L
;l@ r * * l@
;Cn r l @ l@
;al l * * al
;l@ r l _ al
;l l * * l
;al l ] ] l
;K@ r * * K@
;Cn r K @ K@
;aK l * * aK
;K@ r K _ aK
;K l * * K
;aK l ] ] K
;k@ r * * k@
;Cn r k @ k@
;ak l * * ak
;k@ r k _ ak
;k l * * k
;ak l ] ] k
;J@ r * * J@
;Cn r J @ J@
;aJ l * * aJ
;J@ r J _ aJ
;J l * * J
;aJ l ] ] J
;j@ r * * j@
;Cn r j @ j@
;aj l * * aj
;j@ r j _ aj
;j l * * j
;aj l ] ] j
;I@ r * * I@
;Cn r I @ I@
;aI l * * aI
;I@ r I _ aI
;I l * * I
;aI l ] ] I
;i@ r * * i@
;Cn r i @ i@
;ai l * * ai
;i@ r i _ ai
;i l * * i
;ai l ] ] i
;H@ r * * H@
;Cn r H @ H@
;aH l * * aH
;H@ r H _ aH
;H l * * H
;aH l ] ] H
;h@ r * * h@
;Cn r h @ h@
;ah l * * ah
;h@ r h _ ah
;h l * * h
;ah l ] ] h
;G@ r * * G@
;Cn r G @ G@
;aG l * * aG
;G@ r G _ aG
;G l * * G
;aG l ] ] G
;g@ r * * g@
;Cn r g @ g@
;ag l * * ag
;g@ r g _ ag
;g l * * g
;ag l ] ] g
;F@ r * * F@
;Cn r F @ F@
;aF l * * aF
;F@ r F _ aF
;F l * * F
;aF l ] ] F
;f@ r * * f@
;Cn r f @ f@
;af l * * af
;f@ r f _ af
;f l * * f
;af l ] ] f
;E@ r * * E@
;Cn r E @ E@
;aE l * * aE
;E@ r E _ aE
;E l * * E
;aE l ] ] E
;e@ r * * e@
;Cn r e @ e@
;ae l * * ae
;e@ r e _ ae
;e l * * e
;ae l ] ] e
;D@ r * * D@
;Cn r D @ D@
;aD l * * aD
;D@ r D _ aD
;D l * * D
;aD l ] ] D
;d@ r * * d@
;Cn r d @ d@
;ad l * * ad
;d@ r d _ ad
;d l * * d
;ad l ] ] d
;C@ r * * C@
;Cn r C @ C@
;aC l * * aC
;C@ r C _ aC
;C l * * C
;aC l ] ] C
;c@ r * * c@
;Cn r c @ c@
;ac l * * ac
;c@ r c _ ac
;c l * * c
;ac l ] ] c
;B@ r * * B@
;Cn r B @ B@
;aB l * * aB
;B@ r B _ aB
;B l * * B
;aB l ] ] B
;b@ r * * b@
;Cn r b @ b@
;ab l * * ab
;b@ r b _ ab
;b l * * b
;ab l ] ] b
;A@ r * * A@
;Cn r A @ A@
;aA l * * aA
;A@ r A _ aA
;A l * * A
;aA l ] ] A
;a@ r * * a@
;Cn r a @ a@
;aa l * * aa
;a@ r a _ aa
;a l * * a
;aa l ] ] a
;9@ r * * 9@
;Cn r 9 @ 9@
;a9c l * * a9c
;9@ r 9 _ a9c
;9c l * * 9c
;a9c l ] ] 9c
;8@ r * * 8@
;Cn r 8 @ 8@
;a8c l * * a8c
;8@ r 8 _ a8c
;8c l * * 8c
;a8c l ] ] 8c
;7@ r * * 7@
;Cn r 7 @ 7@
;a7c l * * a7c
;7@ r 7 _ a7c
;7c l * * 7c
;a7c l ] ] 7c
;6@ r * * 6@
;Cn r 6 @ 6@
;a6c l * * a6c
;6@ r 6 _ a6c
;6c l * * 6c
;a6c l ] ] 6c
;5@ r * * 5@
;Cn r 5 @ 5@
;a5c l * * a5c
;5@ r 5 _ a5c
;5c l * * 5c
;a5c l ] ] 5c
;4@ r * * 4@
;Cn r 4 @ 4@
;a4c l * * a4c
;4@ r 4 _ a4c
;4c l * * 4c
;a4c l ] ] 4c
;3@ r * * 3@
;Cn r 3 @ 3@
;a3c l * * a3c
;3@ r 3 _ a3c
;3c l * * 3c
;a3c l ] ] 3c
;2@ r * * 2@
;Cn r 2 @ 2@
;a2c l * * a2c
;2@ r 2 _ a2c
;2c l * * 2c
;a2c l ] ] 2c
;1@ r * * 1@
;Cn r 1 @ 1@
;a1c l * * a1c
;1@ r 1 _ a1c
;1c l * * 1c
;a1c l ] ] 1c
;0@ r * * 0@
;Cn r 0 @ 0@
;a0c l * * a0c
;0@ r 0 _ a0c
;0c l * * 0c
;a0c l ] ] 0c
;Z l @ Z 9
;z l @ z 9
;Y l @ Y 9
;y l @ y 9
;X l @ X 9
;x l @ x 9
;W l @ W 9
;w l @ w 9
;V l @ V 9
;v l @ v 9
;U l @ U 9
;u l @ u 9
;T l @ T 9
;t l @ t 9
;S l @ S 9
;s l @ s 9
;R l @ R 9
;r l @ r 9
;Q l @ Q 9
;q l @ q 9
;P l @ P 9
;p l @ p 9
;O l @ O 9
;o l @ o 9
;N l @ N 9
;n l @ n 9
;M l @ M 9
;m l @ m 9
;L l @ L 9
;l l @ l 9
;K l @ K 9
;k l @ k 9
;J l @ J 9
;j l @ j 9
;I l @ I 9
;i l @ i 9
;H l @ H 9
;h l @ h 9
;G l @ G 9
;g l @ g 9
;F l @ F 9
;f l @ f 9
;E l @ E 9
;e l @ e 9
;D l @ D 9
;d l @ d 9
;C l @ C 9
;c l @ c 9
;B l @ B 9
;b l @ b 9
;A l @ A 9
;a l @ a 9
;9c l @ 9 9
;8c l @ 8 9
;7c l @ 7 9
;6c l @ 6 9
;5c l @ 5 9
;4c l @ 4 9
;3c l @ 3 9
;2c l @ 2 9
;1c l @ 1 9
;0c l @ 0 9
;8 r * * 8
;9 r ( ( 8
;8 r ] _ 7
;7 l _ _ 6
;5 l * * 5
;0 * ( ( 5
;3 r * * 3
;5 l ) _ )3
;3 r * * 4
;)3 l _ _ 4
;4 r _ _ 3
;3 r ( _ 2
;2 l _ _ 1
;2 l * * 0
;6 l ( ( 0

```

Try it online!

Try it reversed!

I used this site to reverse it.
> 6 votes

# Answer
# 05AB1E, 2 bytes

```
RI

```

Try it online or try it online reversed.

**Explanation:**

```
R   # Reverse the (implicit) input
 I  # Push the input
    # (output the top of the stack implicitly as result)

I   # Push the input
 R  # Reverse it
    # (output the top of the stack implicitly as result)

```
> 5 votes

# Answer
# , 7 bytes

```
,&.|:@]

```

Reversed:

```
]@:|.&,

```

Try it online!

Jonah's comment on Adam's APL answer made me take the challenge. It was pretty hard indeed, because the inflections `.` and `:` always attach to the symbol on their left, and a sole `|` (abstract value) isn't happy with strings.

### How these work

Basically, it is a random mix of no-ops connected through various connectors.

```
,&.|:@]
     @]   Pass the argument unchanged
 &.|:     Apply inverse of |: (transpose), no-op on single string
,         Ravel, no-op on a single string
 &.|:     Apply |: again, still no-op

]@:|.&,
     &,   Ravel, no-op
 @:|.     Reverse
]         Pass the argument unchanged

```

This answer is one byte shorter than the trivial comment-abuse:

# , 8 bytes

```
]NB.BN.|

```

Reversed:

```
|.NB.BN]

```

Try it online!

In J, the in-line comment marker is `NB.`, which is longer than every other language I know of.
> 5 votes

# Answer
# Charcoal, 2 bytes

```
Ｓ←

```

Try it online! Explanation:  implicitly prints the explicit input and  moves the cursor left (no effect on the final output). Reversed:

```
←Ｓ

```

Try it online!  changes the direction of the implicit print of the explicit input  thus reversing the output.
> 4 votes

# Answer
# Python 3, 27 bytes

```
lambda s:s#]1-::[s:s adbmal

```

Try it online!

!enilno ti yrT
> 4 votes

# Answer
# Gaia, 2 bytes

```
pv

```

Try it online!

Try it reversed!

Very similar solution to other golfing languages.

### Explanation

```
p    Print the (implicitly grabbed) input
 v   Reverse the input

```

### Reverse

```
v    Reverse the (implicitly grabbed) input
 p   Print the result

```
> 4 votes

# Answer
# 9, 4 bytes

```
][.|

```

Attempt This Online!

See this answer for the 7-byter that works in previous versions.

J 9 (re-)introduces modifier trains and adds some adverb and conjunction equivalents of identity functions (`]` and `[`):

```
]: Ident (adverb)    / u]:  evaluates to u
]. Dex (conjunction) / u].v evaluates to v
[. Lev (conjunction) / u[.v evaluates to u

```

The above code parses as

```
] [. |    left operand ([.) out of identity(]) and absolute value(|),
          which is identity

```

while the reverse `|.[]` parses as a 3-train:

```
|. [ ]    left argument ([) out of the results of reverse (|.) and identity (])
          which is reverse

```
> 4 votes

# Answer
# Cubix, 19 bytes

```
.@o?A^;/|?$oqBA.UW.

```

Try it online!

Cubified

```
    . @
    o ?
A ^ ; / | ? $ o
q B A . U W . .
    . .
    . .

```
* `A^` get all the input and enter the loop
* `o?` output the TOS of stack and test
* `@` exit if it tests to negative
* `/;^` reflect back, pop TOS and re-enter loop

All other commands are avoided.

**Reversed**

```
.WU.ABqo$?|/;^A?o@.

```

Try it online!

Cubified

```
   . W
    U .
A B q o $ ? | /
; ^ A ? o @ . .
    . .
    . .

```
* `ABq` Get all input, reverse and drop TOS to bottom of stack
* `o$?|?` output TOS, skip the test and relect back onto test
* `@` halt if test if negative
* `WUq` change lane, u-turn onto drop TOS start of loop
> 3 votes

# Answer
# Wolfram Language (Mathematica), 16 bytes

```
1&esreveR//#& &1

```

Try it online!

**Reversed**:

```
1& &#//Reverse&1

```

Try it online!

Takes a list of characters as input. For string input, use `StringReverse`.
> 3 votes

# Answer
# Pip, 4 bytes

```
aVRa

```

Try it online! !enilno ti yrT

Makes use of the fact that `RV` is the reverse operator but `VR` is an undefined variable. Both versions print the value of their last expression; in the standard version, that's `a` (with the first `a` and the `VR` being no-ops), while in the reversed version, that's `RVa` (with the first `a` being a no-op).
> 3 votes

# Answer
# Perl 5 `-p`, 11 bytes

The obvious.

```
#esrever=_$

```
> 3 votes

# Answer
# Pushy, 4 bytes

```
"\"@

```

Try it online: Forwards, Backwards

Simple implementation with the comment character `\`. In the forwards program, `"` prints the input and the rest is a comment; in the backwards program, `@` reverses the input before printing.

We could alternatively replace `\` with `c`, which would clear the input from the stack.
> 3 votes

# Answer
# Jelly, 2 bytes

```
Uṛ

```

Try it online!

Reversed!

## Explanation

```
U  | Reverse
 ṛ | Right argument (when used in a monadic chain like this, will return the original argument to the chain)

```

## Explanation (reversed)

```
ṛ  | Right argument (when used in a monadic chain and followed by a monadic link, will return the output of that monadic link)
 U | Reverse

```

Seven other two-byters `Ṛṛ ḷU ḷṚ Uȧ Ṛȧ ȯU ȯṚ`
> 2 votes

# Answer
# Japt, 2 bytes

```
ÔU

```

Try it | Reversed
> 2 votes

# Answer
## MathGolf, 3 bytes

```
x;l

```

## Explanation:

```
x   Reverse the implicit input
 ;  Discard the string
  l Push a string input
Implicit output TOS

```

Reversed:

```
l   Push a string input
 ;  Discard it
  x Reverse the implicit input
Implicit output TOS

```
> 2 votes

# Answer
# C (gcc), 56 bytes

Nothing fancy. Would have used `puts()` but then trailing whitespace would not have been consistent between the two variants.

```
f(int*s){printf(s);}//};))1+s(f,s*(rahctup&&s*{)s*rahc(f

```

Try it online!

```
f(char*s){*s&&putchar(*s,f(s+1));}//};)s(ftnirp{)s*tni(f

```

Reversed!
> 2 votes

# Answer
## , 2 bytes

Pretty much the same as the 05AB1E solution.

```
a_

```

## Explanation

```
a   % Push the input
 _  % Reverse the input
    % Implicit print the top of the stack

```

## noitanalpxE

```
_   % Reverse the implicit input
 a  % Push the input
    % Implicit print the top of the stack

```
> 2 votes

# Answer
# BRASCA (brasca-online), 5 bytes

The broken loops crash the Python-based interpreter, but it works on brasca-online.

```
,[o],

```

```
,]o[,

```

Try it! | !ti yrT

## Explanation

```
,     - Reverses stack                     (1,2,3 => 3,2,1)
 [o]  - Output stack one by one            (3,2,1 => empty)
    , - Reverse it again                   (empty => empty)

```

Reversed:

```
,     - Reverses stack                     (1,2,3 => 3,2,1)
 ]o[  - Broken loops, output top of stack  (3,2,1 => 3,2  )
    , - Reverses it again                  (3,2   => 2,3  )
      - Implicit output the stack reversed (2,3   => empty)

```
> 2 votes

# Answer
# Factor, 17 bytes

```
[ ] ! ] esrever [

```

Try it online!

!enilno ti yrT

Fixed thanks to Bubbler
> 2 votes

# Answer
# Stack Exchange, 2 bytes

```
EP

```

Reversed:

```
PE

```

Sadly, there is no online interpreter, especially since this language is still a work in progress (although `P` and `E` are two of the commands I've finalized).

Stack Exchange is a language that resolves around stacks. It is a stack-based language where the only data structure is a stack. A string is represented as a stack of characters, and a character is represented by a stack of empty stacks where the length represents a codepoint.

The `E` command encloses all elements of the main stack in a stack and pushes that stack onto the main stack. The `P` dumps all elements of the top stack onto the main stack in reverse. `P` does this in reverse because it's easier to make it stack-safe that way, but I didn't realize until now that it's perfect for this challenge. Whereas `PE` dumps the input onto the stack in reverse and bundles it back up in a stack so it can be returned, `EP` encloses the input in a singleton stack and then unwraps it again, making no change.

As an example, running `EP` on the input `{ {{}{}{}} {} {{}{}} {{}} {} }` returns the same stack back, whereas running `PE` returns `{ { {} {{}} {{}{}} {} {{}{}{}} } }`. `{ {{}{}{}} {} {{}{}} {{}} {} }` represents the string made of the characters `\u0003`, `\u0000`, `\u0002`, `\u0001`, and `\u0000`.
> 2 votes

# Answer
# Brain-Flak, 13 bytes

```
#><}><)><}{({

```

Try it online!

Forward: Just a comment, so that it just outputs the input

Reversed:

```
{({}<>)<>}<>#

```

Try it online!

Move everything to the second stack, so it is reversed.
> 1 votes

# Answer
# Kotlin, 15 bytes

My first Kotlin answer, and far shorter than the java equivalent!

```
s//)(desrever.s

```

Try it online!

Reversed:

```
s.reversed()//s

```

!enilno ti yrT
> 1 votes

# Answer
# CJam, 7 bytes

```
qe#e%Wq

```

Boring version with comments. If CJam would fail silently i could have saved like 3 bytes in 2 questions already!
> 1 votes

# Answer
# Stax, 2 bytes

```
Pr

```

Run it Reversed
> 1 votes

# Answer
# PHP, 27 bytes

```
<?=$argn;#;)ngra$(verrts=?<

```

Try it online!

Try it online!
> 1 votes

# Answer
# x86 opcode, 19 bytes

```
85 c9 7e 0e 49 8a 06 8a 24 0e 88 26 88 04 0e 46 e2 ee c3

```

!enilno ti yrT

# 17 bytes

```
f:  cmp esi, edi
    jae ok
    dec edi
    mov al, [esi]
    mov ah, [edi]
    mov [esi], ah
    mov [edi], al
    inc esi
    jmp f
ok: ret

```

input `esi`(begin) and `edi`(end)
> 1 votes

# Answer
# MAWP, 12 bytes

```
%|0~[;]~0~|%

```

It would have been cute to have a palindromic solution.

The program inserts a zero at the end of the string and prints it normally, or it does the opposite. Try it!

!ti yrT
> 1 votes

# Answer
# Google Sheets, 69

Forward:

```
=A1&T(N("(N^1,))1A(NEL(ECNEUQES-)1A(NEL+1,1A(DIM((alumroFyarrA,(NIOJ=

```

Backward:

```
=JOIN(,ArrayFormula((MID(A1,1+LEN(A1)-SEQUENCE(LEN(A1)),1^N("(N(T&1A=

```

Easy enough. Google Sheets auto-closes quotes and parens.

`T(<number>)` is always an empty string. `N("...")` is always 0.
> 1 votes

# Answer
# Rust, 34 bytes

```
|s|s//)(tcelloc.)(ver.)(srahc.s|s|

```

Reversed:

```
|s|s.chars().rev().collect()//s|s|

```

Try it online
> 1 votes

# Answer
# Pxem, 29 bytes (Filename) + 0 bytes (Content) = 29 bytes, syntaxically not valid.

* Filename (escaped some): `.w.o.i.c\001.+.a.d.p.a.+.\001c.i.w.`
    + Reversed: `.w.i.c\001.+.a.p.d.a.+.\001c.i.o.w.`
* Content: empty

## How it works

### Original

As in this, except with `.d`: exiting/returning command. Since pxemi.2.min.posixism automatically removes deadcode, the code after that will be ignored, even `.a` comes before `.w` (which is syntax error).

### Reversed

Since Pxem is stack-oriented, not outputting any characters until EOF would produce input reversed. Then `.p` outputs from top to bottom, which is in reverse order compared from original input.

## TIO links

---

# Pxem, 39 bytes (Filename) + 0 bytes (Content) = 39 bytes, syntaxically safe.

* Filename: `.w?.s.o.i.c\001.+.a?.d.p.s.?a.+.\001c.i.s.?w.`
    + Reversed: `.w?.s.i.c\001.+.a?.s.p.d.?a.+.\001c.i.o.s.?w.`
> 1 votes

# Answer
# VBA, 23 bytes

```
?[A1]')]1A[(esreveRrtS?

```

Input is in cell `A1` of the active sheet. Code must be run from the immediate window. It's a simple implementation where a backtick indicates the rest of the line is a comment.
> 1 votes

# Answer
# Raku, 9 bytes

```
~*#pilf.*

```

This seems too trivial for a Try It Online link...

`#` is the comment character. Forwards, `~*` is an anonymous function that stringifies its argument. Backwards, `*.flip` is another anonymous function that calls the `flip` method on its argument, which reverses strings, or the string representation of objects implicitly convertible to strings (numbers, etc).
> 1 votes

# Answer
# Vyxal, 2 bytes

```
#Ṙ

```

Try it Online!

Same as Keg
> 1 votes

# Answer
# RProgN 2, 2 bytes

```
pi

```

*There's a joke to be made about π here, but I can't find it.*

`wi` can be used instead, which doesn't include a trailing newline.

Try it online!

!enilno ti yrT

## Explained

```
pi
p  | [p]rint the top of the stack, popping.
 i | [i]nverse the top of the stack, doing nothing.

```

## denialpxE

```
ip
i  | [i]nverse the top of the stack
 p | [p]rint the top of the stack, popping.

```
> 1 votes

# Answer
# Python 3.11, 35 bytes

A full program, not just a lambda.

```
print(input())#)]1-::[)(tupni(tnirp

```

Attempt this online!

Reversed:

```
print(input()[::-1])#))(tupni(tnirp

```
> 0 votes

# Answer
# TypeScript's Type System, 84 bytes

Same comment out the opposite code trick.

Forwards:

```
type F<S>=S//V:>`}gnirts&V{$}C{$`,R<F?`}R refni{$}C refni{$`sdnetxe S=>""=V,S<F epyt

```

Try it at the TypeScript playground!

Backwards:

```
type F<S,V="">=S extends`${infer C}${infer R}`?F<R,`${C}${V&string}`>:V//S=>S<F epyt

```

!dnuorgyalp tpircSepyT eht ta ti yrT
> 0 votes

---
Tags: code-golf, string, source-layout
---


# Question
Title: I palindrome the source code, you palindrome the input!
*This is a rip-off of a rip-off of a rip-off of a rip-off of a rip-off. Go upvote those!*

Your task, if you accept it, is to write a program/function that outputs/returns its input/args. The tricky part is that if I make your source code palindrome via duplicating reversed source code after the original code, the output must be returned "palindromize".

The source code will be only duplicated once.

## Examples

Let's say your source code is `ABC` and the input is `xyz`. If i run `ABC` the output must be `xyz`. But if i run `ABCCBA` instead, the output must be `xyzzyx`.

Put it in a table:

```
Input: "xyz"
code ABC => "xyz"
code ABCCBA => "xyzzyx" (aware that it isn't "xyzyx")

```

## Details

Your code *before* processing should return the input.

Your code *after* processing should return the input with reversed input following no matter what input is.

**The process**:

Your code, **no matter what**, will be followed with a *reversed* code after it. Even if it's already palindrome by itself.

**Multiline code**:

Multiline code will be treated as *single line* code but with `\n`(newline)

## Rules

* Input can be taken in any convenient format.
* Output can be in any convenient format as well. As long as it follow the input-reversed input order.
* Standard Loopholes are forbidden.

## Scoring

This is code-golf so the answer with the fewest amount of bytes wins.

# Answer
# Haskell, Full program, 39 bytes

```
iddi=(++)<*>reverse;main=interact--
 id

```

Try it online!

## Mirrored

```
iddi=(++)<*>reverse;main=interact--
 iddi
--tcaretni=niam;esrever>*<)++(=iddi

```

Try it online!

Very simple approach for a full program. We have two "lines" (separated by `;` rather than an actual line break) of boilerplate ending in `--` and then the function `id`. When the program is reversed `id` gets changed to `iddi`, which we have defined to do the intended operation.

# Haskell, Function, 20 bytes

```
f x=x--x esrever++

```

Try it online!

## Mirrored

```
f x=x--x esrever++

 ++reverse x--x=x f

```

Try it online!

This one is also a pretty simple approach. We have a function `f x=x` and a payload hidden in a comment. When the code is revealed the payload extends our function with `++reverse x`.

# Haskell, Function, No Comments, 39 bytes

```
f=id where;di x y=y<>x;id=>>esrever=di;

```

Try it online!

## Mirrored

```
f=id where;di x y=y<>x;id=>>esrever=di;;id=reverse>>=di;x><y=y x id;erehw di=f

```

Try it online!

The relevant function is `f`. This one is likely not optimal. I will explain it when I shorten it down a bit.
> 14 votes

# Answer
# , 65 bytes, no comments

```
xx=paste0(x<-scan(,""),intToUtf8(rev(utf8ToInt(x))));`+`=cat;""+x

```

Try it online!

Palindromized:

```
xx=paste0(x<-scan(,""),intToUtf8(rev(utf8ToInt(x))));`+`=cat;""+xx+"";tac=`+`;))))x(tnIoT8ftu(ver(8ftUoTtni,)"",(nacs-<x(0etsap=xx

```

Try it online!

The vanilla version defines `+` to be an alias of `cat`, so that the call `""+x` outputs `x`. In the palindromized version, we call `""+xx+""` instead, outputting `xx` which is defined as the concatenation of `x` and its mirror. The code errors after producing the desired output.

There is an extra space at the beginning and end of the output, which was allowed by OP.

---

Previous version with same byte count, with comments but with no errors or extra spaces:

## , 65 bytes

```
function(x,xx=paste0(x,intToUtf8(rev(utf8ToInt(x)))),`?`=cat)?#
x

```

Try it online!

Try it online palindromized!
> 10 votes

# Answer
## Python, ~~44~~ ~~43~~ ~~42~~ ~~41~~ 40 bytes

a little trick with comment solves this problem

-1 byte thanks to @Wheat Wizard with the ";"

-1 byte thanks to @Jonathan Allan with the reversed line

-1 byte thanks to @Jonathan Allan again with Walrus Operator

-1 byte thanks to @qwatry for combining two line and saved an innocent byte from being used.

```
print(n:=input(),end='')#)]1-::[n(tnirp

```

**mirrored**

```
print(n:=input(),end='')#)]1-::[n(tnirp

print(n[::-1])#)''=dne,)(tupni=:n(tnirp

```

Try it online!
> 9 votes

# Answer
# APL (Dyalog Unicode), 3 bytes

```
⌽⊢,

```

Try it online!

A function that returns the string unmodified.

```
⌽⊢,,⊢⌽

```

Try it online!!enilno ti yrT

A function that returns the string with its mirror appended.

### How it works

```
⌽⊢,  ⍝ Input: a string S (char vector)
  ,  ⍝ Ravel of S (no-op on a char vector)
⌽    ⍝ Reverse of S
 ⊢   ⍝ Select the right one (therefore no-op as a whole)

⌽⊢,,⊢⌽
   ,⊢⌽  ⍝ Same as above, but select the reverse of S
 ⊢,     ⍝ Append the above to S (S + rev(S))
⌽       ⍝ Reverse the entire string,
        ⍝ but no-op since the string is already palindrome

```
> 8 votes

# Answer
# JavaScript (SpiderMonkey), 31 bytes

```
f=([a,...b])=>!a?'':a+f(b)//a+

```

Try it online!
> 5 votes

# Answer
# Stax, 5 bytes

```
{m:xx

```

Run and debug it

Run and debug itti gubed dna nuR

Fixed, and now 1 byte shorter.

## Explanation

```
{m:xx
{m    map each char to itself
  :x  escape regex special characters
    x push the input again

     xx:m{
     x     push the input once more
      x    push the input again
       :m  mirror it
         { error on unterminated block, exiting and displaying top of stack

```
> 4 votes

# Answer
# Vyxal, 2 bytes

```
m?

```

Try it Online!

A blatant port of the 05ab1e answer. Imaginary brownie points for anyone who can give me an answer to the question posed by my answer.
> 4 votes

# Answer
# Charcoal, 3 bytes

```
θ⮌ω

```

Try it online! Palindromised:

```
θ⮌ωω⮌θ

```

Try it online! Explanation:

```
θ

```

Print the input.

```
⮌ω

```

Print the reverse of the empty string.

```
ω

```

Print the empty string.

```
⮌θ

```

Print the reverse of the input.
> 4 votes

# Answer
# 05AB1E, ~~2~~ ~~3~~ 2 bytes

-1 bytes thanks to @Razetime

```
ºI

```

Try it online!

Try it online!!enilno ti yrT
> 3 votes

# Answer
# Jelly, 3 bytes

```
Ṛ;ṛ

```

Try it online!

## Palindromized

```
Ṛ;ṛṛ;Ṛ

```

Try it online!!enilno ti yrT

I believe a 2-byte solution is not possible. However, it's nice that this answer is a case-insensitive palindrome.
> 3 votes

# Answer
# Japt, 5 bytes

```
'1ê U

```

Try it

* palindromized

'1ê UU ê1'

Try it
> 3 votes

# Answer
# Brainfuck, 7 bytes

`,[.>,]+`

## Mirrored

`,[.>,]++[,<.],`

This solution is probably a bit cheating as it is optical palindrome. So not just order of characters is reversed, but characters are too. `>` becomes `<` and `[` becomes `]`. `+-,` are kept the same as they are (almost) optically same when reversed.

This was the only way as it is impossible to construct loops in brainfuck when code is reversed, because code like `[...]` would become `]...[` which is invalid code in brainfuck.

## How it works

```
,[      load first character and start loop
 .      print last loaded character
 >,     load next character into next cell
]       if last character is null byte end loop
+       sets value of cell to 1
mirrored part:
+       sets value of cell to 2
[       starts loop
 ,      no more characters are there so it just sets cell to 0
 <.     print previous cell
]       end loop when there are no more characters
,       does nothing; just reads another null byte

```
> 3 votes

# Answer
# JavaScript, 79 bytes

```
m=process.argv[2]//
console.log(m)//
//)``nioj.)(esrever.``tilps.m(gol.elosnoc

```

Palindromed:

```
m=process.argv[2]//
console.log(m)//
//)``nioj.)(esrever.``tilps.m(gol.elosnoc

console.log(m.split``.reverse().join``)//
//)m(gol.elosnoc
//]2[vgra.ssecorp=m

```

Try it online!

Try it online!!enilno ti yrT
> 2 votes

# Answer
# \>\<\>, 17 bytes

```
<o:\?(0~!:i
<o>;

```

Try it online!

Palindromified:

# \>\<\>, 34 bytes

```
<o:\?(0~!:i
<o>;

;>o<
i:!~0(?\:o<

```

Try it online!!enilno ti yrT

Explanation, if not palindromized:

```
<    | send the IP leftward (golfier due to the second line)
i    | push one character of input; stack = [i]
:    | duplicate and push the top value of the stack; stack = [i,i]
!    | skip the next instruction
~    | pop (drop) the top element of the stack (skipped)
0    | push literal 0; stack = [i,i,0]
(    | pop x then pop y and push 1 if x < y else push 0; stack = [i,bool]
?    | pop the stack and skip the next instruction if the value was 0 (checks for -1 terminator); stack = [i]
\    | send ip upwards, wrapping around vertically (only if input value was terminating -1)
 :o  | non-destructively output the top value, thereby accumulating the input onto the stack as we go
     | or
 ;   | halt

```

When palindrominated, instead of wrapping back around to `;`, we instead go through `~`, dropping the top value of the stack (known to be `-1`), then hit `>o<`, outputting the top value of the stack until the stack is empty (i.e. the input in reverse) and then terminate via error.
> 2 votes

# Answer
# Bash, 12 bytes

```
tee a#a ver

```

Try it online!

Try it online (palindromized)!

## Explanation

```
tee a#a ver  # Copy STDIN to file a (with implicit output)

rev a#a eet  # Using file a as STDIN, reverse STDIN (with implicit output)

```
> 2 votes

# Answer
# Java, 37 bytes

```
s->s//)(esrever.)s(reffuBgnirtS wen+

```

Try it online!

Mirrored:

```
s->s//)(esrever.)s(reffuBgnirtS wen+

+new StringBuffer(s).reverse()//s>-s

```

Try it online!
> 2 votes

# Answer
# PHP -F, 32 bytes

```
echo$argn;//;)ngra$(verrts ohce

```

Try it online!

**palindromed:**

```
echo$argn;//;)ngra$(verrts ohce

echo strrev($argn);//;ngra$ohce

```

Try it online!

Notice the new line at the end of the code
> 2 votes

# Answer
# JavaScript (V8), 39 bytes

```
(s,ss)=>//``nioj.``esrever.]s...[+s||
s

```

Try it online!

When palindromised it becomes:

```
(s,ss)=>//``nioj.``esrever.]s...[+s||
ss
||s+[...s].reverse``.join``//>=)ss,s(

```
> 1 votes

# Answer
# CJam, 8 bytes

```
qe#e%W_

```

Try it online!

It has a newline at the end.

**Reversed**:

```
qe#e%W_

_W%e#eq

```

Try it online!
> 1 votes

# Answer
# JavaScript, 31 bytes

```
s=>s//``nioj.)(esrever.]s...[+

```

Try it online!

Mirrored:

```
s=>s//``nioj.)(esrever.]s...[+

+[...s].reverse().join``//s>=s

```

Try it online!
> 1 votes

# Answer
# Perl 5 `-p`, 14 bytes

```
#;esrever=._$

```

Try it online!

Note the trailing newline.

Perl `-p` prints the input after the code runs. The normal code does nothing to manipulate the input, being commented out. The palindromed code:

```
#;esrever=._$

$_.=reverse;#

```

takes the input and appends the reverse of it to the input before printing.

Try it online!!enilno ti yrT
> 1 votes

# Answer
# , 4 bytes

```
,[.|

```

Attempt This Online!

Uses the 4-byte answer for reverse.

```
,[.|    input: string s
,[.|    [. selects the left one out of , and |
        and , returns s unmodified when called monadically

,[.||.[,    input: string s
    |.[,    select left out of |. and ,, which is |. (reverse) of s
,[.|        same as above, but now called with s on the left side and rev(s) on the right
            so , concatenates the two instead

```
> 1 votes

# Answer
# GolfScript, 6 bytes

```
#%1-.

```

Try it online!

Try it online!(palendromized)
> 0 votes

# Answer
# Haskell (GHC 8.4.1), 32 bytes, no comments

```
c x y=y<>x
iddi=reverse>>=c
id

```

The function for this part of the problem is `id`.

Unfortunately, TIO has an older version of GHC, which doesn't export the `(<>)` operator in `Prelude`. I can't use the standard `(++)` operator because it's a palindrome (more on this later).

## Mirrored

```
c x y=y<>x
iddi=reverse>>=c
iddi
c=>>esrever=iddi
x><y=y x c

```

The function for this part of the problem is `iddi`.

## How?

```
c x y=y<>x

```

This line defines a new function `c`, that is basically the concatenation operator `(++)` with its arguments swapped. I was forced to use `(<>)` instead of `(++)` because the latter is a palindrome and would mess things up in the mirrored part.

---

```
iddi=reverse>>=c

```

This line defines a new function `iddi`, which basically implements the "mirror" functionality. Expanding the `(>>=)` operator for clarity, the definition can be rewritten as

```
iddi s=c(reverse s)s -- = s<>reverse s

```

---

```
c=>>esrever=iddi
x><y=y x c

```

This part of the mirrored code is just garbage. Fortunately, it's *syntactically correct* garbage. These two line define two new operators, `(=>>)` and `(><)`, in terms of the previously defined functions `iddi` and `c`, whose names are (very conveniently) palindromic strings.

The reason why I can't use `(++)` instead of `(<>)` is that in this case the mirrored part of the code would try to redefine `(++)`, leading to an unpleasant result.
> 0 votes

# Answer
# Pxem (esolang-box notation), 43 bytes.

Some unprintables are escaped.

```
.e
e.z\001.rXX.a.w.s.p.d.a.w.c.o.i.cED.-.+.ae.

```

## Parindromed

```
.e
e.z\001.rXX.a.w.s.p.d.a.w.c.o.i.cED.-.+.ae..ea.+.-.DEc.i.o.c.w.a.d.p.s.w.a.XXr.\001z.e
e.

```

### With comments

For parindromed.

```
XX.z
# MAIN ROUTINE
# call with empty stack
.a.eXX.z

# SUBROUTINE
# should be called with either
.aXX.z
# if top is not e, then push zero
# else e is popped
.ae.z\001.rXX.aXX.z
# if top is not zero, then print and pop each item
# (except top .; discarded) and return
.a.w.s.p.d.aXX.z
# cat program BUT preserve each item
# XXX: where does EOF: -1 go?
.a.w.c.o.i.cED.-.+.aXX.z
# NOTE if not parindromed, the next section and so far is e.,
# which .e and so far would not be there
# if parindromed, call with stack
.ae..eXX.z
# garbage, then reaching to .D returns to main section
.aa.+.-.DXX.z
# and garbage
.aEc.i.o.c.w.a.d.p.s.w.a.XXr.\001z.e\ne.

```

Try it online!
> 0 votes

---
Tags: code-golf, string, source-layout, palindrome
---


# Question
Title: How many ways to cut a number into an equation?
*Too bad! I had such a beautiful equation, but I lost all my `=+-*`, so there is nothing left but a chain of digits, looking like a number: `7512`. But was it `7+5=12` or `7-5=1*2` or `7=5*1+2` or `7=5+1*2`? Or are there even more valid possibilities?*

Your task: **For a given positive integer number, return the number of true equations containing the digits of that number in the given order, using plus and minus and multiplication operators.**

* dot-before-dash calculation is used, so 1+2\*3 is 7, not 9
* plus and minus are only allowed as operators, not as (prefix) sign, so neither negative numbers in the equation nor superfluous plus padding
* no division to keep rules simple
* input numbers are integers ranging from `0` to `999999`
* no leading zeroes, neither in input, nor in equations
* operators are allowed to appear several times, but of course only exactly one `=`
* a single digit as input leads to `0` as output, because you can't do any equation with it
* the smallest number to return `1` is `11` (equation is `1=1`)
* don't underestimate the possibilities for higher numbers like `1111` (`10`possible equations: `11=11 1*1=1*1 1+1=1+1 1-1=1-1 1=1*1*1 1=1-1+1 1=1+1-1 1*1*1=1 1-1+1=1 1+1-1=1`
* you are free to use anything from brute force to intelligent algorithms, execution time is irrelevant, just *don't use many bytes of code*, because we are golfing

Check your code with these examples:

```
7      --> 0
42     --> 0
77     --> 1
101    --> 3
121    --> 1
1001   --> 12
1111   --> 10
7512   --> 5
12345  --> 5
110000 --> 203
902180 --> 37

```

# Answer
# GNU `sed -E`,  ~~214 200 181 171~~  169 bytes

For some not-so-obvious reason, I decided to solve this by myself in `sed`, misusing the shell for expression evaluation with the `e` flag of the GNU version of the tool:

```
G:1;s/(\S*[0-9])([0-9]\S*\n)/\1_\2\1==\2\1+\2\1-\2\1*\2/;t1;s/_//g;:2;s/(\n|^)[^=]+\n/\n/;s/\S*=\S+=\S*//;t2;s/\S*/+$((&))/g;s/\S*[ =*+-]0[0-9]\S*//g;s/.*/echo $((&))/e

```

**Try it online!**

* `G` appends the (empty) hold space, so it adds a newline to the end, which is used as a separator
* `:1;s/(\S*[0-9])([0-9]\S*\n)/\1_\2\1==\2\1+\2\1-\2\1*\2/;t1` loops to add operators or `==` between each pair of digits, marking already considered pairs by `_`
* `s/_//g` removes the `_` markers
* `:2;s/(\n|^)[^=]+\n/\n/;s/\S*=\S+=\S*//;t2` removes items without `==` or with more than one `==`
* `s/\S*/+$((&))/g` turns each equation in to an arithmetic expansion `$(())`
* `s/\S*[ =*+-]0[0-9]\S*//g` is needed to remove all equations including a leading zero
* `s/.*/echo $((&))/e` finally evaluates the whole rubbish
> 13 votes

# Answer
# JavaScript (ES6), 107 bytes

*-26 bytes (!) thanks to @tsh*

```
f=([c,...a],s,g=o=>f(a,[s]+c+o))=>c?g``+g`==`+g`+`+g`-`+g`*`:/^(?!.*\D0\d)[^=]*==[^=]*\d$/.test(s)&&eval(s)

```

Try it online!

### How?

We recursively build all possible expressions obtained by adding `""`, `"=="`, `"+"`, `"-"` or `"*"` after each character.

For each expression, we test whether it matches:

```
//         .--------------------> no number may start with '0'
//         |      .-------------> left part
//         |      |   .---------> comparison operator
//         |      |   |  .------> right part (except the last character)
//         |      |   |  |   .--> we must end with a digit
//    _____|___  _|_  | _|_  |
//   /         \/   \/\/   \/\
   /^(?!.*\D0\d)[^=]*==[^=]*\d$/

```

If it does, we can safely `eval()`'uate it and increment the final result if it's truthy.
> 7 votes

# Answer
# Vyxal, 28 bytes

```
øṖ'⌊=A;ƛṄfð`+*-,`VΠEƛk-İ⁼]f∑

```

Attempt This Online! Semi-port of Jonathan Allan's Jelly answer, but much clunkier. The `A` flag runs testcases.

```
øṖ                           # Partitions
  '   ;                      # Where
     A                       # All substrings
    =                        # Are equivalent under
   ⌊                         # Cast to integer
       ƛ                 ]   # For each partition
                  Π          # Cartesian product of
        Ṅf                   # Join with spaces and flattening
          ð`+*-,`V           # Then replacing spaces with "+*-,"
                  Π          # Resulting in all combinations of the operators and strings
                   E         # Evaluate as Python
                    ƛ    ]   # Map each to
                        ⁼    # Whether it remains the same under
                     k-İ     # [x[-1], x[1]] - ensures it is a 2-item list with both items the same
                          f∑ # Flatten and count truthy values

```
> 6 votes

# Answer
# Python, 178 bytes

*-2 bytes, thanks to corvus\_192*

```
lambda s:len({*filter(eval,q(s,"=="))})
q=lambda s,c:[l+c+r for i in range(1,len(s))for l in e(s[:i])for r in e(s[i:])]
e=lambda s:[s]*(s==str(int(s)))+q(s,"+")+q(s,"-")+q(s,"*")

```

Attempt This Online!

*Takes the string representation of the number as input*

Generates all possible equations, uses `eval` to compare the results

The `*(s==str(int(s)))` part prevents leading zeros
> 5 votes

# Answer
# Jelly,  ~~35 34 32~~  31 bytes

-3 thanks to Unrelated String! (Filtering leading zero decimals with `ḌVÐṀ` rather than the somewhat clunky `ḌD$ƑƇḌ`. Also `Ṛṁ2ƊƑ` -\> `.ị$Ƒ`)

```
DŒṖḌVÐṀżFŒV.ị$ƑʋⱮL’“*+,-”ṗƲ$€FS

```

A monadic Link that accepts a positive integer and yields the count.

**Try it online!**

### How?

```
DŒṖḌVÐṀżFŒV.ị$ƑʋⱮL’“*+,-”ṗƲ$€FS - Link: positive integer, N
D                               - get a list of N's digits
 ŒṖ                             - all partitions of that list
   Ḍ                            - convert each part of each from base ten
                                  : e.g. [0,7,2] -> 72
     ÐṀ                         - keep those maximal under:
    V                           -   evaluate as Jelly code (e.g. [4,72,1]-> 4721)
                                  : i.e. those that had no leading zero digit
                            €   - for each DecimalisedPartition:
                           $    -   last two links as a monad:
                          Ʋ     -     last four links as a monad:
                 L              -       length
                  ’             -       decrement
                   “*+,-”       -       "*+,-"
                         ṗ      -       Cartesian power
                Ɱ               -     map across these operator lists with:
               ʋ                -       last four links as a dyad:
       ż                        -         {DecimalisedPartition} zip {Operators}
        F                       -         flatten
         ŒV                     -         evaluate as Python code
              Ƒ                 -         is {X=that} invariant under?:
             $                  -           last two links as a monad:
           .                    -             0.5
            ị                   -             index into {X} -> [last(X), first(X)]
                                          : i.e. is exactly two equal values?
                             F  - flatten
                              S - sum

```
> 5 votes

# Answer
# Python, 255 bytes

```
lambda s:len({q for r in range(len(s)+1)for o in combinations("+-*"*len(s),r)for p in permutations([*s,"==",*o])if match(f"{n}=={n}$",q:="".join(p))and s==sub("\D","",q)and eval(q)})
m="(0|[1-9]\d*)"
n=f"{m}(\D{m})*"
from itertools import*
from re import*

```

Attempt This Online!
> 2 votes

# Answer
# Ruby, ~~117~~ 113 bytes

Takes a string as input. Creates every possible combination of operators and counts which ones have no leading zeroes and `eval` to `true`.

This is probably the only time in Ruby golfing when `do`/`end` will ever be cheaper than the curly brace syntax, since that allows `rescue SyntaxError` without adding a `begin` block like it normally would require. (Inline `rescue` doesn't catch SyntaxError so the longer syntax is needed.)

-4 from Dingus.

```
->s{[p].product(*[%W"#{} == + - *"]*s.size).count do
!p==eval(e=_1.zip(s.chars)*'')&&/0\d/!~e
rescue$!.class;end}

```

Attempt This Online!
> 2 votes

# Answer
# Charcoal, 61 bytes

```
⊞υωＦ⮌θ≔ΣＥυ⁺ι⁺⎇∧κ∨⁼κ0∨⌕κ0⁻§κ¹ＩΣ§κ¹⟦+¦-¦*ω==⟧⟦ω⟧κυＩＬΦυ∧⁼²№ι=ＵＶι

```

Attempt This Online! Link is to verbose version of code. Explanation:

```
⊞υω

```

Start with an empty expression.

```
Ｆ⮌θ

```

Loop over the digits in reverse order.

```
≔ΣＥυ⁺ι⁺⎇∧κ∨⁼κ0∨⌕κ0⁻§κ¹ＩΣ§κ¹⟦+¦-¦*ω==⟧⟦ω⟧κυ

```

For each expression so far, prefix this digit, but if the expression is not empty, and it either does not being with `0` or the `0` is not part of a larger number, then also optionally insert an operator.

```
ＩΣＥΦυ⁼²№ι=ＵＶι

```

For each expression that contains exactly one equality operator, evaluate that as python, and output the the number of expressions for which everything is true.
> 2 votes

# Answer
# 05AB1E, 33 bytes

```
.œʒïJQ}ε©…-+*„==ªsg<ãε®s.ιJ]˜.EáO

```

Try it online or verify all test cases.

**Explanation:**

Step 1: Get all partitions of the input-integer, and remove all partitions that contain parts with leading 0s:

```
.œ         # Get all partitions of the (implicit) input-integer
  ʒ        # Filter the list of lists of parts by:
   ï       #  Cast each part to an integer, removing leading 0s
    J      #  Join all parts back together
     Q     #  Check whether it's equal to the (implicit) input-integer
  }        # Close the filter

```

Try just step 1 online.

Step 2: Create all possible equations of each partition using `-`,`+`,`*`,`==` delimiters:

```
ε          # Map over each remaining partition:
 ©         #  Store the current partition in variable `®` (without popping)
  …-+*     #  Push string "-+*"
      „==ª #  Convert it to a list of characters, and append "==": ["-","+","*","=="]
  s        #  Swap so the partition is at the top again
   g       #  Pop and push its length
    <      #  Decrease it by 1
     ã     #  Get the cartesian power of the ["-","+","*","=="] and this length-1
  ε        #  Inner map each list of operators by:
   ®       #   Push partition `®`
    s      #   Swap so the current list of operators is at the top
     .ι    #   Interleave the two lists
       J   #   And then join them together to a single string
]          # Close the nested maps
 ˜         # Flatten the list of list of equation-strings

```

Try the first two steps online.

Step 3: Evaluate each equation-string as Elixir code: `.E`.
Try the first three steps online.

Step 4: Count the amount of `"true"` values, which under the hood are all `1` (05AB1E's truthy value), making it difficult to find a correct and short way of distinguishing `"true"` from actual `1`s. To give some examples of why this works so weird:

1. Counting the amount of `"true"` in the list results in 0: try it online;
2. Trying to convert it to a flattened list of characters results in an error, since it cannot convert the `"false"` / `"true"` items: try it online;
3. Filtering on 05AB1E-truthy values will keep both the `1` and `"true"`: try it online or try it online;
4. Sorting (after the truthy filter) does work correct, although an additional group-by not: try it online;
5. etc.

Eventually I noticed the `þ` (keep all digits/numbers) and `á` (keep all letters/words) would correctly distinguish between the two, so I've used that to finish my program that utilizes Elixir-equations and evals:

```
á          # Keep all letters/words (which will only keep all "false" and "true")
 O         # Sum this list together, since they're 0 and 1 under the hood
           # (after which this count of "true" items is output implicitly as result)

```
> 2 votes

# Answer
# JavaScript (Node.js), 96 bytes

```
f=([c,...a],s='',g=t=>f(a,s+t))=>/\b0\d/.test(s+=c)?0:a+a?g`+`+g`-`+g`*`+g``+g`===`:eval(s)===!0

```

Try it online!

Unlike Arnauld who tests if exactly one `==` exist, I use `===`:

```
1             => 1
1===1         => true
1===1===1     => false
1===1===1===1 => false

```

so if it results in `true` it's an equation
> 1 votes

---
Tags: code-golf, math, equation
---