Thus said Barry Roberts on Thu, 02 Nov 2006 12:40:49 EST:
> On Thu, Nov 02, 2006 at 05:20:21PM -0700, Andy Bradford wrote:
> > So, unless I'm reading my Python code incorrectly, it would appear
> > that I'm not the only one that misinterpreted which sequence should
> > be used when making the comparision.
>
> Yep. I interpreted it incorrectly.
I did too at first, no big deal (your next version produces correct
output). By the way, here's a tally of runtimes on my PC:
Python: .045ms on average
Tcl [1]: .016ms on average
Perl: .0125ms on average
Looks like Perl wins out on speed. I didn't have PHP installed (who uses
PHP for scripting anyways) so someone else may want to provide it.
[1] Here's my unoptimized Tcl version:
#!/bin/sh
# \
exec tclsh "$0" ${1+"$@"}
while {[gets stdin line] >= 0} {
set sline [split $line]
set good 1
set goodset [list]
set length [llength $sline]
if {$length} {
for {set x 1} {$x < $length} {incr x} {
lappend goodset $x
}
set loopend [expr $length - 1]
for {set x 0} {$x < $loopend} {incr x} {
set next [expr $x + 1]
set res [expr abs([lindex $sline $x] - [lindex $sline $next])]
if {[lsearch -exact $goodset $res] == -1} { set good 0 }
}
if {$good} { puts stdout "match" } else { puts stdout "no match" }
} else {
puts stdout "no match"
}
}
Andy
--
[-----------[system uptime]--------------------------------------------]
6:08pm up 4 days, 7:53, 1 user, load average: 1.00, 1.00, 1.00
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/