| Bytes | Lang | Time | Link |
|---|---|---|---|
| 2032 | 4.3 | 241211T160158Z | fgeorgat |
| 003 | Python | 140717T202849Z | ɐɔıʇǝɥʇu |
| nan | 140717T085757Z | Arnaud | |
| nan | 140717T092136Z | lochok | |
| nan | 140717T063952Z | Thomas W | |
| nan | 140717T004357Z | isaacg |
4.3, 20 chars in python and yet 32bit assembly friendly
For completeness, I also add this python expression which was part of a quora answer some years ago using the so-called kefalonian constant [1], [2] :
- 0xd50e9994>>36-3*m&7
Test case:
- print([0xd50e9994>>(36-3*m)&7 for m in range(1,13)])
[1] https://www.quora.com/What-does-floor-division-in-Python-do/answer/Fotis-Georgatos
Python (3)
Since there are quite a few of these questions these days, I decided to make a program to automatically solve them in 3 (or 2) tokens. Here's the result for this challenge:
G:\Users\Synthetica\Anaconda\python.exe "C:/Users/Synthetica/PycharmProjects/PCCG/Atomic golfer.py"
Input sequence: 0 3 2 5 0 3 5 1 4 6 2 4
f = lambda n: (72997619651120 >> (n << 2)) & 15
f = lambda n: (0x426415305230L >> (n << 2)) & 15
f = lambda n: (0b10000100110010000010101001100000101001000110000 >> (n << 2)) & 15
Process finished with exit code 0
Proof that this works:
f = lambda n: (72997619651120 >> (n << 2)) & 15
for i in range(12):
print i, f(i)
0 0
1 3
2 2
3 5
4 0
5 3
6 5
7 1
8 4
9 6
10 2
11 4
2.0
(127004 >> i) ^ 60233
or (score 2.2) :
(i * 3246) ^ 130159
All found with brute force :-)
35.3
I suspect this may be the least efficient method to create the list:
1.7801122128869781e+003 * n -
1.7215267321373362e+003 * n ^ 2 +
8.3107487075415247e+002 * n ^ 3 -
2.0576746235987866e+002 * n ^ 4 +
1.7702949291688071e+001 * n ^ 5 +
3.7551387326116981e+000 * n ^ 6 -
1.3296432299817251e+000 * n ^ 7 +
1.8138635864087030e-001 * n ^ 8 -
1.3366764519057219e-002 * n ^ 9 +
5.2402527302299116e-004 * n ^ 10 -
8.5946393615396631e-006 * n ^ 11 -
7.0418841304671321e+002
I just calculated the polynomial regression. I'm tempted to see what other terrible method could be attempted.
Notably, I could save 3.3 points if the result was rounded. At this point, I don't think that matters.
3.2
Zero based solution:
7 & (37383146136 >> (i*3))
One based solution:
7 & (299065169088 >> (i*3))
I initially thought that the %7 operation would be counted as well and % being an expensive operation here, I tried to solve it without it.
I came to a result of 3.2 like this:
// Construction of the number
// Use 3 bits per entry and shift to correct place
long c = 0;
int[] nums = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
for (int i = nums.Length - 1; i >= 0; i--)
{
c <<= 3;
c += nums[i];
}
// c = 37383146136
// Actual challenge
for (int i = 0; i < 13; i++)
{
Console.Write("{0} ",7 & 37383146136 >> i*3);
}
I'd be interested in optimizations using this approach (without %). Thanks.
2 2.2
I love arbitrary precision arithmetic.
0x4126030156610>>(n<<2)
Or, if you don't like hex,
1146104239711760>>(n<<2)
Test:
print([(0x4126030156610>>(n<<2))%7 for n in range(1,13)])
[0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]