# Introduction

It was just a normal day, here at your military base. Suddenly, you looked up to see a bomb falling down from the sky! You need to create a program to predict where it will fall, and tell you the location.

# Challenge

You will be given a bomb in the form of Start-X Start-Y X-velocity Y-velocity. You can assume that they will all be positive integers. 0 is a valid input only for Start-x and Start-y. The bomb starts with x Start-x, and y Start-y. Each "frame" (no graphical output required), the bomb will move x-velocity units right, then y-velocity units down. Continue doing this until the bomb reaches y of 0 or below. Then, output what it's x was when it hit the ground.

# Test Cases

1

Input:0 10 2 2

Output:10

2

Input:5 4 3 2

Output:11

3

Input:11,8,7,3

Output:32

This is , so shortest answer in bytes wins!

• Once you do out the math, it looks like the formula leaves little to golf.
– xnor
Commented Apr 4, 2017 at 21:23
• @xnor Maybe the ceiling function could be golfed. But I can't see anywhere else. Commented Apr 4, 2017 at 21:24
• You can assume that they will all be positive integers 0 is not a positive integer. Can you clarify if 0 is a valid input or not? Commented Apr 4, 2017 at 21:26
• Looks like 0 is valid input from test case #1 Commented Apr 4, 2017 at 21:27
• 0 is a valid input only for start-x and start-y. editing now. Commented Apr 4, 2017 at 21:28

# 05AB1E, 9 bytes

¹³²(I÷(*+


Try online

# TI-Basic, 21 bytes

Input :Prompt A,B:X+A+Aint(Y/B-E~9


If the ceiling function did not have to be implemented, it would be more straightforward at 13 bytes:

Input :Prompt A,B:X+AY/B

• Don't you need to prompt for x and y as well? Commented Apr 4, 2017 at 21:28
• @fəˈnɛtɪk In TI-83/84 BASIC, providing no arguments to Input is equivalent to Prompt X,Y, taking location from the graph screen. It's usually more of a savings when only one or two values are needed, although it saves 1 byte in this situation as well. Commented Apr 4, 2017 at 22:03

# Python, 45 28 Bytes

lambda a,b,x,y:a+x*-(-b//y)


Try it online!

• The import has to be scored. meta post Commented Apr 4, 2017 at 21:28
• @mbomb007 Still, with the import is 45 bytes Commented Apr 4, 2017 at 21:28
• Why not use your own ceil function? lambda a,b,x,y:a+x*int(b/y+.5) Commented Apr 4, 2017 at 21:32
• @DJMcMayhem Just made one 2 bytes shorter than yours Commented Apr 4, 2017 at 21:48
• a--b//y*x seems to work. Commented Apr 5, 2017 at 1:25

# Scheme 40 36 Bytes

λ(x y u v)(+ x(* u(ceiling(/ y v))))

• Does scheme require all of those spaces between identifiers and parentheses Commented Apr 4, 2017 at 21:57
• Actually I can get rid of some of them...thanks Commented Apr 4, 2017 at 22:00

(a#b)x y=a-x*div(-b)y


The trivial answer: defines an operator that takes 4 arguments and then uses the formula.

Could probably be golfed more.

EDIT: Yep, Ørjan Johansen points out we can use a-x*div b(-y), which brings us to 22 bytes. Try it online!

At this point, the code is really more other people than mine, so I'm going to mark this answer community wiki. Feel free to golf this further if you want :)

• Ouch, importing Data.Ratio ... try a-x*div(-b)y. Commented Apr 5, 2017 at 1:28

# JavaScript, 29 28 bytes

Thanks @user5090812 for golfing off 1 byte

(a,b,x,y)=>a+x*((b+y-1)/y|0)


Try it online!

If it did not have to move x then y but was instead falling in a straight line it would be 18 bytes

(a,b,x,y)=>a+x*b/y

• You could do (a,b,x,y)=>a+x*(b/y|0+1) and save 5 bytes Commented Apr 4, 2017 at 22:28
• @powelles If I do that I will end up overshooting for exact values. Commented Apr 4, 2017 at 23:54
• Weird. I expected x|0+1 to perform the same as Math.ceil and didn't actually test it. Commented Apr 5, 2017 at 0:30
• @powelles if you have 1|0+1 you end up with 2. With Math.ceil you will get 1 Commented Apr 5, 2017 at 0:36
• I mistakenly made the assumption that ceiling could be implemented as floor+1. Commented Apr 5, 2017 at 0:53

# C#, 46 bytes

(a,b,c,d)=>a+c*(int)Math.Ceiling((double)b/d);


# Ruby, 21 bytes

->x,y,v,w{x-v*(y/-w)}


# Java 7, 66 bytes

int f(int a,int b,int x,int y){return a+x*(int)Math.ceil(1f*b/y);}