Re: Sudoku
On 7/27/05, Ian Phillipps <[EMAIL PROTECTED]> wrote: > On Wed, 27 Jul 2005 at 10:15:25 -0400, Quantum Mechanic wrote: > > 1) Not strict and warnings clean. > > 2) perl -c on > > if( $puzmap[$bestpos] & 1 == 0 ) > > gives: > > "Possible precedence problem on bitwise & operator at > > sudoku_ip.pl line ..." > > Hmm... it's warning-clean on my 5.8.4 - what version are you using? 5.8.6
re: Sudoku
1) Not strict and warnings clean. 2) perl -c on if( $puzmap[$bestpos] & 1 == 0 ) gives: "Possible precedence problem on bitwise & operator at sudoku_ip.pl line ..." but this seems to be a clash between undeclared variables. The intended precedence seems to be if( ( $puzmap[$bestpos] & 1 ) == 0 ) but this gives me: "Whoops - bestpos is a given square at..." Changing the precedence to if( $puzmap[$bestpos] & ( 1 == 0 ) seems to generate the right answer. Is this what you intended?
Re: "Secret" operators
--- Philippe 'BooK' Bruhat <[EMAIL PROTECTED]> wrote: > > symbolnicknameRole > -- > <=> spaceship documented > operator > > 0+venus numification > }{eskimo greeting END{} in > one-liners > =()= goatse > ~-inchworm on a stick > high-precedence numification > ~~inchwormscalar > "@{[]}" join $", ... > -+- spacestation > high-precedence numification > Other naming suggestions: ~- inchworm or cotton candy (on a stick) ~~ caterpillar "@{[]}"cyclops (one eye with eyebrows, mustache, and square mouth) -+-cross-hair (or half cross-hair) or vanishing point (horizon line) or reticule ]->[ Frowning Sam (resembles the Muppet named Sam the Eagle) Beaker (the nerdish Muppet with the perpetual surprised look) = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Meet the all-new My Yahoo! - Try it today! http://my.yahoo.com
Re: "Secret" operators
--- Andrew Savige <[EMAIL PROTECTED]> wrote: > > Let's not forget the Ton Hospel "high-precedence > decrement" > operator ~- invented during a golf tournament > (anyone remember > which one?). > What did he call it? I'd suggest the "inchworm", because in some fonts, it resembles an inchworm on a stick. -QM = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Yahoo! Mail - now with 250MB free storage. Learn more. http://info.mail.yahoo.com/mail_250
Re: "Secret" operators
--- José Castro <[EMAIL PROTECTED]> wrote: > * Quantum Mechanic ([EMAIL PROTECTED]) > wrote: > > $foo = ($bar) = (9,8,7); > > > > RHS list > > ($bar) array > > $bar <- 7 (rest discarded) > > No, no, no. > > $bar <- 9 > Yes, that was a typo -- thanks. > It's the same as > > $foo = ($bar, undef, undef) = (9, 8, 7); > > Now the funny thing is that the result from > > $foo = ($bar, undef, undef, undef) = (9, 8, 7); > > is still the same :-) Ah, but that supports my theory. It's not the LHS of the ($bar,...)= assignment that generates the data for $foo -- it's the RHS. The LHS of the ($bar,...)= assignment determines the *context* of the $foo= assignment. Q.E.D. The quantity of elements on the LHS don't matter, but the quality of the LHS does. -QM = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Yahoo! Mail - now with 250MB free storage. Learn more. http://info.mail.yahoo.com/mail_250
Re: "Secret" operators
--- Bernie Cosell <[EMAIL PROTECTED]> wrote: > On 1 Feb 2005 at 12:36, Ronald J Kimball wrote: > > > ... A list assignment in scalar context > > returns the number of elements on the right-hand > side of the assignment. > > Which is an odd inconsistency, because in list > context a list assignment > returns the left-hand-side-list, so you might guess > that in scalar > context it'd return the number of elements in the > lhs list... It seems there are multiple contexts flying around. I'm no expert, but it seems to develop this way: $foo = $bar = (9,8,7); RHS list $bar scalar $bar <- 7 (last element of list) $foo <- 7 $foo = ($bar) = (9,8,7); RHS list ($bar) array $bar <- 7 (rest discarded) $foo <- 3, size of RHS of ($bar) assignment Therefore, $foo = () = (9,8,7) RHS list () array no assignment targets, but... $foo <- 3, size of RHS of () assignment My assumption is that =()= creates an intermediate assignment, which subtley shifts the context so that $foo gets the count of (9,8,7) in the last case, instead of the last element of (9,8,7) as in the first case. =()= forks the assigment flow. The elements of the right operand are assigned (if possible) to the contained array, as in $foo = ($bar) = (9,8,7); or $foo = @bar = (9,8,7); The left operand of =()= is assigned the element count of the other assignment. Someone familiar with the core will have to clue me in on the accuracy of my theory. -QM = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? The all-new My Yahoo! - Get yours free! http://my.yahoo.com
Re: tough regex problem
Can you reverse the string and use lookahead? return split( m|(?=$sep)|, reverse ${$buf_ref} ) if wantarray ; --- Uri Guttman <[EMAIL PROTECTED]> wrote: > > in file::slurp i currently split the file into lines > (or records based > on $/) using this code: > > return split( m|(?<=$sep)|, ${$buf_ref} ) if > wantarray ; > > where $sep is set from $/. > > that works correctly and is fast. but it has one > flaw, it can't do > paragraph mode since lookbehind can't handle > variable width regexes as > \n\n+ is. so i am looking for an m// solution that > properly splits a > buffer into records. it is not as easy as it seems. > it has to behave > exactly like the split does. there are several > corner cases such as an > empty file and a partial line ending a file. even a > normal file of lines > is tricky as you don't want to return an bogus empty > line after the last > real line. here are a few broken attempts to help > you avoid pitfalls: > > /(.*?$sep|.+)/sg# doesn't handle an empty file > /.*?(?:$sep|\z)/gs # adds a bogus empty line at > the end > > i already passed this problem to a top regex person > and he sent me the > second one above (obviously untested! :). > > so fame, glory and an acknowledgement in the new > release all go to the > valiant warrior who solves this. > > let the fl^Wgames begin! > > uri > > -- > Uri Guttman -- [EMAIL PROTECTED] > http://www.stemsystems.com > --Perl Consulting, Stem Development, Systems > Architecture, Design and Coding- > Search or Offer Perl Jobs > http://jobs.perl.org > = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses. http://promotions.yahoo.com/new_mail
re: Padding a length of string
Brian Morgan [EMAIL PROTECTED] wrote: > $max = $ARGV[0]; > $key = $ARGV[1]; > $pad_string = $ARGV[2]; > @key_chars = split(//, $key); > $count = $#key_chars + 1; > while ($count <= $max){ > $key .= $pad_string; > $count++; > } > print $key; You had part of the solution in your subject [length]: $key .= $pad_string x ($max - length($key)); print $key; = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Yahoo! Photos: High-quality 4x6 digital prints for 25¢ http://photos.yahoo.com/ph/print_splash
Re: pattern finding problem
I don't think you can do that without (??:code) blocks. Have you looked at Regexp::Common? There are examples there (such as for palindromes) that might be useful. --- "Aaron J. Mackey" <[EMAIL PROTECTED]> wrote: > > On Mar 2, 2004, at 9:37 AM, Jeff Abrahamson wrote: > > > > Do you allow overlapping patterns? For example, > if you are looking > > for 1212, does the following string contain three > instances or only > > two? > > > > 12121212 > > > > Yes, three. > > > Do you allow intervening characters? Searching > for 12, do you match > > on this? > > > > 132 > > If the pattern is "2 of [12] in a substring of > length 3", then yes. If > the pattern is "1 of '12' in a substring of length > 3", then no. > > > Are you doing full regex matching, subsequence > matching, or simple > > string matching? If the latter, I guess this is > easy using KMP and > > can be done in linear time, so you must be asking > about regex... > > Regex matching, normally because the pattern of > interest has ambiguity > > > In the regex case you can simplify the problem by > creating a new > > alphabet with symbols P and Q. Create a new > string S on the new > > alphabet, where the k-th symbol of S is P if an > instance of your > > pattern (of length less than B) begins at location > k in the original > > string. Otherwise symbol k is Q. With the symbol > at position k store > > the length of the shortest instance of the pattern > that begins at > > position k. > > Could this handle overlapping cases? > > -Aaron > = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Yahoo! Search - Find what youre looking for faster http://search.yahoo.com
re: golf tee puzzle
Jonathan E. Paton [mailto:[EMAIL PROTECTED] wrote: >What about a meet-in-the-middle algorithm, with one graph > created by running forwards, and one by running backwards. > You would require to calculate ALL board positions to a > given depth in each direction. Yes, good thought. Unfortunately, the number of board states becomes very large with increasing N. It is just manageable at N=7, but I'm also interested in pushing this as far as I can. Perhaps I'll put some adaptive logic in so that small boards are solved quickly, while large boards can still be solved without running out of space. Ronald J Kimball [mailto:[EMAIL PROTECTED] wrote: > Since the rotations/reflections are equivalent, you could save a lot of > memory by only caching a canonical instance of each board state. Yes, I'm planning to do this next. It should help a little, trading space for time. Steffen Mueller [mailto:[EMAIL PROTECTED] wrote: > I think you could either use your hard disk for caching (I know it's > slower, but CPU&time may not be the limiting factor) or think about > using a more compact representation of the board - What about a bit > string? Or a C-style array? There are modules for that. Oh, and > pack/unpack are friends. :) Yes, I've already converted to a bit string for board keys. Perhaps more interesting: I started using a tied hash for the board keys. When it runs out of memory, I start the program over, and it reports the correct number of hash keys, and uses less memory (for a while). So I think my problem is a memory leak somewhere. There is one main recursive routine, which creates a number of "my" variables. I suspect that I'm somehow keeping a reference to a variable that I shouldn't be, and that's causing my memory problem. [I looked for memory leak posts on the boards, and the general consensus is that most of them have been plugged. I can't presume to have found one with such a simple program, especially not using any modules.] Cheers, QM = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com
Re: golf tee puzzle
--- "Evan A. Zacks" <[EMAIL PROTECTED]> wrote: > Japhy wrote a peg game solver awhile back: > > http://www.perlmonks.org/index.pl?node_id=121626 Yes, that's very good, and uses minimal code. However, it's not immediately extensible to any size in it's present form. It's also somewhat brute force, though there are some speedups. For example, only starting with the 1st 5 pegs works well. There's only 1 redundant peg in that list (numbered from 0, pegs 1 & 2 are equivalent). I came at it from another direction, starting out caching the board state (equivalent to @state) for each board seen. [In most cases, there are several "paths" to a given board state.] I also used some other speedups, like precomputing the jump neighbors for each hole, and computing all rotations/reflections of each board and caching all of them (there are 5 equivalents for each board state, besides itself). The problem space soon blows up rather large for larger board sizes. For instance, I've seen it run out of memory on a large machine (caching boards) for N=7 (7 pegs on a side, 28 holes total), having cached about 1M boards. But N=8 finds a solution in a few minutes. Stopping at the first solution, it doesn't run out of memory. I'm working on balancing time and memory so that larger N will still find a solution in a reasonable time, but not run out of memory. I'll have to check out the book mentioned in the other post for some tips. Thanks, QM = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com
golf tee puzzle
I've been fiddling with a golf tee puzzle solver, and was wondering what others have done in this area. I've tried some googles, but can't find much of use. [Perhaps I'm not using the right terms.] Anyone have some resources? Interested in discussing this toy? -QM = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com
re: NPL Puzzler
Abigail wrote: > I too get two solutions, and if one is ambiguous due to a * b * c, the > other is too, due to a + b + c. I'm not using base-3 counting, but I'm > using recursion: I played with Bernie's try, and Abigail's, and also extended them somewhat, to handle other operators, target values, and digit sets. It seemed obvious to try adding a zero to the digit set, though some of the results would be trivially "+0" the 1..9 set. I also tried this list of operators: @ops = ( "", " + ", " * ", " - ", " / ", " % ", " ** ", " << ", " >> ", " ^ ", " | ", " ~ " ); Bernie's solution would stop after several minutes, with "Out of memory". ??? Must be that the garbage collection isn't happening. I checked the resources as it ran again, and it was using up 20M after just a few minutes, and continued to rise steadily. So the recursive solution seems to handle the larger problem space more readily, as each substring is kept around until all its variations are evaluated. But with the iterative solution, each unique substring is created, piecemeal, for each variation. Probably an order of magnitude worse when the garbage collector is on strike. But the recursive version eventually does the same. BTW, how to make garbage collection run? I'm using 5.005_03 built for sun4-solaris, though I could try it out on 5.6.0. Or do I have a completely different issue? -QM = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos & More http://faith.yahoo.com
Re: Mysql performace 30000 record
Slides look good to me! Since you're using a dictionary, "separate" has "a rat" in the middle, and "boundary" has 3 syllables. -QM shwern@poboxcom wrote: --- For some reason this code caught my eye and I started to clean it up. Then I decided to write down notes on the steps I was taking because it provided such a nice little microcosm on Perl refactoring. The sort of code below is very common. So I've written up a bunch of slides showing the steps I walked through to understand and cleanup the code below. It's rough, but should be readable. Should provide a nice real-world example to go along with the refactoring talk I gave at YAPC::Europe. http://www.pobox.com/~schwern/talks/Refactoring_DBI_Example/ http://www.pobox.com/~schwern/talks/Refactoring/ = ~~ Quantum Mechanics: The dreams stuff is made of __ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos & More http://faith.yahoo.com
RE: Great programming language shootout
[EMAIL PROTECTED] wrote: > Another list (discussing ICON) got me to: > http://www.bagley.org/~doug/shootout/ > > and checking on perl's results found it sort of in the > middle. > http://www.bagley.org/~doug/shootout/lang/perl/ > > This was one of the scripts: Given the criteria for that test, there is little you can do to improve it, since it must follow as closely as possible the C program given. Now, if you're looking for a speedup, that's a different question. In my early Perl years I once stole a golfish solution of this off the NG from an Abigail post, and sped it up by making some obvious improvements. For example, in the Sieve mentioned above, every prime number found is used to sieve the numbers above it, starting with twice that prime. With real numbers, suppose we've just found that 17 is prime. The SoE then checks 2*17=34, 3*17=51, etc., to see if they've been removed from the list yet. But we know that all multiples of 17 have already been removed up to, but not including, 17*17. At any rate, here's my script. It could probably be speeded up some more -- maybe someone would like to take a shot at it? #!perl # # modified Sieve of Eratosthenes, counts primes # first argument is highest number to check # second argument non-zero prints out all primes found use integer; # first prime, last number to check for priime my ( $prime, $last ) = ( 2, ( shift or 50 ) ); # switch to print out list of primes my $list = ( shift or 0 ); # initialize sieve, index 0 = number 0 my @sieve = ( 0, 0, map { 1 } ( $prime .. $last ) ); $sieve[ $last+1 ] = -1; # stop flag while ( ( $product = $prime * $prime ) <= $last ) { # mark all multiples do { $sieve[ $product ] = 0; } while ( ( $product += $prime ) <= $last ); # find next prime do { $prime++ } until $sieve[ $prime ]; # stop flag will end "do" loop } if ( $list ) { map { print "$_ " if $sieve[ $_ ] } ( 0 .. $last ); print "\n"; } map { $count++ if $sieve[ $_ ] } ( 0 .. $last ); print "Count: $count\n"; __END__ __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com