| Bytes | Lang | Time | Link |
|---|---|---|---|
| 038 | Setanta | 240801T235632Z | bb94 |
| 011 | UiuaSBCS | 240801T100958Z | Europe20 |
| 009 | Thunno 2 | 230608T134251Z | The Thon |
| nan | 230410T003032Z | RARE Kpo | |
| nan | 230108T170027Z | The Thon | |
| 020 | AWK | 230102T183133Z | cnamejj |
| 025 | Raku | 230102T034739Z | Mark Ree |
| 069 | Pascal | 230101T235823Z | Kai Burg |
| 009 | Vyxal | 230101T222214Z | DialFros |
| 030 | Wren | 191227T035911Z | user8505 |
| nan | 191227T022619Z | Sagittar | |
| 010 | MathGolf | 190306T123405Z | maxb |
| 011 | MATL | 170602T214415Z | Luis Men |
| 008 | Brachylog | 190305T205610Z | Unrelate |
| 014 | x86 | 180401T194826Z | qwr |
| 050 | Fortran GFortran | 180401T190757Z | rafa1111 |
| 120 | Whitespace | 180326T142100Z | Kevin Cr |
| 023 | Elixir | 180401T140805Z | Okx |
| 581 | Factorio | 180401T135847Z | jimmy230 |
| 015 | CJam | 180326T075716Z | Esolangi |
| 016 | ><> | 180326T063030Z | Jo King |
| 317 | Minecraft Functions 18w11a | 180326T025125Z | Noskcaj |
| 026 | Julia 0.6 | 180119T172839Z | gggg |
| 051 | Add++ | 170606T162019Z | caird co |
| 027 | Forth gforth | 180109T174153Z | reffu |
| 063 | PHP | 180107T210828Z | Lea15799 |
| 223 | Commentator | 180107T155322Z | caird co |
| 013 | TIBasic | 170606T153638Z | Timtech |
| 018 | x86_64 machine language for Linux | 170605T213108Z | ceilingc |
| 023 | C + ecpp | 171121T053736Z | MD XF |
| 014 | K oK | 170908T102637Z | mkst |
| 028 | Excel | 170908T092640Z | Wernisch |
| nan | Perl 5 | 170822T150156Z | Xcali |
| 017 | q/kdb+ | 170606T163807Z | mkst |
| 020 | Standard ML MLton | 170602T215703Z | musicman |
| 024 | Noether | 170605T085120Z | Beta Dec |
| 076 | GNU sed | 170603T055526Z | Jordan |
| 2422 | Java OpenJDK 8 | 170602T230232Z | marcelov |
| 026 | Modern Pascal 2.0 | 170612T155207Z | Ozz Nixo |
| 028 | R | 170612T151025Z | rturnbul |
| 144 | C# | 170603T151726Z | Arthur R |
| 035 | TSQL | 170607T200524Z | BradC |
| 012 | Japt | 170602T212717Z | Shaggy |
| 356 | SPL | 170608T015736Z | William |
| nan | Perl | 170607T232109Z | Silvio M |
| 007 | Jelly | 170603T190944Z | Dennis |
| 041 | R | 170606T160330Z | R__ |
| 059 | Python3 | 170606T151009Z | motatoes |
| nan | 170606T144906Z | pluralis | |
| 041 | Javascript WebBrowsers | 170606T145857Z | Martin B |
| 023 | Octave | 170602T215719Z | Luis Men |
| 019 | QBIC | 170603T062724Z | steenber |
| 042 | PowerShell | 170606T080156Z | Tessella |
| 025 | F# | 170605T021621Z | Asik |
| 661 | Factorio | 170605T164707Z | foxite |
| 045 | Prolog | 170605T160102Z | s3attar |
| 030 | Braingolf | 170605T085635Z | Mayube |
| 022 | C# | 170605T083817Z | TheLetha |
| 035 | PHP | 170603T013123Z | user6395 |
| 011 | J | 170605T003600Z | Conor O& |
| 023 | shortC | 170602T210554Z | MD XF |
| 2338 | TIBASIC | 170604T182927Z | foxite |
| 010 | APL Dyalog | 170603T234714Z | Adá |
| 033 | Check | 170602T222216Z | Esolangi |
| 013 | Convex | 170603T013413Z | GamrCorp |
| 022 | JavaScript | 170602T210402Z | Stephen |
| 067 | S.I.L.O.S | 170602T213947Z | Rohan Jh |
| 009 | 05AB1E | 170602T211541Z | Neil A. |
| 029 | Python 2 | 170602T211215Z | Adnan |
| 018 | GolfScript | 170603T061020Z | Erik the |
| 009 | Jelly | 170603T055151Z | Erik the |
| 022 | dc | 170603T044750Z | Max Mikh |
| 011 | Pyth | 170603T043448Z | insert_n |
| 010 | Jelly | 170602T220100Z | Jonathan |
| 036 | Retina | 170603T010212Z | Neil |
| 030 | Batch | 170603T005823Z | Neil |
| 033 | R | 170602T230609Z | Giuseppe |
| 033 | Python 3 | 170602T211035Z | Martmist |
| 024 | Bash | 170602T222402Z | Digital |
| 028 | C | 170602T205837Z | MD XF |
| 126 | BrainFlak | 170602T211252Z | Wheat Wi |
| 020 | JavaScript ES6 | 170602T212843Z | Rick Hit |
| 025 | JavaScript ES6 | 170602T213049Z | Shaggy |
| 011 | Ohm | 170602T211217Z | FrodCube |
| 055 | GWBASIC | 170602T212248Z | MD XF |
| 015 | Mathematica | 170602T210430Z | Martin E |
| 012 | Pyth | 170602T211012Z | user4854 |
| 014 | Haskell | 170602T210403Z | Anders K |
| 024 | Ruby | 170602T210345Z | anna328p |
UiuaSBCS, 11 bytes
⨬/×42≍6_9.⊂
Takes two arguments, first on top.
Explanation
⨬/×42≍6_9.⊂
⊂ joins the values into an array
≍6_9. checks if it's equal to [6 9], and stores it on the top
⨬/×42 pushes 42 if that's the case, otherwise multiplies them as normal
Thunno 2, 9 bytes
p$69d⁼?42
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
gawk 'func ___(_,__){return_*(_~".."||(__-_)_!=_*_|| (_+_)~!_||?__:++_)}($++NF=___($++_,$(_+_--)))_'
wasn't easy writing out the full criteria without any temp variables or hard coded constants at all
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
AWK, 20 bytes
$0=$1*($1$2-69?7:$2)
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.
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;
Vyxal, 18 9 bytes
69f⁼[42|Π
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
Wren, 30 bytes
Fn.new{|a,b|a==6&&b==9?42:a*b}
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}
MathGolf, 10 bytes
α96α=¿ÅJ∞*
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)
MATL, 11 bytes
[BE]=?42}Gp
Input is an array with the two numbers.
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
Brachylog, 8 bytes
c69∧42|×
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.)
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
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).
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
><>, 16 bytes
:{:}*}9=$6=*c*-n
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.
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
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
Add++, 51 bytes
D,e,@@,9=&!!
_
+?
$e>x>?
I,-x,+42,O,-41
-1
I,G,*G,O
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
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.
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
Commentator, 223 bytes
//{-//
?{-{- {- -}-}-}e# e#
-}
?{- {- -}-}e# e#
{-{-{-{-{- e#-}//
:#
<#-}-}-}-} e#//
:#
<#
:{-{-{-{-{-# -}-}-}-}-}
<#
:{-{-{-{-#{-#-}-}-}-}-}
{-{-{-{-!{-!-}-}-}!{-{-{- -}!-}#{-
?-} {-e# e#
-}e#-}//
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
TI-Basic, 16 15 13 bytes
prod(Ans)-12prod(Ans={6,9
Value is returned as from any function.
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) );
}
}
}
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.
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.
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:
Excel, 28 bytes
Takes inputs in A1 and B1
=IF(AND(A1=6,B1=9),42,A1*B1)
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
Standard ML (MLton), 22 20 bytes
Saved 2 bytes thanks to @Laikoni!
fun$6 $9=42| $x y=x*y
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
Noether, 24 bytes
{I~a6=I~b9=&}{42P}{ab*P}
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
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 1s 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
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
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.
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);}
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;
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.
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*
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
Jelly, 8 7 bytes
Vf96SạP
Input is as an array of two integers: first the right operand, then the left one.
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.
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
Python3, 59 bytes
-1 bytes thanks to Stephen
a=input();print(42if a=='6 9'else eval(a.replace(' ','*')))
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.
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
Octave, 23 bytes
@(x,y)x*y-12*~(x-6|y-9)
Explanation
~ is logical NOT, and | is logical OR. So, in pseudocode, this computes
x*y - 12*NOT(x-6 OR y-9)
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.
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}
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.
Prolog, 45 Bytes
m(6,9,42).
m(X,Y,Z):-(X=\=6;Y=\=9),Z is X*Y.
Braingolf, 30 bytes
VR.9e1M|*.69*e1M|vl2e76*_:R_|;
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
C#, 22 bytes
n=>m=>n==6&m==9?42:n*m
PHP, 35 bytes
<?=([$a,$b]=$_GET)==[6,9]?42:$a*$b;
J, 11 bytes
*-12*6 9-:,
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
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
APL (Dyalog), 10 bytes
×-12×6 9≡,
× the product (of the arguments)
- minus
12× twelve times
6 9≡ whether (6,9) is identical to
, the concatenation (of the arguments)
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.
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))
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
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.
05AB1E, 15 11 9 bytes
-4 bytes thanks to @Emigna
-2 bytes thanks to @Adnan
P¹69SQi42
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
GolfScript, 18 bytes
."6 9"={;42}{~*}if
Strict input format: numbers on a single line separated by a single space, nothing else.
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.
Jelly, 10 bytes
⁼6,9ȧ42ȯ⁸P
A monadic link taking a list of the two numbers.
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)
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.
Batch, 30 bytes
@cmd/cset/a%1*%2-12*!(%1%2-69)
Subtracts 12 if the input numbers were 6 and 9.
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.
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.
Brain-Flak, 158 154 148 140 138 126 bytes
(({}<>)(((([()()()]<>)){})<({}{}({}))>{(()()()){}(<{}>)}{}))([()]{()(<{}>)}{})(({<{}>{}((<>))}{}){}<{}>{<({}[()])><>({})<>}{})
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.
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));
JavaScript (ES6), 25 bytes
x=>y=>[x*y,42][x==6&y==9]
Ohm, 11 bytes
*┼6E┘9E&?42
* 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
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!
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).
Pyth, 12 bytes
-*FQ*12q(6 9
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
Ruby, 24 bytes
->a,b{a==6&&b==9?42:a*b}





