Skip to content

Instantly share code, notes, and snippets.

View kimwalisch's full-sized avatar

Kim Walisch kimwalisch

  • Luxembourg
  • 03:39 (UTC +01:00)
View GitHub Profile
@kimwalisch
kimwalisch / segmented_sieve5.cpp
Last active March 4, 2018 17:32
Identify primes
for (; n <= high; n += 2)
if (sieve[n - low]) // n is a prime
count++;
@kimwalisch
kimwalisch / segmented_bit_sieve1.cpp
Last active March 6, 2018 13:36
Segmented bit sieving
// sieve segment using bit array
for (std::size_t i = 0; i < primes.size(); i++)
{
int64_t j = multiples[i];
for (int64_t k = primes[i] * 2; j < segment_size; j += k)
sieve[j >> 4] &= unset_bit[j & 15];
multiples[i] = j - segment_size;
}
@kimwalisch
kimwalisch / segmented_bit_sieve.cpp
Last active September 24, 2021 12:42
Segmented sieve of Eratosthenes using a bit array
/// @file segmented_bit_sieve.cpp
/// @author Kim Walisch, <[email protected]>
/// @brief This is an implementation of the segmented sieve of
/// Eratosthenes which uses a bit array with 16 numbers per
/// byte. It generates the primes below 10^10 in 7.25 seconds
/// on an Intel Core i7-6700 3.4 GHz CPU.
/// @license Public domain.
#include <iostream>
#include <algorithm>
@kimwalisch
kimwalisch / segmented_bit_sieve2.cpp
Last active March 6, 2018 10:06
Counting bits in the segmented sieve of Eratosthenes
// unset bits > limit
if (high == limit)
{
int64_t bits = 0xff << (limit % 16 + 1) / 2;
sieve[sieve_size - 1] &= ~bits;
}
// count primes
for (int64_t n = 0; n < sieve_size; n++)
count += popcnt[sieve[n]];
@kimwalisch
kimwalisch / gist:e1a821b3a7f8b66b4be02326f45941da
Created December 13, 2018 13:53 — forked from TooTallNate/gist:906665
Output of "sysctl -a hw" on my iPhone 4.
hw.ncpu: 1
hw.byteorder: 1234
hw.memsize: 527433728
hw.activecpu: 1
hw.physicalcpu: 1
hw.physicalcpu_max: 1
hw.logicalcpu: 1
hw.logicalcpu_max: 1
hw.cputype: 12
hw.cpusubtype: 9
@kimwalisch
kimwalisch / contents_scale_test.py
Created June 11, 2021 09:10 — forked from akiross/contents_scale_test.py
Zooming QtQuick Painted item using contents size
#!/usr/bin/env python3
from PyQt5.QtGui import QPainter
from PyQt5.QtCore import *
from PyQt5.QtQuick import *
from PyQt5.QtWidgets import *
class Item(QQuickPaintedItem):
def __init__(self, useBoundRect, parent=None):
super().__init__(parent)
env:
OSX v10.4.11
Python 2.5
mercurial v1.2.1
git v1.6.3.1
repos:
using python repository as of 2009-06-18