The bus driver picks up the children from their homes every morning for school. All the homes are positioned around a circular street and the bus driver has to stop at every home exactly once.

One monday morning the bus driver decided to only pick up every second child he encountered along his way. However, he still had to pick up every single children, so this meant he was willing to go multiple rounds.

The houses are indexed from 1 to N (they come in order). The bus driver starts at the first (index 1) house and does not change directions during his trip. You must find the index of the house the last child is picked up from.


A single positive number N read from the standard input representing the number of houses along the street.


Output the index of the house the last child is picked up from to the standard output.


Input: 10

Output: 4

The order of pickups are as follows: 1 3 5 7 9 2 6 10 8 4

Shortest code wins!

  • \$\begingroup\$ Why the restrictive input/output? It is common to allow anonymous functions that take an argument as input and return a value as output, as well as STDIN and STDOUT. \$\endgroup\$ – sporklpony Apr 13 '17 at 15:08
  • \$\begingroup\$ This is a special case of this challenge, but since this problem has a closed form solution for k = 2, it might be worth keeping this open separately. \$\endgroup\$ – Martin Ender Apr 13 '17 at 15:12
  • 1
    \$\begingroup\$ @MartinEnder That makes it more of a dupe of this one, which is currently closed as a dupe of the other :/ \$\endgroup\$ – Geobits Apr 13 '17 at 15:18
  • \$\begingroup\$ I guess it's also subtly different because this one counts out the first in each pair, not the second. \$\endgroup\$ – Martin Ender Apr 13 '17 at 15:18
  • \$\begingroup\$ That's the same as the ninja challenge though. \$\endgroup\$ – Martin Ender Apr 13 '17 at 15:21

Browse other questions tagged or ask your own question.