<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="http://www.pythonblogs.com/styles/rss.css" type="text/css"?>
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>
 <channel>
  <title>utilities &amp; musings</title>
  <link>http://utilities-musings.pythonblogs.com/56_utilities__musings</link>
  <description></description>
  <pubDate>Sat, 01 May 2010 09:22:25 -0700</pubDate>
  <generator>http://www.lifetype.net</generator>
    <item>
   <title>new version of my cp() function that returns a generator.</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;div&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
&lt;span class=&quot;kw1&quot;&gt;def&lt;/span&gt; cp&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;*lists&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:      
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
  ps = &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;*&lt;span class=&quot;kw1&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;lists&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
  ls = &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;l&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; l &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; lists&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
  &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
    yield &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;l&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;p&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; l, p &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;lists, ps&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
    &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; c &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; reversed&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;lists&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
      ps&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;c&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;ps&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;c&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;+&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; % ls&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;c&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; ps&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;c&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;:
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
        &lt;span class=&quot;kw1&quot;&gt;break&lt;/span&gt;
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
    &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;:
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
      &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt;
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;
&lt;/div&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/280_new_version_of_my_cp_function_that_returns_a_generator.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/280_new_version_of_my_cp_function_that_returns_a_generator.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/280_new_version_of_my_cp_function_that_returns_a_generator.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>useful</category>
         <pubDate>Thu, 29 Apr 2010 18:50:50 -0700</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>matrix multiplier with lc</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;def&lt;/span&gt; mm&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;m1, m2&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
  n = &lt;span class=&quot;kw1&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;m2&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;not&lt;/span&gt; n == &lt;span class=&quot;kw1&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;m1&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;: 
    &lt;span class=&quot;kw1&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;ValueError&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;error: mismatched dimensions (width 1 must equal height 2)&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;sum&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;m1i&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;k&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;*m2&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;k&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; k &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;n&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; m1i &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; m1&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; j &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;m2&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
note, i think this actually might return the columns and rows transposed.&amp;nbsp; i haven&#039;t checked it out. 
&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/159_matrix_multiplier_with_lc.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/159_matrix_multiplier_with_lc.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/159_matrix_multiplier_with_lc.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>useful</category>
         <pubDate>Tue, 06 Apr 2010 18:55:34 -0700</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>update to my xrange()</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;
I made a couple of improvements to my xrange function.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;def&lt;/span&gt; xr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;start=&lt;span class=&quot;kw1&quot;&gt;None&lt;/span&gt;, end=&lt;span class=&quot;kw1&quot;&gt;None&lt;/span&gt;, increment=&lt;span class=&quot;kw1&quot;&gt;None&lt;/span&gt;, count=&lt;span class=&quot;kw1&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; start &lt;span class=&quot;kw1&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;None&lt;/span&gt;:
    start = &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; end &lt;span class=&quot;kw1&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;None&lt;/span&gt;: 
    end = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; count &lt;span class=&quot;kw1&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;None&lt;/span&gt;: 
    count = &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; increment &lt;span class=&quot;kw1&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;None&lt;/span&gt;:
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; end &amp;gt;= &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;or&lt;/span&gt; count &amp;gt;= &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;:
      increment = &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;:
      increment = &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;end-start&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;/count
  n = &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; n &amp;lt; count:
    r = start+increment*n
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; r &amp;gt;= end:
      &lt;span class=&quot;kw1&quot;&gt;break&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; r==&lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;r&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
      r=&lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;r&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    n += &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;
    yield r&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;
&lt;p&gt;
You can run it with any combination of or none of the optional parameters. &amp;nbsp;Since it&#039;s a generator, if &lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;end &lt;/span&gt;or &lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;count &lt;/span&gt;isn&#039;t defined, it&#039;ll just keep on going. &amp;nbsp;&lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;increment &lt;/span&gt;defaults to 1, unless it can be derived from &lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;end&lt;/span&gt; and &lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;count&lt;/span&gt;. &amp;nbsp;&lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;start &lt;/span&gt;defaults to 0.&amp;nbsp; If &lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;end &lt;em&gt;and&lt;/em&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt; count &lt;/span&gt;are defined, it&#039;ll go until &lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;end &lt;/span&gt;or &lt;span style=&quot;font-family: &#039;courier new&#039;,courier&quot;&gt;count &lt;/span&gt;is reached - whichever comes first.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Caveat.. Don&#039;t run this like &lt;span style=&quot;font-family: courier new,courier&quot;&gt;xr(100)&lt;/span&gt;, that&#039;ll tell it to start at 100 and go up.&amp;nbsp; Fixing that while still allowing &lt;span style=&quot;font-family: courier new,courier&quot;&gt;xr()&lt;/span&gt; would be a PITA.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/151_update_to_my_xrange.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/151_update_to_my_xrange.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/151_update_to_my_xrange.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>useful</category>
         <pubDate>Sat, 13 Mar 2010 01:37:20 -0800</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>easy way to remember Python&#039;s precedence order.</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px; font-family: Helvetica, Arial, serif&quot;&gt;a good way to remember Python&#039;s order of operations:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;a = &lt;span class=&quot;kw1&quot;&gt;lambda&lt;/span&gt;: b &lt;span class=&quot;kw1&quot;&gt;or&lt;/span&gt; c &lt;span class=&quot;kw1&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;not&lt;/span&gt; d &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; e &lt;span class=&quot;kw1&quot;&gt;is&lt;/span&gt; f != g == h &amp;lt; i | j ^ k &amp;amp; l &amp;lt;&amp;lt; m + n * o ** p ** -q&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;the entire line is evaluated right-to-left.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px; font-family: Helvetica, Arial, serif&quot;&gt;(** is put in there twice to show that it&#039;s right-associative.)&lt;/span&gt;&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/146_easy_way_to_remember_pythons_precedence_order.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/146_easy_way_to_remember_pythons_precedence_order.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/146_easy_way_to_remember_pythons_precedence_order.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>useful</category>
         <pubDate>Sun, 28 Feb 2010 14:21:42 -0800</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>factoring large numbers</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;
this program will factor numbers up to 10e19 in almost no-time
&lt;/p&gt;
&lt;p&gt;
requires a file of prime numbers, the file i have is about 530MB.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;co1&quot;&gt;##by Richard A. Nichols III, 2007&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;## &lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;##factor() returns the factorization of a given number.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;## &lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;##primes.txt should be a newline-separated list of all prime numbers to&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;##an arbitrary limit.  i got my primes from&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;##http://primes.utm.edu/lists/small/millions/ and converted them to the above&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;##format.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;## &lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;##it runs pretty fast up until numbers in the order of 10**19&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;
inf = &lt;span class=&quot;kw1&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&#039;primes.&lt;span class=&quot;me1&quot;&gt;txt&lt;/span&gt;&#039;,&#039;r&#039;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
primes = &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;inf.&lt;span class=&quot;me1&quot;&gt;readline&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
primesset = set&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;primes&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;def&lt;/span&gt; factor&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;number, factors=&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;, lpi=&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
  &lt;span class=&quot;kw1&quot;&gt;global&lt;/span&gt; primes, primesset
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; number &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; primesset:
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; factors+&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;number&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; factors &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
  sqrt = &lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;number ** .&lt;span class=&quot;nu0&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  pi = lpi
  prime = primes&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;pi&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; prime &amp;lt;= sqrt:
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; pi==&lt;span class=&quot;kw1&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;primes&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
      p = inf.&lt;span class=&quot;me1&quot;&gt;readline&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; p==&#039;&#039; &lt;span class=&quot;kw1&quot;&gt;or&lt;/span&gt; p==&#039;\n&#039;: &lt;span class=&quot;kw1&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;ValueError&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;--Cannot factor because the prime numbers list has been exhausted--&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      prime = &lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;p&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      primes += &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;prime&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
      primesset.&lt;span class=&quot;me1&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;prime&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;:
      prime = primes&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;pi&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; number % prime == &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;:
      &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; factor&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;number/prime, factors+&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;prime&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;, pi&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    pi += &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; factors+&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;number&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; factors &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; 
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;__name__&lt;/span&gt; == &lt;span class=&quot;st0&quot;&gt;&quot;__main__&quot;&lt;/span&gt;:
&amp;nbsp;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;==&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;:
    &lt;span class=&quot;kw1&quot;&gt;try&lt;/span&gt;: factors = factor&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;ValueError&lt;/span&gt;, e: &lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt; e
    &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;: &lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt; &#039;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&#039;+&#039;, &#039;.&lt;span class=&quot;me1&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;f&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; f &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; factors&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;+&#039;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&#039; &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; factors &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;prime&quot;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;:
    &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; x &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
      number = &lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&#039;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&#039;*&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;x+&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt; number
      &lt;span class=&quot;kw1&quot;&gt;try&lt;/span&gt;: factors = factor&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;number&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;ValueError&lt;/span&gt;, e: &lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt; e
      &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;: &lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt; &#039;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&#039;+&#039;, &#039;.&lt;span class=&quot;me1&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;f&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; f &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; factors&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;+&#039;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&#039; &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; factors &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;prime&quot;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;&lt;/pre&gt;
&lt;p&gt; 
&lt;/p&gt;
&lt;p&gt;
ex:
&lt;/p&gt;
&lt;p&gt;
D:\projects\py&amp;gt;factor.py 0923840284985&lt;br /&gt;
[5, 59, 107, 1193, 24533]
&lt;/p&gt;
&lt;p&gt;
running factor.py with no parameter will execute a demonstration&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/145_factoring_large_numbers.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/145_factoring_large_numbers.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/145_factoring_large_numbers.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>General</category>
         <pubDate>Fri, 26 Feb 2010 06:06:42 -0800</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>absrel</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;
i made this for a guy named eep for his philosophy of &amp;quot;absolute relativity&amp;quot;.&amp;nbsp; it uses Pygame.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;, pygame, &lt;span class=&quot;kw1&quot;&gt;math&lt;/span&gt;, &lt;span class=&quot;kw1&quot;&gt;random&lt;/span&gt;
&amp;nbsp;
size = width, height =  &lt;span class=&quot;nu0&quot;&gt;512&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;512&lt;/span&gt;
minradius = &lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;
maxspeed = &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;
minspeed = -&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;#depthspeeds = [1,1,1,1,1,1,1,1,1,1]&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;#edit any of those numbers you wish.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;#speeds may be negative or positive. negative is counterclockwise.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;#you must have at least log height/minradius base 2 numbers in depthspeeds.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;#comment out the depthspeeds line to randomize.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;#maxspeed and minspeed are only used if depthspeeds are randomized.&lt;/span&gt;
&amp;nbsp;
depths = &lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;math&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;height/minradius, &lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;random&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;seed&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;depthspeeds&quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;globals&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
  depthspeeds = &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;random&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;uniform&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;minspeed, maxspeed&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; x &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;depths&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
black = &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;class&lt;/span&gt; circle:
  &lt;span class=&quot;kw1&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;, angle, depth, distance&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
    &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;radius&lt;/span&gt; = height/&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;**depth/&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;depth&lt;/span&gt; = depth
    &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;angle&lt;/span&gt; = angle
    &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;distance&lt;/span&gt; = distance
    &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;angleinc&lt;/span&gt; = &lt;span class=&quot;kw1&quot;&gt;math&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;atan2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;depthspeeds&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;depth&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;,distance&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;depth&lt;/span&gt; &amp;lt; depths-&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:
      &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;child1&lt;/span&gt; = circle&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;math&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;pi&lt;/span&gt;/&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;, depth+&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;, height/&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;**depth/&lt;span class=&quot;nu0&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;child2&lt;/span&gt; = circle&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;math&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;pi&lt;/span&gt;*&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;.&lt;span class=&quot;nu0&quot;&gt;5&lt;/span&gt;, depth+&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;, height/&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;**depth/&lt;span class=&quot;nu0&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;def&lt;/span&gt; docircle&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;, pivotx, pivoty&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
    posx = pivotx+&lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;distance&lt;/span&gt;*&lt;span class=&quot;kw1&quot;&gt;math&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;angle&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    posy = pivoty+&lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;distance&lt;/span&gt;*&lt;span class=&quot;kw1&quot;&gt;math&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;angle&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    pygame.&lt;span class=&quot;me1&quot;&gt;draw&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;circle&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;screen, &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;255&lt;/span&gt;,&lt;span class=&quot;nu0&quot;&gt;255&lt;/span&gt;,&lt;span class=&quot;nu0&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;posx, posy&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;radius&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;angle&lt;/span&gt; += &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;angleinc&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;depth&lt;/span&gt; &amp;lt; depths-&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:
      &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;child1&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;docircle&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;posx, posy&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;child2&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;docircle&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;posx, posy&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
pygame.&lt;span class=&quot;me1&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
screen = pygame.&lt;span class=&quot;me1&quot;&gt;display&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;set_mode&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;size&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
maincircle = circle&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; pygame.&lt;span class=&quot;me1&quot;&gt;event&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;poll&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;type&lt;/span&gt; != pygame.&lt;span class=&quot;me1&quot;&gt;QUIT&lt;/span&gt;:
  screen.&lt;span class=&quot;me1&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;black&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  maincircle.&lt;span class=&quot;me1&quot;&gt;docircle&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;width/&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;, height/&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  pygame.&lt;span class=&quot;me1&quot;&gt;display&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;flip&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;#by Richard A. Nichols III&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;&lt;/pre&gt;
&lt;p&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/144_absrel.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/144_absrel.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/144_absrel.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>General</category>
         <pubDate>Fri, 26 Feb 2010 03:22:40 -0800</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>phonic anagrams</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;
shows an anagram of a given word, but works using phonems instead of letters.
&lt;/p&gt;
&lt;p&gt;
requires the cmu phonic dictionary (freely downloadable).&amp;nbsp; might use an old version;just replacethe version number.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;import&lt;/span&gt; re
word = &lt;span class=&quot;kw1&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;ENTER YOUR WORD: &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;upper&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
dict = &lt;span class=&quot;kw1&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;cmudict.0.6d&quot;&lt;/span&gt;,&lt;span class=&quot;st0&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; True:
  line1 = dict.&lt;span class=&quot;me1&quot;&gt;readline&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;   
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; line1 == &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;: &lt;span class=&quot;kw1&quot;&gt;break&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; line1&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;==word:
    dict.&lt;span class=&quot;me1&quot;&gt;seek&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; True:
      line2 = dict.&lt;span class=&quot;me1&quot;&gt;readline&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; line2==&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;: &lt;span class=&quot;kw1&quot;&gt;break&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; line2&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;:&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;==&lt;span class=&quot;st0&quot;&gt;&quot;##&quot;&lt;/span&gt;: &lt;span class=&quot;kw1&quot;&gt;continue&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; phonemes3, phonemes5, p &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;re.&lt;span class=&quot;me1&quot;&gt;sub&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;\d&quot;&lt;/span&gt;,&lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;,x&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; x &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; line1&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;re.&lt;span class=&quot;me1&quot;&gt;sub&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;\d&quot;&lt;/span&gt;, &lt;span class=&quot;st0&quot;&gt;&quot;&quot;&lt;/span&gt;, x&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; x &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; line2&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;line1&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;, line2&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; phoneme &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; phonemes5:
          &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; phoneme &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; phonemes3: phonemes3.&lt;span class=&quot;me1&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;phoneme&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
          &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;: &lt;span class=&quot;kw1&quot;&gt;break&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;:
          &lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;\n&quot;&lt;/span&gt;+line2&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span class=&quot;st0&quot;&gt;&quot;*&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;p&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;,
&amp;nbsp;
&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
results with *&#039;s are results that have not only the same phonems, but the same phonems with the same emphasis.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
ex:
&lt;/p&gt;
&lt;p&gt;
ENTER YOUR WORD: littering&lt;br /&gt;
&lt;br /&gt;
&#039;TIL *&lt;br /&gt;
ARE(2) *&lt;br /&gt;
EARL&lt;br /&gt;
EARLE&lt;br /&gt;
EARLL&lt;br /&gt;
ENGLERT *&lt;br /&gt;
ER *&lt;br /&gt;
ERL&lt;br /&gt;
ERLING&lt;br /&gt;
ERR(2)&lt;br /&gt;
ERTE&lt;br /&gt;
EURE&lt;br /&gt;
IL *&lt;br /&gt;
ILL *&lt;br /&gt;
ING *&lt;br /&gt;
INGER *&lt;br /&gt;
IT *&lt;br /&gt;
IT&#039;LL(2) *&lt;br /&gt;
IT(2) *&lt;br /&gt;
LING *&lt;br /&gt;
LINGER(2) *&lt;br /&gt;
LIT *&lt;br /&gt;
LITT *&lt;br /&gt;
LITTER *&lt;br /&gt;
LITTERING *&lt;br /&gt;
LUHR&lt;br /&gt;
LYNG *&lt;br /&gt;
NG(2) *&lt;br /&gt;
OR(2) *&lt;br /&gt;
TER&lt;br /&gt;
TIL *&lt;br /&gt;
TILL *&lt;br /&gt;
TILLER *&lt;br /&gt;
TILLING *&lt;br /&gt;
TING *&lt;br /&gt;
TO(2) *&lt;br /&gt;
UR 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/143_phonic_anagrams.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/143_phonic_anagrams.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/143_phonic_anagrams.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>General</category>
         <pubDate>Fri, 26 Feb 2010 02:50:47 -0800</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>textshift.py</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;
A fun way of ciphering text
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;
text = &#039; &#039;.&lt;span class=&quot;me1&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;not&lt;/span&gt; text:
  text = &lt;span class=&quot;kw1&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
nonalphas = &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;p, c&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;p, c&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; enumerate&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;text&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;not&lt;/span&gt; c.&lt;span class=&quot;me1&quot;&gt;isalpha&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
capitals = &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;p &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; p, c &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; enumerate&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;text&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; c.&lt;span class=&quot;me1&quot;&gt;isupper&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; sh &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;-&lt;span class=&quot;nu0&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;nu0&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;:
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; sh:
    text3 = &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;c &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; c &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; text.&lt;span class=&quot;me1&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; c.&lt;span class=&quot;me1&quot;&gt;isalpha&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
    text3 = text3&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;sh:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; + text3&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;:sh&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; p, c &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; nonalphas:
      text3.&lt;span class=&quot;me1&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;p, c&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; p &lt;span class=&quot;kw1&quot;&gt;in&lt;/span&gt; capitals:
      text3&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;p&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; = text3&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;p&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;upper&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt; &#039;&#039;.&lt;span class=&quot;me1&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;text3&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
&lt;br /&gt;
enter a sentence, and then select the cipher with the offset that looks best 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;ex:
&lt;/p&gt;
&lt;p&gt;
D:\projects\py&amp;gt;textshift.py&lt;br /&gt;
This is the day that the Lord hath made.&lt;br /&gt;
Rdha th mad eth isis the Dayt hatt helo.&lt;br /&gt;
Dhat hm ade thi sist hed Ayth atth elor.&lt;br /&gt;
Hath ma det his isth eda Ytha tthe lord.&lt;br /&gt;
Athm ad eth isi sthe day That thel ordh.&lt;br /&gt;
Thma de thi sis thed ayt Hatt helo rdha.&lt;br /&gt;
Hmad et his ist heda yth Atth elor dhat.&lt;br /&gt;
Made th isi sth eday tha Tthe lord hath.&lt;br /&gt;
Adet hi sis the dayt hat Thel ordh athm.&lt;br /&gt;
Deth is ist hed ayth att Helo rdha thma.&lt;br /&gt;
Ethi si sth eda ytha tth Elor dhat hmad.&lt;br /&gt;
Hisi st hed ayt hatt hel Ordh athm adet.&lt;br /&gt;
Isis th eda yth atth elo Rdha thma deth.&lt;br /&gt;
Sist he day tha tthe lor Dhat hmad ethi.&lt;br /&gt;
Isth ed ayt hat thel ord Hath made this.&lt;br /&gt;
Sthe da yth att helo rdh Athm adet hisi.&lt;br /&gt;
Thed ay tha tth elor dha Thma deth isis.&lt;br /&gt;
Heda yt hat the lord hat Hmad ethi sist.&lt;br /&gt;
Eday th att hel ordh ath Made this isth.&lt;br /&gt;
Dayt ha tth elo rdha thm Adet hisi sthe.&lt;br /&gt;
Ayth at the lor dhat hma Deth isis thed. 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/142_textshiftpy.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/142_textshiftpy.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/142_textshiftpy.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>General</category>
         <pubDate>Fri, 26 Feb 2010 02:45:21 -0800</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>timer</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;co1&quot;&gt;#timer.py&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;import&lt;/span&gt; pygame, time, &lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;
p = &lt;span class=&quot;kw1&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;int&lt;/span&gt;, &#039;&#039;.&lt;span class=&quot;me1&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&#039;:&#039;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
s = p.&lt;span class=&quot;me1&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; p: s += p.&lt;span class=&quot;me1&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;*&lt;span class=&quot;nu0&quot;&gt;60&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; p: s += p.&lt;span class=&quot;me1&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;*&lt;span class=&quot;nu0&quot;&gt;3600&lt;/span&gt;
time.&lt;span class=&quot;me1&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;s&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
pygame.&lt;span class=&quot;me1&quot;&gt;mixer&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;11025&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
pygame.&lt;span class=&quot;me1&quot;&gt;mixer&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;Sound&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&#039;d:\\utils\\ringin.&lt;span class=&quot;me1&quot;&gt;wav&lt;/span&gt;&#039;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;play&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
time.&lt;span class=&quot;me1&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
and a batch file that goes..
&lt;/p&gt;
&lt;p&gt;
@echo off&lt;br /&gt;
@echo current time is %TIME%&lt;br /&gt;
start d:\python26\pythonw \utils\timer.py %*&lt;br /&gt;
&lt;br /&gt;
example:
&lt;/p&gt;
&lt;p&gt;
D:\&amp;gt;timer 4:00&lt;br /&gt;
current time is&amp;nbsp; 5:41:52.74&lt;br /&gt;
D:\&amp;gt;timer 4&lt;br /&gt;
current time is&amp;nbsp; 5:41:56.07&lt;br /&gt;
D:\&amp;gt;timer 4:10:00&lt;br /&gt;
current time is&amp;nbsp; 5:42:05.34
&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/141_timer.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/141_timer.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/141_timer.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>useful</category>
         <pubDate>Fri, 26 Feb 2010 02:41:06 -0800</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
    <item>
   <title>calculator</title>
   <description>
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://utilities-musings.pythonblogs.com/plugins/plogeshi/styles/plogeshi.css&quot; /&gt;&lt;p&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;from&lt;/span&gt; __future__ &lt;span class=&quot;kw1&quot;&gt;import&lt;/span&gt; division
&lt;span class=&quot;kw1&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;math&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;import&lt;/span&gt; *
&lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;eval&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&#039; &#039;.&lt;span class=&quot;me1&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;sys&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
and then i have a batch file that goes:
&lt;/p&gt;
&lt;p&gt;
@echo off&lt;br /&gt;
if &amp;quot;%1&amp;quot;==&amp;quot;&amp;quot; goto calc&lt;br /&gt;
d:\python26\python d:\utils\calc.py %*&lt;br /&gt;
goto end&lt;br /&gt;
:calc&lt;br /&gt;
calc.exe&lt;br /&gt;
:end
&lt;/p&gt;
&lt;p&gt;
ex:
&lt;/p&gt;
&lt;p&gt;
C:\&amp;gt;calc 12*sin(1)&lt;br /&gt;
10.0976518177&lt;br /&gt;
&lt;br /&gt;
C:\&amp;gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
   </description>
   <link>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/140_calculator.html</link>
   <comments>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/140_calculator.html</comments>
   <guid>http://utilities-musings.pythonblogs.com/56_utilities__musings/archive/140_calculator.html</guid>
      <dc:creator>ikiel</dc:creator>
      
    <category>useful</category>
         <pubDate>Fri, 26 Feb 2010 02:32:28 -0800</pubDate>
   <source url="http://utilities-musings.pythonblogs.com/56_utilities__musings/feeds/rss20">utilities &amp; musings</source>
     </item>
   </channel>
</rss>