CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Wed, 06 Aug 2025 06:11:34 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20090404155155
location: https://web.archive.org/web/20090404155155/https://code.activestate.com/feeds/tags/algorithms/
server-timing: captures_list;dur=0.530329, exclusion.robots;dur=0.017390, exclusion.robots.policy;dur=0.007568, esindex;dur=0.009606, cdx.remote;dur=10.151733, LoadShardBlock;dur=222.646568, PetaboxLoader3.datanode;dur=102.483615, PetaboxLoader3.resolve;dur=56.799624
x-app-server: wwwb-app218
x-ts: 302
x-tr: 260
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: wb-p-SERVER=wwwb-app218; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Wed, 06 Aug 2025 06:11:34 GMT
content-type: application/atom+xml
content-length: 19975
x-archive-orig-date: Sat, 04 Apr 2009 15:51:55 GMT
x-archive-orig-server: Apache/2.2.3 (CentOS)
x-archive-orig-content-length: 19975
x-archive-orig-expires: Sat, 04 Apr 2009 16:01:55 GMT
x-archive-orig-vary: Cookie
x-archive-orig-last-modified: Sat, 04 Apr 2009 15:51:55 GMT
x-archive-orig-etag: 3e669ef2ed3b2118cd947c7c003a8908
x-archive-orig-cache-control: max-age=600
x-archive-orig-via: 1.0 box19.activestate.com:3129 (squid/2.6.STABLE21)
x-archive-orig-connection: close
cache-control: max-age=1800
x-archive-guessed-content-type: text/xml
x-archive-guessed-charset: utf-8
memento-datetime: Sat, 04 Apr 2009 15:51:55 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Fri, 19 Sep 2008 04:17:30 GMT", ; rel="prev memento"; datetime="Mon, 02 Feb 2009 19:25:54 GMT", ; rel="memento"; datetime="Sat, 04 Apr 2009 15:51:55 GMT", ; rel="last memento"; datetime="Sat, 04 Apr 2009 15:51:55 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_9_20090404153255_crawl102-c/52_9_20090404155153_crawl103.arc.gz
server-timing: captures_list;dur=0.869237, exclusion.robots;dur=0.028651, exclusion.robots.policy;dur=0.012567, esindex;dur=0.016838, cdx.remote;dur=22.392035, LoadShardBlock;dur=150.541294, PetaboxLoader3.datanode;dur=116.934843, PetaboxLoader3.resolve;dur=265.776461, load_resource;dur=245.949320
x-app-server: wwwb-app218
x-ts: 200
x-tr: 465
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
accept-ranges: bytes
ActiveState Code: Recipes tagged with "algorithms" https://code.activestate.com/recipes/tags/algorithms/ 2009-03-07T04:42:51Z Recently added recipes tagged with "algorithms" Factorial-Lambda (Python)
2009-01-17T04:16:16Z Fouad Teniou https://ActiveState%20Code/recipes/users/4155345/ https://code.activestate.com/recipes/576616/
<p style="color: grey">
Python
recipe 576616
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/math/">math</a>).
Revision 3.
</p>
<p>If n is a positive integer,factorial(n!) is the product of all the positive integers from 1 up to the given integer.
However, different types of functions are applied,including the anonymous lambda to generate the factorial number, because it is simple and returns a value ( a new function ), which can be assigned a name.</p>
Easy State Pattern - support for implementing state machines (Python)
2009-01-15T06:34:48Z Rodney Drenth https://ActiveState%20Code/recipes/users/4050661/ https://code.activestate.com/recipes/576613/
<p style="color: grey">
Python
recipe 576613
by <a href="/recipes/users/4050661/">Rodney Drenth</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/metaclasses/">metaclasses</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/state machine/">state machine</a>, <a href="/recipes/tags/state pattern/">state pattern</a>).
Revision 2.
</p>
<p>Provides is a module that gives support for implementing state machines. States are implemented as subclasses, derived from the state machine class. Methods that are state dependant or which cause transitions are declared using decorators. Because states can be subclasses of other states, common behaviour among several states is easily supported. The implementation allows for implementing multiple states or substates within a class.</p>
<p>This module best support statem achines implemeting controllers for embedded systems, implementing user interfaces, or in discrete event model simulation.
Parsers, which generally have many states and where you would need to define
a Transaction method for each different character encountered would be more easily implemented by other means.</p>
FizzBuzz (Python)
2009-01-14T01:51:22Z Louis Riviere https://ActiveState%20Code/recipes/users/4035877/ https://code.activestate.com/recipes/576612/
<p style="color: grey">
Python
recipe 576612
by <a href="/recipes/users/4035877/">Louis Riviere</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/FizzBuzz/">FizzBuzz</a>).
Revision 4.
</p>
<p>A Loopless FizzBuzz</p>
Sieve of Eratosthenes (Python)
2008-12-27T11:45:09Z Louis Riviere https://ActiveState%20Code/recipes/users/4035877/ https://code.activestate.com/recipes/576596/
<p style="color: grey">
Python
recipe 576596
by <a href="/recipes/users/4035877/">Louis Riviere</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/Eratosthenes/">Eratosthenes</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/primes/">primes</a>).
Revision 3.
</p>
<p>Returns primes < n.</p>
Efficient generation of permutations (Python)
2008-12-22T06:11:55Z nnarula https://ActiveState%20Code/recipes/users/4168533/ https://code.activestate.com/recipes/576593/
<p style="color: grey">
Python
recipe 576593
by <a href="/recipes/users/4168533/">nnarula</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/Permutations/">Permutations</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This code builds an iterator on the fly that will successfully return unique permutations of n integers, m at a time (nPm). It does not use recursion, so stack size is not a problem.
Sample usage
it= build(n,p) <br />
it.next() # returns permutation</p>
<p>it=build(n) is the same as build(n,n) do it will generate n! unique permuatations.</p>
<p>I worte it over the weekend and have tested it reasonably for n upto 30 and p from 1 to 30 </p>
Dependency resolver (Python)
2008-12-05T00:38:47Z Louis Riviere https://ActiveState%20Code/recipes/users/4035877/ https://code.activestate.com/recipes/576570/
<p style="color: grey">
Python
recipe 576570
by <a href="/recipes/users/4035877/">Louis Riviere</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/dependency/">dependency</a>, <a href="/recipes/tags/resolver/">resolver</a>).
Revision 4.
</p>
<p>Shows the order in which "tasks" can be "done". <br />
Groups tasks that can be done simultaneously.</p>
Circle (Python)
2008-10-16T06:01:38Z Fouad Teniou https://ActiveState%20Code/recipes/users/4155345/ https://code.activestate.com/recipes/576531/
<p style="color: grey">
Python
recipe 576531
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 12.
</p>
<p>Circle is a program for students and tutors in higher education. Circle program provide the user with the standard form ( x –x0)^2 + (y-y0)^2 = r^2, radius and centre(x0,y0), once the user input the Constants' values of the circle Equation of the form Ax^2 + Ay^2 + Dx + Ey + F = 0. if r^2 = 0, Circle program point and display that the graph is the single point (x0,y0), and if r^2 < 0 , Circle program point that the equation has no real solutions, thus no graph. However Circle program also does compute and display the reverse method if the user input the radius and centre values, it display both forms of the circle equation </p>
Ellipse (Python)
2009-02-14T04:09:28Z Fouad Teniou https://ActiveState%20Code/recipes/users/4155345/ https://code.activestate.com/recipes/576513/
<p style="color: grey">
Python
recipe 576513
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 8.
</p>
<p>In early 1600 Johannas Kepler conclude that all the planets in the solar system move in elliptical orbits with the sun at a focus, thus, the importance of ellipse in science.
Ellipse is a Python program for students and tutors at higher levels of education .
There are two equations of an ellipse : x^2/a^2 + y^2/b^2 and: x^2/b^2 + y^2/a^2 the foci are on the x axis or y axis.
From Ellipse program the student will be able to sketch the ellipse, by drawing a box with (a) and (-a) units on the major axis and ( b) and (-b) units on the minor axis.
Since Ellipse program determine the values of a and b and the position of the foci c.
c = Square-Root (a^2 – b^2)</p>
Pycol (Python)
2008-08-01T10:43:16Z Fouad Teniou https://ActiveState%20Code/recipes/users/4155345/ https://code.activestate.com/recipes/576374/
<p style="color: grey">
Python
recipe 576374
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 57.
</p>
<p>Pycol can be used by students to compute trigonometric functions,(Sine,Cosine,Tangent,Cosecant,Secant, and Cotangent) of an angle(X) expressed in degrees rather than radians, since this is not available in Python math or cmath modules.
Yet it is a standard method of measuring such ratios at colleges,universities and all mathematics books including Calculus.
Pycol can also be used to express angles from degrees into radians and vice versa, and into degrees, minutes, and seconds</p>
Merge join for N iterators (Python)
2008-10-29T03:50:37Z Joel Nothman https://ActiveState%20Code/recipes/users/4165330/ https://code.activestate.com/recipes/576371/
<p style="color: grey">
Python
recipe 576371
by <a href="/recipes/users/4165330/">Joel Nothman</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 2.
</p>
<p>Performs a merge join on any number of iterators with sorted, unique keys. I.e., iterate through the data in parallel, outputting successive keys and all corresponding values from each iterator, or None if not available.</p>
Weighted random choice (Python)
2008-07-22T06:11:19Z Facundo Batista https://ActiveState%20Code/recipes/users/2016392/ https://code.activestate.com/recipes/576370/
<p style="color: grey">
Python
recipe 576370
by <a href="/recipes/users/2016392/">Facundo Batista</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>Choices randomly an element from a list, not uniformly, but using a given weight for each element.</p>
Y combinator (Python)
2008-07-31T23:57:07Z kay schluehr https://ActiveState%20Code/recipes/users/2398921/ https://code.activestate.com/recipes/576366/
<p style="color: grey">
Python
recipe 576366
by <a href="/recipes/users/2398921/">kay schluehr</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 4.
</p>
<p>The Y combinator is a famous higher order function used to implement recursion on anonymous functions i.e. lambda expressions. Y combinators have the fixed point property which is formally expressed by the relation Y(f) = f(Y(f)).</p>
Simple Cached Functions (Python)
2008-07-20T19:51:17Z Justin Shaw https://ActiveState%20Code/recipes/users/1523109/ https://code.activestate.com/recipes/576365/
<p style="color: grey">
Python
recipe 576365
by <a href="/recipes/users/1523109/">Justin Shaw</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 2.
</p>
<p>This is a simplified version of George Sakkis recipe entitled "Cache decorator in python 2.4" (<a href="https://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325205" rel="nofollow">https://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325205</a>). In this version, no extra classes are required and this is small enough to implement on the fly.</p>
Container (Python)
2008-07-29T05:29:17Z Fouad Teniou https://ActiveState%20Code/recipes/users/4155345/ https://code.activestate.com/recipes/574428/
<p style="color: grey">
Python
recipe 574428
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 9.
</p>
<p>Container can be used to contain sets of differents numbers and strings, and applying maths' operations such as intersection, union and other functions.</p>
Converter (Python)
2009-03-07T04:42:51Z Fouad Teniou https://ActiveState%20Code/recipes/users/4155345/ https://code.activestate.com/recipes/573457/
<p style="color: grey">
Python
recipe 573457
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 8.
</p>
<p>Converter can be used to convert fundamental measures, metric, mass, liquid and temperature.
The output is set to give the best conversion accuracy and layout that could be used for professional projects</p>
RSA (Python)
2008-05-31T21:04:03Z Collin Stocks https://ActiveState%20Code/recipes/users/4149235/ https://code.activestate.com/recipes/572196/
<p style="color: grey">
Python
recipe 572196
by <a href="/recipes/users/4149235/">Collin Stocks</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 2.
</p>
<p>This is my Python implementation of the RSA algorithm, including functions to generate prime numbers from a password string. It also includes a file-like object that sometimes works, so don't count on it. This recipe is by no means complete or stable, so be very careful when using code in it. It should be used more as a platform for writing a better implementation of RSA. As far as I know, it is not compatible with any other RSA implementations.</p>
Date & time RFC822 formatted for RSS2, etc (straw man) (Python)
2008-05-07T17:33:26Z Bill Bell https://ActiveState%20Code/recipes/users/98151/ https://code.activestate.com/recipes/572190/
<p style="color: grey">
Python
recipe 572190
by <a href="/recipes/users/98151/">Bill Bell</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>I live in a geographical area whose daylight savings time provisions seem to fool software. I would therefore like to avoid mentioning time zone when I create a timestamp in RFC822 format. I have looked for but could not find an elegant way of expressing what I want. In hopes that someone will see this and be aghast at my ignorance, then provide something nice, I humbly offer the following.</p>
<p>It takes a datetime and gives back an RFC822 timestamp (I think).</p>
SPICE (Python)
2008-04-19T20:08:36Z Stephen Chappell https://ActiveState%20Code/recipes/users/2608421/ https://code.activestate.com/recipes/572159/
<p style="color: grey">
Python
recipe 572159
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>This module provides access to a standardized implementation
of SPICE (Stephen's Power-Inspired, Computerized Encryption).</p>
<p>This code has just been revised and rewritten. As such it may
still contain bugs that were not found after testing the code.</p>
BK-tree (Python)
2008-04-18T06:40:20Z bearophile - https://ActiveState%20Code/recipes/users/2403049/ https://code.activestate.com/recipes/572156/
<p style="color: grey">
Python
recipe 572156
by <a href="/recipes/users/2403049/">bearophile -</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>Fast Levenshtein distance and BK-tree implementations in Python.</p>
tkMath, convert between pixels, inches, cm and mm (Python)
2008-04-12T02:25:41Z Ronald Longo https://ActiveState%20Code/recipes/users/4093058/ https://code.activestate.com/recipes/552745/
<p style="color: grey">
Python
recipe 552745
by <a href="/recipes/users/4093058/">Ronald Longo</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 6.
</p>
<p>If you're writing some Tkinter software and you're sizing something in inches or centimeters and tkinter only gives you feedback in pixel distances then you may need a way to get back to your prefered units of measure. I recently found myself in this situation. There's nothing fancy about the set of functions here, it's more about the little known winfo_fpixels() function. Once you know about this everything else is a piece of cake. These functions are simple, but convenient.</p>