# Queueing With Friends

You're with your best bud, Jim, at the amusement park and as your favorite ride comes into view, you and Jim exchange glances. Naturally you race to get in line. Unfortunately he wins because you're a golfer and he plays a real sport (sorry friends). In fact, you're so far behind that you and Jim are separated by x people. Assuming the line is length n and you're at the back and the line zigs and zags every j people, at what positions in the line will you and Jim be in the same column allowing you to chat (only one row apart)?

# Input

3 Integers

• n - The length of the line. This number will always be greater than or equal to j and will be in the form y * j where y is a positive integer (the number of rows in the queue).
• j - The number of people in one row of the line (the number of columns in one row). This number will always be greater than 0.
• x - The number of people between you and Jim such that 0 <= x < 2j - 1. Hint: If this number is odd, then your output should be empty.

# Output

A list of integer positions in the line at which Jim is in the same column as you.
1 These integers can be 0 or 1-indexed as long as you specify in your answer.
2 These integers can assume you start at position 0 or position n-1 as long as you specify in your answer.

# Example In this example, the input would be n = 9, j = 3, x = 0. The output should be 2, 5 because your position is 2 or 5 when you're in the same column as Jim

# Test Cases

[9, 3, 0] -> [2, 5]
[12, 3, 0] -> [2, 5, 8]
[9, 3, 1] -> []
[9, 3, 2] -> [1, 4]
[14, 7, 10] -> 
[24, 4, 6] -> [0, 4, 8, 12, 16]


# Scoring

This is , so the shortest answer (in bytes) wins.

• I'm queuerious to see some interesting solutions to this! (sorry bad pun and also improper use of the word but whatever, don't judge me :P) Mar 27, 2017 at 13:16
• Can we return a falsy value instead of an empty array? Mar 27, 2017 at 13:41
• @Riker I see no reason to disallow that. Go for it
– Poke
Mar 27, 2017 at 13:57

# Python 2, 454140 37 bytes

lambda n,j,x:range(j-x/2,x%2or n-x,j)


Pretty much the trivial solution. I just quickly scanned for patterns and found a pattern. 1-indexed, 1 is at the back of the queue.

-4 bytes by avoiding ternaries and using an array for the values instead
-1 byte thanks to some inspiration from @DeadPossum, by using and instead of ternaries or array selectors
-3 bytes by switching to or in the opposite order. Only works because of 1-indexing

Also, crossed out 4 is still 4 on all of the 4s :(

Try it online!

• Lol, you posted just 14 minutes, before me :) My version is shorter by 3 bytes: lambda n,j,x:x%2-1and range(j-x/2,n-j+1,j) Mar 27, 2017 at 13:47
• @DeadPossum Nice. I have another solution that's one byte shorter than that, lol Mar 27, 2017 at 13:48
• I had a mistake in second argument of range. It shouldn't be n-j+1, so lambda n,j,x:x%2-1and range(j-x/2,n-x,j) is shorter by one more in total of 40 bytes Mar 27, 2017 at 13:53
• @DeadPossum Wait, were we allowed to return a falsy value instead of an empty array? Mar 27, 2017 at 13:55
• @FelipeNardiBatista that's what "1-indexed" means, btw. Mar 27, 2017 at 14:14

# Pip, 22 21 bytes

20 bytes of code, +1 for -p flag.

c%2?lv-c/2+b*\,a/b-1


Takes n, j, and x as command-line arguments. 0-indexed, starting at position 0. Try it online!

### Explanation

This is my original 22-byte version because it's a bit more understandable.

                       a, b, c are cmdline args; l is [] (implicit)
c%2?                   Test c mod 2
l                  If it's 1 (truthy), return empty list; else:
a/b-1  Number of rows in the queue minus 1
,       Range(^)
b*        Multiply each element by b
b-1-c/2+          Add (b-1)-c/2 to each element
Output in [1;2;3] format (implicit, -p flag)


The formula was obtained by observing the pattern for n=9, j=3:

x Output
0 [2;5]
2 [1;4]
4 [0;3]


If we take x/2 (0,1,2), subtract it from j-1 (2,1,0), and add that to [0;3], we get the correct result in all cases.

# Java 8 lambda, 101 bytes

(n,j,x)->{int[]i=new int[n/j-1];int c=0,k=j-x/2;for(;k<n-x;k+=j)i[c++]=k;return x/2==0?i:new int;}


Almost-direct port of my Python answer. Range doesn't exist in Java though.

(n#j)x|odd$round x=[]|m<-j-x/2=[m,m+j..n-x]  Pretty much directly ported from the Python answer from HyperNeutrino More well-formatted code: f n j x |odd$round x = []

int[]r=new int[n/j-1];for(int i=1;i<n/j;i++){r[i-1]=i*j-x/2-1;}return(x%2==0)?r:new int;