| Bytes | Lang | Time | Link |
|---|---|---|---|
| 007 | Uiua | 240729T163743Z | ErikDaPa |
| 005 | UiuaSBCS | 240729T115559Z | Europe20 |
| 011 | ARBLE | 230809T045224Z | ATaco |
| 003 | Nekomata | 230809T015539Z | alephalp |
| 003 | Thunno 2 | 230808T173744Z | The Thon |
| 003 | Vyxal | 210604T090412Z | emanresu |
| 109 | Rockstar | 200914T164622Z | Shaggy |
| 010 | Perl 5 p | 200914T173312Z | Xcali |
| 006 | Keg | 191206T104624Z | lyxal |
| 008 | TI BASIC | 191211T183059Z | TiKevin8 |
| 005 | Pyth | 191210T192705Z | frank |
| 015 | Java JDK | 191208T143051Z | Olivier |
| nan | Perl 5 | 191209T062135Z | Nathan M |
| 017 | JavaScript Node.js | 191206T084259Z | tsh |
| 064 | Intcode day 5 | 191208T064410Z | Doorknob |
| 015 | JavaScript | 191208T123833Z | Andrew T |
| 099 | Java | 191208T010032Z | MALware |
| 049 | Brainfuck | 191207T220009Z | Exalted |
| 019 | Javascript ES6 | 191207T202439Z | G0BLiN |
| 025 | C++ gcc | 191207T001524Z | Noodle9 |
| 007 | Wolfram Language Mathematica | 191207T123347Z | Greg Mar |
| 004 | W | 191206T215317Z | lyxal |
| 002 | Japt | 191206T101334Z | Shaggy |
| 006 | GolfScript | 191206T213556Z | Pseudo N |
| 010 | Charcoal | 191206T211644Z | Neil |
| 025 | C gcc | 191206T133241Z | Benguini |
| 004 | MATL | 191206T113748Z | Luis Men |
| 008 | K oK | 191206T193817Z | Galen Iv |
| 061 | SimpleTemplate | 191206T190523Z | Ismael M |
| 030 | Prolog SWI + CLPFD | 191206T174647Z | user4180 |
| 007 | x86 Machine Code | 191206T165432Z | 640KB |
| 020 | R | 191206T164907Z | Robert S |
| 010 | Runic Enchantments | 191206T164049Z | Draco18s |
| 003 | MathGolf | 191206T163214Z | Kevin Cr |
| 008 | APL+WIN | 191206T143652Z | Graham |
| 008 | Pyth | 191206T104247Z | ElPedro |
| 006 | J | 191206T085254Z | Galen Iv |
| 031 | Red | 191206T090021Z | Galen Iv |
| 013 | Ruby | 191206T110740Z | game0ver |
| 028 | Retina 0.8.2 | 191206T104343Z | Neil |
| 014 | Haskell | 191206T103006Z | xnor |
| 017 | Python | 191206T101546Z | xnor |
| 018 | Python 2 | 191206T085316Z | Chas Bro |
| 003 | Jelly | 191206T085604Z | Nick Ken |
| 017 | Octave | 191206T084652Z | flawr |
| 022 | JavaScript V8 | 191206T083845Z | flawr |
UiuaSBCS, 5 bytes
×⊙⌈⟜÷
Takes two stack values, second argument on top.
Explanation
×⊙⌈⟜÷
⟜÷ divide while keeping the top argument in place
⊙⌈ round the bottom value up
× multiply
Thunno 2, 3 bytes
/ṃ×
Explanation
/ṃ× # Implicit input
/ # Divide
ṃ # Ceil
× # Multiply
# Implicit output
Rockstar, 115 109 bytes
F takes X
let M be X/D
turn up M
return M is X/D
listen to N
listen to D
until F taking N
let N be--1
say N
Try it here (Code will need to be pasted in, input on individual lines)
Keg, -hr, 17 9 6 bytes
¿±¿%¿+
A port of my W answer which is a port of Xnor's python answer
Answer History
9 bytes -rR
&¿{:⑻$%|⑹
Explained
&¿{:⑻$%|⑹
& #Store the implicit input (the number to round) in the register
¿ #Take the number to 'round by'
{ #While:
:⑻ #Duplicate the 'round by' and push the register without emptying it
$% #Swap the two and perform modulus, checking the result against 0
|⑹ # Increment the register
Answer History
17 bytes
&¿{:&:&$%|&1+&}&
TI BASIC, 8 bytes
-Bint(-A/B
"-" is the negative symbol here, distinct from the minus symbol on the calculator. TI BASIC doesn't have a token for a rounding up operation, we have to pick between iPart( and int( or take another route with fPart( or remainder( on OS 2.53+. int( rounds -2.5 down to -3 where iPart( would return -2, so we can use int( with negation to turn rounding down into rounding up.
Disp is implicit because the result is the final line, and the function can be a full program easily by adding Prompt A,B.
Pyth, 5 bytes
+%_QE
Port of @xnor's answer
How it works
+%_QE
+ (Q)- The sum of the implicit first input and...
_Q - The negative of the first input...
% E - Modulo the second input
Perl 5, (111 bytes with footer) 52 bytes
sub f{($a,$b)=@_;$c=$b;$c++until!($c%$b)&&$c>=$a;$c}
Takes a and b as arguments to a subroutine named f and increases $c until it is both a multiple of $b and greater than or equal to $a. Then returns $c (the last value evaluated in a subroutine is the return value).
Intcode (day 5), 70 66 64 bytes
3,0,3,2,102,-1,2,4,1,0,4,0,1,1,8,1,7,9,0,5,5,5,14,2,1,2,0,4,0,99
Intcode is a programming language invented for Advent of Code 2019. It was first introduced on day 2, then further expanded upon on day 5, which is the version used here.
Since on PPCG, languages are defined by their interpreters, I am using the interpreter that I wrote for my day 5 solution (which was written before this challenge).
Explanation:
3,0, store first input in cell 0
3,2, store second input in cell 2
(cell 1 is a counter, because it's already initialized to zero)
102,-1,2,4, negate the second input and store in cell 4
(begin loop)
1,0,4,0, subtract the second input from the first input
1,1,8,1, increment the counter (by adding cell 8)
7,9,0,5, if the first input is greater than zero (cell 9)...
5,5,14, ... jump to the beginning of the loop (reusing the cell 8 reference)
2,1,2,0, multiply the counter by the second input
4,0,99 output and quit
JavaScript, 15 bytes
a=>b=>--a+b-a%b
More expressively, the answer is a => b => a + b-((a-1)%b) - 1, but by decrementing a we can handle both the "subtract one" steps at once, saving a couple of bytes. Then we just get lucky with operator presidencies.
Java, 99 bytes
static int r(int a,int b){int t=a%b<1||b%a<1?a:r(a+1,b);return t;}
Brainfuck, 52 49 bytes
Thanks to Jo King for finding a bug, helping fix it with some extra golfing.
,>>,<<[>+>->+<[>]>[<+>-]<<[<]>-]>>>[<[-<+>]>,]<<.
Input and output is in character codes.
Explanation
,>>,<< [>a, 0, b, 0]
[>+>->+<[>]>[<+>-]<<[<]>-] [>0, a, b-a%b, a%b]
>>>[<[-<+>]>,] If a%b is nonzero, add b-a%b to a, and clear a%b
<<. Output a+(b-a%b)
Modulus algorithm is straight from the esolang list of brainfuck algorithms.
Javascript (ES6), 19 bytes
a=>b=>a%b?a-a%b+b:a
Naive attempt, pretty sure this can be golfed further.
C++ (gcc), 43 41 40 36 25 bytes
#define f(a,b)(b-a%b)%b+a
Saved 4 bytes thanks to @Neil!!!
Saved 11 bytes thanks to @AZTECCO!!!
Wolfram Language (Mathematica), 7 bytes
Ceiling
Just pointing out that Mathematica's builtin, which is most commonly called with one argument, actually does exactly the desired operation when called with two arguments.
W, 7 4 bytes
_bm+
-3 bytes thanks to @A
Answer History
0a-bma+
Yet another port of xnor's Python answer.
Japt, 2 bytes
cV
cV :Implicit input of integers U & V
cV :Round U up to the nearest multiple of V
With input as an array:
rc
rc :Implicit input of array
r :Reduce by
c :Rounding the first element up to the nearest multiple of the second
Less Trivial!, 6 bytes
_vV}aU
_vV}aU :Implicit input of integers U & V
_ :Function taking an integer Z as input
vV : Is Z divisible by V?
} :End function
aU :Starting from U, return the first integer that returns true when passed through that function
ôV ævV
ôV ævV :Implicit input of integers U & V
ôV :Range [U,U+V]
æ :Get first element
vV : Divisible by V
GolfScript, 6 bytes
.~)@%+
Function which consumes A and B from the stack, assuming B is below A.
Explanation:
#Example input: A = 12, B = 5 stack is 5 12
.~) #Duplicate A and negate the duplicate stack is 5 12 -12
@ #Pull 3rd from top to top stack is 12 -12 5
% #Second to top mod top stack is 12 3
+ #Add remaining values stack is 15
Charcoal, 10 bytes
≔±NθI×θ÷Nθ
Try it online! Link is to verbose version of code. Takes \$ b \$ first and \$ a \$ second. Explanation:
≔±Nθ
Input \$ b \$, negate it, and save the result.
I×θ÷Nθ
Input \$ a \$ and compute \$ -b \lfloor \frac a {-b} \rfloor \$, then cast to string for implicit print.
C (gcc), 47 31 25 bytes
f(a,b){a=a%b?f(++a,b):a;}
-16 bytes thanks to A̲̲ (forgot that return types and parameters would default to int if not defined, whoops!)
-6 thanks to AZTECCO for using a ternary and making the function recursive
MATL, 4 bytes
:ien
Explanation
Consider inputs 12, 5.
% Implicit input
: % Range
% STACK: [1 2 3 4 5 6 7 8 9 10 11 12]
i % Input
% STACK: [1 2 3 4 5 6 7 8 9 10 11 12], 5
e % Reshape as a matrix with that number of rows, padding with zeros
% STACK: [1 6 11;
2 7 12;
3 8 0;
4 9 0;
5 10 0]
n % Number of elements
% STACK: 15
% Implicit display
SimpleTemplate, 61 bytes
This was quite fun! Sadly, I had to do the dumb way :(
{@fn F A,B}{@whileA is notmultipleB}{@incA}{@/}{@returnA}{@/}
Creates a function that iterates until it finds a number that's multiple of the 2nd number.
This was actually way smaller than doing it without a function.
Ungolfed:
{@fn F numberA, numberB}
{@while numberA is not multiple of numberB}
{@inc by 1 numberA}
{@/}
{@return numberA}
{@/}
Should be mostly straightforward.
You can see it running on https://ideone.com/MR7t1E (golfed version only).
Prolog (SWI) + CLPFD, 30 bytes
f(R,X,Y):-R#=_*Y,R-Y#<X,R#>=X.
f(R,X,Y)
f is a predicate taking in a variable R, and two integers X and Y.
The CLPFD constraints are expressed using the #-prefixed operators. , means and, so f is true iff all these constraints are satisfied, i.e.,
1) R#=_*Y R is a multiple of Y , and
2) R-Y#<X R-Y < X , and
3) R#>=X R >= X .
x86 Machine Code, 7 bytes
Since x86 integer division instructions do only floor rounding, this uses the formula: f(a,b) = floor((a+b-1)/b)*b to accomplish ceiling rounding.
02 C3 ADD AL, BL ; a = a + b
48 DEC AX ; a = a - 1
F6 F3 DIV BL ; a = a / b
F6 E3 MUL BL ; a = a * b
Input is in AL and BL, output is AL.
Testing
Here is output from a test program for PC DOS that takes interactive input.
Download and test ROUNDMY.COM.
Runic Enchantments, 10 bytes
ii:},'cA*@
ii Read a, read b
:} Dup b, rotate to bottom of stack
, Divide
'cA Ceiling
* Multiply
@ Output and terminate
MathGolf, 3 bytes
/ü*
Similar approach as other answers: \$\lceil\frac{a}{b}\rceil b\$.
I/O as floats with .0, with the inputs in the order a b.
Explanation:
/ # Divide the second (implicit) input by the first (implicit) input
# i.e. 3.0 5.0 → 1.666...
ü # Ceil it
# → 2
* # Multiply it by the first (implicit) input
# → 6.0
# (output the entire stack joined together implicitly as result)
Pyth, 8 bytes
AQ+G%_GH
Simple port of the Python answer from xnor so please give that answer an upvote.
Debugged:
==================================================
assign('Q',eval_input())
assign('[G,H]',Q)
imp_print(plus(G,mod(neg(G),H)))
==================================================
J, 6 bytes
]*>.@%
] the right argument
* multiplied by
>.@ the ceiling of
% the left argument dividided by the right one
If we can swap the order of the aruments:
J, 5 bytes
]+[|-
Red, 31 bytes
func[a b][round/to/ceiling a b]
Just a built-in round with refinements to, which scales the first argument according to the second, and ceiling, which indicates the direction.
Red, 25 bytes
func[a b][0 - a // b + a]
A port of xnor's Python answer. Don't forget to upvote his answer!
Retina 0.8.2, 28 bytes
\d+
$*
r`1+(\2*) (1+)
$1$2
1
Try it online! Link includes test cases. Explanation:
\d+
$*
Convert the inputs to unary.
r`
Process this stage from right-to-left, so that \2 gets to match \$ b \$ first, allowing us to refer to it when matching within \$ a \$.
1+(\2*) (1+)
Match \$ b \$ in \2, then as many copies of \$ b \$ as we can, without completely exhausting \$ a \$. \1 thus matches \$ b \lfloor \frac {a - 1} b \rfloor = b \lceil \frac {a - b} b \rceil \$
$1$2
Add that to \$ b \$ to give \$ b \lceil \frac a b \rceil \$.
1
Convert to decimal.
Python, 17 bytes
lambda a,b:a+-a%b
Since this doesn't use division, it works for both Python 2 and 3. Note that we can't cut out the + sign because a-a%b does a-(a%b), whereas we want to do(-a)%b and add that to a. We could also write it as -a%b+a.
JavaScript (V8), 22 bytes
This is the function \$(a,b) \mapsto \left\lceil \frac{a}{b} \right\rceil b\$.
a=>b=>Math.ceil(a/b)*b
