title: Swapping "Good" and "Bad"

text:
# Question
Title: Swapping "Good" and "Bad"
**Challenge Description:**

Write a program that asks the user for input. The user will enter `Good` or `Bad`. You do not have to support any other input. If the user enters `Good`, print `Bad` and vice versa (to stdout etc).

**Notes:**

*1)* You cannot use any other pair of two words.

*2)* Your program only has to ask and print once.

*3)* You do not need to display prompt string.

*4)* The output must appear separated from the input by any means.

*5)* No function is allowed accepting the value and returning the result; User must interact with the program.

*Good luck!*

# Answer
> 53 votes
# Python 3,  ~~32~~  31 bytes

```
exit('GBoaodd'['G'<input()::2])

```

**Try it online!**

### How?

Tests if input is `'Good'` by comparing `'G'<input()`.

Uses the fact that in Python `False==0` and `True==1` to use the result as the `start` index of a slice of `'GBoaodd'` using an undefined `stop` and a `step` of `2` with `'GBoaodd'[start:stop:step]`.

Prints to STDERR (saving a byte with `exit` in place of `print`).

# Answer
> 20 votes
# APL (Dyalog Unicode), 13 bytesSBCS

Full program that prompts for input from stdin and prints to stdout.

```
'GooBad'~¯1↓⍞

```

Try it online!

prompt for input from stdin; `Good` or `Bad`

`¯1↓` drop the last character (`d`); `Goo` or `Ba`

`'GooBad'~` multiset subtract those characters from these; `Bad` or `Good`

# Answer
> 13 votes
## bash, 20 bytes

```
sed s/$1//<<<GoodBad

```

Try it online!

# Answer
> 11 votes
# Turing Machine But Way Worse, 405 bytes

```
0 0 0 1 1 0 0
1 1 1 1 2 0 0
0 2 0 1 3 0 0
0 3 0 1 4 0 0
0 4 0 1 5 0 0
1 5 0 1 6 0 0
0 5 1 1 h 0 0
1 6 1 1 7 0 0
1 7 0 1 8 1 0
0 8 0 1 9 0 0
1 9 1 1 9 0 0
0 9 0 1 a 0 0
1 a 0 1 a 0 0
0 a 0 0 b 0 0
0 b 1 1 c 1 0
0 c 0 0 d 0 0
1 d 0 0 e 0 0
0 e 0 0 f 0 0
0 f 1 1 g 1 1
1 h 1 1 i 0 0
0 i 1 1 j 1 0
0 j 0 1 k 0 0
1 k 1 1 k 0 0
0 k 0 1 l 0 0
0 l 1 1 l 0 0
1 l 1 0 m 1 0
1 m 1 1 n 1 0
1 n 1 1 o 0 0
0 o 0 1 p 1 1

```

Try it online!

Well, this took a while.

**UNFINISHED EXPLANATION**:

```
0 0 0 1 1 0 0 Start going to the sixth bit
1 1 1 1 2 0 0
0 2 0 1 3 0 0
0 3 0 1 4 0 0
0 4 0 1 5 0 0 End going to the sixth bit
1 5 0 1 6 0 0 If the sixth bit is 1, then it is Good. Start transforming "G" to "B" and go to state 6
0 5 1 1 h 0 0 Else, it is Bad. Start transforming "B" to "G" and go to state h
1 6 1 1 7 0 0 Keep on transforming "G" to "B"
1 7 0 1 8 1 0 End transforming and print "B"
0 8 0 1 9 0 0 We are in the first "o" in "Good". Start moving into the 5th bit.
1 9 1 1 9 0 0
0 9 0 1 a 0 0
1 a 0 1 a 0 0 Do some looping magic and start transforming "o" to "a"
0 a 0 0 b 0 0 End looping magic
0 b 1 1 c 1 0 End transforming and print "a"
0 c 0 0 d 0 0
1 d 0 0 e 0 0 Start transforming "a" to "d"
0 e 0 0 f 0 0
0 f 1 1 g 1 1 Stop transforming, print "d", and terminate
1 h 1 1 i 0 0 Continue transforming "B" to "G"
0 i 1 1 j 1 0 Stop transforming and print out "G"
0 j 0 1 k 0 0 Start going into position to print out "oo"
1 k 1 1 k 0 0
0 k 0 1 l 0 0 Move more efficiently using LOOPING MAGIC1!1111111
0 l 1 1 l 0 0 looping magic end, start transforming
1 l 1 0 m 1 0 end transforming and print out out "o"
1 m 1 1 n 1 0 print out "o" again
1 n 1 1 o 0 0 get into the "d" byte
0 o 0 1 p 1 1 print "d" and execute YOU HAVE BEEN TERMINATED

```

# Answer
> 8 votes
# 8088 Assembly, IBM PC DOS, 25 bytes

**Unassembled:**

```
BA 0110     MOV  DX, OFFSET GB  ; point DX to 'Good','Bad' string
D1 EE       SHR  SI, 1          ; point SI to DOS PSP (80H)
02 04       ADD  AL, [SI]       ; add input string length to AL, set parity flag
7B 02       JNP  DISP           ; if odd parity, input was 'Bad' so jump to display 'Good'
02 D0       ADD  DL, AL         ; otherwise add string length as offset for 'Bad' string
        DISP:
B4 09       MOV  AH, 9          ; DOS display string function
CD 21       INT  21H            ; call DOS API, write string to console
C3          RET                 ; return to DOS
        GB  DB  'Good$','Bad$'

```

**Explanation:**

Looks at the length of input string (plus leading space) that DOS stores at memory address `80H`, and adds it to `AL` (initially `0` by DOS). If there is an odd number of `1` bits in the binary representation of the string length, the CPU parity flag is set to odd, and vice-versa. So input string `' Bad'` length `4` (`0000 0100`), is odd parity and input string `' Good'` is `5` (`0000 0101`) is even parity.

`DX` is initially set to point to the string `'Good$Bad$'`, and if parity is even (meaning input was `' Good'`) advance the string pointer by that length (`5`) so it now points to `'Bad$'`. If parity is odd, do nothing since it already points to `'Good$'`. Then use DOS API to display a `$` terminated string to console.

**Example:**

Download and test GOODBAD.COM or build from `xxd` dump:

```
0000000: ba10 01d1 ee02 047b 0202 d0b4 09cd 21c3  .......{......!.
0000010: 476f 6f64 2442 6164 24                   Good$Bad$

```

# Answer
> 7 votes
## Python 3, ~~38~~ ~~37~~ ~~34~~ 33 bytes

```
exit("C">input()and"Good"or"Bad")

```

Try it online!

`exit()` : returns an exit code as output

`"C">input()` : Checks whether the input is larger than the string `C` in the alphabetical order

`and"Good"` : If the result is `True`, then returns with `Good`

`or"Bad"` : Otherwise, returns with `Bad`

# Answer
> 7 votes
# Jelly, 8 bytes

```
“Ċ³ṫ³»œṣ

```

**Try it online!**

A full program expecting a Python formatted string as an argument

### How?

```
“Ċ³ṫ³»œṣ - Main Link: list of characters, S
“Ċ³ṫ³»   - compression of dictionary words "Good"+"Bad" = ['G','o','o','d','B','a','d']
      œṣ - split on sublists equal to S
         - implicit, smashing print

```

# Answer
> 6 votes
# C, ~~39~~ 38 bytes

```
main(){puts("Good\0Bad"+getchar()%6);}

```

Try it online!

Saved one byte thanks to @tsh.

# Answer
> 6 votes
# brainfuck, 72 bytes

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

```

Try it online!

Explanation: ,\>+++++\>,\>,\>,\>,

Read either: "G", 5, "o", "o", "d" or "B", 5, "a", "d", 0

\[\<\<\<\<\[-\<-\>\>---\<\]\<.\>\>+.\>\>.\>\>\>\] If the last character is not zero:

Substract 5 from the first cell once and from the third cell thrice. Increment cell 3

Output cells 1, 3, 5.

\<\[\<\<\<\[-\<+\>\>+++\<\]\<.\>\>-..\>.\>\>\]

Otherwise add 5 to the first cell once and to the third cell thrice.

Decrement cell 3

Output cells 1, 3, 3, 4

# Answer
> 5 votes
# , ~~42~~ ~~37~~ ~~35~~ 32 bytes

-10 thanks to Giuseppe and AkselA!

```
`if`(scan(,'')>'C','Bad','Good')

```

Try it online!

# Answer
> 5 votes
# sed, ~~21 16~~  13 bytes

*Thanks @Cowsquack for the hints.*

```
/B/cGood
cBad

```

~~Try it online! Try it online!~~ Try it online!

TIL `c` will short-circuit the current line's parsing.

# Answer
> 5 votes
# Retina, 10 bytes

```
:`GoodBad

```

Try it online!

`:` swaps the input and the regex, so this computes `'GoodBad'.replace(input, '')`.

# Answer
> 4 votes
## Haskell, ~~36~~ 34 bytes

```
interact g
g"Bad"="Good"
g _="Bad"

```

Try it online!

Edit: -2 bytes thanks to @cole

# Answer
> 4 votes
# JavaScript 31 bytes

I like Arnauld's answer, but I would like it to accept user input and be runnable on StackExchange like so:

```
alert(prompt()[3]?'Bad':'Good')
```

# Answer
> 4 votes
# Shakespeare Programming Language, 582 bytes

(Whitespace added for readability)

```
G.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]Ajax:
Open mind.Be you nicer the sum ofa big cat the cube ofa big big cat?If solet usScene V.
You is the sum ofthe sum ofyou a big big cat a cat.Speak thy.You is the sum ofyou twice twice twice the sum ofa big big cat a cat.Speak thy.Speak thy.You is the square oftwice the sum ofa big big cat a cat.Let usScene X.
Scene V:.Ajax:
You is the sum ofthe sum ofyou a big big pig a pig.Speak thy.You is the sum ofyou the sum ofa big big big big big cat a pig.Speak thy.You is the sum ofyou the sum ofa big cat a cat.
Scene X:.Ajax:Speak thy.

```

Try it online!

I get the first letter of the input with `Open mind`. Then I need to determine what it is. Of all the numbers between `B`=66 and `G`=71, my brute forcer says 66 is the shortest to write (`the sum ofa big cat the cube ofa big big cat`), so I compare the first letter of the input to 66. Scene I continues to print `Good`, or Scene V prints `Bad`.

# Answer
> 4 votes
# Charcoal, 13 bytes

```
¿⁻ＬＳ³Ba¦Goo¦d

```

Try it online!

### Explanation:

```
¿⁻ＬＳ³          If length of input minus 3 is truthy:
      Ba¦         print Ba
         Goo¦       else print Goo
             d        print d

```

# Answer
> 3 votes
# Befunge-93, ~~20~~ 18 bytes

```
"BadooGB"~-_#@,,<,

```

Try it online!

*-2 bytes thanks to Jo King*

# Answer
> 3 votes
# Ruby, 22 bytes

```
->n{n>?F?"Bad":"Good"}

```

Try it online!

# Answer
> 3 votes
# 05AB1E, ~~10~~ 9 bytes

```
”‚¿‰±”áIK

```

-1 byte thanks to *@Emigna*.

Try it online or verify both test cases.

**Explanation:**

```
”‚¿‰±”     # Push dictionary string "Good Bad"
      á    # Only keep letters (to remove the space)
       IK  # Remove the input
           # (output the result implicitly)

```

See this 05AB1E tip of mine (section *How to use the dictionary?*), to understand why `”‚¿‰±”` is `"Good Bad"`.

# Answer
> 3 votes
# Ruby, 30 28 bytes

```
puts %w|Good Bad|-gets.split

```

Not the golf-iest, but I like the abuse of split to remove the trailing newline and convert to an array in one call.

EDIT -2 bytes thanks to Value Ink's suggestion!

# Answer
> 3 votes
# Java (JDK), 124 bytes

```
interface G{static void main(String[]a){System.out.print(new java.util.Scanner(System.in).next().length()>3?"Bad":"Good");}}

```

Try it online!

Most likely, there‘s still some room for improvement, but I‘m entirely new to code golfing.

# Answer
> 3 votes
# GolfScript, 11 bytes

```
"GoodBad"\/

```

Try it online!

## Explanation

```
"GoodBad"   # Define the lookup table "GoodBad"
         \  # Swap the input so that it can be used by /
          / # Split the lookup table by occurences of the input
            # Implicit print, smashing

```

# Answer
> 3 votes
# JavaScript, ~~35~~ ~~32~~ 31 bytes

-3 bytes thanks to @xigoi

-1 byte thanks to @l4m2

```
alert(prompt()[3]?'Bad':'Good')
```

# Answer
> 3 votes
# C (gcc), 48 bytes

```
main(){puts(getchar()-66?"Bad":"Good");}

```

Try It Online!

The program only actually takes one character as input, although `getchar` reads until a newline is found unlike `getch` which only *lets* you input a single character. It checks if there's a difference between that character and the ascii code for 'B' (66), printing "Bad" if there is and "Good" if there isn't.

# Answer
> 2 votes
# Stax, ~~9~~ 8 bytes

```
çEF♫a║▬h

```

Run and debug it

~~Essentially `replace("BadGood", input, "")`.~~

Multiset xor with "GooBa". Algorithm copied verbatim from Luis Mendo

# Answer
> 2 votes
# Jelly, 9 bytes

```
“GooBa”œ^

```

Try it online!

### Explanation

Multiset symmetric difference between the input and the string `“GooBa”`.

# Answer
> 2 votes
# Retina 0.8.2, 20 bytes

```
oo
o
T`G\oaB`Ro
o
oo

```

Try it online! Link includes test suite. Explanation:

```
oo
o

```

Turn `Good` into `God`.

```
T`G\oaB`Ro

```

Transpose the letters `GoaB` with the reverse of that list, thus exchanging `G` with `B` and `o` with `a`, i.e. exchanging `God` with `Bad`.

```
o
oo

```

Turn `God` into `Good`.

# Answer
> 2 votes
# PowerShell, ~~22~~ 20 bytes

```
'Good','Bad'-ne$args

```

Try it online!

*-2 bytes thanks to mazzy*

# Answer
> 2 votes
# Java, 30 bytes

```
s->s.charAt(0)>66?"Bad":"Good"

```

TIO

# Answer
> 2 votes
# Perl 5 `-p`, 15 bytes

```
$_=/B/?Good:Bad

```

Try it online!

# Answer
> 2 votes
# Excel, 24 bytes

```
=IF(A1>"C","Bad","Good")

```

Using @MilkyWay90's `<C` suggestion.

# Answer
> 2 votes
# PHP, ~~26~~ 23 bytes

A ternary is just cheaper:

```
<?=$argn==Bad?Goo:Ba?>d

```

Try it online!

**Original answer, 26 bytes**

```
<?=[Ba,Goo][$argn==Bad]?>d

```

Try it online!

**Or 21 bytes (but this is basically Arnauld's answer)**

```
<?=$argn[3]?Ba:Goo?>d

```

Try it online!

# Answer
> 2 votes
## Keg, 22 bytes

```
?^_^_o=[^aB^_|^ooG^]

```

# Answer
> 2 votes
# brainfuck, 52 bytes

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

```

Try it online!

Relies on Bad being one letter shorter than Good, so the last input is empty.

### Explanation:

```
,>,,<<,       Get input into the first three cells
[             If the last letter was not empty (i.e. Good)
 >-----.      Decrement 'G' to 'B' and print
 <---.        Decrement 'd' to 'a' and print
 +++.         Increment back to 'd' and print
>>]           End loop
>[            If it is Bad instead
 +++++.       Increment 'B' to 'G' and print
 +[-<-->]<-.. Manipulate into  'o' and print twice
 >>.          Print 'd'
>]            End loop

```

# Answer
> 2 votes
## Keg, `-rt` ~~20~~ ~~17~~ ~~15~~ ~~13~~ ~~8~~ 7 bytes (SBCS)

```
-᠀‘5ƳP↫

```

Transpiles to:

```
from KegLib import *
from Stackd import Stack
stack = Stack()
printed = False
iterable(stack, 'GoodBad')
string_input(stack)
maths(stack, '-')

if not printed:
    printing = ""
    for item in stack:
        if type(item) in [str, Stack]:
            printing += str(item)
        elif type(item) == Coherse.char:
            printing += item.v

        elif item < 10 or item > 256:
            printing += str(item)
        else:
            printing += chr(item)
    print(printing)

```

It's a port of the 05AB1E answer. Essentially, it:

* Pushes the string `"GoodBad"`
* Takes input as a string
* Subtracts the input from the pushed string. This works by replacing the first instance of the input within `GoodBad` with nothing.
* Implicitly prints the resulting string.
* The `-rt` flag tells Keg to read tokens from right to left.

## Answer History

```
?G=[øBad|ø‘5Ƴ

```

Transpiles to the following:

```
from KegLib import *
from Stackd import Stack
stack = Stack()
printed = False
Input(stack)
character(stack, 'G')
comparative(stack, '=')
if bool(stack.pop()):
    empty(stack)
    character(stack, 'B')
    character(stack, 'a')
    character(stack, 'd')

else:
    empty(stack)
    iterable(stack, 'Good')

if not printed:
    printing = ""
    for item in stack:
        if type(item) is Stack:
            printing += str(item)

        elif type(item) is str:
            printing += custom_format(item)
        elif type(item) == Coherse.char:
            printing += item.v

        elif item < 10 or item > 256:
            printing += str(item)
        else:
            printing += chr(item)
    print(printing)

```

### Explanation

```
?G=[øBad|ø‘5Ƴ

?            #Get input from user
 G=          #If the first letter is "G"
   [øBad     #Clear the stack and push "Bad"
        |    #Else,
         ø‘5Ƴ#Clear the stack and push the compressed string "Good"

```

# Answer
> 2 votes
# Boolfuck, ~~110~~ 68 bytes

```
,+;+[;+;;;;+;+;+;<;]>+;;[+;;;+;+;+;;;;+;+;;+;+;;;;+];+;;+;;;+;+;;+;;

```

Thanks to Jo King for the massively improved solution!

Try it with Online!

# Answer
> 2 votes
# Boolfuck, 47 bytes

```
+>,+;>,;,+;>;;;+;+;+[;<;;;,;+;;+;<];;+;+;;+;;+;

```

Try it online!

Uses the fact that you can basically just take in the input as bits and then invert certain bits to turn it into the opposite letter.

### Explanation:

```
+>,+;>,;,+;>;;;+;+;+    Print the first letter by inverting the first and third bits of the input
                        'B' = 01000010
                        'G' = 11100010
                        This leaves the tape as
                            1 1 1 1' in the case of Bad
                            1 0 0 1' in the case of Good
                        By making the center cells the inverted bits
[;<;;;,;+;;+;<]         Print the center letters by looping over the two pairs of cells
                        0 1' results in 'a' = 10000110
                        1 1' results in 'o' = 11110110 by printing the 1 in the 2-4th places
                        1 1 1 1' loops twice, while 1 0 0 1' only loops once
;;+;+;;+;;+;            Finally print 'd' = 00100110

```

# Answer
> 2 votes
# Zsh, ~~21~~ 20 bytes

***-1** by just defining a variable first instead of using an empty fallback*

```
x=GoodBad
<<<${x/$1}

```

~~Try it online!~~ Try it online!

```
<<<${${[implicit parameter]:-fallback}/pattern[/implicit empty replacement]}

```

No coreutils, and nearly as good as the Bash+coreutils answer (which is compatible with Zsh).

# Answer
> 2 votes
# Whitespace, ~~114~~ ~~104~~ 103 bytes

```
(much whitespace)
```

Try it online!

-5 bytes thanks to Jo King.

-5 bytes by determining if the input is odd or even instead of subtracting "B"

-1 byte thanks to Kevin Cruijssen by using the initial 3 as address for reading characters

```
sssttl      push "d"
sls         dup (address for "retrieve")
sls         dup (address for "readc")
tlts        readc
ttt         retrieve
ssstsl      push 2
tstt        mod (determine if input is even or odd)
ltssl       jz good
sssl        push "a"
ssttttttl   push "B"
lsll        jmp print
lsssl       lbl good
ssstttsl    push "o"
sls         dup
sstttstsl   push "G"

lssl        lbl print
sssttsssstl 97
tsss        add
tlss        printc
lsll        jmp print

```

# Answer
> 2 votes
# PHP, 30 bytes

```
<?=strtok(BaGoo,readline()).d;

```

Best suppress notices.

# Answer
> 2 votes
# C# (Visual C# Interactive Compiler), 30 bytes

```
Write(Read()>'B'?"Bad":"Good")

```

Try it online!

# Answer
> 2 votes
# Kotlin, 52 bytes

```
fun main()=print("GoodBad".replace(readLine()!!,""))

```

Try it online!

# Answer
> 2 votes
# MAWP, 59 bytes

```
%|~88W7MA{88W7M;99W65WM!;;25W25WW;}<88W2M;99W44WM;25W25WW;>

```

Try it!

# Answer
> 2 votes
**Javascript 50 bytes**

```
alert((305786-parseInt(prompt(),26)).toString(26))
```

# Answer
> 2 votes
# Vyxal `r`, 7 bytes

```
`ƛ⁋«Ṫ`-

```

Try it Online!

This is irony in a nutshell.

## Explained

```
`...`-
`...`  # the string "GoodBad"
     - # ^ - input (removes it)

```

In the spirit of my Keg answer, here's the compiled code:

```
global stack, register, printed, output, MAP_START, MAP_OFFSET, _join, _vertical_join, use_encoding, input_level, raw_strings, retain_items, reverse_args, this_function
stack.append("GoodBad")

rhs, lhs = pop(stack, 2); stack.append(subtract(lhs, rhs))

```

# Answer
> 2 votes
# .COM, 31 bytes

```
org 0x100
mov dx, 0x100
mov eax, 0xA20 + '$$'*0x10000
int 0x21
inc dx
inc dx
xor dword [0x102], 'Good' xor ('Bad'+0x0d000000)
mov al, 0x20
int 0x29     ; Avoid "Badd"
mov ah, 9
int 0x21
ret

```

# Answer
> 1 votes
**My shortest possible solution in Python (43 bytes)**

```
print({'Good':'Bad','Bad':'Good'}[input()])

```

**And MilkyWay90 further golfed version (-2 bytes)**

```
print({'G':'Bad','B':'Good'}[input()[0]])

```

# Answer
> 1 votes
# Wolfram Language (Mathematica), ~~48~~ ~~44~~ 38 bytes

```
If[$ScriptInputString=="Bad",Good,Bad]

```

Try it online!

-4 bytes thanks to Jonathan Allan: using symbols instead of strings as output

-6 bytes by removing `Print@`, which is implicit in the command-line version of WolframScript and can be simulated on TIO with the `-print` argument

# Answer
> 1 votes
# K (oK), 16 bytes

**Solution:**

```
$`Bad`Good"Bad"~

```

Try it online!

Returns `"Good"` if input is `"Bad"` otherwise returns `"Bad"` for all other inputs.

# Answer
> 1 votes
# C# (Visual C# Interactive Compiler), 23 bytes

```
a=>a[0]>66?"Bad":"Good"

```

Try it online!

# Answer
> 1 votes
# ///, 23 bytes

```
/#Good/Bad//#Bad/Good/#

```

Try it online!

There is no other way to take input in /// so it is hard-coded:

```
/#Good/Bad//#Bad/Good/#<INPUT HERE>

```

# Answer
> 1 votes
## Windows batch, ~~53~~ ~~48~~ 47 bytes

-1 bytes, thanks to @Neil for noticing the trivialness of the space before `else`.

```
set/pa=
if %a%==Bad (echo Good)else (echo Bad)

```

`set/pa=` prompt for input and set a to that input

`if %a%==Bad (echo Good)else (echo Bad)` antonym for `Good` and `Bad`. Unfortunately Windows batch requires whitespace...

# Answer
> 1 votes
# Pyth, 12 bytes

```
+-"GooBa"z\d

```

Try it online!

```
+-"GooBa"z\d   Implicit: z=input()
 -"GooBa"z     Keep letters in "GooBa" which do not appear in z
+         \d   Append "d", implicit print

```

# Answer
> 1 votes
# Runic Enchantments, 21 bytes

```
"Bad":i≠7*?~"Good"@

```

Try it online!

Prints `Good` when the input is `Bad` and prints `Bad` for all other inputs.

# Answer
> 1 votes
# Sinclair ZX80 BASIC (4K ROM) - 46 tokenized BASIC bytes

```
 1 INPUT A$
 2 IF A$="GOOD" THEN PRINT "BAD"
 3 IF A$="BAD" THEN PRINT "GOOD"

```

### Sinclair ZX81 BASIC (Also Timex TS 1000/1500 or ZX80 with 8K ROM upgrade) - 45 tokenized BASIC bytes

```
 1 INPUT A$
 2 PRINT "GOOD" AND A$="BAD";"BAD" AND A$="GOOD"

```

# Answer
> 1 votes
# Python 3, 37 bytes

```
print(['Bad','Good'][input()=='Bad'])

```

Try it online!

# Answer
> 1 votes
# Underload, ~~26~~ ~~25~~ 16 bytes

```
(Bad)(Good)Bad^S

```

Since Underload has no input instructions, input is hard-coded (The ‘Bad’ on the right).

Really proud of this one: Underload has no way to check strings, so I had to go off of the fact the ‘Bad’ contains an `a`, which is an instruction that puts brackets around the top thing in the stack.

Edit: Saved 9 bytes over my old one by getting rid of 2 pairs of brackets, only using one `S` and getting rid of some `!`s and `^`s

Try it with Bad!

Try it with Good!

# Answer
> 1 votes
# Racket, 38 bytes

```
(write(match(read)['Bad'Good][_'Bad]))

```

# Answer
> 1 votes
# Extended BrainFuck: ~~29~~ 28

```
,>,,,[>|"Bad">>]<[>|"Good">]

```

*-1 bytes thanks to @JoKing*

The compiled bf code can run on an interpreter that expects stream end after the last letter and a interpreter that uses 0 as the EOF value. eg. `bf -n` or `beef`. eg

```
> bf ebf.bf < GoodBad.ebf > GoodBad.bf
> echo Bad | bf -n GoodBad.bf
Good
> echo Good | bf -n GoodBad.bf
Bad

```

# Answer
> 1 votes
# 33, 20 bytes

```
Itj71m"Good"'Bad'ntp

```

I don't have it on TIO yet, I'll update this when I do.

Explanation:

```
It                   | Get input
  j71m           n   | If the first character is 'G'
      "Good"       p | - Print "Good"
            'Bad' tp | Else, print "Bad"

```

# Answer
> 1 votes
# Wren, 30 bytes

```
Fn.new{|x|"GooBa".trim(x)+"d"}

```

Try it online!

## Explanation

```
Fn.new{|x|                   } // New anonymous function with parameter x
                               // Sample input: "Bad"
          "GooBa"              // Define a string
                 .trim(x)      // Trim out all characters in the input string
                               // "GooBa" - "Bad" = "Goo"
                         +"d"  // Return the string joined with a "d": "Good"

```

# Answer
> 1 votes
# `d`, ~~12~~ ~~11~~ 9 bytes

Realized that I could use the implicit quote system. Still can't beat Keg with the decompression. (Alternative 9-byter:`§D⑺y⒁v⑼z¬`; but that's the same bytecount)

```
☺DΩy±v∞z↓

```

## Explanation

% Sample input: "Bad"
% Implicitly prepend a quote for this string
GooBa"     % Stack: ["Bad","GooBa"]
      S    % Stack: ["GooBa","Bad"]
       t   % "GooBa".trim("Bad"), which is "Goo"
        'd % Stack: ["Goo","d"]
           % Stack: ["Good"]

% Implicit output
```
</code></pre>

# Answer
> 1 votes
# Pushy, 17 bytes

```
.F`Goo`x?c`Ba`;H"

```

Try it online!

## Explanation:

```
                  \ Implicit: input on main stack.
.F                \ Pop last letter, and move to auxiliary stack.
  `Goo`           \ Push 'Goo' to main stack.
       x?     ;   \ If the stacks are equal:
         c`Ba`    \    Replace 'Goo' with 'Ba'
               H  \ Push 'd', as char(d) = 100 = H
                " \ Print stack

```

# Answer
> 1 votes
# naz, 66 bytes

```
9a7m4a2x1v1x1f1r3x1v2l5s1o2d3m2s1o3a1o0x1x2f5a1o2d3m6a2o9s2s1o0x1f

```

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

```
9a7m4a2x1v                   # Set variable 1 equal to 67 ("C")
1x1f                         # Function 1
    1r3x1v2l                 # Read the first byte of input
                             # Jump to function 2 if it's less than variable 1
            5s1o2d3m2s1o3a1o # Otherwise, output "Bad"

1x2f5a1o2d3m6a2o9s2s1o       # Function 2
                             # Output "Good"
1f                           # Call function 1

```

# Answer
> 1 votes
# `j`, 8 bytes

Still doesn't tie with Keg. Help!

```
♥d←╖←I¡%

```

Uncompressed:

```
G'%Av%?S,

```

# Explanation

<pre><code>           % Implcitly start a compressed string
G'         % "good" in the dictionary
  %        % Capitalize
   Av      % "bad" in the dictionary
     %     % Capitalize
      ?    % End compressed string
       S   % Swap so that the input comes to the top
        ,  % Split the string on the input

Flag:j     % Implicit smash on output list
```

# Answer
> 1 votes
# FALSE, 23 bytes

```
^'B=$["Good"]?~["Bad"]?

```

Try it online!

## Explanation

The program gets an input character and checks if it is equal to 'B'. If it is, it prints 'Good', and if it isn't it prints 'Bad'. This makes use of the fact that 'Good' and 'Bad' are easily differentiable based on simply the first character of each word.

```
^                  {Get input character}
'B=                {See if input char is equal to 'B'}
["Good"]?~["Bad"]? {If top of stack is TRUE, print "Good", else print "Bad"}

```

Note: Curly brackets denote comments in FALSE. In the past I've used '//' to comment FALSE code in my explanations, but since it isn't syntactically valid I'm now trying to use FALSE's comment syntax.

# Answer
> 1 votes
# APOL, 32 bytes

Just checks if the input starts with "G".

`g(["Good" "Bad"] I(=(g(i) "G")))`

# Answer
> 1 votes
# (e-)TeX, 48 bytes

```
\read0to~\expanded{\def\##1~{#1}}\#Good Bad \bye

```

Output is to dvi/pdf file.

# Answer
> 1 votes
# Pip, 12 bytes

```
"GoodBad"RMq

```

Attempt This Online!

### Explanation

```
           q  ; Read a line of input from stdin
         RM   ; Remove that substring from
"GoodBad"     ; This literal string

```

# Answer
> 1 votes
# QBasic, 37 bytes

```
INPUT s$
IF"C"<s$THEN?"Bad"ELSE?"Good

```

Try it at Archive.org

### Explanation

Uses string comparison to separate the two cases. Ungolfed:

```
INPUT s$
IF "C" < s$ THEN PRINT "Bad" ELSE PRINT "Good"

```

# Answer
> 1 votes
# Python 3, 30 Bytes

```
exit({'Good','Bad'}-{input()})

```

Uses the same `exit` trick as the other python 3 solution. It's unclear to me if this solution is necessarily allowed by the problem, but the output is certainly separated from the input, so I think it counts.

# Answer
> 1 votes
# Factor, 29 bytes

```
read1 66 = "Good""Bad"? print

```

Try it online!

# Answer
> 1 votes
# *Acc!!*, 105 bytes

```
N
Count i while _/71 {
Write 66
Write 97
0
}
Count i while _ {
Write 71
Write 111
Write 111
0
}
Write 100

```

Try it online!

### Explanation

```
# Read a character from stdin (user must enter a full line)
N
# Loop while the character code int-divided by 71 is nonzero (i.e. G was entered)
Count i while _ / 71 {
  # Write Ba
  Write 66
  Write 97
  # Set accumulator to 0 to exit the loop
  0
}
# Loop while the accumulator is nonzero (i.e. previous loop did not run)
Count i while _ {
  # Write Goo
  Write 71
  Write 111
  Write 111
  # Set accumulator to 0 to exit the loop
  0
}
# Write d
Write 100

```

# Answer
> 1 votes
# Thunno, \\$15\log\_{256}(96)\approx\\$ 12.35 bytes

```
"Bad"Dz0=?"Good

```

Attempt This Online!

```
"Bad"Dz0=?"Good  # Implicit input
"Bad"D           # Push the string bad and duplicate           (STACK: "Bad", "Bad")
      z0         # Push the input                              (STACK: "Bad", "Bad", input)
        =?"Good  # If they are equal, push the string "Good"   (STACK: "Bad", "Good") IF input == "Bad"
                 # Otherwise, the stack is left as-is          (STACK: "Bad") IF input != "Bad"
                 # Implicit output of top of stack

```

# Answer
> 0 votes
# Attache, 24 bytes

```
$Good'$Bad^^Stdin[]|Echo

```

Try it online!

## Explanation

```
$Good'$Bad^^Stdin[]|Echo
$Good'$Bad                   an array of the strings "Good" and "Bad"
          ^^                 remove from this array
            Stdin[]          standard input
                             this leaves us with a singleton array of the swapped element
                   |Echo     pipe the Echo function to each member of this array
                             (in this case, only prints the one element)

```

## Alternatives

**25 bytes:** `$Good'$Bad⩓Stdin[]|Echo`

**26 bytes:** `[$Good,$Bad]^^Stdin[]|Echo`

**29 bytes:** `Echo@If[Stdin[]@3,$Bad,$Good]`

**29 bytes:** `Echo@[$Bad,$Good][Stdin[]<$G]`

**37 bytes:** `[4875396,32943]^^STN@Stdin[]|Echo@NTS`

**44 bytes:** `Good:=$Bad;Bad:=$Good;Print@EvalHere@Stdin[]`

# Answer
> 0 votes
# F# (.NET Core), ~~50~~ 35 bytes

Down to 35 thanks to @Expired Data

```
 fun a->if a>"B"then"Bad"else"Good"

```

Try it online!

Original:

F# (.NET Core), 50 bytes

```
printf(if stdin.ReadLine()>"B"then"Bad"else"Good")

```

Try it online!

# Answer
> 0 votes
# Python 2, 32 bytes

```
print('Good','Bad')['C'<input()]

```

Try it online!

Using `exit` requires extra brackets around the whole expression so in this case `print` is 1 byte shorter.

# Answer
> 0 votes
# Python 3, 33 bytes

```
exit(['Bad','Good'][input()<'G'])

```

Try it online!

Prints to stderr, to save one byte over `print()`.

# Answer
> 0 votes
# Japt `-P`, 11 bytes

```
"GoodBad"qU

```

Try it

### Explanation:

```
"GoodBad"qU     U = Input             "Good"        "Bad"
"GoodBad"       String literal        "GoodBad"     "GoodBad"
         qU     Split at U            ["","Bad"]    ["Good",""]
-P              Join into a string    "Bad"         "Good"

```

## Alternative

```
"GoodBad"rU

```

`r` replaces `U` with `""`

Try it

# Answer
> 0 votes
# Dart, 77 bytes

```
import'dart:io';main()=>print('BadGood'.replaceAll(stdin.readLineSync(),''));

```

Try it online!

# Answer
> 0 votes
# Pepe, 104 bytes

```
rEEeREeEeeeEEErrEEreeEeeeEEEreeEEeEEEEreeEEeEEEEreeEEeeEeeREerREEreeEeeeeEereeEEeeeeEreeEEeeEeeREeReEree

```

Try it online!

## With comments

```
# Prepare stacks
rEEe        # r ← Input
REeEeeeEEE  # R ← 'G'

# Create label i (outputs "Good")
rrEE { reeEeeeEEE reeEEeEEEE reeEEeEEEE reeEEeeEee } REe

# Create label 'G' (outputs "Bad")
rREE { reeEeeeeEe reeEEeeeeE reeEEeeEee } REe

# Compare values
ReE  # If the first letter of input is 'G', go to label 'G'
ree  # Otherwise, go to label i

```

# Answer
> 0 votes
# Zozotez: 22

```
(?(=(r)'Bad)'Good'Bad)

```

# Answer
> 0 votes
# ScPL, 61 bytes

```
ChooseFromMenu''[Good Bad]
Case
Text'Bad'
Case
Text'Good'
End

```

Editor Link

The first argument to ChooseFromMenu is the title, which doesn't matter so we put an empty string. The second argument is the list of choices.

Cases do not require a label, they go based on order.

Seperators between things are only required when they are not seperated some other way, for example `a b` needs a space because `ab` is one argument, but `a'b'` does not because the ' starts another argument.

# Answer
> 0 votes
# Java (OpenJDK 8), ~~51~~ 42 bytes

```
g->{if(g=="Bad")return"Good";return"Bad";}

```

Try it online!

Checks if input is `Bad`.

-9 to @JoKing

# Answer
> 0 votes
# PHP, 31 bytes

```
readline()=="Bad"?"Good":"Bad";

```

Try it online!

## Another way, 41 bytes

```
["Bad"=>"Good","Good"=>"Bad"][readline()];

```

Try it online!

# Answer
> 0 votes
## GNU Smalltalk, 34B

Please forgive me for submitting a code snippet if Smalltalk does have input. I am a complete novice to Smalltalk.

```
i<'C'ifTrue:['Good']ifFalse:['Bad']

```

You replace the name i with the intended input.

# Answer
> 0 votes
# TI-BASIC, 38 bytes

```
Input Str1:"GoodBad
sub(Ans,abs(inString(Ans,Str1)-5)+1,4

```

Prompts the user to input the string, then prints the other string as specified in the challenge.

**Explanation:**

```
Input Str1                               ;get the input
"GoodBad "                               ;leave "GoodBad " in Ans. closing quote
                                         ;  is added for clarity (isn't in program)
            inString(Ans,Str1)           ;get the 1-indexed position of the input
                                         ;  in "GoodBad "
        abs(                  -5)+1      ;subtract 5, get the absolute value,
                                         ;  then add 1
sub(Ans, ...                       ,4    ;get the substring of "GoodBad " starting
                                         ;  at the position just calculated with
                                         ;  a length of 4.  leave the result in Ans
                                         ;implicit print of Ans

```

# Answer
> 0 votes
# Thunno 2, 9 bytes

```
’⁽ȯBad’$o

```

Attempt This Online!

#### Explanation

```
’⁽ȯBad’$o  # Implicit input
’⁽ȯBad’    # Compressed string "GoodBad"
       $o  # Remove the input
           # Implicit output

```

---
Tags: code-golf, string
---


# Question
Title: What do you get when you multiply 6 by 9? (42)
I love math. But I can't find a single calculator that can multiply correctly. They seem to get everything right except 6\*9 (It's the question to life, the universe, and everything! How could they get that wrong?!). So I want you all to write a function for me that can multiply 2 numbers correctly (and 6\*9 equals 42 instead of 54. 9\*6 equals 54 still).

Oh, and I'm going to have to build the source in Minecraft so... fewest bytes win!

Recap

* Take 2 numbers as input (type doesn't matter, but only 2 items will be passed, and order must be consistent. So streams, and arrays are ok as long as they preserve the order they where passed in. I.e., a map won't work because it doesn't preserve the order)
* Output multiple of both numbers except if they are 6 and 9, then output 42 (order matters!)
    + PS. I never was really good with counting, so I think only integers from 0 to 99 are real numbers (type used doesn't matter)
* Fewest bytes per language wins!

**Leaderboard:**

```
var QUESTION_ID=124242,OVERRIDE_USER=61474;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&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(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.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(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+r.match(SCORE_REG)[0],language:r.match(LANG_REG)[0].replace(/<\/?[^>]*>/g,"").trim(),link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/\d+((?=$)|(?= Bytes))/i,OVERRIDE_REG=/^Override\s*header:\s*/i;LANG_REG=/^[^,(\n\r]+/i
```

```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;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="//cdn.sstatic.net/Sites/codegolf/all.css?v=617d0685f6f3"> <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><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><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

# Answer
## Mathematica, 15 bytes

Byte count assumes Windows ANSI encoding (CP-1252).

```
6±9=42
±n__:=1n

```

Defines a binary operator `±` which solves the problem. We simply define `6±9=42` as a special case which takes precedence and then add a fallback definition which makes `±` equal to multiplication. The latter uses a fairly interesting golfing trick. The reason this works is actually quite elaborate and we need to look into *sequences*. A sequence is similar to what's known as a *splat* in other languages. It's basically a "list" without any wrapper around it. E.g. `f[1, Sequence[2, 3, 4], 5]` is really just `f[1, 2, 3, 4, 5]`. The other important concept is that all operators are just syntactic sugar. In particular, `±` can be used as a unary or binary operator and represents the head `PlusMinus`. So `±x` is `PlusMinus[x]` and `a±b` is `PlusMinus[a,b]`.

Now we have the definition `±n__`. This is shorthand for defining `PlusMinus[n__]`. But `n__` represents an arbitrary *sequence* of arguments. So this actually adds a definition for binary (and n-ary) usagess of `PlusMinus` as well. The value of this definition is `1n`. How does this multiply the arguments? Well, `1n` uses Mathematica's implicit multiplication by juxtaposition so it's equivalent to `1*n`. But `*` is also just shorthand for `Times[1,n]`. Now, `n` is sequence of arguments. So if we invoke `a±b` then this will actually become `Times[1,a,b]`. And that's just `a*b`.

I think it's quite neat how this syntax abuse lets us define a binary operator using unary syntax. We could now even do `PlusMinus[2,3,4]` to compute `24` (which can also be written as `±##&[2,3,4]` or `2±Sequence[3,4]` but it's just getting crazy at that point).
> 68 votes

# Answer
# Haskell, 14 bytes

```
6&9=42
a&b=a*b

```

Try it online!
> 59 votes

# Answer
# C, ~~32~~ ~~31~~ ~~29~~ 28 bytes

-2 thanks to Digital Trauma
-1 thanks to musicman523

```
#define f(a,b)a^6|b^9?a*b:42

```

Pretty simple. Declares a macro function `f` that takes two arguments, `a` and `b`.
If `a` is `6` and `b` is `9`, return `42`. Otherwise return `a` x `b`.

Try it online!
> 28 votes

# Answer
# JavaScript (ES6), 20 bytes

```
x=>y=>x-6|y-9?x*y:42

```

**Explanation:**

Iff x==6 and y==9, `x-6|y-9` will be 0 (falsy), and 42 will be the result.

**Snippet:**

```
f=

x=>y=>x-6|y-9?x*y:42

console.log(f(6)(9));
console.log(f(9)(6));
```
> 18 votes

# Answer
# Python 2, ~~30~~ 29 bytes

Thanks to *Jonathan Allan* for saving a byte!

```
lambda x,y:x*[y,7][6==x==y-3]

```

Try it online!
> 14 votes

# Answer
# 05AB1E, ~~15~~ ~~11~~ 9 bytes

-4 bytes thanks to @Emigna

-2 bytes thanks to @Adnan

```
P¹69SQi42

```

Try it online!

How it works

```
P          # multiply input
 ¹         # push first number
  69       # the number 69
    S      # split per character
     Q     # equality for both inputs
       i42 # if so, print 42
           # otherwise print product

```
> 11 votes

# Answer
# Java (OpenJDK 8), ~~24~~ 22 bytes

*-2 bytes thanks to @OlivierGrégoire*

```
a->b->a==6&b==9?42:a*b

```

Try it online!
> 11 votes

# Answer
# Ruby, 24 bytes

```
->a,b{a==6&&b==9?42:a*b}

```
> 6 votes

# Answer
# Brain-Flak, ~~158~~ ~~154~~ ~~148~~ ~~140~~ ~~138~~ 126 bytes

```
(({}<>)(((([()()()]<>)){})<({}{}({}))>{(()()()){}(<{}>)}{}))([()]{()(<{}>)}{})(({<{}>{}((<>))}{}){}<{}>{<({}[()])><>({})<>}{})

```

Try it online!

# Explanation

This code is pretty simple. We make copies of the top two items on the stack, we subtract 6 from one and 9 from the other. We then take the `not` of the two values. We `and` those values, multiply the result by 12. Multiply the inputs and subtract the two results.
> 6 votes

# Answer
# MATL, 11 bytes

```
[BE]=?42}Gp

```

Input is an array with the two numbers.

Try it online!

### Explanation

```
[BE]    % Push array [6, 9]
=       % Implicit input: array of two numbers. Compare with [6, 9] element-wise
?       % If the two entries are true
  42    %   Push 42
}       % Else
  G     %   Push input
  p     %   Product of array
        % Implicit end. Implicit display

```
> 6 votes

# Answer
# Jelly, ~~8~~ 7 bytes

```
Vf96SạP

```

Input is as an array of two integers: first the right operand, then the left one.

Try it online!

### How it works

```
Vf96SạP  Main link. Argument: [b, a]

V        Cast [b, a] to string, then eval the resulting string.
         For [b, a] = [9, 6], this yields 96.
 f96     Filter with 96, yielding [96] if V returned 96, [] otherwise.
    S    Take the sum, yielding either 96 or 0.
      P  Compute the product of [b, a], yielding ba = ab.
     ạ   Compute the absolute difference of the results to both sides.
         When the sum is 0, this simply yields the product.
         However, when [b, a] = [9, 6], this yields 96 - 54 = 42.

```
> 6 votes

# Answer
# Factorio, 661 bytes, 6 combinators with 9 connections

There is one constant combinator set to output A and B. Change these to set the input.

Blueprint string (0.15.18):

```
0eNrNVm2O2jAQvcv8rEKFvSHLRuqPtrfYCkUhGWAkYkfOGDVCOUBv0bP1JLWTLQuB3U0QbfcPYvzxZt68eYr3sNxaLA0phngPlGlVQfxtDxWtVbr1a1yXCDEQYwEBqLTwUY4Z5WgmmS6WpFLWBpoASOX4HWLRBG8C+EScKr6MIJtFAKiYmLCrpw3qRNliicaleK2SAEpduata+fQObiI+zgKo/R+XIyeDWbcrA18IG71NlrhJd+RuuytPmInby1ucyq+uyFScnPHakWHrVg4VdScmnz2fPzQhjnxQlKlpS4zhk7ugLZd2BCTu0NS8IbXusMvalWgVJyuji4SUA4OYjcWmS606nm31wv8YzI+7SS66axbusHxh1zeITGaJ21C4w41XtyeHHCXH9D+o8eVUjYd3qoY47bc86rWPo158/yze2iCqPtxsmHx3r9ry3E6ylU9cTUv0aITDygwPZaaGeFMgUzbM99NBg/aMegPnV+gxRg6oLtFNZFsjfLhiJB+huZn1B87O7Crr/0Pnfz11vug5/9ePn+/E+2Hf++4beNHV8uzgRWWica6ejnDKiraM5oWXwhtC2CcVDo+FxfAWDfwc3Y9jLv4288cj5qG8IXU3Ie2zKj56xgXgZrNqOURhKGfR/GE6nzfNb7OMaxo=

```

The output is signal Z and is to be taken from the top and bottom deciders.
> 6 votes

# Answer
## Factorio, 581 bytes, 3 combinators with 4 connections

Blueprint string (0.16.36):

```
0eNqllNtu4jAQht9lLldmldNCFWkvto/RCkUhGWAkYkfOGDVCefeOnV1Km7ACemPJ9vibf04+webgsLWkGfITUGV0B/nrCTra6fLgz7hvEXIgxgYU6LLxO2/HpeZFZZoN6ZKNhUEB6RrfII+HtQLUTEw44sKmL7RrNmjF4AyqsaIa7SVHQWs6eWq0dy+46OcvBT3ki1hc1GSxGi8T5XWwNYdig/vySPJYXvxFFnJXB0znT7dkOy4mYR3JspOTs6DRYoFHtD3vSe98XP/CFZ9xtsqe0mW29KdNW9qgOYffgjCOW3eHk+eR3fai1WkuttY0BWlhQM7W4TC61mPAIYzYLxbry6yS7FKxJFs54rANFdhZRP3VMBnWQk08ZvZ+ChpExqSCyX9bYVLCRfxRwbmabenAaK+03rX0/RnT5z7VJbroQnUH7HkGlq7OsDFtc8WYzWJ8WxbTs4rSEu8bZKpuGoXopkn4gH5vGEKiO/SMO5vbtCgDEjTCjwcm5AWGO4ZgknX16Tq7OhRfHiZXypU91PTRd6ZYdIjo8PnmF3+1AvmfuuBq+bRKYmnWKM2G4R1hAPnz

```

The bottom left constant combinator should be set to output A and B as input. The output is signal Z from the bottom right arithmetic combinator.

```
Top left: 2147483640 A, 2147483637 B
Top right: If everything = 2147483646 output B, input count
Bottom left: (input) A, (input) B
Bottom right: A * B -> Z

```
> 6 votes

# Answer
# , 33 bytes

```
function(a,b)`if`(a-6|b-9,a*b,42)

```

Returns a function.

Try it online!
> 5 votes

# Answer
# GW-BASIC, 55 bytes

```
1INPUT A:INPUT B
2IF A=6THEN IF B=9THEN ?"42":END
3?A*B

```

Output:

The first machine at pcjs has IBM BASIC, which is practically the same thing. To test this, head over there, hit `Run` on the machine, Press `Enter`-`Enter` and type `BASICA` to get into BASIC mode. Then enter the source code (it will automatically prettyprint for you), type `RUN`, input two integers, and done!
> 4 votes

# Answer
# Japt, ~~13~~ ~~11~~ 12 bytes

```
¥6&V¥9?42:N×

```

Try it online

* ~~2~~ 1 bytes saved thanks to obarakon.
> 4 votes

# Answer
# JavaScript (ES6), 25 bytes

```
x=>y=>[x*y,42][x==6&y==9]

```
> 4 votes

# Answer
## Check, ~~34~~ 33 bytes

```
.:+&>#v
#>42#v#9-!\>6-!*?
 d* ##p

```

Check is my new esolang. It uses a combination of 2D and 1D semantics.

Input is two numbers passed through command line arguments.

### Explanation

The stack starts with the command line arguments on it. Let's call the arguments `a` and `b`.

The first part, `.:+&`, essentially duplicates the stack, leaving it as `a, b, a, b`. `>` pushes 0 to the stack (it is part of a numeric literal completed by `9`).

`#` switches to 2D semantics, and `v` redirects the IP downwards. The IP immediately runs into a `#`, which switches back to 1D semantics again.

`9-!` checks whether `b` is equal to 9 (by subtracting 9 and taking the logical NOT). `\>6-!` then checks whether `a` is equal to 6. The stack now contains `a, b, 1, 1` if and only if `b==9` and `a==6`. Multiplying with `*` takes the logical AND of these two values, giving `a, b, 1` if the inputs were `6` and `9`, and `a, b, 0` otherwise.

After this, the IP runs into a `?`. This will switch to 2D mode if the top stack value is nonzero, and otherwise will continue in 1D mode.

If the top stack value was `1`, this means that the other stack values are `6` and `9`, so we push 42 to the stack with `>42` and then move down to the second `#` on the last line.

If the top stack value was `0`, then execution moves down to the next line. `d` removes the `0` (as `?` does not do so), and then we multiply the two inputs with `*`. The `##` switches in and out of 2D mode, doing nothing.

The branches have now joined again. The stack either contains `6, 9, 1, 42`, or `a*b`. `p` prints the top stack value and then the program ends, discarding the rest of the stack.
> 4 votes

# Answer
# Python 3, ~~36~~ 33 bytes

```
lambda x,y:42if x==6==y-3else x*y

```

Try it online!
> 3 votes

# Answer
# Standard ML (MLton), ~~22~~ 20 bytes

Saved 2 bytes thanks to @Laikoni!

```
fun$6 $9=42| $x y=x*y

```

Try it online!

This is the kind of thing SML is meant for, which is why it beats shortC and Python.

The old version looked much nicer. :P
> 3 votes

# Answer
# APL (Dyalog), 10 bytes

```
×-12×6 9≡,

```

Try it online!

`×` the product (of the arguments)

`-` minus

`12×` twelve times

`6 9≡` whether (6,9) is identical to

`,` the concatenation (of the arguments)
> 3 votes

# Answer
**R, 41 I think** I don't know how to count bytes I am new :D

```
function(a,b){

if(a==6&b==9){42} else {a*b}

}

```

I define a funtion whose arguments are a and b **in this order**. If a equals to 6 and b equals to 9 it returns 42, otherwise, a times b
> 3 votes

# Answer
## SPL, 356 bytes

```
a.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]Ajax:Listen to your heart!Puck:Listen to your heart!Are you as big as the sum of a big big big cat and a cat?If so, am I as big as the sum of a big big cat and a big cat?If so, you are as big as the product of I and the sum of I and a cat.If not, you are as big as the product of you and I.Open your heart

```

With newlines and spaces:

```
a.                       *Title*
Ajax,.                   *Declare variable Ajax*
Puck,.                   *Declare variable Puck*
Act I:.
Scene I:.
[Enter Ajax and Puck]
Ajax: Listen to your heart!                  *Set Puck's value to user input*
Puck: Listen to your heart!                  *Set Ajax's value to user input*
      Are you as big as the sum of a big
       big big cat and a cat?                *Is Ajax=9?*
      If so, am I as big as the sum of a
       big big cat and a big cat?            *Is Puck=6?*
      If so, you are as big as the product
       of I and the sum of I and a cat.      *If so, set Ajax=42*
      If not, you are as big as the product
       of you and I.                         *If not set Ajax=(Ajax)(Puck)*
      Open your heart                        *Print Ajax's value*

```
> 3 votes

# Answer
# Brachylog, 8 bytes

```
c69∧42|×

```

Try it online!

A predicate which takes a pair of numbers as its input variable and outputs their correct product through its output variable.

```
            If the input
c           concatenated
 69         is 69,
   ∧42      then output 42,
      |     otherwise
       ×    output the product of all numbers in the input.

```

I have no clue why `[0,69]c69` fails, but I am very glad that it does! (Running `69~cᶠw` confirms that `[6,9]` is the only two-element list that concatenates to `69`.)
> 3 votes

# Answer
# Python 3, 33 bytes

```
lambda x,y:42*(x==6)*(y==9)or x*y

```

Try it online!
> 3 votes

# Answer
## Pascal, 69 characters

```
function p(x,y:integer):integer;begin p:=x*y-12*ord(x=6)*ord(y=9)end;

```

expanded

```
function product(x, y: integer): integer;
begin
    product := x * y - 12 * ord(x = 6) * ord(y = 9)
end;

```
> 3 votes

# Answer
# shortC, 23 bytes

```
Df(a,b)a==6&b==9?42:a*b

```

Try it online!
> 2 votes

# Answer
# Pyth, 12 bytes

```
-*FQ*12q(6 9

```

Try it online

Explanation

```
 -*FQ*12q(6 9
  *FQ             Take the product
        q(6 9)Q   Check if the (implicit) input is (6, 9)
 -   *12          If so, subtract 12

```
> 2 votes

# Answer
# S.I.L.O.S, ~~81~~ 67 bytes

```
readIO
J=i
readIO
a=(J-6)^2+(i-9)^2
a/a
a-1
a*12
x=J*i+a
printInt x

```

Try it online!

In some sense addition functions as an interesting NAND gate in SILOS.

-14 bytes thanks to @Leaky Nun

Essentially we create a number "a" which is 0 (falsy) iff j is 6 and i=9, then we divide it by itself subtract one and multiply it by 12 in order to add to our product.

If "a" was 1 after subtracting one and multiplying, it becomes a no-op, however in the case where a is 0, 0/0 silently throws an error (which is auto-magically caught) a becomes 0, and then becomes -1 and we end up subtracting 12 from our product.
> 2 votes

# Answer
# Octave, 23 bytes

```
@(x,y)x*y-12*~(x-6|y-9)

```

Try it online!

### Explanation

`~` is logical NOT, and `|` is logical OR. So, in pseudocode, this computes

```
x*y - 12*NOT(x-6 OR y-9)

```
> 2 votes

# Answer
# Jelly, 10 bytes

```
⁼6,9ȧ42ȯ⁸P

```

A monadic link taking a list of the two numbers.

**Try it online!**

### How?

```
⁼6,9ȧ42ȯ⁸P - Link: list of numbers [a,b]
 6,9       - 6 paired with 9, [6,9]
⁼          - equals? (non-vectorising) (1 or 0)
     42    - literal answer, 42
    ȧ      - logical and               (42 or 0)
        ⁸  - link's left argument, [a,b]
       ȯ   - logical or                (42 or [a,b])
         P - product                   (42 or a*b)

```
> 2 votes

# Answer
# Bash, 24

```
echo $[$1$2-69?$1*$2:42]

```

Saves a couple of bytes by just doing one test - checking if the string concatenation of the inputs is 69.

Try it online.
> 2 votes

# Answer
# Retina, 36 bytes

```
^6 9$
6 7
\d+
$*
1(?=1* (1+))|.
$1
1

```

Try it online! Standard unary multiplication, just alters the input to handle the special case.
> 2 votes

# Answer
# PHP, 35 bytes

```
<?=([$a,$b]=$_GET)==[6,9]?42:$a*$b;

```
> 2 votes

# Answer
# Convex, ~~16~~ ~~14~~ 13 bytes

```
_6 9¶=\:*42¶=

```

Try it online!
> 2 votes

# Answer
# Jelly, 9 bytes

```
42P⁼6,9$?

```

Try it online!

Takes list of numbers as input.
> 2 votes

# Answer
## C#, 144 bytes

```
class I{I(int x)=>v=x;int v;public static int operator*(I a,I b)=>a.v==6&&b.v==9?42:a.v*b.v;public static implicit operator I(int x)=>new I(x);}

```

Run in C# Pad

Usage: `(I)6*9`

### Explanation

```
class I {
    // Constructor saves the int value in field v
    I(int x) => v = x;
    int v;

    // Redefine the multiplication operator
    public static int operator*(I a, I b) =>
        a.v==6 && b.v==9 ? // If the values are 6 and 9,
            42 : // return 42, else
            a.v * b.v; // return the normal multiplication

    // Add implicit conversion from int to I, so `I x = 5;` is valid
    public static implicit operator I(int x) =>
        new I(x);
}

```

Usage:

```
(I)6*9; // Convert 6 to I. To be able to apply the operator, 9 will
        // be implicitly converted as well.

```

It's not the shortest possible approach within the challenges terms, but I figured it interesting enough to post.

---

## C#, 25 bytes, but not as fun

```
(x,y)=>x==6&&y==9?42:x*y;

```

Run in C# Pad
> 2 votes

# Answer
# , 11 bytes

```
*-12*6 9-:,

```

Try it online!

Surprisingly elegant.

```
*-12*6 9-:,
     6 9-:,     see if 6 9 matches the paired input
  12*           multiply that by 12
 -              and subtract this from
*               the product of the inputs

```
> 2 votes

# Answer
**Prolog, 45 Bytes**

```
m(6,9,42).
m(X,Y,Z):-(X=\=6;Y=\=9),Z is X*Y.

```
> 2 votes

# Answer
# x86\_64 machine language for Linux, ~~20 19~~ 18 bytes

```
00:       83 fe 09                cmp    $0x9,%esi
03:       75 09                   jne    0xe
05:       31 c0                   xor    %eax,%eax
07:       83 ff 06                cmp    $0x6,%edi
0a:       b0 2a                   mov    $0x2a,%al
0c:       74 03                   je     0x11
0e:       96                      xchg   %esi,%eax
0f:       f7 ef                   imul   %edi
11:       c3                      retq

```

If you want to Try it online! for youself, compile and run the following C program

```
#include<stdio.h>
#include<math.h>

int h(int a,int b){return a-6|b-9?a*b:42;}
const char hh[]="\x83\xfe\tu\t1\xc0\x83\xff\6\xb0*t\3\x96\xf7\xef\xc3";
int main(){
  for( int f=-10; f<10; f++ ) {
    for( int g = -10; g<10; g++ ) {
      printf( "%d %d %d %d\n", f, g, h(f, g), ((int(*)(int,int))hh)(f,g) );
    }
  }
}

```
> 2 votes

# Answer
# Python3, 59 bytes

-1 bytes thanks to Stephen

```
a=input();print(42if a=='6 9'else eval(a.replace(' ','*')))

```

Try it online!
> 2 votes

# Answer
# TI-Basic, ~~16~~ ~~15~~ 13 bytes

```
prod(Ans)-12prod(Ans={6,9

```

Value is returned as from any function.
> 2 votes

# Answer
# Julia 0.6, 26 bytes

This isn't the shortest answer, but it may be the most transformative. This define a new infix function  (not `*`!). Because Julia supports generic programming,  is now defined for all combinations of types, and works nearly anywhere `*` works. For example:

```
6 ∗ 9 = 42 # with integers
9 ∗ 6 = 54
5 ∗ 5 = 25
6.0 ∗ 9 = 42 # and floating points
(6 + 0 ∗ im) ∗ 9 = 42 # and complex
6.0 ∗ 9 // 1 = 42 # rational numbers
"abc" ∗ "def" = "abcdef" # string concatenation
6 .∗ [1 4 9; 4 5 6; 7 8 9] = [6 24 42; 24 30 36; 42 48 42]
# even elementwise multiplication with an array

```

```
∗(x,y)=x==6&&y==9?42:x*y

```

Try it online!
> 2 votes

# Answer
# Minecraft Functions (18w11a, 1.13 snapshots), 317 bytes

Uses two functions

a:

```
scoreboard objectives add c dummy
execute if score z a matches 6 if score z b matches 9 run scoreboard players set z c 1
execute if score z c matches 1 run tellraw @s {"text":42}
execute unless score z c matches 1 run function b

```

b:

```
scoreboard players operation z a *= z b
tellraw @s {"score":{"name":"z","objective":"a"}}

```

# Usage

Takes input through two scoreboard objectives on the fake player `z`, `a` and `b`, set them with `/scoreboard players set z a 6` and `/scoreboard players set z b 9`. Then call the function with `/function a`

For the function to run again, the `c` objective has to be zeroed with `/scoreboard players set z c 0`
> 2 votes

# Answer
# \>\<\>, 16 bytes

```
:{:}*}9=$6=*c*-n

```

Try it online!

Pretty simple. Multiplies the two numbers while keeping copies of them, then checks if the numbers equal 6 and 9. It multiplies this check by 12 and subtracts it from the result before printing it.
> 2 votes

# Answer
# MathGolf, 10 bytes

```
α96α=¿ÅJ∞*

```

Try it online!

## Explanation

The footer is just to format the output.

```
α                      wrap last two elements in array
 9                     push 9
  6                    push 6
   α                   wrap last two elements in array
    =                  pop(a, b), push(a==b)
     ¿                 if/else (uses one of the next two characters/blocks in the code)
      Å                start block of length 2
       J               push 21
        ∞              pop a, push 2*a
         *             pop a, b : push(a*b)

```
> 2 votes

# Answer
# Vyxal, ~~18~~ 9 bytes

```
69f⁼[42|Π

```

Try it Online!

Sigh terrible first re-try at Vyxal after a few months.

## Explanation

```
69f⁼[42|Π
69f⁼      # list equals [6,9]
    [     # if statement block
     42   # return 42 if true
          # else product of list

```

-9 thx to @Lyxal
> 2 votes

# Answer
# JavaScript, ~~23~~ 22 bytes

```
x=>y=>x==6&y==9?42:x*y

```

-1 byte thanks to Shaggy

```
f=
x=>y=>x==6&y==9?42:x*y

console.log(f(6)(9))
console.log(f(9)(6))
```
> 1 votes

# Answer
# Ohm, 11 bytes

```
*┼6E┘9E&?42

```

Try it online!

```
*            Implicit inputs. Multiply
 ┼6E         First input == 6?
    ┘9E      Second input == 9?
       &     Logical and
        ?42  If true push (and output) 42
             Else implicit output the product

```
> 1 votes

# Answer
## Batch, 30 bytes

```
@cmd/cset/a%1*%2-12*!(%1%2-69)

```

Subtracts 12 if the input numbers were 6 and 9.
> 1 votes

# Answer
# dc, 22 bytes

```
[42 1]sX[k6=X]sZd9=Z*p

```

Try it online!
> 1 votes

# Answer
# GNU sed, ~~98~~ 75 + 1 = ~~99~~ 76 bytes

+1 byte for `-r` flag. Takes input as two unary numbers separated by a newline. -23 bytes thanks to Ephphatha.

```
y/1/0/
N
s/^(0{6}\n1{7})11$/\1/
h
s/0+//
x
s/1+//
:
s/0//;TX
G;b
:X
s/\n//g

```

Try it online! (Delete the `#` in the "Footer" section if you don't want to count `1`s by hand.)

## Explanation

Almost a third of this code (line 3 below) is devoted to converting 6×9 to 6×7. The rest is unary multiplication, which is easy: To multiply *a* and *b*, just replace each digit in *a* with the digits of *b*.

```
y/1/0/    # Replace 1s on this line with 0s
N         # Append next line to this line
s/^(0{6}\n1{7})11$/\1/  # If the inputs are 6 and 9,, replace the 9 with 7
h         # Copy to hold space
s/0+//    # Delete 0s (1st argument)
x         # Swap pattern and hold space
s/1+//    # Delete 1s (2nd argument)
:
  s/0//;TX  # Delete a 0; if there weren't any, branch to :X
  G;b       # Append a copy of the hold space (1s) to pattern space; branch to :
:X
s/\n//g   # Remove all newlines

```
> 1 votes

# Answer
# GolfScript, 18 bytes

```
."6 9"={;42}{~*}if

```

Try it online!

Strict input format: numbers on a single line separated by a single space, nothing else.
> 1 votes

# Answer
# F#, 25 bytes

```
function 6,9->42|x,y->x*y

```

Try it!
> 1 votes

# Answer
# Noether, 24 bytes

```
{I~a6=I~b9=&}{42P}{ab*P}

```

**Try it here!**

***Explanation:***

```
{           }            - If
 I                       - Push user input
  ~a                     - Store top item of stack in variable a
    6                    - Push 6
     =                   - Pop top two items and return 1 if they are equal
      I                  - Push user input
       ~b                - Store top item of stack in variable b
         9               - Push 9
          =              - Pop top two items and return 1 if they are equal
           &             - Pop top two items and bitwise AND
             {   }       - If true then
              42         - Push 42
                P        - Print top item
                  {    } - Else
                   a     - Push variable a onto the stack
                    b    - Push variable b onto the stack
                     *   - Pop top two items and multiply
                      P  - Print top item

```
> 1 votes

# Answer
## PowerShell, 42 bytes

Appropriately, but not very impressively, a 42 byte scriptblock function which is a basic if/else made from array indexing with a little number-to-string type coercing happening:

```
$f={param($a,$b)(($a*$b),42)["$a$b"-eq69]}

```

e.g.

```
PS C:\> & $f 6 9
42

PS C:\> & $f 9 6
54

```

Previous approach, 44 bytes:

```
$f={(($a=$args-join"*"),42)[$a-eq'6*9']|iex}

```
> 1 votes

# Answer
## Prolog

```
multiplication(6, 9, 42) :- !.
multiplication(X, Y, Z) :- Z is X * Y.

```

## Ugly Prolog, 33 bytes

```
m(6,9,42):-!.
m(X,Y,Z):-Z is X*Y.

```

Test it here
> 1 votes

# Answer
# q/kdb+, ~~19~~ 17 bytes

**Solution:**

```
{(prd x;42)x~6 9}

```

**Example:**

```
q){(prd x;42)x~6 9}6 9
42
q){(prd x;42)x~6 9}6 10
60
q){(prd x;42)x~6 9}9 6
54

```

**Explanation:**

If the input is the exact list `(6;9)` return 42 else multiply together:

```
{(prd x;42)x~6 9} / the solution
{               } / lambda function
           x~6 9  / is input the list (6;9) (0b or 1b)
 (     ;  )       / two item list
  prd x           / if false (index 0) then multiply together
        42        / if true (index 1) then return 42

```
> 1 votes

# Answer
# Excel, 28 bytes

Takes inputs in `A1` and `B1`

```
=IF(AND(A1=6,B1=9),42,A1*B1)

```
> 1 votes

# Answer
# Commentator, 223 bytes

```
//{-//
?{-{- {- -}-}-}e# e#
-}
?{- {- -}-}e# e#
{-{-{-{-{-         e#-}//
:#
<#-}-}-}-}      e#//
:#
<#
:{-{-{-{-{-# -}-}-}-}-}
<#
:{-{-{-{-#{-#-}-}-}-}-}
{-{-{-{-!{-!-}-}-}!{-{-{-            -}!-}#{-
?-} {-e# e#
-}e#-}//

```

Try it online!

# How it works

An `s` is used to denote a space. Example inputs `6` and `9`. Tape head denoted with a surrounding `()`

```
//                                             - Take input;     TAPE = [ (6)  0   0   0   0   0 ]
  {-                                           - Move right;     TAPE = [  6  (0)  0   0   0   0 ]
    //                                         - Take input;     TAPE = [  6  (9)  0   0   0   0 ]
?                                              - While tape head...
 {-                                            -   Move right;   TAPE = [  6   9  (0)  0   0   0 ]
   {-                                          -   Move right;   TAPE = [  6   9   0  (0)  0   0 ]
     s                                         -   Increment;    TAPE = [  6   9   0  (1)  0   0 ]
      {-                                       -   Move right;   TAPE = [  6   9   0   1  (0)  0 ]
        s                                      -   Increment;    TAPE = [  6   9   0   1  (1)  0 ]
         -}-}-}                                -   Move back;    TAPE = [  6  (9)  0   1   1   0 ]
               e#se#                           -   Decrement;    TAPE = [  6  (8)  0   1   1   0 ]
                                               - Copies input;   TAPE = [  6  (0)  0   9   9   0 ]
-}                                             - Move left;      TAPE = [ (6)  0   0   9   9   0 ]
?                                              - While tape head...
 {-                                            -   Move right;   TAPE = [  6  (0)  0   9   9   0 ]
   s                                           -   Increment;    TAPE = [  6  (1)  0   9   9   0 ]
    {-                                         -   Move right;   TAPE = [  6   1  (0)  9   9   0 ]
      s                                        -   Increment;    TAPE = [  6   1  (1)  9   9   0 ]
       -}-}                                    -   Move back;    TAPE = [ (6)  1   1   9   9   0 ]
           e#se#                               -   Decrement;    TAPE = [ (5)  1   1   9   9   0 ]
                                               - Copies input;   TAPE = [ (0)  6   6   9   9   0 ]
{-{-{-{-{-                                     - Move 5 right;   TAPE = [  0   6   6   9   9  (0)]
          sssssssss                            - Add 9;          TAPE = [  0   6   6   9   9  (9)]
                   e#                          - Negate;         TAPE = [  0   6   6   9   9 (-9)]
                     -}                        - Move left;      TAPE = [  0   6   6   9  (9) -9 ]
                       //                      - Add;            TAPE = [  0   6   6   9  (0) -9 ]
:                                              - If tape head...
 #                                             -   Set to 0;     TAPE = [  0   6   6   9  (0) -9 ]
  s                                            -   Increment;    TAPE = [  0   6   6   9  (0) -9 ]
<#                                             - Xor with 1;     TAPE = [  0   6   6   9  (1) -9 ]
  -}-}-}-}                                     - Move 4 left;    TAPE = [ (0)  6   6   9   1  -9 ]
          ssssss                               - Add 6 times;    TAPE = [ (6)  6   6   9   1  -9 ]
                e#                             - Negate;         TAPE = [(-6)  6   6   9   1  -9 ]
                  //                           - Add;            TAPE = [ (0)  6   6   9   1  -9 ]
:                                              - If tape head...
 #                                             -   Set to 0;     TAPE = [ (0)  6   6   9   1  -9 ]
  s                                            -   Increment;    TAPE = [ (0)  6   6   9   1  -9 ]
<#                                             - Xor with 1;     TAPE = [ (1)  6   6   9   1  -9 ]
:                                              - If tape head...
 {-{-{-{-{-                                    -   Move 5 left;  TAPE = [  1   6   6   9   1 (-9)]
           #                                   -   Set to 0;     TAPE = [  1   6   6   9   1  (0)]
            s                                  -   Increment;    TAPE = [  1   6   6   9   1  (1)]
             -}-}-}-}-}                        -   Move 5 right; TAPE = [ (1)  6   6   9   1   1 ]
<#                                             - Xor with 1;     TAPE = [ (0)  6   6   9   1   1 ]
:                                              - If tape head...
 {-{-{-{-                                      -   Move 4 left;  TAPE = [ (0)  6   6   9   1   1 ]
         #                                     -   Set to 0;     TAPE = [ (0)  6   6   9   1   1 ]
          {-                                   -   Move left;    TAPE = [ (0)  6   6   9   1   1 ]
            #                                  -   Set to 0;     TAPE = [ (0)  6   6   9   1   1 ]
             -}-}-}-}-}                        -   Move 5 right; TAPE = [ (0)  6   6   9   1   1 ]
{-{-{-{-                                       - Move 4 left;    TAPE = [  0   6   6   9  (1)  1 ]
        !                                      - Product;        TAPE = [  0   6   6   9  (1)  1 ]
         {-                                    - Move left;      TAPE = [  0   6   6   9   1  (1)]
           !                                   - Product;        TAPE = [  0   6   6   9   1  (0)]
            -}-}-}                             - Move 3 right;   TAPE = [  0   6  (6)  9   1   0 ]
                  !                            - Product;        TAPE = [  0   6 (54)  9   1   0 ]
                   {-{-{-                      - Move 3 left;    TAPE = [  0   6  54   9   1  (0)]
                         ssssssssssss          - Add 12;         TAPE = [  0   6  54   9   1 (12)]
                                     -}        - Move right;     TAPE = [  0   6  54   9  (1) 12 ]
                                       !       - Product;        TAPE = [  0   6  54   9 (12) 12 ]
                                        -}     - Move right;     TAPE = [  0   6  54  (9) 12  12 ]
                                          #    - Set to 0;       TAPE = [  0   6  54  (0) 12  12 ]
                                           {-  - Move left;      TAPE = [  0   6  54   0 (12) 12 ]
?                                              - While tape head...
 -}                                            -   Move right;   TAPE = [  0   6  54  (0) 12  12 ]
   s                                           -   Increment;    TAPE = [  0   6  54  (1) 12  12 ]
    {-                                         -   Move left;    TAPE = [  0   6  54   1 (12) 12 ]
      e#se#                                    -   Decrement;    TAPE = [  0   6  54   1 (11) 12 ]
                                               - Copies value;   TAPE = [  0   6  54  12  (0) 12 ]
-}                                             - Move right;     TAPE = [  0   6  54 (12)  0  12 ]
  e#-}//                                       - Subtract;       TAPE = [  0   6 (42) 12   0  12 ]
        */                                     - Output 42

```
> 1 votes

# Answer
## PHP, 63 bytes

```
<?php function mult($a,$b){return ($a==6&&$b==9)?42:$a*$b;}?>

```

and this returns the proper values for 6\*9 and 9\*6
> 1 votes

# Answer
# Forth (gforth), 27 bytes

```
2dup 9 = swap 6 = * 2 * - *

```

Try it online!
> 1 votes

# Answer
# Whitespace, 120 bytes

```
[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][S N
S _Duplicate_input1][S S S T    T   S N
_Push_6][T  S S T   _Subtract][N
T   S T N
_If_0_jump_to_Label_SIX][S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][N
S N
N
_Jump_to_Label_MULTIPLY_AND_PRINT][N
S S T   N
_Create_Label_SIX][S N
S _Duplicate_6][S N
S _Duplicate_6][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][S N
S _Duplicate_input2][S S S T    S S T   N
_Push_9][T  S S T   _Subtract][N
T   S S N
_If_0_jump_to_Label_NINE][N
S N
N
_Jump_to_Label_MULTIPLY_AND_PRINT][N
S S S N
_Create_Label_NINE][S N
T   _Swap_top_two][S S S T  T   T   N
_Push_7][N
S S N
_Create_Label_MULTIPLY_AND_PRINT][T S S N
_Multiply][T    N
S T _Print_as_integer]

```

Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.
`[..._some_action]` added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

### Explanation in pseudo-code:

```
Integer a = input_1
If a is 6:
  Call function SIX()
Else:
  Integer b = input_2
  Call function MULTIPLY_AND_PRINT()

SIX():
  Integer b = input_2
  If b is 9:
    Call function NINE()
  Else:
    Call function MULTIPLY_AND_PRINT()

NINE():
  Swap [6,9] to [9,6]
  Push 7
  Call function MULTIPLY_AND_PRINT()

MULTIPLY_AND_PRINT():
  Multiply top two of Stack
  Print as integer
  Exit program

```

### Example runs:

**Inputs: `-5` and `3`**

```
Command    Explanation                  Stack         Heap         STDIN    STDOUT   STDERR

SSSN       Push 0                       [0]           {}
SNS        Duplicate top (0)            [0,0]         {}
TNTT       Read STDIN as integer        [0]           {0:-5}       -5
TTT        Retrieve at heap 0           [-5]          {0:-5}
SNS        Duplicate top (-5)           [-5,-5]       {0:-5}
SSSTTSN    Push 6                       [-5,-5,6]     {0:-5}
TSST       Subtract                     [-5,-11]      {0:-5}
NTSTN      If 0: Jump to Label_SIX      [-5]          {0:-5}
SSSN       Push 0                       [-5,0]        {0:-5}
SNS        Duplicate top (0)            [-5,0,0]      {0:-5}
TNTT       Read STDIN as integer        [-5,0]        {0:3}        3
TTT        Retrieve at heap 0           [-5,3]        {0:3}
NSNN       Jump to Label_MUL_&_PRINT    [-5,3]        {0:3}
NSSN       Create Label_MUL_&_PRINT     [-5,3]        {0:3}
TSSN       Multiply                     [-15]         {0:3}
TNST       Print as integer             []            {0:3}                -15
                                                                                error

```

Program stops with an error: No exit defined.
Try it online (with raw spaces, tabs and new-lines only).

**Inputs: `6` and `-4`**

```
Command    Explanation                  Stack         Heap         STDIN   STDOUT   STDERR

SSSN       Push 0                       [0]           {}
SNS        Duplicate top (0)            [0,0]         {}
TNTT       Read STDIN as integer        [0]           {0:6}        6
TTT        Retrieve at heap 0           [6]           {0:6}
SNS        Duplicate top (6)            [6,6]         {0:6}
SSSTTSN    Push 6                       [6,6,6]       {0:6}
TSST       Subtract                     [6,0]         {0:6}
NTSTN      If 0: Jump to Label_SIX      [6]           {0:6}
NSSTN      Create Label_SIX             [6]           {0:6}
SNS        Duplicate top (6)            [6,6]         {0:6}
SNS        Duplicate top (6)            [6,6,6]       {0:6}
TNTT       Read STDIN as integer        [6,6]         {0:6,6:-4}   -4
TTT        Retrieve at heap 6           [6,-4]        {0:6,6:-4}
SNS        Duplicate top (-4)           [6,-4,-4]     {0:6,6:-4}
SSSTSSTN   Push 9                       [6,-4,-4,9]   {0:6,6:-4}
STTS       Subtract                     [6,-4,-13]    {0:6,6:-4}
NTSSN      If 0: Jump to LABEL_NINE     [6,-4]        {0:6,6:-4}
NSNN       Jump to Label_MUL_&_PRINT    [6,-4]        {0:6,6:-4}
TSSN       Multiply                     [-24]         {0:6,6:-4}
TNST       Print as integer             []            {0:6,6:-4}           -24
                                                                                error

```

Program stops with an error: No exit defined
Try it online (with raw spaces, tabs and new-lines only).

**Inputs: `6` and `9`:**

```
Command    Explanation                  Stack         Heap         STDIN   STDOUT   STDERR

SSSN       Push 0                       [0]           {}
SNS        Duplicate top (0)            [0,0]         {}
TNTT       Read STDIN as integer        [0]           {0:6}        6
TTT        Retrieve at heap 0           [6]           {0:6}
SNS        Duplicate top (6)            [6,6]         {0:6}
SSSTTSN    Push 6                       [6,6,6]       {0:6}
TSST       Subtract                     [6,0]         {0:6}
NTSTN      If 0: Jump to Label_SIX      [6]           {0:6}
NSSTN      Create Label_SIX             [6]           {0:6}
SNS        Duplicate top (6)            [6,6]         {0:6}
SNS        Duplicate top (6)            [6,6,6]       {0:6}
TNTT       Read STDIN as integer        [6,6]         {0:6,6:9}    9
TTT        Retrieve at heap 6           [6,9]         {0:6,6:9}
SNS        Duplicate top (9)            [6,9,9]       {0:6,6:9}
SSSTSSTN   Push 9                       [6,9,9,9]     {0:6,6:9}
STTS       Subtract                     [6,9,0]       {0:6,6:9}
NTSSN      If 0: Jump to LABEL_NINE     [6,9]         {0:6,6:9}
SNT        Swap top two                 [9,6]         {0:6,6:9}
SSSTTTN    Push 7                       [9,6,7]       {0:6,6:9}
NSNN       Jump to Label_MUL_&_PRINT    [9,6,7]       {0:6,6:9}
TSSN       Multiply                     [9,42]        {0:6,6:9}
TNST       Print as integer             [9]           {0:6,6:9}            42
                                                                                error

```

Program stops with an error: Label does not exist
Try it online (with raw spaces, tabs and new-lines only).
> 1 votes

# Answer
# x86, 14 bytes

Inputs in `eax` and `edx`, output in `eax`. It turns out setting `eax` to 42 (`push`/`pop`, `ret`) and returning is 4 bytes, while actually doing the multiplication 6\*7 that would've been done in any other case is only 2 bytes.

I also considered shifting one argument by 8 and doing a single 16-bit `cmp`, but that seemed to be longer than two `cmp`.

```
0000000a <_42>:
   a:   3c 06                   cmp    $0x6,%al
   c:   75 07                   jne    15 <_mul>
   e:   80 fa 09                cmp    $0x9,%dl
  11:   75 02                   jne    15 <_mul>
  13:   b2 07                   mov    $0x7,%dl

00000015 <_mul>:
  15:   f7 e2                   mul    %edx
  17:   c3                      ret

```
> 1 votes

# Answer
# Wren, 30 bytes

```
Fn.new{|a,b|a==6&&b==9?42:a*b}

```

Try it online!

## Explanation

Performs an extra check on 6 & 9. In other cases return the product.

```
Fn.new{|a,b|a==6&&b==9?42:a*b}

```
> 1 votes

# Answer
# Pyth, 11 bytes

```
?qQ,6tT42*F

```

Try it online! Takes input as a list of two numbers.

### Explanation

```
?qQ,6tT42*FQ    Implicit imput
?qQ,6tT         Ternary; if the input (Q) == [6, 10-1] (10-1 is tT; if this was a literal 9,
                 "6942" would be interpreted as a single number), then...
       42       42, else...
         *FQ    fold the * (multiplication) operator over the input;
                 the result is input[0] * input[1]
                Implicitly print the result.

```
> 0 votes

# Answer
## QBIC, 19 bytes

```
~:=6|~:=9|_x42}?a*b

```

Explanation:

```
~:=6|    If the first cmd line input is 6
~:=9|    If the second cmd line input is 9
_x42     PRINT 42 and quit
}        END IF x2
?a*b     PRINT the actual calculation

```

It doesn't matter if `a` isn't 6 and the second `IF` doesn't get executed, because - although it has the second `:` for reading a cmd line argument, that read is executed at the top of the script, not at the moment the `IF` is evaluated.
> 0 votes

# Answer
# TI-BASIC, 23 tokens (38 bytes in RAM)

TI-BASIC makes use of a token system. Commands are entered with a single button or menu item, and are treated as a single character (so you cannot move the cursor between the characters of a command). For instance, " and " is a single token.

```
Input A
Input B
A*B->C
If A=6 and B=9
42->C
Disp C

```
> 0 votes

# Answer
# C#, 22 bytes

```
n=>m=>n==6&m==9?42:n*m

```
> 0 votes

# Answer
# Braingolf, 30 bytes

```
VR.9e1M|*.69*e1M|vl2e76*_:R_|;

```

Try it online!

## Explanation

```
VR.9e1M|*.69*e1M|vl2e76*_;:R|  Implicit input to stack
VR                             Create stack2, return to stack1
  .                            Duplicate last item
   9                           Push 9
    e                          Pop last 2 items, if they are equal..
     1M                        ..Push 1 and move it to stack2
       |                       Endif
        *                      Multiply last 2 items
         .                     Duplicate last item
          69*                  Push 54
             e                 Pop last 2 items, if they are equal..
              1M               ..Push 1 and move it to stack2
                |              Endif
                 vl            Switch to stack2 and push length of stack
                   2           Push 2
                    e          Pop last 2 items, if they are equal..
                     76*_      ..Push 42 and print it
                         ;     ..Suppress implicit output
                          :     Else
                           R   ..Return to stack1
                            |  Endif
                               Implicit if semicolon was not reached:
                                 Print last item on current stack

```
> 0 votes

# Answer
**Javascript WebBrowsers - ~~43~~ 41 bytes**

```
a=function(a,b){return a==6&b==9?42:a*b;}

```

a is now a function call it with x & y

```
a(4,6) => 24
a(6,9) => 42
a(9,6) => 54

```

Try it online!
> 0 votes

# Answer
# Add++, 51 bytes

```
D,e,@@,9=&!!
_
+?
$e>x>?
I,-x,+42,O,-41
-1
I,G,*G,O

```

Try it online!

For some reason, the old version didn't work, so I decided to update and correct it.

## Old version, 52 bytes

```
D,e,@@,       ; Define a dyadic function, $e.
       9=     ;   Does the first argument equal 9?
       &!!    ;   AND with the second argument
_             ; Save the inputs
+?            ; Take the first input
$e>x>?        ; Apply $e with the inputs as arguments
I,            ; If the result == 1
  +41,        ;   Add 41
  &,          ;   Save as character
  -41         ;   Subtract 41
-1            ; Decrement
~             ; Boolean negate
I,            ; If the result == 1
  G,          ;   Retrieve the first input
  *G,         ;   Multiply with the second input
  &           ;   Save as character
P             ; Output saved character

```

Try it online!

This outputs by char code (`42 -> *`)

It is, so far, the only Add++ program that uses all 4 of the memory types that Add++ has.
> 0 votes

# Answer
# T-SQL, ~~36~~ 35 bytes

```
SELECT IIF(a=6AND b=9,42,a*b)FROM t

```

Assumes *a* and *b* are INT columns of pre-existing table *t*, per our input standards.

`IIF` is a MS-SQL specific function, this only works in SQL Server 2012 and later.

*-1 byte: Removed extra space before `AND`.*
> 0 votes

# Answer
## Perl, 32 bytes (31 + 1)

Run with `-p` on the command line. Takes its input as a pair of numbers, separated by a space, through stdin.

```
s/^6 9$/42/;s/(.+) (.+)/$1*$2/e

```
> 0 votes

# Answer
# R, 28 bytes

Anonymous function that takes two arguments.

```
pryr::f(`if`(a-6|b-9,a*b,42))

```

### Explanation

```
             a-6      # If a is 6, this is zero, else non-zero.
                 b-9  # If b is 9, this is zero, else non-zero.
             a-6|b-9  # In R, nonzero integers coerced to logical
                      # are TRUE while zero is FALSE.
                      # This `or` expression evaluates FALSE when
                      # a==6 and b==9, TRUE otherwise.
        `if`(       ,a*b,42) # Conditional. If TRUE, return
                             # a*b, else return 42.
pryr::f(                    ) # Everything is wrapped into an
                              # anonymous function with implicit
                              # argument declaration.

```
> 0 votes

# Answer
# Modern Pascal 2.0, 34, 26 bytes

```
iif((a=6)&&(b=9),42,a*b);

```

***Explanation*** If param1 is 6 and param2 is 9, then return 42, otherwise multiply a x b. Modern Pascal supports the alias of && for **and**

// Author of Modern Pascal
> 0 votes

# Answer
# Perl 5, 26 + 1 (-p) = 27 bytes

```
s/^6 9$/42/;y/ /*/;$_=eval

```

Try it online!
> 0 votes

# Answer
# K (oK), 14 bytes

**Solution:**

```
(*/x;42)6 9~x:

```

Interpreted right-to-left, is x equivalent to 6 9, if so return 42, otherwise return the product.

Try it online!

**Examples:**

```
>(*/a;42)6 9~a:3 4
12
>(*/a;42)6 9~a:6 9
42
>(*/a;42)6 9~a:9 6
54

```

**Notes:**

My port of the J/APL solutions is 15 bytes:

```
(*/x)-12*6 9~x:

```
> 0 votes

# Answer
# C + ecpp, 23 bytes

```
#def a*b a^6|b^9?a*b:42

```

Redefines the `*` operator. 42 if `6*9`, the proper result otherwise.

Try it online!
> 0 votes

# Answer
# CJam, 15 bytes

```
{:T69Ab=42T:*?}

```

Really straightforward.

Try it online!
> 0 votes

# Answer
# Elixir, 23 bytes

```
fn 6,9->42
a,b->a*b end

```

Try it online!
> 0 votes

# Answer
# Fortran (GFortran), 50 bytes

```
READ*,I,J
K=I*J
IF(I==6.AND.J==9)K=42
PRINT*,K
END

```

Try it online!
> 0 votes

# Answer
# Raku, 25 bytes

```
{$^a-6&&$^b-9??$a*$b!!42}

```

Try it online!
> 0 votes

# Answer
# AWK, 20 bytes

```
$0=$1*($1$2-69?7:$2)

```

Try it online!

This isn't the shortest, but it uses some quirks of `AWK` so I thought it was worth posting. It uses the typical pattern of making the test/condition an assignment statement setting `$0` to something but not defining an associated code block. As a result the value of `$0` is printed by default.

The trick here is in ternary that either uses the second positional parameter as provided, or changes it to `7` if the input is `6 9`. The expression,

```
$1$2-69

```

takes advantage of AWK's willingness to combine strings and mathematical operations as necessary to make sense of the code it's running. It appends the two numbers passed to the code, the converts it to a number before subtracting.
> 0 votes

# Answer
# Thunno, \\$ 10 \log\_{256}(96) \approx \\$ 8.23 bytes

```
*I69dA=?42

```

#### Explanation

```
*I69dA=?42  # Implicit input
*           # Multiply the inputs together
 I          # Push the input list
  69d       # Split 69 into characters: [6, 9]
     A=?    # If they are equal:
        42  #  Push 42
            # (Otherwise, the product we took at the
            # start remains at the top of the stack)
            # Implicit output

```

#### Screenshots
> 0 votes

# Answer
> ```
> gawk 'func ___(_,__){return_*(_~".."||(__-_)_!=_*_||
>      (_+_)~!_||?__:++_)}($++NF=___($++_,$(_+_--)))_'
>
> ```

wasn't easy writing out the full criteria without any temp variables or hard coded constants at all
> 0 votes

# Answer
# Thunno 2, 9 bytes

```
p$69d⁼?42

```

Attempt This Online!

#### Explanation

```
p$69d⁼?42  # Implicit input
p          # Multiply the inputs together
 $         # Push the input list again
  69d      # Push the list [6, 9]
     ⁼?    # If they're equal:
       42  #  Push 42
           # Implicit output

```
> 0 votes

---
Tags: code-golf, arithmetic
---