Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Perl in programming contests and problem solving

by rsFalse (Pilgrim)
on Jul 25, 2017 at 20:49 UTC ( #1196047=perlquestion: print w/replies, xml ) Need Help??
rsFalse has asked for the wisdom of the Perl Monks concerning the following question:

Hello.

There are many programming contests and websites for problem solving. Do you like to solve problems and when do you use Perl? Can you suggest programming contests or websites with string problems or something at which Perl excels?

Usually in programming contests there are algorithmic problems. You are given some task, which contain: 1. problems description, 2. input constraints and format, 3. output format, 4. time and memory limits. Then you write and submit some code, and testing system tests your code using some test cases which you do not know, except you know constraints. After testing, system tells verdict: accepted, wrong-answer, time-limit-exceeded or something else.
Some examples of online contests are: codeforces (many languages available, Perl including), topcoder; some examples of online judges are: SPOJ, ProjectEuler, Timus, Rosalind. Some online judges like Project Euler accepts only answers, not code. Majority of people write solutions for these problems in C++ language. Less people use Java, C, Python, Pascal. That is because C++ is fast and short to express and have macros. Many problems are composed in such way that only very fast algorithm can solve all edge cases in a given time limit. For example if author's solution solve the problem in 1 s, then time limit can be set around 2-5 s. If author solved with C++, then it is often impossible to achieve such speed with higher level languages, like Perl or Python. So, Perl was used mostly not in usual competitive programming, but in golf contests :D

I am using Perl in contests for fun and am solving easiest tasks, when tasks which are more difficult require better understanding of algorithms and data structures.

If you want to try Perl in solving some string problems, I can suggest codeforces.com -> problemset and choose tag "strings". You can see pieces of test cases and solutions of other users to comparison code and comparison time program consumed on each test case. If you have a nice solution for a problem or you are stuck in it you can start discussion here(?). Websites have their own forums/blogs for discussing problems, but usually these discussions are not language specific. That discussions can be about which Perl structures to use to gain better speed or similar. While using Perl I've discovered that many my solutions on simple tasks are about the same speed as Python users. And do you know if any of more popular online judge systems are written in Perl?
  • Comment on Perl in programming contests and problem solving

Replies are listed 'Best First'.
Re: Perl in programming contests and problem solving
by choroba (Bishop) on Jul 25, 2017 at 21:00 UTC
    There's also HackerRank that supports Perl among other languages and sets the time limit differently for each language (default is 9s for Perl, compared to 10s for Python and Ruby, or 2s for C and C++). There are many categories, you might be interested in the "Strings" subdomain in the "Algorithms" domain, or the "Regex" domain. Coincidentally, I'll be presenting some tricks I used to solve some of the tougher assignments at HackerRank at the Perl Conference in Amsterdam in two weeks.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Maybe there will be possibility to watch your presentation online, or you publish your notes?

      I like when contest website give more time for slower languages. Then more problems are solvable in more languages, not only in compiled ones.
Re: Perl in programming contests and problem solving
by davido (Archbishop) on Jul 26, 2017 at 06:04 UTC

    If the problems are well written, well classified, and well tested they will not favor one general purpose language over another where solutions from each language use optimal algorithms.

    I've seen many cases of people belly-aching over having solutions rejected, blaming the site, or the language, when the fact is their solutions were not optimal for the tests. If there is a strong bias toward compiled languages in a given programming contest then either move on or use that language. But so often the issue really is simply a matter of not coming up with the best algorithm for the task.

    Of course this is based on my anecdotal observations. It's possible that there are also many such contests that pit compiler against compiler. But the most interesting problem sites present the problems in a way that any language can be used and can achieve a successful answer if the solution is sufficiently insightful and well implemented.


    Dave

Re: Perl in programming contests and problem solving
by sundialsvc4 (Abbot) on Jul 26, 2017 at 00:43 UTC

    I hate to rain on this Perl-oriented parade, but it actually makes comparatively little difference – especially in a contest situation, which is a very-artificial situation where you are challenged to create a one-off solution that will be judged but that will not survive the contest.   It is tacitly assumed that you either will be employing an interpreter-driven language (such as Perl) or that you it will not matter if you do or don’t.

    Perl(5) is a good, clean, high-performance implementation of a relatively-sparse language.   (Perl6, IMHO, is a travesty.)   Efficient memory-manager, industry-reference implementation of regular expressions, and a killer CPAN library which is useful to your contest only if you are permitted to use it.   But, the language is sparse.   Nearly everything that you would take-for-granted in a language such as Java simply do not exist.

    Comparisons between Perl and other interpreted languages, particularly Python, are simply not useful to me, because, underneath their superficial differences (such as syntax), which do not really matter, there are deep differences, which do.   (For instance, “Guido (Python ...) was heavily influenced by LISP.”)

    A programming contest, if well-envisioned, should first and foremost challenge your ability to develop (or, to select ...) suitable algorithms, not to code them in this-or-that particular language.   All language implementors can be counted on to be good at what they do, and to provide you with what is actually a mostly-equal playing field.   The operative question then becomes, “did you use Bubble Sort, or MergeSort?”   If you win a contest, it will be because your algorithm is better, and this factor alone will handily exceed any difference – most of the time – between implementation languages.

      > For instance, “Guido (Python ...) was heavily influenced by LISP.”)

      Again the same bullshit?

      You obviously know Lisp even less than Perl!

      For the interested reader see Re^5: [OT] Python vs R (linked list vs array ) and following.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      PS: I'm wondering, are you a BS bot experiment and we the Turing test?

        Par for the course I'm afraid.

        Thanks for the link, especially these comments get to the heart of it:

        > I first learned about map through Perl. That's also where I learned

        > about anonymous functions, although Perl doesn't use the word "lambda."

        IIRC, Larry Wall expressly acknowledges Lisp's contribution for these features and others.

        > They were added to Python just before the 1.0 release, as a contribution

        > by someone other than Guido. He's noted for saying way back in 1994

        > ] To be honest, I wish I hadn't introduced lambda, map, filter and

        > ] reduce -- they support a style that is inconsistent with the rest of

        > ] Python. ...

        Priceless!

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

      Nearly everything that you would take-for-granted in a language such as Java simply do not exist.

      Like what?

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1196047]
Approved by choroba
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2017-12-12 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (323 votes). Check out past polls.

    Notices?