title: Confused badminton players

text:
# Question
Title: Confused badminton players
# Introduction

*Jim* and *Bob* are playing badminton doubles against two other players, but mid-game they face a dilemma:
After a fast-paced rally they have no idea who has to serve next and where they have to stand for the next serve.
Bad enough they only know the scores in order.

## Rules:

To help them out, you have to know the rules:

1. If the serving team has an even score, serving is done by the player on the right side (relatively facing towards the net)
2. If the serving team has an odd score, serving is done by the left player.
3. If the serving team changes, the players' position remains.
4. If one team keeps the right to serve the ball, the two players of that team swap places, so the same player serves again.
5. The team, that scored last, serves next.

**This is where you come to help them out.**

# Your task:

Your task is to take the scores in order and return the position for *all four* players according to the rules as well as the player, who has to serve next.

# Specification:

## Input:

Input is a string / array / set / whatever you like containing all scores in the order they are scored.
Example: `"0:0, 0:1, 0:2, 1:2, 1:3"` or `["0:0", "0:1", "0:2", "1:2", "1:3"]`
You may assume team 1 (the left part of the score) served first in the beginning.

*The input is not secured to be valid!*

## Output:

Your program / function / script has to output an ASCII-art style badminton court (don't care about orientation) with the position of the players and some representation of the player serving next (a single line saying `Next to serve is >Player1<` is enough).

**Example output of the example given above (`"0:0, 0:1, 0:2, 1:2, 1:3"`):**

```
|-----|-----|
|-Jim-|-Bob-| //Team 1
|###########|
|-P4--|-P3--| //Team 2
|-----|-----|
Player P4 of team 2 serves next.

```

The players are named Jim, Bob, P3 and P4. P3 and P4 swap their places after scoring "0:2" and keeping the right to serve. Jim and Bob never scored two times in a row and thus never swap places.

# Last notes about input and output:

* Input is assumed to be always in order with the first (*left*) score to be team 1, which may be assumed to have served first.
* The names of the players are irrelevant as long as it is documented which player belongs to which team.
* Team 1 is always the upper/left team in your output.
* Even though a usual badminton round ends when one team scores 21 (without overtime), you may assume the game to be as long as the two teams want to play.
* Sometimes the input may be incomplete (missing a score). Then your program has to output an error message indicating invalid input (`E` for `Error!` is enough for golfing reasons).

# Scoring:

This is code-golf, so the least amount of bytes wins.
There are bonuses to claim though:

* **-20%** if you output the court and server for every single serve.
* **-10%** if your program allows to choose the serving team.
* **-15%** if the user can choose the names for the players.

The bonus percentages are first added and then applied to the byte count, resulting in a maximum bonus of *45%*!

# Test cases (so you don't have to come up with your own):

(Strings only, including output and validation):
**Example1:**

```
0:0, 1:0, 2:0, 3:0, 3:1, 3:2, 4:2, 4:3, 5:3, 6:3, 6:4, 7:4, 7:5, 7:6, 8:6, 8:7, 9:7, 10:7, 11:7, 12:7, 12:8, 12:9, 13:9

```

Output:

```
|-----|-----|
|-Bob-|-Jim-| //Team 1
|###########|
|-P4--|-P3--| //Team 2
|-----|-----|
Player Jim of team 1 serves next.

```

**Example2:**

```
0:0, 0:1, 0:2, 1:2, 2:2, 3:3, 4:3, 4:4 -> Invalid
                          /\              Both teams can't score at the same time/missing intermediate score

```

Output:

```
Invalid input! Please check input and try again.

```

**In case you have questions or need clarification, please ask so I can improve the challenge.**

# Answer
> 4 votes
# Python 2: 320 chars - 45% = 176

```
def f(n,t,s):
 for l,r in zip(s,s[1:]):
  d=[r[0]-l[0],r[1]-l[1]]
  if[0,1]!=sorted(d):print'E';break
  if d[1]==t:v=2*t;n[v:v+2]=n[v:v+2][::-1]
  t=d[1];m=max(map(len,n))+2;z=('|'+'-'*m)*2;c='|{:^%d}'%m;print'|\n'.join([z,c*2,'|#'+'#'*2*m,c*2,z,'Player {} of team {} serves next.\n']).format(*n+[n[2*t+(t+r[t])%2],t+1])

```

I'm not happy with lots of things. For instance the line `d=[r[0]-l[0],r[1]-l[1]]` is so ugly. But spend quite some time in golfing this.

Claims all 3 bonuses. Please tell me, if I my output is not entirely the way you wanted. The question was not very clear.

## Usage:

This defines a python method. The parameters are a list of strings (the names of the players), an integer 0 or 1 (serving team) and a list of tuples of the scores.

```
f(["Jim","Bob","P3","P4"],0,[(0, 0), (0, 1), (0, 2), (1, 2), (1, 3)])
f(["Jim","Bob","A","Montgomery"],0,[(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (3, 2), (4, 2), (4, 3), (5, 3), (6, 3), (6, 4), (7, 4), (7, 5), (7, 6), (8, 6), (8, 7), (9, 7), (10, 7), (11, 7), (12, 7), (12, 8), (12, 9), (13, 9)])
f(["Jim","Bob","P3","P4"],0,[(0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (3, 3), (4, 3), (4, 4)])

```

## Output:

```
|-----|-----|
| Jim | Bob |
|###########|
| P4  | P3  |
|-----|-----|
Player P4 of team 2 serves next.

|------------|------------|
|    Bob     |    Jim     |
|#########################|
| Montgomery |     A      |
|------------|------------|
Player Jim of team 1 serves next.

E

```

This is of course shortened, for the full output visit http://pastebin.com/AzbnEbaH.

---
Tags: code-golf, ascii-art
---


# Question
Title: Remove a weight so the rest can't be balanced
This code-golf challenge is based on the following puzzle:

> You have an odd number of tokens whose weights are known whole numbers, and they don't all have the same weight. Show that there's a token you can remove so that the remaining tokens can't be split into two equal-size sets that have the same total weight.

Here's the canonical solution to the puzzle, which also suggests an algorithm to do it (spoilers if you want to solve the puzzle yourself):

> If all the weights are even or all odd, the problem is unchanged if we truncate the least significant bit from each one (i.e. floor-divide by 2). Keep doing that until there's at least one even weight and one odd weight -- this must happen eventually because the total weight decreases at each step. Then, remove a weight whose parity is opposite the parity of the sum, leaving an odd total weight, which clearly prevents an even split.

Your goal is to figure out such a weight to remove. Shortest code wins.

**Input:**

An odd-size list of positive whole numbers, not all the same. Any list-like structure is fine, though it has to work with the numbers in any order.

**Output:**

One of those numbers, such that the remaining numbers can't be partitioned into two sets with equal size and equal sum. You must output the number, not its index.

If there's multiple choices, any one of them is fine. It doesn't have to be the number chosen by the solution above.

Your code should be able to handle test cases like below within one second.

**Test cases:**

```
[1, 2, 3]
1

[3, 3, 3, 3, 3, 3, 5]
3

[1, 2, 3, 4, 5, 6, 7, 8, 9]
2

[1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
1

[128, 256, 256]
256

[18770, 10578, 7506, 5458, 4434, 6482, 5458, 4434, 2386, 11602, 1362, 16722, 11602, 23890, 12626, 47442, 57682, 35154, 57682, 81234, 44370, 12626, 12626, 46418, 68946, 91474, 2386, 43346, 46418, 35154, 32082]
7506

```

If you want to see all possible outputs (this is just to show, your code must output exactly one):

```
[1, 2, 3]
{1, 2, 3}

[3, 3, 3, 3, 3, 3, 5]
{3}

[1, 2, 3, 4, 5, 6, 7, 8, 9]
{2, 4, 6, 8}

[1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
{1}

[128, 256, 256]
{256}

[18770, 10578, 7506, 5458, 4434, 6482, 5458, 4434, 2386, 11602, 1362, 16722, 11602, 23890, 12626, 47442, 57682, 35154, 57682, 81234, 44370, 12626, 12626, 46418, 68946, 91474, 2386, 43346, 46418, 35154, 32082]
{68946, 5458, 44370, 46418, 11602, 23890, 7506, 91474, 32082, 1362, 81234}

```

# Answer
# CJam, 19 17

```
q~:T{T:^^2bW%}$W=

```

Input format:

```
[1 2 3 4 5 6 7 8 9]

```

2 bytes thanks to Optimizer.
> 2 votes

# Answer
# Python 2, 99

This came out pretty badly.

```
s=input()
b=1
while{x&b for x in s}<{0,b}:b+=b
print[x for x in s if(reduce(int.__xor__,s)^x)&b][0]

```

Numbers may be input comma-delimited.
> 1 votes

---
Tags: code-golf
---


# Question
Title: Implement range function without using numbers in code
You have to create a function `range`, such that it takes two (integer) arguments `a` and `b` (`a < b`) and returns all the numbers in between them. So:

```
range(5, 10) // should output 6, 7, 8, 9
range(-5, 2) // should output -4, -3, -2, -1, 0, 1
range(5, 0) // can throw an error/empty/null/undefined/whatever (a is not < b)
// bonus points for non integer handling
range(0.5, 4.5) // 1.5, 2.5, 3.5
range(0.5, 4) // range doesn't make sense, error/null/empty
range(5, 5) // etc. should return empty/null/undefined/whatever

```

Your code must **not use any numbers at all**, but you can use arithmetic operators. If your language has a `range` function in-built, you cannot use that as well.

Shortest code wins.

# Answer
> 0 votes
# Javascript (49)(45)

As feersum said, I do not know why anyone would have to use numbers here.

```
f=(a,b)=>{for(c=[];a<b;c.push(a++));return c}

```

Old:

```
f=(a,b)=>{c=[];for(;a<b;a++){c.push(a);}return c}

```

I am sure it can be golfed down further=)

---
Tags: code-golf, restricted-source
---