Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Perl Puzzles

by moritz (Cardinal)
on Oct 10, 2010 at 08:41 UTC ( [id://864460]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Puzzles
in thread Perl Puzzles

Similar in spirit, but less focused on math are 99 Lisp problems (but can be approached in Perl too), and rosettacode.

Also I solved the greplin programming challenge yesterday (in Perl 6 :-) -- nice, but only three tasks.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^3: Perl Puzzles
by eyepopslikeamosquito (Archbishop) on Oct 10, 2010 at 08:55 UTC

    That reminds me of a Rosetta code problem I did a few years ago at Perl Monks.

    Write a Perl function to reverse a string of words. For example, given an input string of:
    " one two three four "
    the function should produce:
    "four three two one"
    That is, the input string reversed word by word, with a single space between each word and with no leading or trailing space. You may assume the input string consists only of alphabetic characters, spaces and tabs.

    When you've written your function, you can view many solutions to this problem in Perl and other languages at Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell).

    Update: Two more.

    Given an input string, for example "ZBBBCZZ", produce a list, for example, ["Z", "BBB", "C", "ZZ"]. That is, break the input string into pieces based on change of character. Solutions at Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...).

    Given a list of strings, for example ("a", "bb", "c", "d", "e", "f", "g", "h"), and a chunksize, for example 3, write a subroutine to return a multi-line string, for example:

    a bb c d e f g h
    The output string must contain a single space between each array element and a newline every chunksize items. Note that no trailing space is permitted on any line and the last line must be properly newline-terminated. Solutions at Rosetta code: Split an array into chunks.

      Oh, dear. Too bad I wasn't around for that one - my off-the-cuff solutions seem to be a good bit shorter than the ones presented there. {sigh} Oh, the things I lose out on by not having a time machine...

      # Perl $ perl -wlne'print "@{[reverse split]}"' one two three four four three two one # Bash, as a script #!/bin/bash a=($@);for ((b=${#a[*]};b>=0;b--)); do c+=(${a[$b]}); done echo ${c[*]}

      Not that this addresses the original question. :)

      Back on topic: some years ago, Mark-Jason Dominus ran a "Quiz-of-the-Week" mailing list in which he came up with interesting challenges for Perl hackers. As I recall, he wasn't able to continue it; some other people tried carrying it (Shlomi Fish among them, IIRC), but it eventually died off. While it lasted, however, it was quite a bit of fun - it might be worth your while to take a look at the archives and see if anything strikes your fancy.


      --
      "Language shapes the way we think, and determines what we can think about."
      -- B. L. Whorf

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://864460]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-29 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found