More fun with Python and regular expressions. Following up on a previous post, I wanted to share a little test regex function I wrote in Python to help me as I work through the regular expression book.
I’m mostly working at the interactive prompt and had been running commands from Python re (the regex module) as I experimented with different regular expressions. This was good as I spent time in help(re) and built up some muscle memory for Python regex functions, but it was becoming repetitious to keep typing the commands for analyzing the results of a match. Once I started learning about writing functions in Python, I realized it was time to enhance my …
by Scott Carpenter on 29 March 2008 at 10:34 am
Permalink |
Comments (2) | filed under code, python, regex
|
An objection I’ve had to many programming books and web sites is that they don’t make sample code available under a free software license. This is within the rights of the author, of course, but it seems counter to the spirit of teaching and sharing knowledge to restrict the use of example code.
A writer of instructional material may be doing so to earn some money, but I hope he or she is also motivated by the desire to help others. I think the best authors and teachers are motivated strongly by this desire. And if this is the case, I think it reasonably follows that the author of a programming work should want their students to be able to freely use their source code in the students’ own creations.
I was happy to exchange words recently with an …
by Scott Carpenter on 14 September 2007 at 3:15 pm
Permalink |
Comments (0) | filed under ai, books, code, freedom, java
|
To celebrate this great day, here’s a little bit of free software, released under the terms of the GNU General Public License, version 3: a Java class I wrote to find all permutations for a given string. I may later post some more in the way of documentation, but for now, por ejemplo:
PermutationIterator p = new PermutationIterator(”123″);
while ( p.hasNext() ) {
System.out.println( p.next() );
}
Produces:
123
132
213
231
312
321
Since we can compute the factorial to know how many total permutations there are for a given string length, it’s a little bit faster to avoid the call to hasNext():
for (int i=0; i < p.totalPermutations(); i++) {
System.out.println( p.next() );
}
You can also supply an integer for “N” and get permutations for an alphabetic string:
p = new PermutationIterator(20);
//…yada yada
To get:
abcdefghijklmnopqrst
abcdefghijklmnopqrts
abcdefghijklmnopqsrt
abcdefghijklmnopqstr
abcdefghijklmnopqtrs
abcdefghijklmnopqtsr
…
2,432,902,008,176,639,993 more permutations…
…
rstqponmlkjihgfedcba
And now for the code, below the fold. Happy GPLv3 …
by Scott Carpenter on 29 June 2007 at 11:23 pm
Permalink |
Comments (4) | filed under code, java
|
Updated, 27 September 2007: See notes below…
I’ve mentioned a few times lately that I’m working on my backup plan for GNU/Linux. I started by looking at great free software tools like Samba’s rsync and GNU Tar, and I don’t think I need to look much further than them. There is also GNU Cpio, which I haven’t really investigated yet.
I may have more to say later about my rsync and tar adventures, but for today here’s something I came up with to emulate a feature of a tool I had in Windows that I couldn’t find how to do with existing tools in GNU. The xcopy DOS command lets you recursively copy files modified after a certain date by using the …
by Scott Carpenter on 15 April 2007 at 10:00 pm
Permalink |
Comments (16) | filed under bash, code, how-to
|