All problems

Swap Two Numbers Without a Temp Variable

easyPythonBasics

A trainee is being shown how values actually move around in memory, using an exercise that takes the obvious tool away. Two numbers arrive and have to come back out in the opposite order — but you may not park one of them in a third variable while you shuffle, which is the move almost everyone reaches for first.

Task: Read two integers and print them in the opposite order, without using a third variable to hold either value.

Input

A single line holding two integers separated by a single space: a, then b. Either may be negative, and the two may be equal.

Output

One line holding the two values in the opposite order — b first, then a — separated by a single space.

Example:

Input:
3 7

Output:
7 3

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…