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 (Cardinal) 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 (Cardinal) 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

A reply falls below the community's threshold of quality. You may see it by logging in.