Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: (Efficiency Golf) Triangular numbers

by Abigail (Deacon)
on May 30, 2001 at 17:58 UTC ( #84259=note: print w/replies, xml ) Need Help??


in reply to (Efficiency Golf) Triangular numbers

There is no need for the program to run very long. A paper and pencil puzzler will beat your 'running for many hours' program.

I will not post the solution here, but I will provide a link to the program. It's about 80 lines, but more than half of the lines are comments.

  • Comment on Re: (Efficiency Golf) Triangular numbers

Replies are listed 'Best First'.
Re: Re: (Efficiency Golf) Triangular numbers
by blakem (Monsignor) on May 31, 2001 at 11:28 UTC
    I'm familiar with assigning to slices of a hash, and its use in this line:

    @seen {$t, $h, $r, $e} = ();

    was very clever. However, why did you use slices in these lines?

    @seen {$n,} = (); .... @seen {$o,} = ();
    Aren't they equivalent to:
    $seen{$n} = undef; $seen{$o} = undef;
    Or even just:
    @seen {$n} = (); # note the lack of comma after $n .... @seen {$o} = ();
    I guess its that trailing comma that looks odd to me.

    -Blake
    p.s. props on the @HIGH and @LOW generation... very sneaky!

      I used @seen {$n,} = (); and not $seen {$n} = undef; because I used the slice in the other case as well. I wanted to use as much identical syntax as possible, and didn't see a reason to special case adding a single key.

      As for using a trailing comma, all I can say is that using -w is useful. If you use it, you'll see why the comma was used.

      -- Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://84259]
help
Chatterbox?
[Cosmic37]: if ( $line =~ /$mydt/ ) { print $line; }
[Cosmic37]: I try to match successive date times stored in variable $mydt
[Cosmic37]: I guess it is searching for the string "$mydt"
[Corion]: Indeed cool, erix ;)
[Cosmic37]: rather than the value of $mydt which is a date time strong such as 2016-01-01 12:30:56
[Corion]: Cosmic37: No, but maybe $mydt doesn't contain what you think it does, or it contains characters that are special in a regular expression? Try if( $line =~ /\Q$mydt\E/) { ... for a literal match
[Cosmic37]: I mean string grrr
[Corion]: Maybe add an else branch in which you print what the values of $line and $mydt are?
[Cosmic37]: ah thank you I will try
[Cosmic37]: you are right $mydt did not contain what I expected... :-D I will now think :-D

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2017-06-29 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (673 votes). Check out past polls.