📜 ⬆️ ⬇️

Perl Golf at YAPC :: Russia 2014



We in REG.RU scary love to participate in interesting events. We love them so much that even they themselves began to organize them. For example, on June 13-14, with the sponsorship of the company and the active participation of colleagues, we held a regular conference of perl-programmers YAPC :: Russia 2014 . As always, a great company has gathered, time has been pleasant and rewarding. In addition, the venue for the conference this year was St. Petersburg for the first time, and even in the midst of white nights! Some funny pictures from the event can be seen on social networks ( VKontakte and Facebook ), and we even posted some reports on YouTube (and still do not lose hope to post the rest).

Among other things, cultural leisure, I decided to repeat the experience of last year’s YAPC :: Europe conference and again hold the Perl Golf competition.

Here we had a problem this time:
')

Erds number


Pal Erdös is a famous Hungarian mathematician.
Erdös wrote 1475 articles in his life, and many of these works were co-authored. Traditionally, in mathematics, a joint article is the exception rather than the rule; therefore, the presence of such a large number of co-authors gave rise to the concept of Erdos number in the folklore of mathematicians.

This number is defined as follows:
  • at Erdos himself it is zero,
  • for Erdös direct co-authors, this number is one,
  • co-authors of people with Erdosh number equal to n have Erdosh number n + 1.
© Wikipedia

At the same time, it is necessary to take into account that the shortest number is chosen from several options of links, i.e. the minimum possible number.

Input data:
The first line contains the name of the scientist for whom you need to determine the Erds number. Subsequent lines contain a list of publications: authors' names, separated by a comma and a space, and the title of the work, separated by a colon. The given surname may not appear in any publication.

Example:
Chen Smith, Martin, Erdos: Newtonian forms of prime factor matrices Erdos, Reisig: Stuttering in petri nets Smith, Chen: First oder derivates in structured programming Jablonski, Hsueh: Selfstabilizing data structures 

Data is submitted to STDIN:
 cat data | perl golf.pl 

Task:
Print the Erds number for a given scientist. In case there is no connection with Erdös, output Inf.

You can check the performance of the solution by the attached test suite:
 prove test.pl 

The size of the solution can be calculated using the golfcount.pl script:
 perl golfcount.pl golf.pl 

The text of the task, a set of tests and supporting scripts are on the GitHub .

Solutions were tested on perl version 5.16.0, on later versions there may be warnings about the smartmatch experimentality.

Surprisingly, the fight for the victory in the competition turned bitter. Participants sent improved versions of their decisions literally until the last minutes before the debriefing and fought for each character. And the decisions themselves turned out to be more diverse than last time. Here's what the final standings looked like:

1 (137 characters) - Victor Sapunkov
2 (139 characters) - Nikolay Shulyakovsky
3 (140 characters) - Denis Ibayev
4 (156 characters) - Pavel Scherbinin
5 (180 characters) - Sergey Romanov
6 (190 characters) - Evgeny Breykin
7 (200 characters) - Dmitry Latin
8 (205 characters) - Ilya Kolesnikov
9 (243 characters) - Evgeny Vostrov
10 (393 characters) - Dmitry Tigrov

As usual, the solution with the most active use of regexp won. Who would doubt that. It looks like this:
 #!/usr/bin/perl -0np $i=$_;$_=unpack('%32W',$i);$o=length$i>249;s/\s*(^|$)\s*//mg;s/69/0/;s/83/1/;s/67/{2-$o}/e;s/73/Inf/;s/^$//;s/\s+//g;s/\s*\z\s*/\n/m 

All participants received prizes from the company REG.RU, as well as a large cart of attention and respect from colleagues.



All those who are not indifferent to the wisdom of Perla propose to test their strength and try to exceed the results of the contestants. Well, or at least try to figure out how their solutions work. To make it easier to do this, next to each solution ( golf.pl ) is its copy in formatted form ( golf_formatted.pl ). Not that it helped much. But still.

If you suddenly managed to make an even shorter decision, or come up with some particularly successful trick - feel free to share, with pleasure I will add your decision to the publication.



Some decisions from the post comments:


107 characters - xtender
160 characters - brom_portret
81 characters - biophreak

Thanks to everyone who took the time to compete!

Source: https://habr.com/ru/post/235767/


All Articles