Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Mission: Obfuscation (1)

by jynx (Priest)
on Nov 19, 2002 at 01:22 UTC ( #214003=perlmeditation: print w/replies, xml ) Need Help??

Yeah, yeah, cheesy title. Couldn't think of anything better, so sue me...

Anyway, This is an obfuscation contest. i'm going to lay down some parameters (hopefully strict, clear, and concise as to input and output) and you (my lucky reader) are going to try to create the most obfuscated program you can that adheres to the specifications.


  1. You are to receive a number on command line. The number will be positive (> 0) and less than 999,999 (due to constraints on my time).
  2. You will output a certain number of primes equal to the number submitted on command line. They will probably not be the smallest, but they must be in order and no duplicates.
  3. The algorithm:
    1. Let p be 3.
    2. Iterate over the expression x^2 + x + p such that 0 < x < p.
    3. For every number iterated over, check to see whether it is prime or not (using any algorithm). If it is add it to the list of primes found so far.
    4. Increment p to the next prime.
    5. Repeat from step 2 until the number of primes specified is found.
  4. When printing primes, print 2 first, then the rest.
  5. Printing more primes is not faultable, but not optimal. Printing more than twice the number specified will automatically discount your entry.
  6. All primes output must be \s delimited.
  7. All entries must be smaller than 4k of text.
  8. All entries must finish before the heat death of the universe.
  9. Strict and warnings are not necessary. No modules.
That should be specific enough. If there are any ambiguities please let me know. Please treat this roughly the same as a golf contest, with a different goal in mind. And as always, have fun :-)


Update: The "contest" will finish December 1st (of 2002) and <shameless plug> there will be a prize! </shameless plug>

Update2: i'm not going to give a prize when only 2 people entered submissions (sorry). i may by consolation prizes for them so that they don't feel gypped, but hopefully i'll get more turn-out next time... ;-)

Replies are listed 'Best First'.
Re: Mission: Obfuscation (1)
by premchai21 (Curate) on Nov 19, 2002 at 02:18 UTC
    Well, let's see now...
    #!/usr/bin/perl sub p{($p::P)=@_;for$P(2..sqrt($p::P)){$P::p=$p::P/$P;($P::p==int($P:: +p)) && return(0);}return($p::P>1)};$p::p=3;$\=$,=$/;$P::P=0; p:for$p(1..($p::p-1)){p($P=$p**2+$p+$p::p)&& push(@P,$P)} for$p(1..$#P){$P[$p]=(grep{($_!=$p)&&($P[$_]==$P[$p])} (0..$#P))?0:$P[$p]}$p::p=0;$p::p=$P[$P::P++]until$p::p; $P[@P]=@P;$_||($P[-1]--)for@P;(pop(@P)>=$ARGV[0])||goto p; print((sort{$a<=>$b}grep{$_}(2,@P))[0..$ARGV[0]-1]);

    Update: Thanks to jynx for pointing out the duplicates printed by the original version. Should be fixed now, and perhaps slightly more obfuscated as well.

Re: Mission: Obfuscation (1)
by jryan (Vicar) on Nov 19, 2002 at 06:45 UTC

    I was a bit disappointed that I had to follow a certain algorithm, but at least I took a few liberties with the 2nd step (Iterate over the expression x^2 + x + p such that 0 < x < p). Oh, and there isn't a single loop, if/unless statement, or subroutine in my entire program ;)

    #!/usr/bin/perl -w use strict; my($p,$x)=3;p:{$x=0;x:{$_='s`.*(\\$x\\*\\*2\\+\\$x\\+\\$p).*`$1`ee'; eval"y/\\\\//d;$_";keys%_>$ARGV[0]-2?last p:(1x($_))!~/^(11+?)\1+$/x &&!exists$_{$_}?++$_{$_}:1;++$x;;$x<$p?goto x:last}$p=(sort{$b<=>$a} keys%_)[0];;goto p}$,=$";eval "@{[print=>q<2,sort{$a<=>$b}keys%_>]}"

    Enjoy. (at least until BooK tops it!)

Re: Mission: Obfuscation (1)
by diotalevi (Canon) on Nov 19, 2002 at 02:31 UTC

    I'm just going to voice a thought theorbtwo brought p but that I agreed with. How about not making the specific algorithm be mandatory - leave the implementation up to the writer. You only need to verify the result.

    __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;

      Yeah, the problem is that some algorithms will automatically make it harder to read. By standardizing the algorithm people can't do something completely out there and gain an advantage there. In golf the advantage is all about finding the shortest algorithm and then use arcane knowledge to save strokes. Since algorithms are generally known for golf contests most of the solution lies in using more arcane knowledge.

      *sigh* i suppose my issue is that an obfuscation must start with an interesting algorithm. Just finding primes isn't interesting (and in fact there is no one right way to do it) but having a prime generator (albeit incomplete) is a bit interesting. This gives people not so good at obfuscation a chance because all that needs be obfuscated is the window dressing. It's more a way to see who can provide the most interesting window dressing, which is (imho) the smaller and more difficult part of obfuscation.

      So essentially i posted this:

      1. Because i can't recall having seen one before
      2. Because (again imho) many people need to work on their window dressing, and this is an excuse to have them try just for fun.
      Sorry if it's not as interesting, but i did have specific intentions. If i can think of a problem that has very few solutions than i might allow indeterminate algorithms to be used, but until then levelling the playing field for neophites is a goal i aspire for.


      PS Also, the result is harder to verify if any algorithm is used (not necessarily here, but in the general case)...

      update: PS2: i did try to make the algorithm more general so that (hopefully many) liberties could be taken, and there are some things in the algorithm that can also be taken by principle rather than letter (one need not start at 3 for example. one could start at 1 or 2 just as easily so long as the output is correct). Unfortunately --as always -- my attempt to put thoughts to words is poor at best...

Re: Mission: Obfuscation (1)
by diotalevi (Canon) on Nov 20, 2002 at 18:18 UTC

    So when is the contest over? I've working up a doozy and it'll probably be done by tonight or tomorrow but I want to be sure it gets in on time...

    __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;


      i'm thinking December 1st at the moment. That's 10 more days and roughly 2 weeks for the whole of it. i'm guessing people will long since have stopped posting by then, but the date is convenient for other purposes as well...


What happened to Mission: Obfuscation (1)?
by Mr. Muskrat (Canon) on Feb 06, 2003 at 17:14 UTC
    Last post says it ends December 1, 2002 but only two people entered? And here it is February 6, 2003 with no winner...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://214003]
Approved by premchai21
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2023-02-02 15:17 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (19 votes). Check out past polls.