title: From Programming Puzzles to Code Golf

text:
# Question
Title: From Programming Puzzles to Code Golf
Your task is to write a program that outputs the *exact* string `Programming Puzzles` (trailing newline optional), but when all spaces, tabs, and newlines are removed it outputs `Code Golf` (trailing newline optional.)

Your byte count is the count of the first program, with spaces still there.

# Notes

* The spaces in `Code Golf` *and* `Programming Puzzles` will be removed as part of the removal, so plan accordingly.
* In encodings where 0x09, 0x0A and 0x20 aren't tabs, newlines or spaces respectively, those chars will be removed.
* If your code is

```
42  $@ rw$
@42

```

then that must output `Programming Puzzles`. Also, in the same language,

```
42$@rw$@42

```

must output `Code Golf`.

This is , so the shortest code in bytes wins! Good luck!

# Answer
# Python 2, 50 bytes

```
print["Code\40Golf","Programming Puzzles"][" ">""]

```

Try it online!

With all spaces removed:

```
print["Code\40Golf","ProgrammingPuzzles"]["">""]

```

Try that online!

Thanks to Stephen S for 3 bytes, and Erik the Outgolfer for 1
> 71 votes

# Answer
# Python 2, ~~48~~ 47 bytes

-1 byte thanks to Erik the Outgolfer

```
print' 'and'Programming Puzzles'or'Code\40Golf'

```

Try it online!

```
print''and'ProgrammingPuzzles'or'Code\40Golf'

```

Try it online!
> 59 votes

# Answer
# Jelly, 17 bytes

```
“Ñ1ɦ+£)G“½ċṭ6 Ỵ»Ṃ

```

Try it online!

### How it works

As in the other Jelly answer, `Ñ1ɦ+£)G` and `½ċṭ6Ỵ` encode the strings **Programming Puzzles** and **Code Golf**.  begins a string literal and separates one string form another, while `»` selects the kind of literal (dictionary-based compression), so this yields

```
["Programming Puzzles", "Code Golf"]

```

then takes the minimum, yielding **Code Golf**.

However, by adding a space between `½ċṭ6` and , we get a completely different second string, and the literal evaluates to

```
["Programming Puzzles", "caird coinheringaahing"]

```

Since **caird coinheringaahing** is lexicographically larger than **Programming Puzzles**,  selects the first string instead.
> 29 votes

# Answer
# C, ~~64~~ ~~62~~ ~~53~~ 52 bytes

```
f(){puts(*" "?"Programming Puzzles":"Code\40Golf");}

```

Try it Online!

Uses the fact that C strings end with a null character
> 26 votes

# Answer
# 05AB1E, 15 bytes

```
”ƒËŠˆ”" "v”–±ÇÀ

```

Try it online!

**Explanation**

```
”ƒËŠˆ”           # push "Code Golf"
      " "v       # for each character in the string " " do
          ”–±ÇÀ  # push "Programming Puzzles"
                 # implicitly output top of stack

```
> 22 votes

# Answer
# Jelly, 18 bytes

```
“½ċṭ6Ỵ»ḷ
“Ñ1ɦ+£)G»

```

Try it online!

## Explanation

In the program as written, the first line is a helper function that's never run. The second line (the last in the program) is the main program, and is the compressed representation of the string `"Programming Puzzles"` (which is then printed implicitly).

If you remove the newline, the whole thing becomes one large program. `“½ċṭ6Ỵ»` is the compressed representation of the string `"Code Golf"`.  evaluates but ignores its right hand argument, leaving the same value as before it ran; it can be used to evaluate functions for their side effects (something I've done before now), but it can also be used, as here, to effectively comment out code.

Interestingly, the actual logic here is shorter than the 05AB1E entry, but the code as a whole comes out longer because the string compressor is less good at compressing these particular strings.
> 16 votes

# Answer
# CJam, 38 bytes

```
" ""Programming Puzzles""Dpef!Hpmg":(?

```

Try it online! or with spaces removed

**Explanation**

```
" "                    e# Push this string.
"Programming Puzzles"  e# Push "Programming Puzzles".
"Dpef!Hpmg":(          e# Push "Dpef!Hpmg" and decrement each char, giving "Code Golf".
?                      e# If the first string is true (non-empty) return the second string,
                       e#   else return the third.

```

Whether spaces are in the program or not determines if the first string is truthy or falsy.
> 15 votes

# Answer
# Javascript, ~~46~~ ~~43~~ 42 Bytes

```
x=>" "?"Programming Puzzles":"Code\40Golf"

```

```
console.log((x=>" "?"Programming Puzzles":"Code\40Golf")())
console.log((x=>""?"ProgrammingPuzzles":"Code\40Golf")())
```
> 14 votes

# Answer
## Haskell, 48 bytes

```
a _="Programming Puzzles";a4="Code\32Golf";f=a 4
a_="ProgrammingPuzzles";a4="Code\32Golf";f=a4

```

Defines function `f` which returns the corresponding string.

For reference, the old version is:

### Haskell, 49/47 bytes

```
f""="Code\32Golf";f(_)="Programming Puzzles";f" "

```

with spaces removed

```
f""="Code\32Golf";f(_)="ProgrammingPuzzles";f""

```

Two simple pattern matches. `(_)` matches all patterns. You can improve the without-spaces version by one byte by defining the second pattern as `f" "=`/`f""=`, but this gives a "Pattern match is redundant" warning.

Alternative solution with the same byte count:

```
last$"Code\32Golf":["Programming Puzzles"|" ">""]
last$"Code\32Golf":["ProgrammingPuzzles"|"">""]

```
> 10 votes

# Answer
## Wolfram language, 62 bytes

```
"Programming Puzzles"[ToExpression@"\"Code\\.20Golf\""][[0 1]]

```

The space in `[[0 1]]` is implicit multiplication, so this is equivalent to `[[0]]`. Without a space, `01` is just `1`. The 0th and 1st parts of this expression are the strings we want.

Another solution of questionable validity (44 bytes, 2 saved by Kelly Lowder):

```
"Programming Puzzles"["Code\.20Golf"][[0 1]]

```

The `\.20` gets replaced by a space immediately when typed into a Mathematica environment, so it's not clear if it gets removed along with the other spaces…
> 10 votes

# Answer
## Excel - 56 Bytes

```
=IF(""=" ","Code"&CHAR(32)&"Golf","Programming Puzzles")

```

Very similar to most of the other answers... nothing fancy here.
> 7 votes

# Answer
# Ohm, ~~33~~ 32 bytes

Uses CP437 encoding.

```
▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀
▀4>~H├MS░l╬δ

```

Try it online! or try without whitespace

### Explanation

**With whitespace:**

```
▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀    Main wire

▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀    Push "Programming Puzzles" (compressed string)
                       Implicitly output the top stack element

▀4>~H├MS░l╬δ           Helper wire (never called)

```

**Without whitespace:**

```
▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀▀4>~H├MS░l╬δ    Main wire

▀Bn¬i≈╣Ü╝Rb╡°╧S½uÇ▀                Push "Programming Puzzles" (compressed string)
                   ▀4>~H├MS░l╬δ    Push "Code Golf" (compressed string)
                                   Implicitly output top stack element

```
> 6 votes

# Answer
# Japt, 29 bytes

With spaces:

```
`Co¸{S}Golf`r `PžgŸmÚÁ Puzz¤s

```

Try it online!

Without spaces:

```
`Co¸{S}Golf`r`PžgŸmÚÁPuzz¤s

```

Try it online!

---

This takes advantage of the fact that in Japt, a space closes a method call. With spaces, the code is roughly equivalent to this JavaScript code:

```
("Code"+(S)+"Golf").r(),"Programming Puzzles"

```

This is evaluated as JavaScript, and the result is sent to STDOUT. Since the last expression is `"Programming Puzzles"`, that string is printed.

Without spaces, the code is roughly equivalent to:

```
("Code"+(S)+"Golf").r("ProgrammingPuzzles")

```

(If you haven't figured it out by now, the `S` variable is a single space.) The `.r()` method on a string, if given one argument, removes all instances of that argument from the string. Since `"Code Golf"` does not contain `"ProgrammingPuzzles"`, it returns `"Code Golf"` unchanged, which is then sent to STDOUT.
> 6 votes

# Answer
# Brachylog, 44 bytes

```
" "Ṣ∧"Programming Puzzles"w|"Code"wṢw"Golf"w

```

Try it online!

### Explanation

```
" "Ṣ                                           If " " = Ṣ (which is itself " ")
    ∧"Programming Puzzles"w                    Write "Programming Puzzles"
                           |                   Else
                            "Code"w            Write "Code"
                                   Ṣw          Write " "
                                     "Golf"w   Write "Golf"

```
> 5 votes

# Answer
## Alice, 44 bytes

```
/"floG!"t"edoC"#
 /"selzzuP gnimmargorP"d&o@

```

Try it online!

Without whitespace:

```
/"floG!"t"edoC"#/"selzzuPgnimmargorP"d&o@

```

Try it online!

### Explanation

In the first program, the two mirrors `/` redirect the instruction pointer onto the second line. `"selzzuP gnimmargorP"` pushes the required code points in revere order, `d` pushes the stack depth and `&o` prints that many bytes. `@` terminates the program.

Without the whitespace, the program is all on a single line. In that case, the instruction pointer can't move in Ordinal mode, so the `/` effectively become no-ops (technically, the IP simply doesn't move for one step, the same `/` gets executed again, and the IP reflects back to Cardinal mode). So if we drop those from the program, it looks like this:

```
"floG!"t"edoC"#"selzzuPgnimmargorP"d&o@

```

To include the space in `Code Golf`, we use an exclamation mark instead and decrement it with `t`. After we've got all the code points on the stack, `#` skips the next command, which is the entire second string. `d&o` then prints the stack again, and `@` terminates the program.
> 5 votes

# Answer
# PHP, 44 Bytes

ternary operator

```
<?=" "?"Programming Puzzles":"Code\x20Golf";

```

## PHP, 51 Bytes

comment

```
<?=/** /"Code\x20Golf"/*/"Programming Puzzles"/**/;

```

## PHP, 57 Bytes

array switch

```
<?=["Code\x20Golf","Programming Puzzles"][(ord("
")/10)];

```
> 4 votes

# Answer
# Common Lisp (SBCL), 52 bytes

```
(format`,t"~[Programming Puzzles~;Code~@TGolf~]"0 1)

```

Prints `Programming Puzzles`

```
(format`,t"~[ProgrammingPuzzles~;Code~@TGolf~]"01)

```

Prints `Code Golf`

Ungolfed:

```
(format t "~[Programming Puzzles~;Code Golf~]" 0 1)

```

Explaination:

The trick basically comes from how `#'format` works in Common Lisp.

In CL, most whitespace can be omitted provided that there is no ambiguity about where tokens start or end. The first trick was separating the `format` and `t` symbols. I had to unambiguously end the `format` symbol without changing how `t` was interpreted. Luckily, \` in CL ends the preceding token before it gets processed, and `,` cancels the effect of \` (\` is used to implement templating, where the next expression following it gets "quoted", but any sub-expression prefixed with a `,` is evaluated and the result included in the template, so \`, is nearly a no-op).

The third argument to `format` is the template string. `format` is similar to printf in C, but has much more powerful formatting directives and use ~ to indicate them instead of %. ~\[ and ~\] allow you to select between multiple options for printing, with ~; separating them. An additional argument is supplied to format- the numeric index of which one you want printed. In order to ensure that the " " in Code Golf survives, I used the tabulation directive ~T, which is used to insert whitespace, generally to align text into columns. ~@T is a variation which just inserts a given number of spaces, defaulting to 1.

Finally, there are two arguments to format- 0 and 1. Before whitespace is removed, the 0 is used by ~\[~;~\] to select "Programming Puzzles" and the extra format argument (the 1) is dropped (I'm not sure how standard dropping extra format arguments is, but this works on Steel Bank Common Lisp). After whitespace is removed, there is only one argument (01) which selects "Code Golf" instead.
> 4 votes

# Answer
# Perl 5, ~~43~~ 41 bytes

```
say" "?"Programming Puzzles":Code.$".Golf

```

Try it online!

Uses the fact that `' '` is true in perl and `''` is false. The `$"` variable is set to a space by default.

Thanks to @NahuelFouilleul for removing two bytes.
> 4 votes

# Answer
# C# ~~88~~ ~~81~~ ~~70~~ 63 bytes

```
Func<string>@a=()=>" "==""?"Code\x20Golf":"Programming Puzzles";

```

With whitespace stripped:

```
Func<string>@a=()=>""==""?"Code\x20Golf":"ProgrammingPuzzles";

```

Thanks to BrianJ for showing me how to have no space between a method return type and the method name, PeterTaylor for saving ~~7~~ 18 bytes, and Patrick Huizinga for saving 7 bytes.

Same method as everyone else really, ~~technically this could be considered invalid because the method doesn't specify a return type for the method, but there *has* to be whitespace between the return type and the method name.~~
> 3 votes

# Answer
# R, 50 bytes

I think this is the same as this Javascript answer, and basically the same idea as all the others.

```
`if`(' '=='','Code\x20Golf','Programming Puzzles')

```
> 3 votes

# Answer
# Pyth, 37 bytes

```
?" ""Programming Puzzles""Code\40Golf

```

Try it here.

```
?"""ProgrammingPuzzles""Code\40Golf

```

Try it here.
> 3 votes

# Answer
# \>\<\>, ~~47~~ 45 bytes

```
! v"floG!"1-"edoC"!
o<>"selzzuP gnimmargorP">

```

Try it online!

*Thanks to randomra for -2 (clever two `!`s so that I can use only one `>o<`.)*

The code shouts "Flog! Flog! Flog!" and resembes a fish.
> 3 votes

# Answer
# dc, 50

```
[pq]sm[Programming Puzzles]dZ19=m[Code]n32P[Golf]p

```

Try it online.

`[ ]` defines a string - `Z` measures its length. If the length is 19 then it contains a space and the macro stored in the m register is called, which prints `Programming Puzzles` and quits. Otherwise `Code Golf` is printed.
> 3 votes

# Answer
# \>\<\>, 42 bytes

With whitespace

```
\"floG"48*"edoC"
/>o<"Programming Puzzles"

```

Try it online!

Without whitespace

```
\"floG"48*"edoC"/>o<"ProgrammingPuzzles"

```

Try it online!
> 3 votes

# Answer
# Java 8, ~~74~~ ~~50~~ 48 bytes

```
()=>" "==""?"Code\040Golf":"Programming Puzzles"

```
> 3 votes

# Answer
# Befunge, 47 bytes

```
# <"floG"84*"edoC">:#,_@#" Programming Puzzles"

```

Try it Online

Without spaces it skip the first \< and prints Code Golf instead
> 3 votes

# Answer
# APL (Dyalog Unicode), ~~₄₅~~ ~~₄₁~~ 39 bytesSBCS

Anonymous lambda. Takes dummy argument.

```
{'Programming Puzzles'
⊢4⌽9↑'GolfCode'}

```

Try it online!

This function is a so called "dfn" which terminates with and returns the first non-assignment, i.e. `Programming Puzzles`.

Removing all whitespace gives:

```
{'ProgrammingPuzzles'⊢4⌽9↑'GolfCode'}

```

Try it online!

This takes the last nine characters of `GolfCode` thus padding with a trailing space, then cyclically rotates that 4 steps to the left.  ignores the text on its left and returns the text on its right.
> 3 votes

# Answer
# Python 3, ~~**72**~~ **68 bytes**

Had output backwards at first, thanks Draco18s, then saved 4 bytes, thanks Jo King

```
a=0;ab="Programming";a
b="Code";ad="Puzzles";a
d="Golf";print(ab,ad)

```

Try it online!
> 3 votes

# Answer
# Japt, 32 bytes

```
" "?`PžgŸmÚÁ Puzz¤s`:`Co¸{S}Golf

```

Try it online!
> 2 votes

# Answer
# PowerShell, 56 bytes

```
('Programming Puzzles',('Code'+[char]32+'Golf'))[!(' ')]

```

Try it online!

Pretty basic I would say, but it gets the job done
> 2 votes

# Answer
**PowerShell, 54 bytes**

```
"$((('Programming','Puzzles'),('Code','Golf'))[!' '])"

```

Try it online!

Without spaces

```
"$((('Programming','Puzzles'),('Code','Golf'))[!''])"

```

Try it online!
> 2 votes

# Answer
# T-SQL, ~~96~~ ~~82~~ ~~81~~ 67 bytes

```
print+iif(len(' x')=2,'Programming Puzzles','Code'+char(32)+'Golf')

```

**Try it online** | **Without spaces**

Old version (96 bytes):

```
select(case'x'when(replace(' ',' ','x'))then'Programming Puzzles'else'Code'+nchar(32)+'Golf'end)

```
> 2 votes

# Answer
# MATL, ~~39~~ 37 bytes

*Thanks to @Sanchises for removing 2 bytes*.

```
'Dpef!Hpmg'qc%
'Programming puzzles'&

```

Try it online!

## Explanation

### With spaces

`'Dpef!Hpmg'` pushes this string.

`q` substracts `1` from each code point, and `c` converts back to characters. This produces the string `'Code Golf'`.

`%` is the comment symbol. The rest of the line (which is empty) is ignored.

`'Programming puzzles'` pushes this string.

`&` specifies that the display function, which is implicitly called at the end of the program, must only print the top of the stack (instead of the whole stack). So the second string is printed.

### Without spaces

`'Dpef!Hpmg'` pushes this string.

`q` substracts `1` from each code point, and `c` converts back to characters. This produces the string `'Code Golf'`.

`%` is the comment symbol. The rest of the line (that is, the rest of the code) is ignored.

At the end of the program the implicit display function is called, which prints the string.
> 2 votes

# Answer
# Haskell, 42 bytes

Simple comment abuse. (Hm, seems to confuse the syntax coloring too.)

```
{-- }"Code\SPGolf"--}"Programming Puzzles"

```
* With the spaces `{-- }"Code\SPGolf"--}` is a bracketed comment. Try it online!
* Without the spaces `{--}` is a bracketed comment and `--}"ProgrammingPuzzles"` an end of line comment. Try it online!
> 2 votes

# Answer
# Pushy, 47 bytes

```
`Dpef!Hpmg `KtkL9=?";
\
c`Programming Puzzles`"

```

**Try it online!**

In its initial form, the top line adds the string "Code Golf" to stack, but with each character incremented, and a trailing space. It then decrements each character and checks if the length is 9 - however, as there is a trailing space, the length is 10, so the conditional is not entered. Therefore the top line is essential a no-op. The third line then prints "Programming Puzzles".

After modification, the program looks like this:

```
`Dpef!Hpmg`KtkL9=?";\c`Programming Puzzles`"

```

The `\` starts a comment therefore the only relevant code is the first half, which gets the string "Code Golf", checks its length (which is now correctly 9 as the space has been removed), and then prints it accordingly.
> 2 votes

# Answer
# Kotlin, 62 bytes

Lambda returning a string.

```
{" ".ifEmpty{"Code\u0020Golf"}.ifBlank{"Programming Puzzles"}}

```

1.3 introduced `ifEmpty` and `ifBlank` which each take a lambda and return its result if the receiving string is empty or contains only whitespace. If the condition fails, the receiving string is passed on instead.

So, if the spaces are removed, then the `ifEmpty` check passes and the `ifBlank` check fails. The reverse is true if the spaces are left.

Try it online!
> 2 votes

# Answer
# MathGolf, 34 bytes

```
╕│Çÿgolf]ûq¶$╦ÿming+û£q$╦α ?;;δ♥$u

```

Try it online!

## Explanation

The code contains only one single space. With it, the stack contains `[['code', 'golf'], ['programming', 'puzzles'], ' ']` when the `?` is reached, otherwise it just contains the two lists. The `?`rotates the top three elements, and implicitly pushes a 0 to the stack when only two elements are on the stack. This means that the order of the elements is different after the `?` depending on if the space is present. It could be shorter by using the non-breaking space character, which is the "discard everything but TOS" operator, but I don't know if that is allowed.

```
╕│Çÿgolf]                                   Push ['code', 'golf']
         ûq¶$╦ÿming+û£q$╦α                  Push ['programming', 'puzzles']
                           ?                Push a space and rotate top 3 stack elements
                            ;;              Discard top two elements
                              δ             Capitalize string
                               ♥$u          Join with spaces

```
> 2 votes

# Answer
# SmileBASIC, 49 bytes

```
TABSTEP=5?"Code","Golf"'
CLS?"Programming Puzzles

```

At first I was afraid I'd need to use `CHR$(32)` to for the space in "Code Golf". Fortunately, I can save exactly 0 characters using commas and TABSTEP.
> 2 votes

# Answer
# bash, 51 bytes

```
(echo Programming Puzzles||dd<<<$'Code\40Golf')2>&-

```

TIO
> 2 votes

# Answer
# Befunge-98 (FBBI), 46 bytes

```
"floG edoCselzzuP gnimmargorP"f3+40# $j$k$8k,@

```

Try it online!

# Explanation:

```
"floG edoCselzzuP gnimmargorP" ¤ Put "Code Golf" and "Programming Puzzles" into
                                 the stack, character by character,
                                 so that "Programming Puzzles" is on top of the stack.
f3+40                          ¤ Push 18, then 4, then 0 to the stack.
     # $                       ¤ With space: Jump over the whitespace and pop the 0.
        j$k$8                    Jump over the 4 next instructions.
             k,@                 Print the 18 top chars from the stack and exit.

```

---

```
     #$                        ¤ Without space: Jump over the `$` instruction,
       j                         Jump over the next 0 instructions.
        $                        Pop 4 from the stack.
         k$                      Pop the top 18 chars from the stack.
           8k,@                  Print out the 8 top chars from the stack and exit.

```
> 2 votes

# Answer
# Wren, 62 bytes

```
System.write(" ".count>0?"Programming Puzzles":"Code\x20Golf")

```

Try it online!

## Explanation

```
System.write(                                                ) // Output
             " ".count>0                                       // Whether the length of this string is larger than 0
                        ?"Programming Puzzles"                 // If true, output "Programming Puzzles"
                                              :"Code\x20Golf"  // Otherwise, output "Code Golf"

```

# Wren, 71 bytes

```
System.write(Num.fromString("0 0")?"Code\x20Golf":"Programming Puzzles")

```

Try it online!

## Explanation

```
System.write(                                                          ) // Output
             Num.fromString("0 0")                                       // Whether converting to a single number is successful
                                                                         // If this isn't successful, it outputs null, which is a false value.
                                  ?"Code\x20Golf"                        // If this is successful, output "Code Golf"
                                                 :"Programming Puzzles"  // Otherwise, output "Programming Puzzles"

```
> 2 votes

# Answer
# c, 73 bytes

With whitespace:

```
main(){printf("%s\n",atoi("- 1")?"Code\x20Golf":"Programming Puzzles");}

```

Without whitespace:

```
main(){printf("%s\n",atoi("-1")?"Code\x20Golf":"Programming Puzzles");}

```
> 2 votes

# Answer
# Zsh, 45 bytes

```
\ ;<<<Programming\ Puzzles||<<<Code$'\40'Golf

```

Try it online!

With spaces:

* `\` : execute the command , (which doesn't exist so does nothing)
* `;`: then
* `<<<Programming\ Puzzles`: print `Programming Puzzles`
* `||` if that fails (which is never does, because printing is always successful):
    + `<<<Code$'\40'Golf`: print `Code Golf` (this doesn't get executed)

Without spaces:

* `\;`: execute the command `;` (which doesn't exist so does nothing with its input)
* `<<<Programming\Puzzles`: and send `;` the input `ProgrammingPuzzles` (which it discards, since it doesn't do anything)
* `||` if that fails (which it always does, since `;` is not a defined command):
    + `<<<Code$'\40'Golf`: print `Code Golf` (`$'\40'` is a space, written with an octal escape)
> 2 votes

# Answer
# Vyxal, 20 bytes

```
` `[`↔ḃ ₄∩`|`¬꘍»₆`½Ṅ

```

Try it Online! and TryitOnline!

## How it works

* `` `` is a string with one space, a truthy value. When spaces are removed, it becomes the empty string ````, which is falsy.
* `[...|...]` is an conditional statement. If the top of the stack is truthy, the first part is executed, otherwise the second part.
    + If true (spaces are not removed): ``↔ḃ ₄∩``, the compressed string ``Programming Puzzles``, is pushed and output
    + Otherwise: ``¬꘍»₆``, the compressed string ``CodeGolf``, is pushed. `½` splits it into the list `⟨`Code`|`Golf`⟩`, which is then joined by spaces with  and implicitly printed.

---

### Vyxal, 21 bytes, for the new site name

Additionally, here is a 21-byte solution for the new site name - Code Golf and Coding Challenges:

```
` `[`¬꘍ »₆`|`⟩₆,→ṗ`⌐Ṅ

```

Try it Online! and TryitOnline!

It works similarly, using `⌐Ṅ` to replace the comma in compressed `Coding,Challenges` with a space.
> 2 votes

# Answer
# GolfScript, 38 bytes

```
" ""Programming Puzzles""Code\sGolf"if

```

Try it online!
> 1 votes

# Answer
# Befunge, 76 bytes

```
" "0`#v_"floG"84*"edoC",,,,,,,,,@
,,,,,@>"selzzuP gnimmargorP",,,,,,,,,,,,,,

```

Try it online!

Not the most compact solution, but then again writing Befunge code without whitespace is pretty difficult.

At the very beginning, it compares a space character with 0. If it's greater, it goes to the bottom row. If it isn't, which is what happens when you replace space with nothing, it stays on the first row.
> 1 votes

# Answer
# Pyth, 36 bytes

```
J
"Programming Puzzles" "Code\40Golf

```

Try it online: with or without whitespace characters

That's a nice challenge for Pyth.

In the above code the newline prints `Programming Puzzles` and the space suppresses the output of `Code Golf`. `J` only assigns the first string to the variable `J`, but doesn't print anything.

After removing the newline and the spaces, the first string doesn't get printed (only assigned), but the second string gets printed implicitly.
> 1 votes

# Answer
# Ruby, 46 bytes

```
puts' '[0]?'Programming Puzzles':"Code\40Golf"

```
> 1 votes

# Answer
# Braingolf, 53 bytes \[non-competing\]

**Holy crap I did it**

```
48*# 1+-?"Programming Puzzles"@19%"Code"1#!-"Golf"@9|

```

So the issue with Braingolf is that the only conditional it has is an "is the last number on the stack greater than 0?" check, which makes this kinda challenge a little tricky, but I persevered and here it is!

Non-competing because the language was created after the date of the challenge

Explanation: Whitespace version:

```
48*                                                    Push the int literals 4 and 8 to the stack, then multiply them together, consuming both and adding the result to the stack (32)
   #<space>                                            Add the charcode of the literal char <space> to the stack, which also happens to be 32
     1+                                                Push int literal 1 to the stack, then add together the last 2 elements of the stack (1 and 32)
       -                                               Subtract the last 2 elements of the stack from each other (33 - 32)
        ?                                              Check if the last element on the stack is greater than 0, 33-32 is 1, so it is (this also consumes the checked number from the stack)
         "Programming Puzzles"                         Add the charcodes for the string "Programming Puzzles" to the stack
                              @19                      Print the last 19 elements of the stack as chars
                                 %                     Else, nothing after this will run, as the ? returned true
                                  "Code"               Push the charcodes for the string "Code" to the stack
                                        1#!-           Push the literal int 1 and the charcode for the character '!' (33) to the stack, then subtract one from the other (33 - 1 = 32, the charcode for a space)
                                            "Golf"     Push the charcodes for the string "Golf" to the stack
                                                  @9   Print the last 9 elements of the stack as characters
                                                    |  End if-else, at this point Braingolf would normally output the last element of the stack, as there is no semicolon in the program, however the stack is empty, so it doesn't.

```

No whitespace version (only the important part):

```
48*        Same as last time, push 4 and 8 to the stack, then multiply them to make 32
   #1      This time add the charcode for the character '1' to the stack (which is 49)
     +     Add the last 2 elements of the stack together (32 + 49 = 81)
      -    Subtract the last 2 elements of the stack from each other, however there is only 1 element in the stack (81) so subtract it from itself, 0
       ?   Is the last (only) element in the stack greater than 0? (no, it is 0)
           At this point the code skips every character up until the % else, and then runs from there to the end.

```
> 1 votes

# Answer
# Befunge-98, 51 bytes

```
]@,k9"Code"*84"Golf";
["selzzuP gnimmargorP">:#,_@;

```

Try it online!

The main idea here is to use the "turn right" operator (`]`) to check if there is a line below the first one. If there is, we print `selzzuP gnimmargorP` backwards. If the newline is removed, we turn right twice to go backwards on the top row. we use the `;`s to skip the "Programming Puzzles" code and print `Code Golf`.

I have other ideas about how to golf this whole thing (having to do with the fact that `ProgrammingPuzzles` is exactly twice as long as `Code Golf`) but I thought I would post a simple version first, considering my other one is in progress.
> 1 votes

# Answer
# Haskell, ~~67~~ 65 bytes

Even if it's longer than the one by @nimi, here's another Haskell solution, that works by abusing the `[]` Monad:

```
λ putStr$[s|s<-[" ">>"Programming Puzzles","Code\32Golf"],s/=""]!!0

  Programming Puzzles

```

Try it online!

```
λ putStr$[s|s<-["">>"Programming Puzzles","Code\32Golf"],s/=""]!!0

  Code Golf

```

Try it online!

Thanks @Laikoni for golfing off 2 bytes!
> 1 votes

# Answer
# Add++, 56 bytes

```
INy,x:" ",Ix,,O"Programming Puzzles",INx,,O"Code\40Golf"

```

Try it online!

Uses a very similar technique to a lot of answers, and has the pseudocode of

```
x = ' '
if x:
    print('Programming Puzzles')
else:
    print('Code Golf')

```

By removing all whitespace, we make `x` equal to the empty string, which is falsey in Add++. Therefore, we output `Code Golf` instead of `Programming Puzzles`. The space in `Code Golf` is simply the octal value \\$40\_8 = 32\_{10}\\$. The only unusual part is the preceding `INy,`. With this, we are able to put all our code on one line, as this is a **compound** statement. Without this, the programming, with whitespace, would look something like this:

```
x:" "
Ix,O"Programming Puzzles"
INx,O"Code\40Golf"

```

But, when you remove the whitespace from this, we cause syntax errors, as outside of compound statements, Add++ has no other line terminator than a newline.
> 1 votes

# Answer
# Ahead, 44 bytes

```
j ~"floG"32"edoC"~"selzzuP gnimmargorP"j~WW@

```

The first space is what's actually important. `j` will "jump over" the next cell in the head's direction; if the space is there it will be jumped over and the head will land on the first `~`, causing it to skip the section that pushes `Code Golf`. When the spaces are removed, the `~` will be jumped over and the first section will be entered instead.

Try it online!
> 1 votes

# Answer
# Keg, ~~35~~ 30 bytes

```
‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\ #ø¶[*;Golf

```

Without spaces:

```
‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\#ø¶[*;Golf

```

## Explained

```
‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\ #ø¶[*;Golf
‘∂⬭⑥⑷‘              #Push the string "Program"
       ¶C≬;Puzz0ɧ;¶     #Push the string "ing Puzzles"
                   \        #Escape the space and implicitly print

------------------------------------------------------------------------------

‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\#ø¶[*;Golf
‘∂⬭⑥⑷‘¶C≬;Puzz0ɧ;¶\#        #Everything as before, but this time:
                     ø      #Empty the stack
                      ¶[*;Golf  #Push the string "Code Golf" and print

```

Try it online!

## Answer History

### 35 bytes

```
`∂⬭;⑥⑷;`¶C≬;Puzz0ɧ;¶+\ #__¶[*;Golf¶

```

Real shifty string compression going on here! Try it online!
> 1 votes

# Answer
# Lua, 56 bytes

```
print((#' '>#'')and'Programming Puzzles'or'Code\32Golf')

```

Try it online!
> 1 votes

# Answer
# Zsh, 49 bytes

```
<<<${${:-ProgrammingPuzzles}/*gP*/$'Code\40Golf'}

```

Try it online!

With spaces (in fact, only one added):

```
<<<${${:-Programming Puzzles}/*gP*/$'Code\40Golf'}

```

Uses `${ /match/replacement}`, and executes it on any string containing `gP`.
> 1 votes

# Answer
# yash, 50 bytes

This is POSIX-compatible.

```
echo Programming Puzzles||echo${IFS}Code${IFS}Golf

```

## How it works

Like @NahuelFouilleul but using `IFS` variable instead.

Try it online!

Tryitonline!
> 1 votes

# Answer
## Ruby, 56 bytes

```
puts"Code\x20Golf"if(" "=="")#
puts"Programming Puzzles"

```

The second string literal should contain a tab.
> 0 votes

# Answer
# Microscript II, 45 bytes

```
" "("Programming Puzzles"ph)"Code"p32Kp"Golf"

```

Or, which is one byte longer:

```
' s#("Programming Puzzles"ph)"Code"p32Kp"Golf"

```
> 0 votes

# Answer
# Microscript, 48 bytes

```
' d32{"floG"z32s"edoC"ah}"selzzuP gnimmargorP"ah

```

Or, which is the same length:

```
" "#{o"selzzuP gnimmargorP"ah}"floG"z32s"edoC"ah

```

Or:

```
' s#{o"selzzuP gnimmargorP"ah}"floG"z32s"edoC"ah

```
> 0 votes

# Answer
# Braingolf, 44 bytes

```
" "?"Programming Puzzles":"Code"48*"Golf"|&@

```

Try it online!

With whitespace removed:

```
""?"ProgrammingPuzzles":"Code"48*"Golf"|&@

```

Try it online!

## Explanation

With whitespace:

```
" "                         push a space character
   ?                        if the last item on the stack > 0...
    "..."                   ...push the string "Programming Puzzles"
         :                  else...
          "..."             ...push the string "Code" and...
               48*          ...push 4 and 8 and multiply them and...
                  "..."     ...push the string "Golf"
                       |    end the conditional
                        &@  print all the characters on the stack

```

Without whitespace:

```
""                          push nothing
  ?                         if the last item on the stack > 0...
   "..."                    ...push the string "ProgrammingPuzzles"
        :                   else...
         "..."              ...push the string "Code" and...
              48*           ...push 4 and 8 and multiply them and...
                 "..."      ...push the string "Golf"
                      |     end the conditional
                       &@   print all the characters on the stack

```
> 0 votes

# Answer
# Pip, 37 bytes

```
"Programming Puzzles"  "Code0Golf"R0s

```

Try it online!

### Explanation

Comment abuse.

Anything following two spaces in Pip is a comment.\* So with the spaces, this is just the string expression `"Programming Puzzles"`, which is autoprinted. Without the spaces, the first expression doesn't do anything, and we instead autoprint `"Code0Golf"R0s`, which replaces the `0` in `Code0Golf` with a space.

My original idea, `' ?"Programming Puzzles""Code0Golf"R0s` (fun with character literals), was 1 byte longer.

<sub>* Spaces at the beginning of a line don't count.</sub>
> 0 votes

# Answer
# Petit Computer BASIC, 40 bytes

```
?"Code","Golf"'
CLS?"Programming Puzzles

```

The original program prints `Code Golf` and then clears the screen and prints `Programming Puzzles`. When whitespace is removed it becomes `?"Code","Golf"'CLS?"Programming Puzzles` (`'` starts a comment), so only `Code Golf` is printed.
> 0 votes

# Answer
# Pxem, filename: ~~47~~ 43 bytes.

```
  .zAaGolf.-Code.p.d.aProgramming Puzzles.p

```

## What it does

Branches with first two spaces.

Try it online!

Tryitonline!
> 0 votes

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


title: Divide Numbers by 0

text:
# Question
Title: Divide Numbers by 0
We've all been told at some point in our lives that dividing by 0 is impossible. And for the most part, that statement is true. But what if there *was* a way to perform the forbidden operation? Welcome to my newest creation: `b`-numbers.

`b`-numbers are a little bit like imaginary numbers: the main pronumeral involved represents an expression that isn't mathematically impossible (`i` represents \\$\sqrt{-1}\\$). In this case \\$b\\$ will be said to represent the expression \\$\frac{1}{0}\\$. From here, it is easy to determine what \\$\frac{x}{0}\\$ would equal:

$$ \frac{x}{0} = \frac{x}{1} \cdot \frac{1}{0} = xb $$

## The Task

Given an expression involving a division by 0, output the simplified value in terms of \\$b\\$. Note that input will be in the form of `n/0` where n is any rational number or any `b`-number in decimal form. Leading 0s and trailing 0s wont be included.

## Example Input

```
4/0
1/0
0/0
80/0
-8/0
1.5/0
2.03/0
-1/0
-3.14/0
b/0
3b/0
-b/0
121/0

```

## Example Output

```
4b
b
0
80b
-8b
1.5b
2.03b
-b
-3.14b
b
3b
-b
121b

```

# Score

This is code golf, so fewest bytes wins. Standard loopholes are forbidden.

## Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```
# Language Name, N bytes

```

where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:

```
# Ruby, <s>104</s> <s>101</s> 96 bytes

```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:

```
# Perl, 43 + 2 (-p flag) = 45 bytes

```

You can also make the language name a link which will then show up in the leaderboard snippet:

```
# [><>](http://esolangs.org/wiki/Fish), 121 bytes

```

```
var QUESTION_ID=191101;
var OVERRIDE_USER=8478;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(d,e){return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){answers.push.apply(answers,d.items),answers_hash=[],answer_ids=[],d.items.forEach(function(e){e.comments=[];var f=+e.share_link.match(/\d+/);answer_ids.push(f),answers_hash[f]=e}),d.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){d.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),d.has_more?getComments():more_answers?getAnswers():process()}})}getAnswers();var SCORE_REG=function(){var d=String.raw`h\d`,e=String.raw`\-?\d+\.?\d*`,f=String.raw`[^\n<>]*`,g=String.raw`<s>${f}</s>|<strike>${f}</strike>|<del>${f}</del>`,h=String.raw`[^\n\d<>]*`,j=String.raw`<[^\n<>]+>`;return new RegExp(String.raw`<${d}>`+String.raw`\s*([^\n,]*[^\s,]),.*?`+String.raw`(${e})`+String.raw`(?=`+String.raw`${h}`+String.raw`(?:(?:${g}|${j})${h})*`+String.raw`</${d}>`+String.raw`)`)}(),OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(d){return d.owner.display_name}function process(){var d=[];answers.forEach(function(n){var o=n.body;n.comments.forEach(function(q){OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>")});var p=o.match(SCORE_REG);p&&d.push({user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link})}),d.sort(function(n,o){var p=n.size,q=o.size;return p-q});var e={},f=1,g=null,h=1;d.forEach(function(n){n.size!=g&&(h=f),g=n.size,++f;var o=jQuery("#answer-template").html();o=o.replace("{{PLACE}}",h+".").replace("{{NAME}}",n.user).replace("{{LANGUAGE}}",n.language).replace("{{SIZE}}",n.size).replace("{{LINK}}",n.link),o=jQuery(o),jQuery("#answers").append(o);var p=n.language;p=jQuery("<i>"+n.language+"</i>").text().toLowerCase(),e[p]=e[p]||{lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p}});var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o){return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0});for(var l=0;l<j.length;++l){var m=jQuery("#language-template").html(),k=j[l];m=m.replace("{{LANGUAGE}}",k.lang).replace("{{NAME}}",k.user).replace("{{SIZE}}",k.size).replace("{{LINK}}",k.link),m=jQuery(m),jQuery("#languages").append(m)}}
```

```
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
```

```
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table>
```

# Answer
# Malbolge Unshackled (20-trit rotation variant), 3,62e6 bytes

Size of this answer exceeds maximum postable program size (eh), so the code is located in my GitHub repository (note: Don't copy the code using CTRL+A and CTRL+C, just rightclick and click "Save destination element as...").

## How to run this?

This might be a tricky part, because naive Haskell interpreter will take ages upon ages to run this. TIO has decent Malbogle Unshackled interpreter, but sadly I won't be able to use it (limitations).

The best one I could find is the fixed 20-trit rotation width variant, that performs very well, **calculating (pretty much) instantly**.

To make the interpreter a bit faster, I've removed all the checks from Matthias Lutter's Malbolge Unshackled interpreter.

```
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* translation = "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72Fh"
        "OA1CB6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@";

typedef struct Word {
    unsigned int area;
    unsigned int high;
    unsigned int low;
} Word;

void word2string(Word w, char* s, int min_length) {
    if (!s) return;
    if (min_length < 1) min_length = 1;
    if (min_length > 20) min_length = 20;
    s[0] = (w.area%3) + '0';
    s[1] = 't';
    char tmp[20];
    int i;
    for (i=0;i<10;i++) {
        tmp[19-i] = (w.low % 3) + '0';
        w.low /= 3;
    }
    for (i=0;i<10;i++) {
        tmp[9-i] = (w.high % 3) + '0';
        w.high /= 3;
    }
    i = 0;
    while (tmp[i] == s[0] && i < 20 - min_length) i++;
    int j = 2;
    while (i < 20) {
        s[j] = tmp[i];
        i++;
        j++;
    }
    s[j] = 0;
}

unsigned int crazy_low(unsigned int a, unsigned int d){
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    int position = 0;
    unsigned int output = 0;
    while (position < 10){
        unsigned int i = a%3;
        unsigned int j = d%3;
        unsigned int out = crz[i+3*j];
        unsigned int multiple = 1;
        int k;
        for (k=0;k<position;k++)
            multiple *= 3;
        output += multiple*out;
        a /= 3;
        d /= 3;
        position++;
    }
    return output;
}

Word zero() {
    Word result = {0, 0, 0};
    return result;
}

Word increment(Word d) {
    d.low++;
    if (d.low >= 59049) {
        d.low = 0;
        d.high++;
        if (d.high >= 59049) {
            fprintf(stderr,"error: overflow\n");
            exit(1);
        }
    }
    return d;
}

Word decrement(Word d) {
    if (d.low == 0) {
        d.low = 59048;
        d.high--;
    }else{
        d.low--;
    }
    return d;
}

Word crazy(Word a, Word d){
    Word output;
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    output.area = crz[a.area+3*d.area];
    output.high = crazy_low(a.high, d.high);
    output.low = crazy_low(a.low, d.low);
    return output;
}

Word rotate_r(Word d){
    unsigned int carry_h = d.high%3;
    unsigned int carry_l = d.low%3;
    d.high = 19683 * carry_l + d.high / 3;
    d.low = 19683 * carry_h + d.low / 3;
    return d;
}

// last_initialized: if set, use to fill newly generated memory with preinitial values...
Word* ptr_to(Word** mem[], Word d, unsigned int last_initialized) {
    if ((mem[d.area])[d.high]) {
        return &(((mem[d.area])[d.high])[d.low]);
    }
    (mem[d.area])[d.high] = (Word*)malloc(59049 * sizeof(Word));
    if (!(mem[d.area])[d.high]) {
        fprintf(stderr,"error: out of memory.\n");
        exit(1);
    }
    if (last_initialized) {
        Word repitition[6];
        repitition[(last_initialized-1) % 6] =
                ((mem[0])[(last_initialized-1) / 59049])
                    [(last_initialized-1) % 59049];
        repitition[(last_initialized) % 6] =
                ((mem[0])[last_initialized / 59049])
                    [last_initialized % 59049];
        unsigned int i;
        for (i=0;i<6;i++) {
            repitition[(last_initialized+1+i) % 6] =
                    crazy(repitition[(last_initialized+i) % 6],
                        repitition[(last_initialized-1+i) % 6]);
        }
        unsigned int offset = (59049*d.high) % 6;
        i = 0;
        while (1){
            ((mem[d.area])[d.high])[i] = repitition[(i+offset)%6];
            if (i == 59048) {
                break;
            }
            i++;
        }
    }
    return &(((mem[d.area])[d.high])[d.low]);
}

unsigned int get_instruction(Word** mem[], Word c,
        unsigned int last_initialized,
        int ignore_invalid) {
    Word* instr = ptr_to(mem, c, last_initialized);
    unsigned int instruction = instr->low;
    instruction = (instruction+c.low + 59049 * c.high
            + (c.area==1?52:(c.area==2?10:0)))%94;
    return instruction;
}

int main(int argc, char* argv[]) {
    Word** memory[3];
    int i,j;
    for (i=0; i<3; i++) {
        memory[i] = (Word**)malloc(59049 * sizeof(Word*));
        if (!memory) {
            fprintf(stderr,"not enough memory.\n");
            return 1;
        }
        for (j=0; j<59049; j++) {
            (memory[i])[j] = 0;
        }
    }
    Word a, c, d;
    unsigned int result;
    FILE* file;
    if (argc < 2) {
        // read program code from STDIN
        file = stdin;
    }else{
        file = fopen(argv[1],"rb");
    }
    if (file == NULL) {
        fprintf(stderr, "File not found: %s\n",argv[1]);
        return 1;
    }
    a = zero();
    c = zero();
    d = zero();
    result = 0;
    while (!feof(file)){
        unsigned int instr;
        Word* cell = ptr_to(memory, d, 0);
        (*cell) = zero();
        result = fread(&cell->low,1,1,file);
        if (result > 1)
            return 1;
        if (result == 0 || cell->low == 0x1a || cell->low == 0x04)
            break;
        instr = (cell->low + d.low + 59049*d.high)%94;
        if (cell->low == ' ' || cell->low == '\t' || cell->low == '\r'
                || cell->low == '\n');
        else if (cell->low >= 33 && cell->low < 127 &&
                (instr == 4 || instr == 5 || instr == 23 || instr == 39
                    || instr == 40 || instr == 62 || instr == 68
                    || instr == 81)) {
            d = increment(d);
        }
    }
    if (file != stdin) {
        fclose(file);
    }
    unsigned int last_initialized = 0;
    while (1){
        *ptr_to(memory, d, 0) = crazy(*ptr_to(memory, decrement(d), 0),
                *ptr_to(memory, decrement(decrement(d)), 0));
        last_initialized = d.low + 59049*d.high;
        if (d.low == 59048) {
            break;
        }
        d = increment(d);
    }
    d = zero();

    unsigned int step = 0;
    while (1) {
        unsigned int instruction = get_instruction(memory, c,
                last_initialized, 0);
        step++;
        switch (instruction){
            case 4:
                c = *ptr_to(memory,d,last_initialized);
                break;
            case 5:
                if (!a.area) {
                    printf("%c",(char)(a.low + 59049*a.high));
                }else if (a.area == 2 && a.low == 59047
                        && a.high == 59048) {
                    printf("\n");
                }
                break;
            case 23:
                a = zero();
                a.low = getchar();
                if (a.low == EOF) {
                    a.low = 59048;
                    a.high = 59048;
                    a.area = 2;
                }else if (a.low == '\n'){
                    a.low = 59047;
                    a.high = 59048;
                    a.area = 2;
                }
                break;
            case 39:
                a = (*ptr_to(memory,d,last_initialized)
                        = rotate_r(*ptr_to(memory,d,last_initialized)));
                break;
            case 40:
                d = *ptr_to(memory,d,last_initialized);
                break;
            case 62:
                a = (*ptr_to(memory,d,last_initialized)
                        = crazy(a, *ptr_to(memory,d,last_initialized)));
                break;
            case 81:
                return 0;
            case 68:
            default:
                break;
        }

        Word* mem_c = ptr_to(memory, c, last_initialized);
        mem_c->low = translation[mem_c->low - 33];

        c = increment(c);
        d = increment(d);
    }
    return 0;
}

```

## It's working!
> 28 votes

# Answer
# PHP, ~~65~~ ~~64~~ ~~61~~ 58 bytes

-1 byte by using a `b` instead of `''` (empty string). Since "b"s are trimmed, it will be same as an empty string in this specific case.

-3 bytes by using `substr` instead of `explode` to get first part of input.

-3 bytes by using better methods to detect `1` and `-1`.

```
<?=($n=substr($argn,0,-2))?trim($n+1?$n-1?$n:b:'-',b).b:0;

```

Try it online!

Tests: Try it online!

If first part of input before "/" (we call it `$n`) is 0, prints 0.

Else prints `$n` itself with any "b" at the end trimmed from it and special cases of -1 and 1 handled, so the "1" digit is not printed. And at the end appends a single "b". The trimming part is to make sure we don't get a double "b" at the end like "3bb".
> 9 votes

# Answer
# Perl 6, 32 bytes

```
{~m/^0/||S/[(\-|^)1|b]?\/0/$0b/}

```

Try it online!

A couple of regexes, one to check if the input is `0/0`, and the other to replace the trailing `/0` with just `b` (and to remove the old `b`, `1`, and/or `-1`)

### Explanation (old)

```
{                          }  # Anonymous codeblock
 ~m/^0/     # Return 0 if the input starts with 0
       ||   # Otherwise
         S/             / /  # Substitute
                     \/0       # The /0
          (        )?          # Optionally starting with
           <wb>1               # 1 or -1
                |b             # Or b
                         b   # With just b

```
> 5 votes

# Answer
# Jelly, 18 bytes

I ended up stealing Erik's `ṾṖ$İƑ¡` for this one (otherwise I'd also have 19)...

```
ṖṖv0ḢṾṖ$İƑ¡,Ạ¡”boḢ

```

A full program which prints the result.

**Try it online!** Or see the test-suite.

### How?

```
ṖṖv0ḢṾṖ$İƑ¡,Ạ¡”boḢ - Main Link: list of characters S
Ṗ                  - discard right-most (of S)
 Ṗ                 - discard right-most
   0               - literal zero
  v                - evaluate as Jelly code with right argument (0)
                   - ... b is covert-to-base, so "nb0" gives [n]
    Ḣ              - head ([n]->n or n->n)
          ¡        - repeat...
         Ƒ         - ...# of times: is invariant under:
        İ          -   reciprocation (n->1/n)
       $           - ...action: last two links as a monad:
     Ṿ             -   un-evaluate (-1->"-1" or 1->"1")
      Ṗ            -   discard right-most ("-1"->"-" or "1"->"")
             ¡     - repeat...
            Ạ      - ...# of times: all?
           ,  ”b   - ...action: pair with a 'b' character
                o  - logical OR with:
                 Ḣ -   head (S)  (i.e. if we end with 0 use the 1st character of the input)
                   - implicit print

```
> 5 votes

# Answer
# Retina, ~~28~~ 24 bytes

```
b?/0
b
^0b
0
(^|-)1b
$1b

```

Try it online!

First try at using Retina, so there's probably considerable room for golfing.
> 3 votes

# Answer
# Jelly, 19 bytes

```
ṖṖḟ”bȯ1VṾṖ$İƑ¡,Ạ¡”b

```

Try it online!

Full program.
> 3 votes

# Answer
# convey, 47 bytes

```
['b'}
 >>~^]] '-'[
 91+>##"@]
{?~""@@<}
 ]11-^}

```

Try it online!

I would like to put off the space betwen the number and 'b' in the output but i dont know how to do it :(

How it works (-3/0):

How it works (1/0):
> 3 votes

# Answer
# Python 3.8 (pre-release), ~~69~~ 66 bytes / ~~73~~ 70 bytes

Python already had a solution here but it didn't work properly on `-1/0`. That solution also uses regex while this one is vanilla python.

## Lambda version (66 bytes)

```
lambda x:{"0":0,"1":"b","-1":"-b"}.get(a:=x[:-2].strip("b"),a+"b")

```

Try it online!

## Print version (70 bytes)

```
print({"0":0,"1":"b","-1":"-b"}.get(a:=input()[:-2].strip("b"),a+"b"))

```

Try it online!

## How it works :

starting from a string `x`:

* `x[:-2]` remove the `/0` part
* `.strip("b")` remove any eventual `b` present in the string
* `a:=` store our new string into `a`

Then we check if our new sring is equal to any `"0"`, `"1"` or `"-1"`:

* if True, `{...}.get()` will replace it by the appropriate string
* else, we will print it inchanged adding `"b"` at the end of the string

Thanks to ovs for reminding me that `str.strip` existed saving 3 bytes on each program
> 3 votes

# Answer
## Keg, 18B

All credit is to Jono 2906.

```
__:b=;[b]^:\1=[_]^

```

## Explanation

```
__                 # Take implicit input and remove the "trash" (/0).
  :b=              # Is the last character equal to b?
     ;             # Negate(decrement) this value.
      [b]          # If the last character is not b, append b.
         ^         # Reverse the stack.
          :\1=     # Is the first character equal to 1?
              [_]  # If so, reduce the value.
                 ^ # Reverse the stack back and implicit output.

```

TIO!
> 2 votes

# Answer
# Python 3, 68 bytes

```
import re
print(re.sub('^0b$','0',re.sub(r'(^1)?b?/0','b',input())))

```

Try it online!
> 2 votes

# Answer
# JavaScript (ES6), 45 bytes

```
s=>+(n=s.split`/`[0])?[n*n-1?n:'-'[~n]]+'b':n

```

Try it online!

### Commented

```
s =>                  // s = input: "numerator/0"
  +(                  //
    n = s.split`/`[0] // n = numerator, as a string
  ) ?                 // if n coerced to a Number is neither equal to 0 nor NaN:
    [ n * n - 1 ?     //   if abs(n) is not equal to 1:
        n             //     append the numerator
      :               //   else:
        '-'[~n]       //     append '-' if n = -1, or an empty string otherwise
    ] + 'b'           //   append 'b'
  :                   // else:
    n                 //   just output the numerator because it's either "0" or
                      //   an expression that already contains 'b'

```
> 2 votes

# Answer
# C (clang), ~~298~~ ~~263~~ ~~217~~ 179 bytes

```
i;f(char*s){for(i=0;s[i]-47&&(*s-49|s[1]-98||!printf("b"));)write(1,s+i,s[i++]!=98);}main(){char*s;gets(s);printf(*s-98&&*s-49|s[1]-47?*s-48?*s-45|s[1]-49?f(s),"b":"-b":"0":"b");}

```

Try it online!

After a while, I actually managed to make this function the way you want. It's pretty big, I will say, I had to debug a lot.

Thanks to ceilingcat for golfing 35 bytes, another 46 bytes, and another 38 bytes.
> 2 votes

# Answer
# Wolfram Language (Mathematica), 37 bytes

```
ToExpression[""<>#~Drop~-2]b/.b^_->b&

```

Try it online!

Takes a list of characters as input.
> 1 votes

# Answer
## C, ~~209~~ ~~203~~ 137 bytes

*-66 bytes thanks to ceilingcat*

```
char a[9];main(f){gets(a);f=strlen(a)-3;a[f+1]=0;printf((*a==55&a[1]==49&f==1?a[1]=98:*a==49&!f?*a=98:a[f]==98|*a==48&!f)?"%s":"%sb",a);}

```

TIO
> 1 votes

# Answer
# naz, 64 bytes

```
6a8m1s2x1v2m4a2x2v1x1f1r3x1v2e3x2v3e1o1f0x1x2f2m4a1o0x1x3f1o0x1f

```

**Explanation** (with `0x` commands removed)

```
6a8m1s2x1v             # Set variable 1 equal to 47 ("/")
2m4a2x2v               # Set variable 2 equal to 98 ("b")
1x1f                   # Function 1
    1r                 # Read a byte of input
      3x1v2e           # Jump to function 2 if it equals variable 1
            3x2v3e     # Jump to function 3 if it equals variable 2
                  1o1f # Otherwise, output it and jump back to the start of the function
1x2f2m4a1o             # Function 2
                       # Set the register equal to 98 and output once
1x3f1o                 # Function 3
                       # Output once
1f                     # Call function 1

```
> 1 votes

# Answer
# Ruby `-p`, 37 bytes

```
sub /(^1|-\K1)?b?\/0/,?b
sub /^0b/,?0

```

Try it online!
> 1 votes

# Answer
# C++ (gcc), 96 bytes

```
#import<ios>
int f(int r,int i){i-=~r;i||printf("-");i--*~-i&&printf("%d",i?:r);i&&printf("b");}

```

Takes as input an integer `r` denoting a real number and the coefficient of a multiple of \\$b\\$ `i`.

Then "divides" by zero and does some hacking to avoid printing deviating results.

Try it online!
> 1 votes

# Answer
# C (gcc), 71 bytes

```
f(r,i){i-=~r;i||printf("-");i--*~-i&&printf("%d",i?:r);i&&printf("b");}

```

Same as my C++ solution but with less boilerplate.

Try it online!
> 1 votes

# Answer
# 05AB1E, 15 bytes

```
¨¨ÐĀiáм'b«Dþi1K

```

Try it online or verify all test cases.

**Explanation:**

```
¨¨               # Remove the last two characters of the (implicit) input
  Ð              # Then triplicate the string
   Āi            # Pop one, and if it's NOT 0 (using Python-style truthify):
     á           #  Pop again and only leave the letters (in case it contains a "b")
      м          #  And remove those letters
       'b«      '#  Then append a trailing "b"
          D      #  Duplicate it
           þ     #  Pop and only leave the digits
            i    #  If this is exactly 1:
             1K  #   Remove the 1
                 # (after which the top of the stack is output implicitly as result)

```
> 1 votes

# Answer
# Brainfuck, 25 bytes

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

```

## Explanation

```
>,[>,]        read from stdin
<[-<+>]<+++   add last two cells and add three ( ascii('/') + ascii('0') + 3 = ascii('b')
[<]>          move pointer to first char to output
[.>]          output until cell w/ value 0

```
> 0 votes

# Answer
# Symja, 85 bytes

```
d(x_):=If((e=StringReplace(x,"/0"->""))!="0",If(StringContainsQ(e,"b"),e,e<>"b"),"0")

```

Try it Online!

I finally answered my own question!
> 0 votes

---
Tags: code-golf, math, number
---


title: Map of India - minimum number of bytes

text:
# Question
Title: Map of India - minimum number of bytes
Your challenge is to make a program(less number of bytes than what the below program takes) that should print the map of India with any special character of choice.

TIO Link

```
#include <stdio.h>
int main()
{
    int a = 10, b = 0, c = 10;
    char* str = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq "
                "TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL"
                "OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm "
                "SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
    while (a != 0)
    {
    a = str[b++];
        while (a-- > 64)
        {
            if (++c == 90)
            {
                c = 10;
                putchar('\n');
            }
            else
            {
                if (b % 2 == 0)
                    putchar('!');
                else
                    putchar(' ');
            }
        }
    }
    return 0;
}

```

**The program outputs:**

```
                !!!!!!
                !!!!!!!!!!
                 !!!!!!!!!!!!!!!
                   !!!!!!!!!!!!!!
                 !!!!!!!!!!!!!!!
                  !!!!!!!!!!!!
                  !!!!!!!!!!!!
                    !!!!!!!!!!!!
                    !!!!!!!!
                    !!!!!!!!!!
                   !!!!!!!!!!!!!!
                 !!!!!!!!!!!!!!!!
                !!!!!!!!!!!!!!!!                                  !!!!!
              !!!!!!!!!!!!!!!!!!!                               !!!!!!!!!!
             !!!!!!!!!!!!!!!!!!!!!!!                 !         !!!!!!!!!!
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!              !!     !!!!!!!!!!!!
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!      !!!!!!!!
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  !!!!!!!!!!!!
   !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!!!!!
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      !!!!!
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!!
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !
      !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       !!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!
               !!!!!!!!!!!!!!!!!!!!!!!!
                !!!!!!!!!!!!!!!!!!!!
                !!!!!!!!!!!!!!!!!!!
                 !!!!!!!!!!!!!!!!
                  !!!!!!!!!!!!!!!!
                  !!!!!!!!!!!!!!!
                   !!!!!!!!!!!!!!
                    !!!!!!!!!!!!
                    !!!!!!!!!!!!
                    !!!!!!!!!!!!
                      !!!!!!!!
                      !!!!!!
                       !!!!

```

# Answer
# Jelly, (110? 113?) 112 bytes

*Notes:* The 2 bytes, `a⁶` (near the end) may be dropped if `1` is acceptable for the ocean. If special character means digits are not acceptable and the ocean must be a space the byte count will be 113 (replace `Ḃa⁶s75Y` with `ị⁾ !s75Y`) which will use `!`.

```
“*ẊñDȯT¹^qɓ\j£œ%ñ2u{ṅʠỴ©ṾÇịṭxẏ¤Ḅʋ⁽~|}ṾṃƑ¡vṀGs®[Ȯkhɗṃ?ƇṿTṫ6HỌ¡ẏṣnD1ı¹ḍ1Ḣ4$ẸObẓ¢ƙṾⱮḃċỵ|)wY)ḌÇḤ~æṣt²5’ḃ70ĖŒṙḂa⁶s75Y

```

A full program printing the map. Uses `0` for the land.

**Try it online!**

### How?

The first 99 bytes:

```
“*ẊñDȯT¹^qɓ\j£œ%ñ2u{ṅʠỴ©ṾÇịṭxẏ¤Ḅʋ⁽~|}ṾṃƑ¡vṀGs®[Ȯkhɗṃ?ƇṿTṫ6HỌ¡ẏṣnD1ı¹ḍ1Ḣ4$ẸObẓ¢ƙṾⱮḃċỵ|)wY)ḌÇḤ~æṣt²5’

```

is a base 250 literal (a very large number). The rest of the code manipulates this number:

```
“ ... ’ḃ70ĖŒṙḂa⁶s75Y - Main link: no arguments
“ ... ’              - the large number above
       ḃ70           - convert to bijective base 70 [16,6,69,10,66,...]
          Ė          - enumerate                    [[1,16],[2,6],[3,69],[4,10],[5,66],...]
           Œṙ        - run length decode            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,...(69 total)...,3,4,4,4,4,4,4,4,4,4,4,5,5,...(66 total)...,5,...]
             Ḃ       - modulo 2                     [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,...(69 total)...,1,0,0,0,0,0,0,0,0,0,0,1,1,...(66 total)...,1,...]
               ⁶     - literal space character
              a      - logical and (vectorises)     [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',0,0,0,0,0,0,' ',' ',...(69 total)...,' ',0,0,0,0,0,0,0,0,0,0,' ',' ',...(66 total)...,' ',...]
                s75  - split into chunks of length 75 (representing the rows of "text")
                   Y - join with newline characters (making a single list of ' ', 0, and '\n')
                     - implicit print (a list containing any characters is smashed, so
                     -             the 0s print as `0` and none of the `[,]` are shown)

```
> 6 votes

# Answer
# Charcoal, 135 134 133 132 126 bytes

```
Ｆ¹²⁶Ｆ…"§”kL↷DXry"Ｒ⁴¹¤'➙ω⎈v¬⌊π2κÿρ“q↷0h˜⁶!⌊P[±9ＮＨ｜N≡H´“i¬›ＦＥ‹t⁵→Z£314➙yqt⟲“⌊⌊‖↷ÞＩuＡ?↷｜⁻c″!!<;‹ＹＳ00y/;↥Ｌ’Ｄ∧§⎈k≕X”ι⎇﹪Ｌ⊞Ｏυω⁷⁵§ *ι⸿

```

Try it online!

Port of my C# answer. Link to the verbose version.

* 6 bytes saved thanks to Neil!
> 7 votes

# Answer
# Bubblegum, 132 bytes

```
00000000: b595 b719 4421 18c3 7aa6 30fb 0f79 a93b  ....D!..z.0..y.;
00000010: 4412 dfc3 25f6 2f32 a451 fda9 f49a 61c1  D...%./2.Q....a.
00000020: 4300 9163 84b7 7d60 6c3e 383b 2618 c852  C..c..}`l>8;&..R
00000030: e080 0290 9856 ed8b f503 1221 503b 106e  .....V.....!P;.n
00000040: 1231 6335 9c70 3027 0245 6242 88a6 0410  .1c5.p0'.EbB....
00000050: b097 c2dd ae27 c2c1 0346 8ca3 a05e 32fe  .....'...F...^2.
00000060: c710 b993 a288 97cc 55f8 2eee 877d 5407  ........U....}T.
00000070: 91cb 6e2e 3ee4 1f5e 1f91 3f00 7423 002d  ..n.>..^..?.t#.-
00000080: 6c98 70df                                l.p.

```

Try it online!
> 4 votes

# Answer
# C# (.NET Core), 240 232 231 227 bytes

```
_=>{var r="";for(int i=0,j,k=0;i<126;i++)for(j=0;j++<@"2(g,d1`0]1_.a.c.a*e,b0]2\2D'45A,093#+,,@0$'.-G*$(*1_1P#.3N$.,(#M*(,W('1R*%0V*#2(#I@'#GIEIEK@O@O>Q<S;U:V6Y5[2^2]1_0`.a.a.c*e(h&"[i]-34;)r+=++k%75<1?'\n':" *"[i%2];return r;}

```

Try it online!

Same approach as for my C# answer for the Batman challenge.

* 4 bytes saved thanks to Neil! His Charcoal tip could also be applied here! :)
> 3 votes

# Answer
# Python 2, ~~227 223 218~~ 216 bytes

* Thanks @Mr. Xcoder for 2 bytes: `j%2>0` can be just `j%2`

```
for k in range(46):print''.join(ord(i)*' !'[j%2]for j,i in enumerate('''E
B>;=?A?C
@;:"

%=.,
+
504'%'#'#)--/13479<;=>??ACF0'''))[75*k:][:75]

```

Try it online!

## Explanation

The idea is to store the information as the count of total characters in a cluster. For eg:`ssssss!!!!ssss` is encoded as `[6,4,4]`(and since we have to just alternate thru two characters, this becomes easy. ;) ) This info can be compiled as a string by ascii characters for each count (see the string literal). Now we simply obtain the count and draw `!` or a space alternately.
> 2 votes

# Answer
# Retina, 289 bytes

```

16:16;,7#/9#,7#/8-18<<"!%20;,9#,7#&,6#@34&/4#"!31;,3#;&!17!9;!%8'"14&5-7=!8&6"!%8'=%9=;&1-10=;2-3"1="!8:2''@!6@%6''8&%>'@8%6"1=&%7@!1=%1>;/3';/>:1>:1>&,>,>%15'¶16#",6#"%17#&,8#&,8#/9#!%20<<-22"!%22:23@45
@
&&
>
4'
=
'#
<
-20
;
"&
:
"¶
/
&%1
-
#¶
,
!%1
'
##
&
!!
%
!¶
#
""
"
!!!!!!
\d+
$*

```

Try it online!
> 1 votes

# Answer
# JavaScript (ES6), ~~254~~ ~~253~~ 251 bytes

```
_=>`f5
f9
ge
id
ge
hb
hb
jb
j7
j9
id
gf
ffx4
diu9
cmg089
7td14b
6z07157
7zo
8z90b
9z71b
250z675
1zg54
5zb72
3zf70
550z2
640z0
dy
cy
dt
dt
dr
dp
do
en
fj
fi
gf
hf
he
id
jb
jb
jb
l7
l5
m3`.replace(/./g,m=>" !"[i%2].repeat(parseInt(m,36)+1,i+=m<"z"),i=0)

```

---

## Test it

```
o.innerText=(
_=>`f5
f9
ge
id
ge
hb
hb
jb
j7
j9
id
gf
ffx4
diu9
cmg089
7td14b
6z07157
7zo
8z90b
9z71b
250z675
1zg54
5zb72
3zf70
550z2
640z0
dy
cy
dt
dt
dr
dp
do
en
fj
fi
gf
hf
he
id
jb
jb
jb
l7
l5
m3`.replace(/./g,m=>" !"[i%2].repeat(parseInt(m,36)+1,i+=m<"z"),i=0)
)()
```

```
<pre id=o>
```
> 1 votes

# Answer
## JavaScript (ES7), 239 bytes

Encodes the shape and the line breaks separately.

```
let f =

_=>'h7hbigkfigjdjdldl9lbkfihhhz6fkwbeoi2ab9vf36d812937991qa1b2db193d472189731i7671d9451h927721486212f10e10fvfvftfrfqgphlhkihjhjgkfldldldn9n7o5'.replace(/1?./g,n=>' X'[i&1].repeat(parseInt(n,36)-1)+((++i|716000693/2**(i/2))&1?'':`
`),i=-26)

o.innerHTML = f()
```

```
<pre id=o style="font-size:6px"></pre>
```
> 1 votes

# Answer
# C (gcc), ~~255 244~~ 239 bytes

```
b,c;main(a){for(;a="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!"[b++];)for(;a-->64;putchar(++c%80?33-b%2:10));}

```

Slightly bugfixed and golfed version of OP's reference implementation. Try it online!

Minimally less golfed:

```
b,c;
main(a){
  for(;a="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!"[b++];)
    for(;a-->64;)
      putchar(++c%80?33-b%2:10);
}

```
> 0 votes

# Answer
# C (gcc), 205 bytes

My solution quickly converged on something extremely close to ceilingcat's golfed version of OP's implementation, but output does differ slightly when it comes to leading spaces on each line, since I worked from the text found in OP's post, which does not exactly match the output of the reference implementation, most likely due to OP missing the leading spaces required for code text, but there *are* answers using that text as reference, so it's somewhat ambiguous.

```
i,j;main(c){for(;c="B8w<tAp@mAo>q>s>q:u<r@mBlBT7DEQ<@IC3;<<P@47>=W:48:AoA`3>C^4><83]:8<g87Ab:5@f:3B83YP73WYUYU[P_P_NaLcKeJfFiEkBnBmAo@p>q>q>s:u8x6b"[i++];)for(;c---50;j++)printf("\n%c"+(!j||j%75),33-i%2);}

```

Try it online!
> 0 votes

# Answer
# Vyxal `j`, 442 bytes

```
»⌐ṫżṫṗƛ&%≠ɽ_~ẇ*⁼3L ≈;n~U7⋏₇ḭǔ°₁>Aµ1I(□]:ȯ≤KWƒʁY•₇⟩-RCa⟨&8ẋżṫẏL_ġN⇧ṗḞΠṄẇ%¨ḃ₆Q<Zǒ,]„∨TC⁋⟩`ɾOn^≬İ¾¨Ṫlṅ^£†i-ẏ₂↓∷×ṘǍ¶G?∑x∪ż∪İɖ¹p*₴Ḣ≈J₀↳₁‡x⌈↳D4xJḢmḃẇDpeH&⋏¹!≥₇∑;↑≬m†¥⁋†₇,Ż∪ß^ċ¡}GBİ£:U~ʁ⌈∴Ṡ^ṗ⁺Ȯo↓Ṅ%Ẏṗ§∴ḭ₈Ṁ‛∑ø≈dOƒ¥¤ɖ4Ẏ{⅛I∞_uė∇ṫḭB?U≤ǔ9F⟑q₴ẆŀṠz∞₁XṖ¨‛₇VB₁τḟAsżǒxP∵9)&∵β"Ż∆ ↲,₴øxJT.t꘍/₴ǎpe↔ḟqȯ(^≥Vḭ⁰Ȯɽτ∆ṙ°÷lW≠⇧Cb≠²∩]±ḭy∧D℅øJǔ₅⅛EGḭ≥ẋZ≥×8nΠḋ⟩)Ṗv‹'⇧@jq≥ḟ⁽]¾fǎ⅛Ȯ⌊bDa^ṀP;}ṫ⁼τ1„√ɽh⇩GW€⁼[6¼U~j_IṘ†gJ↔Ȧ$°§_„)Ż"₅‡xußġ₃ǔ↔×ɖɖ[æ¥s‹⁰≈c†t‹ṪṙḊ꘍bεβ¶∩∩{ǒḢġ†₅⟨L⌐∨H»`! `τ75ẇ

```

Try it Online!

Plain old binary, AKA I'm losing to everyone.
> 0 votes

---
Tags: code-golf, string, ascii-art, kolmogorov-complexity
---


title: I Love Sardines

text:
# Question
Title: I Love Sardines
I love sardines, I can't get enough of them, and so does my computer, the Omnilang 5000, which is language agnostic.

To give my computer the joy of experiencing sardines, I've decided to feed him a number of programs that are capable of displaying on the screen tins of sardines in various orientations, and showing up to ten sardines.

In this challenge, you'll be responsible for creating the programs based on these parameters:

## The input

A number (between 0 and 10) and a letter from one of the following "LR" (representing Left or Right respectively) For example: `3L` or `5R`; how this is input into the program is up to you.

## Output

An open tin of sardines with the sardines facing the indicated direction, with the key (represented by the "`%`" character) and peeled lid (rolled up tin at the end represented by the "`@`" character) located at the top of the tin.

* All sardines must face the direction indicated by the input.
* All sardines will have bodies five characters long between the gill (either "`)`" or "`(`" ) and the tail "`><`"
* The key and peeled lid roll will always be facing the opposite direction to the sardines.
* The tin must have a 3-D look to it as shown below in the examples.
* The minimum height of the tin is 3 sardines in height. So if a number is less than 3, a tin of 3 sardines in height must be shown, with the inputted number of sardines in it. Otherwise, the tin must be the number of sardines high indicated in the input. So input of `0R` or `0L` will show an empty sardine tin.
* Any other input that can't be validated will not show anything.

For example, for "`3L`"

```
 __________
(__________@%
|<*)_____><||
|<*)_____><||
|<*)_____><||
'==========''

```

For "`7R`"

```
   __________
 %@__________)
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ||><_____(*>|
 ''=========='

```

For "`2L`"

```
 __________
(__________@%
|<*)_____><||
|<*)_____><||
|          ||
'==========''

```

For "`0R`"

```
   __________
 %@__________)
 ||          |
 ||          |
 ||          |
 ''=========='

```

"`0L`"

```
 __________
(__________@%
|          ||
|          ||
|          ||
'==========''

```

Invalid input will not return anything...

* This is code golf, so the smallest number of characters will win this challenge.
* No Loopholes as per usual.

# Answer
> 39 votes
# \>\<\>, ~~250~~ 235 + 3 = 238 bytes

```
</~?{"  __________"a:="L"i&
o/?=1l
:/}rv?{~$?{"()__________@%":
l< o/?=1
:&oa/&~$?(3$@0-3:
/!?:</"||><_____(*>|"av?@:$-1
 /=?/v"|<*)_____><||"a/
 \2lo/
\~&
\>:?!\1+$::{a"|"{?:"          ||"{?~
<\?=2 lo
"'":~/~?{"''==========":?{
;!?lo<

```

Try it online, or watch it at the fish playground! Reads the "L" or "R" from STDIN and assumes the number of sardines is already on the stack (needs a `-v` flag for +3 bytes).

Because of course I had to write this in \>\<\>.

# Answer
> 15 votes
# Emojicode, ~~456~~ 448 bytes

```
da0da __________❌n(__________@%  __________❌n%@__________)i⏩0a|<*)_____><||||><_____(*>|▶4i⏩0➖3a|          ||||          |a'==========''''=========='

```

Takes 2 arguments: first one is lines, second one is direction (0 or 1).

Try it online!

"Readable" ungolfed version and pseudocode version:

```

     d
     a   0 d

     a
        __________❌n(__________@%

         __________❌n%@__________)

     i ⏩ 0
       a
         |<*)_____><||

         ||><_____(*>|

     ▶ 4
       i ⏩ 0  ➖ 3
         a
           |          ||

           ||          |

     a
       '==========''

       ''=========='

extendclass int { // this makes the first argument be an int without declaring it
  func (int d) {
    const a = 0 == d // a bool

    if a {
      print " __________\n(__________@%"
    }
    else {
      print "  __________\n%@__________)"
    }

    for i in range(1, arg) {
      if a {
        print "|<*)_____><||"
      }
      else {
        print "||><_____(*>|"
      }
    }

    if 4 > arg {
      for i in range(0, arg - 3) {
        if a {
          print "|          ||"
        }
        else {
          print "||          |"
        {
      }
    }

    if a {
      print "'==========''"
    }
    else {
      print "''=========='"
    {
  }
}

```

# Answer
> 6 votes
# Python 2, 155 bytes

```
lambda x,y,t='_'*10:'\n'.join(x[::1-2*y]for x in[' %s  '%t,'()'[y]+t+'@%']+['|'+('<>**)(%s><<>'%t)[y::2]+'||']*x+['|'+' '*10+'||']*(3-x)+["'"+'='*10+"''"])

```

Try it online!

Input consists of a length 2 tuple. The first element indicates the number of sardines. The second element indicates the direction; `0` for left, `1` for right.

-84 bytes using lambda magic thanks to notjagan and officialaimm

# Answer
> 6 votes
# Fishing, 1311 bytes

```
v+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC?CCCDCC[CCCCCCCCCCCCCCCCCCCCC?CCCCCCCCCCCCCCCCCCCC[CCC[CCCCC?CCCC?DDDDD[CCCCCCCCCCCCCCCCCCC?CCCCCCCCCCCCCCCCC[?CCCCCCCCCCCCCCCC_
  `3`n{n{In{I{`L`{`  __________ `}}!{{rD}}D{{NE`%@__________)`}}!{{E`(__________@%`}}D{{NDE}}}}={d}}!  d  D{{{{{`><_____(*>`}}!{{E`<*)_____><`}}D!{{{E`|`P}PE`||`ND
                                   [DDDDDD|                     [DDDDDDDDDDDDDDDDDDDD|   D     [C?CDDDDDDDDCCCCCCCCCCCCCCCCCCC[DDDDDDDDDDDDDDDDD|[CCCCCCCCCCCCCCCC_
                                                                                D      }=d [^+Cv-|{{{{{`          `}}                    {{{E`||`P}PE`|`ND
                                                                                D       [CCCCCCCCCCCCCCCCCCC?DDDDDDDDD+CCCC                              D
                                                                                D        E`''=========='`{{{= }}}r{{{ [CCCC                              D
                                                                                D                           [^CCCCCCCv|}}}N                              D
                                                                                |DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD]

```

Takes input from `stdin` in the form:

```
5
R

```

Fishing isn't on Try It Online, but there's an interpreter for it in Ruby on the linked esolangs page.

This is the first program I've made in Fishing -- in fact, it's the first program I've made in any 2D language -- so it can probably be a lot shorter. Golfing tips are welcome (though I wouldn't be surprised if no one gave any, considering that even I don't know what the heck I just wrote).

Here's a GIF of the path the program takes for input `1R` (sorry for low quality):

(This was created using an interpreter that I made; there are no publicly available programs that "visualize" Fishing, as far as I know)

# Answer
> 4 votes
# Charcoal, 49 bytes

```
Ａ⌈⟦Ｉθ³⟧ζＢχ²_←↓(↓ζ'×=χ''↖Ｐ↑ζ←↑ζ@%ＦＮ“#∨‹ＶＢ“«ji”ＦＮ‖Ｔ

```

Try it online! Link is to verbose version of code. First argument is number of sardines, second is direction (0 = left, 1 = right).

# Answer
> 3 votes
# SOGL V0.12, ~~51~~ 48 bytes

```
!gX⁴‘gj⁰%!⁵‘b⌡"κN╥█*≤⌡║)‘3b-"÷AZ⁴‘∙_"Χccσ«‘⁰e?±↔

```

Try it Here!
Expects input as the 1st one being the count and the 2nd one - left or right represented by 1 or 0.

Explanation:

```
..‘..‘                          push 2 compressed strings - the 1st two lines of the box - "  __________ " and "%@__________)"
      b⌡                        input times do
        "..‘                      push a line with a sardine - "||><_____(*>|"
            3b-                 push 3-input
               "..‘∙            get an array of that many "||          |"
                    _           put all the arrays contents on the stack
                     "..‘       push "''=========='" - the last line
                         ⁰      wrap all of that in an array
                          e?    if the 2nd input [is not 0]
                            ±↔    reverse the array horizontally

```

# Answer
> 2 votes
## C++, ~~307~~ ~~296~~ 292 bytes

```
#include<string>
auto z(int n,char c){std::string r=c-82?" __________\n(__________@%\n":"  __________\n%@__________)\n";int l=0;for(;l<n;++l)r+=c-82?"|<*)_____><||\n":"||><_____(*>|\n";for(;l<3;++l)r+=c-82?"|          ||\n":"||          |\n";r+=c-82?"'==========''":"''=========='";return r;}

```

Usage :

```
z(<number of sardines>,<'L' or 'R'>);

```

-11 bytes saved thanks to user ThePirateBay -4 bytes thanks to Zacharý

# Answer
> 2 votes
# R, 334 bytes 311 bytes

```
s=function(n,d){
a="__________"
b="'=========='"
if(d == "L"){cat(paste(c(" ",a,"\n(",a,"@%\n",rep("|<*)_____><||\n",n),rep("|          ||\n",max(c(3-n,0))),b,"'\n"),collapse=""))} else {cat(paste(c("  ",a,"\n%@",a,")\n",rep("||><_____(*>|\n",n),rep("||          |\n",max(c(3-n,0))),"'",b,"\n"),collapse=""))}}

```

Function takes a numeric value for n and a string for the direction.

This is my first time posting, so I'll admit I'm not sure how to count bytes of code.

# Answer
> 1 votes
# Python 2, 287 bytes

```
n,d=input()
t,a,b,c,e,k=' __________   ','(__________@% ','|<*)_____><|| ','|          || ',"'=========='' ",'\n'
print[t+k+a+k+k.join([b]*n)+k+k.join([c]*(3-n))+k*(n<3)+e,t[::-1]+k+a[::-1].replace(*'()')+k+k.join([b[::-1].replace(*')(')]*n)+k+k.join([c[::-1]]*(3-n))+k*(n<3)+e[::-1]][d]

```

Try it online!

Input is a comma separated tuple of numbers of this format: `2, 1`. The first number is the amount of fish and the second is is 0 for left and 1 for right.

This started out as an attempt to out-golf the other answer (I totally thought I could), but it sucks. :P If anybody can make head and tail of it and help golf it (I blame it on it being 12 am right now), I'd be glad.

# Answer
> 1 votes
# C# (.NET Core), 289 bytes

```
(h,d)=>{var l=d=='L';string r=(l?" ":"  ")+"__________\n"+(l?"(":"%@")+"__________"+(l?"@%":")")+"\n";for(int i=0;i<(h>3?h:3);i++){r+=(l?"|":"||")+(i<h?(d=='L'?"<*)_____><":(d=='R'?"><_____(*>":"")):"          ")+(l?"||":"|")+'\n';}var b=(l?"'":"''")+"=========="+(l?"''":"'");return r+b;}

```

Try it online!

Takes an integer and a char (L, R) as parameters and outputs the resulting string.

Ugh. Had to deal with some annoying string constants, sadly you cant just do `string * length` in C#. And the method with `new string(char, length)` wouldn't have been worth the byte cost.

---

The algorithm works as follows:

1. At the start we determine if the sardines face right or left, since we will then format our strings accordingly. We create a string for the top, with some conditional operators to switch between the L and R perspective.
2. Then we create a loop that runs 3 times at minimum and the left input times at maximum. That way we can create empty spaces if we have less than 3 sardines in our box.
3. Inside this loop we format a string, depending on the perspective and also, if `h > i`, we put a sardine inside of it. If `i >= h`, there will be an empty space where a sardine would normally be.
4. At the end we create the bottom of the box, again formatted according to perspective.

# Answer
> 1 votes
# Perl 5, 167 + 1 (-n) = 168 bytes

```
($n,$d)=/(\d+)([LR])/ or die;say('R'eq$d?(reverse$_)=~y/()></)(<>/r:$_)for" __________  ","(__________@%",("|<*)_____><||")x$n,("|          ||")x(3-$n),"'==========''"

```

Try it online!

# Answer
> 1 votes
# JavaScript (ES6), ~~283~~ ~~273~~ ~~269~~ 251 bytes

*Saved 10 bytes thanks to @WallyWest*

*Saved 4 bytes removing extra parens*

*Saved 18 bytes thanks to @ThePirateBay*

Suffers from lack of string reversal in the standard library. Defines a function that takes inputs `n` for number of fish and `d` for direction. Throws if `d` is not "L" or "R".

```
(n,d,_=c=>c.repeat(10),x=_(`_`),z=a=>a.reverse``.join``)=>
([p,q,g,r,s]=d>`L`?d>`R`?[]:[`)`,`(`,`>`,z,y=>z(y.split``)]:
[`(`,`)`,`<`,a=>a.join``,y=>y],` ${x}
`+r([p,x,s(`@%`)])+`
`+(r([`|`,g,`*`,q,`_____`,`><`,`||`])+`
`).repeat(n)+r([`'`,_(`=`),`''`]))

```

Try it online

# Answer
> 1 votes
# Vyxal `j`, 91 bytes

```
ð\_₀*+ðd+⅛\(\_₀*`@%`++⅛⁰3WG(\|n⁰≥[ð₀*|`<*)_____><`]\|d++⅛)\'\=₀*\'d++⅛¾¹\R=[ƛṘ`<>()``><)(`Ŀ

```

Try it Online!

```
=== Top row ===
ð\_₀*+ðd+⅛
ð          # A space
 \_₀*      # Ten underscores
     +     # Concatenated
      ðd+  # Two more spaces
         ⅛ # Push to global array
=== Next row ===
\(\_₀*`@%`++⅛
\(            # The parenthesis
  \_₀*        # Ten underscores
      `@%`    # Literal
          ++⅛ # Concatenated and pushed to global array
=== The fishes ===
⁰3WG(\|n⁰≥[ð₀*|`<*)_____><`]\|d++⅛)
⁰3WG                                # Max(3,fish)
    (                             ) # times....
     \|                             # Push pipe
          [                ]        # If...
       n⁰≥                          # Iteration number is greater than or equal to input (missing fish)
           ð₀*                      # Ten spaces
              |                     # Else...
               `<*)_____><`         # A fish
                            \|d     # `||`
                               ++⅛  # Concatenate and push to global array
=== The final row ===
\'\=₀*\'d++⅛
\'           # Literal
  \=₀*       # Ten equalses
      \'d    # Two more apostrophes
             # Concatenated and pushed to global array
=== Flipping + Formatting ===
¾¹\R=[ƛṘ`<>()``><)(`Ŀ
¾                     # Push global array
     [                # If...
 ¹\R=                 # Input is R
      ƛ               # Foreach...
       Ṙ              # Reverse...
        `<>()``><)(`Ŀ # Flip brackets

```

---
Tags: code-golf, ascii-art
---


# Question
Title: Prime Factorization - but on the exponents too
Though there is a prime factorization challenge and it's here, this, I feel, will be a bit more interesting than that one.

To understand this, let's have an example; I will use 5,184 for this. \\$5184 = 2^6 \times 3^4\\$. However, for this challenge, such a factorization is insufficient - the reason is that 6 and 4 are composite - therefore, we must factorize them too: \\$5184 = (2^{2\*3}) \times (3^{2^2})\\$. This containes a total of 0 composite numbers, so we are done.

Your task is to prime-factorize a number. However, unlike in here, if you see a composite number in the exponent, you must then factorize this too.

Input will be a number or a string, and output can be a nested array, nested list, or string.

You must use the fewest numbers necessary: 65536 is \\$2^{2^{2^2}}\\$, not \\$ 2^{2 \times 2 \times 2 \times 2}\\$ or anything similar - however, \\$2^{2^2}\\$ and \\$2^{2 \times 2}\\$ are identical and as such, can be used freely - make of it what you will.

Some example answers to show the format:

5184, 65536 - see above

\\$2^{144} = 2^{2^{2^2} \times 3^2}\\$ or `[2, [2, [2, 2], [3, [2]]]]`, or `"2^(2^2^2)*(3^2)"`, where the brackets are necessary to separate the terms.

\\$5^{125} = 5^{5^3}\\$, or `[5, [5, [3]]]`, or `5^5^3` (note, as \\$a^{b^c} == a^{(b^c)}\\$, the brackets are not necessary.

\\$47,258,883 = 3^9 \times 7^4 = 3^{3 \times 3} \times 7^{2 \times 2}\\$ or \\$3^{3^2} \times 7^{2^2}\\$ or `[3, [3, 2], 7, [2, 2]]` or `[3, [3, [2]], 7, [2, [2]]]` or `3^(3 \times 3) \times 7^(2 \times 2)` or `3^3^2 \times 7^2^2`

\\$2^{81} = 2^{3^{2 \times 2}}\\$ or similar (see above)

\\$5^{343} * 7^{125} = 5^{7^3} \times 7^{5^3}\\$ or similar (see above)

And finally, to check your prime factorization technique:

\\$2^{2162160} \times 3^{1441440} \times 5^{1081080} = 2^{2^{2^2} \times 3^3 \times 5 \times 7 \times 11 \times 13} \times 3^{2^5 \times 3^2 \times 5 \times 7 \times 11 \times 13} \times 5^{2^3 \times 3^3 \times 5 \times 7 \times 11 \times 13}\\$

You may pick any output format and use any non-number or newline separator, and you may include any number of trailing/leading newlines in output, but you must be consistent about your choice and state it in your answer.

As always, this is - shortest code wins.

# Answer
# Jelly, 8 bytes

```
ÆF¹ßẒ?€€

```

A monadic Link accepting a positive integer that yields a list (Note that `[]` represents an empty product).

**Try it online!**

### How?

```
ÆF¹ßẒ?€€ - Link f: integer
ÆF       - prime-factorisation
             e.g. 144 -> [[2,4],[3,2]]
                  (note that 1 -> [])
       € - for each ([prime,exponent] pair in that)
      €  -   for each (v in [prime,exponent]):
     ?   -     if...
    Ẓ    -     ...condition: is prime?
  ¹      -     ...then: no-op
   ß     -     ...else: call this Link with the same arity -> f(v)

```
> 6 votes

# Answer
# Jelly, 15 bytes

```
¹ÆFṛÇṭ¥Ị?@/€$Ẓ?

```

Try it online!

A full program that takes the number and outputs the answer.

This isn't a link because I am using "last link" to refer to itself, so it would break as a link on its own. I fix this for my test suite by making the last link a single atom that calls the next link. For whatever reason, "this link" breaks due to arity related reasons, or something like that. Not sure why.

If Arnauld's return format is acceptable where 1 exponents are returned as `[x, []]`, then:

# Jelly, 12 bytes

```
¹ÆF,ß}¥/€$Ẓ?

```

Try it online!

```
¹ÆF,ß}¥/€$Ẓ?  Main link
           ?  If the input
          Ẓ   is prime
¹             return the input itself
 ()(    )$    otherwise, (call last two links)
 ÆF           compute [prime, exponent] pairs
        €     for each pair
       /      reduce (convert pairs into left and right dyad arguments)
   -()¥       (over last two links)
   ,          pair the left argument (the prime) with
    ß         this link (recurse) called on
     }        the right argument (the exponent)

```

## Explanation

This one is a bit complex so, here's a shitty hand-drawn breakdown:

Or, if you enjoy being able to read:

```
¹ÆFṛÇṭ¥Ị?@/€$Ẓ?
              ?  if
             Ẓ   the input is prime
¹                return the input itself
                 otherwise
 ()(       )$    [combine last two into a monad]
 ÆF              compute [prime, exponent] factorization
           €     for each pair
          /      reduce over (convert pair into left, right arguments for a dyad)
         @       the following dyadic relation, with the arguments swapped
        ?        if
       Ị         the left argument is insignificant (-1 <= ? <= 1) - the left argument is the exponent
   ṛ             return the right argument (just the prime)
                 otherwise
    --¥          [combine last two into a dyad]
    Ç            call this link again on the exponent (technically "call last link" due to weird behavior)
     ṭ           and append that factorization to the prime itself

```
> 14 votes

# Answer
# , 34 32 bytes

```
[:(;<@$:)`(<@[)@.(1=])/"1@|:2&p:

```

Try it online!

Outputs J boxed structure. Eg, `f 1584` is:

```
┌─┬───────┐
│2│┌─┬─┐  │
│ ││2│3│  │
│ │└─┴─┘  │
├─┼───────┤
│3│┌─┬───┐│
│ ││2│┌─┐││
│ ││ ││2│││
│ ││ │└─┘││
│ │└─┴───┘│
└─┴───────┘

```
* `2&p:` is a built in that produces the primes and their exponents as two lists, like:

```
   2&p: 5184
2 3
6 4

```
* `[:(...)/"1@|:` transpose and apply what's in parens to each row, putting it between the two elements so that `[` and `]` are the left and right args in what follows...
* `(;<@$:)`(<@[)@.(1=])` If the right arg is 1 (ie, we've reached a prime), put it in a single box and return `(<@[)`. Otherwise put the left arg in a left box, and into the right box put the function applied recursively to the right arg `$:`.
> 6 votes

# Answer
# JavaScript (ES6), 73 bytes

Returns nested arrays, where \\$k^1\\$ is `[k,[]]`.

```
f=(n,k=2,a=[],i,b=i?[...a,k,f(i)]:a)=>k>n?b:n%k?f(n,k+1,b):f(n/k,k,a,-~i)

```

Try it online!
> 4 votes

# Answer
# Japt, 16 bytes

Japt suffering from its lack of a prime/exponent built-in again. Uses the empty array if the exponent is `1`.

```
*j ªUk ü Ëâ pßDl

```

Try it

```
*j ªUk ü Ëâ pßDl     :Implicit input of integer U
*                    :Multiply by
 j                   :Is prime?
   ª                 :Logical OR with
    Uk               :Prime factors of U
       ü             :Group by value
         Ë           :Map each D
          â          :  Deduplicate
            p        :  Push
             ß       :    Recursive call with argument
              Dl     :      Length of D

```
> 1 votes

# Answer
# Stax, 15 bytes

```
╛⌐í₧?uò╗∩¿7d∩í±

```

Run and debug it

a pretty straightforward recursion.

-3 from recursive.
> 0 votes

# Answer
# Core Maude, 283 bytes

```
mod F is ex RAT *(sort Nat to N). op __ : N N -> N[id: 1]. op e : N N ->
N[right id: 1]. vars A B C D : N . eq e(A,0)= 1 . op f : N -> N . eq f(A)=
A,2,0 . op _,_,_ : N N N -> N . ceq A,B,0 = A if A < B . ceq A,B,C = D,B,s C
if D := A / B . eq A,B,C = e(B,f(C))(A,s B,0)[owise]. endm

```

The `f` function will evaluate the factorization of its input, a natural number. In the output, the `__` (juxtaposition) operator represents multiplication, and the `e` function represents exponentiation. So the term `e(2, 3) (e(3, 3) (5 (7 (11 13))))` represents \\$2^3 \times 3^3 \times 5 \times 7 \times 11 \times 13\\$.

### Example Session

```
             \||||||||||||||||||/
           --- Welcome to Maude ---
             /||||||||||||||||||\
         Maude 3.1 built: Oct 12 2020 20:12:31
         Copyright 1997-2020 SRI International
           Thu Jun  3 08:42:33 2021
Maude> set show stats off .
Maude> set show timing off .
Maude> set show command off .
Maude> mod F is ex RAT *(sort Nat to N). op __ : N N -> N[id: 1]. op e : N N ->
> N[right id: 1]. vars A B C D : N . eq e(A,0)= 1 . op f : N -> N . eq f(A)=
> A,2,0 . op _,_,_ : N N N -> N . ceq A,B,0 = A if A < B . ceq A,B,C = D,B,s C
> if D := A / B . eq A,B,C = e(B,f(C))(A,s B,0)[owise]. endm
Maude> red f(5184) .
result N: e(2, 2 3) e(3, e(2, 2))
Maude> red f(65536) .
result N: e(2, e(2, e(2, 2)))
Maude> red f(1081080) .
result N: e(2, 3) (e(3, 3) (5 (7 (11 13))))
Maude> red f(1441440) .
result N: e(2, 5) (e(3, 2) (5 (7 (11 13))))
Maude> red f(2162160) .
result N: e(2, e(2, 2)) (e(3, 3) (5 (7 (11 13))))
Maude> red f(47258883) .
result N: e(3, e(3, 2)) e(7, e(2, 2))

```

### Ungolfed

```
mod F is
    ex RAT * (sort Nat to N) .

    op __ : N N -> N [id: 1] .
    op e : N N -> N [right id: 1] .

    vars A B C D : N .

    eq e(A, 0) = 1 .

    op f : N -> N .
    eq f(A) = A, 2, 0 .

    op _,_,_ : N N N -> N .
    ceq A, B, 0 = A if A < B .
    ceq A, B, C = D, B, s C if D := A / B .
    eq A, B, C = e(B, f(C)) (A, s B, 0) [owise] .
endm

```

Rather than use the built-in nested list module (`LIST*`), I opted to define my own output operators `__` and `e`. Since Maude allows operators to be declared with identity elements, this saves me having to specify any special rules for 1 (i.e., don't show it).
> 0 votes

---
Tags: code-golf, math, number, primes, factoring
---


# Question
Title: Reverse source code and double the input
For today's challenge you have to take an input, and if your source code is reversed, then the input should be printed doubled.

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 any of be `xyzxyz` or `xyz xyz` or

```
xyz
xyz

```

For any numerical input you should not multiply it with `2`, instead use the upper rule, for input `1` -\> `11` or `1 1` or

```
1
1

```

(Trailing newlines allowed in output, but not the leading ones)

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. (You will not get empty input)

Standard loopholes apply, shortest code wins

original source code's output can be anything

# Answer
# Trivial comment trick

## JavaScript (ES6), 12 bytes

```
s=>s//s+s>=s

```

Try it online!
> 5 votes

# Answer
# Japt, 1 byte

```
p

```

Try it

* Returns S repeated n times with n defaulted to 2.
> 4 votes

# Answer
# Perl 5 (`-0777p` `-M5.01`), 3 bytes

```
yas

```

reversed

```
say

```
* `-0777` to undef input record separator (slurp input).
* `-p` option print default argument (input) to output.
* `-M5.01` to use `say` shorter than `print`
* `yas` : bareword (same as "yas" with the quotes), no-op.

Try it online!
> 3 votes

# Answer
# PowerShell, 8 bytes

```
#2*sgra$

```

Try it online!

!enilno ti yrT

-6 bytes thanks to @NauhelFouilleul
> 2 votes

# Answer
# Keg, `-no`, 2 bytes

```
#:

```

Don't try it online!

Ah yes, bad language design at it's finest. You can't try it online because it desperately needs a pull - and Dennis hasn't been around for a while.

The `-no` flag makes everything output as-is - without it, numbers would attempt to output as characters (not very helpful)

## Explained

```
#:

```

Do nothing: standard cat program

```
:#

```

Duplicate the top of the stack and output the entire stack
> 2 votes

# Answer
# APL (Dyalog Unicode), 3 bytes

Anonymous tacit prefix function.

```
,,,

```

Try it online!

The outer commas ravel (flatten) the argument to a simple string (i.e. a no-op).

The middle comma is concatenation.

The whole function concatenates the string to itself.

Since all characters are identical, this works when reversed too.
> 2 votes

# Answer
# Vyxal, 2 bytes

```
#d

```

Try it Online!

Very good trivial answer. Make sure to wrap input in double quotation marks.

## Explained

```
#d

```

Nothing, a standard cat program

```
d#

```

Double the input string and output.
> 1 votes

# Answer
# Pyth, 2 bytes

```
zz

```

Try it online!

`z` -\> Prints the input.
> 1 votes

# Answer
# Python 3, 17 bytes

```
#)2*)(tupni(tnirp

```

Try it online!

!enilno ti yrT
> 1 votes

# Answer
# PHP -F, 15 bytes

```
;ngra$.ngra$=?<

```

Try it online!

Try it reversed!

---

# PHP, 13 bytes

```
i$.i$>=)i$(nf

```

Outputs error when not reversed.

Try it online!

Try it reversed!
> 1 votes

# Answer
# 05AB1E (legacy), 2 bytes

```
x#

```

Try it online!

!enilno ti yrT

`x` doubles the input
> 1 votes

# Answer
# Charcoal, 3 bytes

```
²×⁰

```

Try it online! Outputs `--`.

```
⁰×²

```

!enilno ti yrT Explanation: Outputs zero `-`s, then doubles the implicit input.

Charcoal normally takes string input, but you can force it to take numeric input. There are various ways of constructing a 5-byte program that forces string output, although in that case the unreversed output will no longer be `--`.

The assumes that both programs need to be syntactically valid, as Charcoal will normally ignore invalid programs rather than exiting with error. Abusing this would allow the programs to be reduced to 2 and 3 bytes respectively.
> 1 votes

# Answer
# Batch, 16 bytes

```
@ rem&1%1% ohce@

```

```
@echo %1%1&rem @

```
> 0 votes

# Answer
# YaBASIC, 8 bytes

```
//$i,$i?

```

Try it online!

```
?i$,i$//

```

!enilno ti yrT

A basic BASIC answer - hide the reversed source behind a comment! Original does nothing, reversed prints input i$ twice. This dialect recognizes // as a comment. I'd shave a byte if it would accept ' like Microsoft BASIC variations do!
> 0 votes

# Answer
# 05AB1E, 1 bytes

*Ties AZTECCO's Japt answer for #1.*

```
«

```

Try it online!

!enilno ti yrT

```
«  # full program
   # implicit input...
«  # concatenated with...
   # implicit input
   # implicit output

```
> 0 votes

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