In 2D Mario, Bullet Bill cannons are two units tall. The Bullet Bill is fired out of the upper unit and travels in a straight line (parallel to the x axis).

Mario is two units tall when standing up and one unit tall when ducking. His jump height is three units. It takes him 0.5 seconds to reach the full height and 0.5 seconds to come back down.


Write a program that helps Mario avoid an incoming Bullet Bill. He may have to jump, duck, or do nothing.


The input will come in the format [bullet_bill_position] [direction] [speed] [mario_position].

  • bullet_bill_position consists of two space-separated integers, x and y. This represents the coordinates of the upper unit of the cannon. The bullet bill will fire from this location.
  • direction will either be left or right (string).
  • speed is the speed of the Bullet Bill in units per second.
  • mario_position consists of x and y and represents the coordinates that Mario is standing on.


[action] [wait_time]

  • action will be one of three strings: duck, jump, or nothing.
  • wait_time only applies to jump. It represents how long Mario should wait before jumping over the Bullet Bill. If action is not jump, this will be left blank.


  • The ground will always be right underneath Mario's feet.
  • Bullet Bills are only one unit tall and one unit wide. Mario will be safe if it passes one unit above his head.
  • Mario will be safe if he lands on the Bullet Bill. Hitting the side or bottom will kill him.
  • There will often be more than one solution. You only have to output one of them.
  • Numerical input will always be integers. However, output may sometimes need to have floats/doubles.

Test Cases

Input: 5 1 left 2.5 0 0

Possible Output: jump 1.5

Explanation: The Bullet Bill will be at Mario's feet in 2 seconds. Mario will jump at 1.5 and touch back down at 2.5. The Bullet Bill passed safely underneath him.

Another Possible Output: jump 1

Explanation: If Mario jumps at 1, he will touch back down at 2 and land on the Bullet Bill.

Input: 0 3 right 100 5 0

Possible Output: nothing

Explanation: The Bullet Bill will pass very quickly over Mario's head. He will be safe.

Input: 0 2 right 1 5 0

Output: duck

Explanation: The Bullet Bill will go where Mario's head would've been.


  • You can write a full program or function.
  • I/O should be to stdin and stdout.


This is . Your score is the number of bytes. The solution with the lowest score in one week will win. Good luck!

  • \$\begingroup\$ Just want to make sure I'm interpreting everything, in a 2x1 column where a Bullet Bill is on top and Mario is ducking on the bottom, Mario still stays alive in this scenario, correct? \$\endgroup\$
    – Kade
    Jul 31, 2015 at 19:29
  • \$\begingroup\$ @Vioz, That's correct, Mario is only one unit tall when ducking. \$\endgroup\$
    – Nick B.
    Jul 31, 2015 at 19:30
  • \$\begingroup\$ May we change the order the input is given? \$\endgroup\$
    – Kade
    Jul 31, 2015 at 19:32
  • 6
    \$\begingroup\$ Is jumping linear speed upwards followed by linear speed downwards, or are we to assume quadratic speed? \$\endgroup\$
    – orlp
    Jul 31, 2015 at 19:37
  • 1
    \$\begingroup\$ @orlp, Physics are a bit simplified for this challenge. In 0.5 seconds, Mario rises up 3 blocks at a constant rate. Then, without stopping, he does the same thing back down. \$\endgroup\$
    – Nick B.
    Jul 31, 2015 at 19:40

3 Answers 3


Python, 72 68 66 bytes

We can ignore left/right - if we assume it's always pointed at us we'll always take the right action. Then if our assumption was wrong we did a useless jump/duck, but that doesn't matter - we'll still be safe.

Similarly, there is no incentive to do nothing. Rather, it's shorter code to always duck, and jump when necessary. Ducking will only be unsafe if the bullet bill is exactly one above the block we're standing on. In that case we will take our x position, bullet bill's y position, take the absolute difference, divide by bullet bill's speed and jump 0.2 seconds before that.

lambda a,b,_,s,x,y:["duck","jump "+`max(0,abs(a-x)/s-.2)`][y+1==b]

Call like this:

f=lambda a,b,_,s,x,y:["duck","jump "+`max(0,abs(a-x)/s-.2)`][y+1==b]
f(5, 1, "left", 2.5, 0, 0)
  • 1
    \$\begingroup\$ Beat me by 20 seconds and 5 bytes :P Nice work! \$\endgroup\$
    – Kade
    Jul 31, 2015 at 20:17
  • \$\begingroup\$ Good job! I like your reasoning for what is necessary and what is unnecessary. \$\endgroup\$
    – Nick B.
    Jul 31, 2015 at 20:22
  • 1
    \$\begingroup\$ @Vioz, You're still welcome to post your solution, even if it's longer. I'd like to see what you came up with. \$\endgroup\$
    – Nick B.
    Jul 31, 2015 at 20:23
  • \$\begingroup\$ @NickB. We have pretty much the exact same line of reasoning :P Had I remembered to implement absolute values and stack rotating in the language I'm working on I would have posted it \$\endgroup\$
    – Kade
    Jul 31, 2015 at 20:31
  • \$\begingroup\$ Surely it's shorter to use a lambda? \$\endgroup\$
    – xnor
    Aug 1, 2015 at 7:02

CJam, 84 80 61 bytes

This is my first program for this, literally just learned CJam last night, for this purpose only. I'm also new to this site's formatting, help would be great with that.


It's no longer longer than the previous answer, but I'm still posting it because I'd like tips and stuff.


ri:X    - Sets Bullet X to X.
ri:Y    - Sets Bullet Y to Y.
r       - Omits direction.
ri:S    - Sets speed to S.
ri:A    - Sets Mario X to A.
ri:B    - Sets Mario Y to B.
];      - Clears the stack.
BY=     - Due to the ? at the end, executes the first block if true (if B=Y) or the second block (in this case "duck") if false.
{"jump" - Outputs jump.
XA<     - Due to the ? after the next two blocks, executes the first block if true (if X<A) or the second block if false.
{AX)-S/}- Solves and outputs (A-(X+1))/S.
{X(A-S/}- Solves and outputs ((X-1)-A)/S.
?}      - Executes block A if the condition before it is true, or block B if not.
"duck"  - Outputs duck.
?       - Executes block A if the condition before it is true, or block B if not.

There's an online interpreter here if needed.

  • \$\begingroup\$ Nevermind. The question contradicts itself. \$\endgroup\$
    – Dennis
    Aug 2, 2015 at 5:35
  • \$\begingroup\$ @Dennis Not exactly sure what that means, not good with terminology and stuff. I'm not too far into coding yet. \$\endgroup\$ Aug 2, 2015 at 5:36

Haskell, 61 Bytes

I found that there's no point in doing nothing. Jump if Bill is at or bellow Mario's feet, otherwise duck.

f a b _ c d e|b<e+2="Jump "++(show$abs(a-d)/c-0.5)|1<2="Duck"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.