1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 05:14:39 +01:00

Fixed behaviour of range function

This commit is contained in:
Daniil Gentili 2016-07-20 17:34:23 +02:00
parent 2cc6300bb5
commit 4f868e09de
2 changed files with 21 additions and 17 deletions

View File

@ -135,8 +135,12 @@ function pyjslib_range($start, $stop = null, $step = 1)
return array_reverse($arr, false);
}
$arr = range($start, $stop, $step);
array_pop($arr);
if($step > 1 && $step > ($start - $stop)) {
$arr = [ $start ];
} else {
$arr = range($start, $stop, $step);
array_pop($arr);
}
return $arr;
}

View File

@ -12,22 +12,22 @@ class PrimeModule
$this->smallprimes = $this->primesbelow(10000);
}
/*
def primesbelow(N):
# http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
#""" Input N>=6, Returns a list of primes, 2 <= p < N """
correction = N % 6 > 1
N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6]
sieve = [True] * (N // 3)
sieve[0] = False
for i in range(int(N ** .5) // 3 + 1):
if sieve[i]:
k = (3 * i + 1) | 1
print(len(sieve[k*k // 3::2*k]))
print(((N // 6 - (k*k)//6 - 1)//k +1))
sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1)
sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1)
def primesbelow(N):
# http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
#""" Input N>=6, Returns a list of primes, 2 <= p < N """
correction = N % 6 > 1
N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6]
sieve = [True] * (N // 3)
sieve[0] = False
for i in range(int(N ** .5) // 3 + 1):
if sieve[i]:
k = (3 * i + 1) | 1
print(len(sieve[k*k // 3::2*k]))
print(((N // 6 - (k*k)//6 - 1)//k +1))
sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1)
sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1)
return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]]
*/
*/
public function primesbelowtwo($N) {
$correction = posmod($N, 6) > 1;
$N = [$N, $N - 1, $N + 4, $N + 3, $N + 2, $N + 1][$N%6];