5
Challenge
Given a list of integers and a velocity, \$v\$, implement a sorting algorithm which simulates a program sorting the list from smallest to biggest at the given velocity.
Einstein's Theory of Special Relativity
What do I mean? Well assume your program takes a time, \$T\$, to sort a particular list. If you ran the program again at a higher velocity, \$v\$, according to a stationary observer your program would run slower and would take a different time, \$T'\$, to sort the same list.
How do you relate \$T\$ to \$T'\$? You use the equation for time dilation:
$$T' = \frac{T}{\sqrt{1-v^2}}$$
If we use geometrised units where \$v\$ is a fraction of the speed of light, and \$0\leq v \lt 1\$.
So you must change your program's running time by a factor of
$$\frac{1}{\sqrt{1-v^2}}$$
Output
You must output the sorted list
Rules
- You are allowed an error of \$\pm0.1 \text{ s}\$
- The length of the list, \$l\$, will be in the range \$1 \leq l \leq 50\$
- The list will contain only integers
- The velocity will be given in geometrised units
- You may sort the list then wait before outputting
Examples
For these examples, assume my program takes a time of \$T = l^2 \text{ s}\$ to run, where \$l\$ is the length of the list, regardless of the contents of the list:
List, Velocity > Sorted list, Time taken
[9,8,7,6,4,3,2,1], 0.5 > [1,2,3,4,5,6,7,8,9], 93.5307
[8,0,0,5,6], 0.1 > [0,0,5,6,8], 25.1259
[7,7,7,7,7,7,7], 0.999 > [7,7,7,7,7,7,7,7], 453.684
Your timings do not need to be as accurate.
Winning
Shortest code wins.
Suppose your program sorts a list
L
in timeT
in the 'normal' rest frame (v=0
). Then, if we run with the same listL
withv=sqrt(0.5)
, how long should your program take to run?2*T
or3*T
or some other number? – Chas Brown – 2018-07-26T00:30:55.570Perhaps use the [tag:time] or [tag:restricted-time] tags? – Asone Tuhid – 2018-07-26T09:09:43.490
@ChasBrown your program should take
T/sqrt(1-v**2)
to run. Forv=sqrt(0.5)
, then your program should run forsqrt(2)*T
– Beta Decay – 2018-07-26T09:17:24.397@ChasBrown If your program runs for a time
T
, then it should pause for a time ofT/sqrt(1-v**2) - T
– Beta Decay – 2018-07-26T09:19:40.040@Beta Decay: I agree with your latter comment ("... should pause... - T"); but your previous with "should run for
sqrt(2)*T
..." still seems a bit off, computationally... – Chas Brown – 2018-07-26T09:40:59.640@ChasBrown What do you mean? – Beta Decay – 2018-07-26T09:42:10.377
@Beta Decay: I mean that, given that
v=0
your program runs forT
; then "Forv=sqrt(0.5)
, then your program should run forsqrt(2)*T
" is not correct as a calculation. However, more generally, "If your program runs for a timeT
(withv=0
), then it should pause for a time ofT/sqrt(1-v**2) - T
" is correct, as a calculation. – Chas Brown – 2018-07-26T09:50:48.223@ChasBrown Overall your program should run for
T' = T/sqrt(1-v**2)
. The sorting section of the program will run forT
, so the pausing section of the program will run forT/sqrt(1-v**2) - T
. Whenv=sqrt(0.5)
, then the program as a whole should run forT' = T/sqrt(1-0.5) = sqrt(2) * T
. Whenv=0
then the program as a whole will run forT' = T/sqrt(1-0) = T
. I'm still not sure what the problem is. – Beta Decay – 2018-07-26T09:56:13.477@Beta Decay: I see now; you're correct. – Chas Brown – 2018-07-26T18:02:39.840