This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/** | |
Run an incremental counter, but return only the values that survive the "lucky number" process. | |
The process is to list all the positive integers, then filter out entries in stages. For all the numbers in a stage, let *N* be the first unfiltered number that is neither 1 nor been already been used as a filter seed for a previous stage, and filter out every Nth number. The first pass uses 2 and therefore filters out every second number, i.e. the even numbers. The second pass uses 3 and therefore filters out every third number that survived the 2-stage. The third pass uses 7 and therefore filters out every seventh number that survived both the 2- and 3-stages. The fourth pass uses 9 and therefore filters out every ninth number that survived the 2-, 3-, and 7-stages. (Note that 2 is the only seed that eliminates itself in its filter. Some definitions of lucky numbers avoid this irregularity by starting with the odd positive integers.) | |
*/ | |
public struct LuckyNumberGenerator<C |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2013 Daryle Walker. | |
// Distributed under the Boost Software License, Version 1.0. (See a copy at | |
// <http://www.boost.org/LICENSE_1_0.txt>.) | |
#ifndef REMOVE_SOME_EXTENTS_HPP | |
#define REMOVE_SOME_EXTENTS_HPP | |
#include <cstddef> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Demostration of variadic function template that runs a series of indexing | |
expressions. Based of a problem I posted at | |
http://stackoverflow.com/q/10171525/1010226 | |
Copyright (C) 2013 Daryle Walker | |
I'm letting anyone use this code under the Boost Software License. | |
*/ | |
#include <cassert> | |
#include <cstddef> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (C) 2013 by Daryle Walker | |
Based on posts off the Boost mailing lists on 2013-Jan-31 by Tim | |
Blechmann and TONGARI. C++11 is required; according to Live Work | |
Space's code-runner (on 2013-Apr-1), only Clang >= 3.2 and | |
GCC >= 4.7 accept it. | |
The original post (Tim Blechmann) of the 7 in the thread: | |
http://article.gmane.org/gmane.comp.lib.boost.devel/238310 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from the final code I provided as an answer to a StackOverflow query | |
// at <http://stackoverflow.com/a/9736489/1010226>. | |
// Copyright 2012 by Daryle Walker | |
#include <algorithm> // min | |
#include <cassert> // assert | |
#include <cmath> // pow | |
#include <cstddef> // size_t | |
#include <iostream> // cout | |
#include <iterator> // back_inserter, begin, end |
NewerOlder