-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ActiveState/master
sync
- Loading branch information
Showing
21 changed files
with
1,426 additions
and
329 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This work is released to the public domain under the CC0 (Creative Commons) license terms: https://creativecommons.org/publicdomain/zero/1.0/legalcode |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### An alias for the tree command | ||
|
||
Author: Unknown | ||
Submitter: Alan Young (harleypig) | ||
|
||
If the tree command does not exist on your system, this alias will fake it. | ||
|
||
I got this from a co-worker a long time ago. I don't remember when, or who it was. If it was you, let me know and I'll update this. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# I got this from a co-worker many moons ago. Unfortunately, I don't remember | ||
# who. Basically, if a tree program is not installed, fake it with this. | ||
|
||
if ! command -v tree > /dev/null 2>&1; then | ||
|
||
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" | ||
|
||
fi |
29 changes: 15 additions & 14 deletions
29
recipes/Python/117119_Sieve_of_Eratosthenes/recipe-117119.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
# Sieve of Eratosthenes | ||
# David Eppstein, UC Irvine, 28 Feb 2002 | ||
# Originaly made by : David Eppstein, UC Irvine, 28 Feb 2002 | ||
# Performance improvements : Gabriel Freitas, 7 Oct 2017 | ||
|
||
from __future__ import generators | ||
from itertools import count | ||
|
||
def eratosthenes(): | ||
'''Yields the sequence of prime numbers via the Sieve of Eratosthenes.''' | ||
D = {} # map composite integers to primes witnessing their compositeness | ||
q = 2 # first integer to test for primality | ||
while 1: | ||
if q not in D: | ||
yield q # not marked composite, must be prime | ||
D[q*q] = [q] # first multiple of q not already marked | ||
else: | ||
for p in D[q]: # move each witness to its next multiple | ||
D.setdefault(p+q,[]).append(p) | ||
del D[q] # no longer need D[q], free memory | ||
q += 1 | ||
"""Yields the sequence of prime numbers via the Sieve of Eratosthenes""" | ||
yield 2 # force yield the first prime number | ||
|
||
D = {} # map composite integers to primes witnessing their compositeness | ||
for q in count(start=3, step=2): | ||
if q not in D: | ||
yield q # not marked composite, must be prime | ||
D[q*q] = [q] # first multiple of q not already marked | ||
else: | ||
for p in D[q]: # move each witness to its next odd multiple | ||
D.setdefault(2*p+q,[]).append(p) | ||
del D[q] # no longer need D[q], free memory |
This file contains 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
This file contains 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
Oops, something went wrong.