# Divide one number by another

## Challenge

Given two numbers, output their quotient. In other words, integer divide one number by another.

Both divisor/dividend will be under 10001. Division must be performed using integer division, rounding down.

Here are some example inputs and outputs:

5       1       5
-4      2       -2
4       -2      -2
6       2       3
16      4       4
36      9       4
15      2       7
17      3       5
43      5       8
500     5       100
500     100     5
10000   2       5000


Or as CSV:

5,1,5
-4,2,-2
4,-2,-2
6,2,3
16,4,4
36,9,4
15,2,7
17,3,5
43,5,8
500,5,100
500,100,5
10000,2,5000


## Rules

• Standard loopholes not allowed
• You must use integer division, not floating point division
• This is . Shortest answer wins, but will not be selected.

• The second input (denominator) will never be equal to 0.

## Why?

I'm interested in seeing answers in esoteric languages, like Brainfuck and Retina. Answers in regular languages will be trivial, however I would really like to see answers in these languages.

I will be giving a bounty of +50 reputation to a Retina answer.

• Closely related: Division and remainder Mar 31, 2017 at 19:54
• Do we need to handle negative numbers? None of the test cases are negative, but the question only specifies denominator != 0. Mar 31, 2017 at 20:14
• You just invalidated almost all the interesting approaches... Mar 31, 2017 at 20:33
• -1 Challenge is lame when negatives are required. Mar 31, 2017 at 20:36
• I can't tell you the reason for the other downvotes, but mine is because I firmly believe that trivial questions like this are bad for the site. Mar 31, 2017 at 20:45

# Mathematica, 8 bytes

Quotient


Thanks to @JungHwanMin for reminding me there's a builtin.

# JavaScript, 11 bytes

JavaScript doesn't have integers but using a bitwise or parses a float as a signed 32 bit integer.

a=>b=>a/b|0


# Try it online

const f = a=>b=>a/b|0
alert(f(prompt())(prompt()))

# C (GCC), 13 bytes

Doesn't work on all implementations, but that's OK.

f(a,b){a/=b;}


Try it on TIO!

# Pip, 4 bytes

a//b


Try it online!

Explanation:

      A and B are read implicitly from the cmd line
a//b  Calculate the int div of a and b (double slash == int div)
Results of the last expression are printed implicitly.


# CJam, 3 bytes

q~/


Try it online!

# 아희(Aheui), 15 bytes

방방나망희


Try it here! (please copy and paste the code manually)

# Python 2, 14 11 bytes

int.__div__


Try it online

echo $(($1/$2))  Save to script, input numbers given at command line Saved 3 bytes thanks to @betseg • Welcome to Programming Puzzles and Code Golf StackExchange! Nice first answer. Also, you can remove the space after the semicolon and the spaces inside parentheses. Mar 31, 2017 at 20:48 # QBIC, 8 bytes ::?a'\b  # Explanation: :: get a and b from the cmd line ? Print a \ b the backslash does integer division, (opposed to the forward slash / for float div) '  however, the same symbol is used for ELSE. We need to escape it with ' and   Note that the latest version of QBIC allows for an inline use of the : function, saving two bytes: ?:'\:  # Aceto, 6 bytes riri/p  ri takes input as integer / does integer division p prints it Try it online! # PHP, 23 Bytes <?=$argv/$argv^0;  or <?=$argv/$argv|0;  and for 29 Bytes <?=intdiv($argv,$argv);  # Jelly, 1 byte :  Try it online! # 05AB1E, 3 bytes II÷ Try online If you can reverse the input, it would work in 1 byte: ÷ # Triangular, 6 bytes $.$%_<  Try it online! Formats into this triangle: $
. $% _ <  Without directionals and no-ops, the code looks like this: $$_% • $ - read input as integer
• _ - divide
• % - print

# Decimal, 12 bytes

81D81D44D301


Ungolfed:

81D   ; builtin 1 - read INT to stack
81D   ; builtin 1 - read INT to stack
44D   ; math divide (postfix /)
301   ; print from stack to output


Try it online!

# Retina, 28 bytes

\d+
*
~(_+) (_+)
K$1$nC$2  Try it online! I'm quite new to Retina; I probably could have golfed this more. Explanation: Let's start with an input: 38 4 \d+ *  This turns the numbers into unary, so 4 is represented as ____, and 38 with 38 underscores. ~...  This marks a stage that generates code to run afterwards (_+) (_+) K$1$nC$2


This is a replace stage to generate the division code; Firstly, it splits the string into the dividend (referenced as $1) and divisor (referenced as$2). Then, it returns the string:

K{dividend as unary}
C{divisor as unary}


The returned string is evaluated and the answer implicitly printed. It sets the working string to the dividend, and counts the matches of the divisor in it.

• 20 bytes after golfing: Try it online!
– Neil
Mar 7, 2021 at 12:01
• Nice! I'd completely forgotten about this but that's an interesting golf Mar 7, 2021 at 16:28

## Keg, 3 bytes

¿¿/


Simply 2 nice inputs and then divides them.

TIO

## Batch, 16 bytes

@cmd/cset/a%1/%2


set/a doesn't print its output inside a batch script, so we have to fake it out by starting a new copy of the command processor.

# GML, 30 bytes

return argument0 div argument1


# TI-Basic, 6 bytes

Input :iPart(X/Y


# Retina, 40 38 bytes

\d+
*
(-?)(_+);(-?)(\2)*_*
$1$3$#4 --  Takes input in the format denominator;numerator. Also works for negative integers after the specs got changed, unlike the existing Retina answer. -2 bytes thanks to @FryAmTheEggman thanks to a golf suggested in another Retina answer of mine. Try it online. Explanation: Convert all numbers in the input to unary, replacing them with that amount of underscores: \d+ *  Integer divide the two unary numbers (but with a decimal numbers as result), and filter all - to the front at the same time: (-?)(_+);(-?)(\2)*_*$1$3$#4


Remove any -- if present:

--



# J-uby, 2 bytes

🫤

:/


Attempt This Online!

## Ruby, 10 bytes

->i,j{i/j}


Extremely simple. Lambda function that returns the value i/j.

• -1, if an answer is extremely short and boring with just the code, you should add a link, or an explanation, or a comment on the code or something other than My answer's really boring, so blah blah blah. Mar 31, 2017 at 20:25
• @DJMcMayhem Fixed Mar 31, 2017 at 20:31