The most complicated piece of code

Let’s have a little contest. I was just reading some stuff about Perl and while I could understand some of the elements used in it, it was sooo obfuscated that it meant nothing to me.

I want to see code examples that would “solve” one of two of the most ancient questions in human history. You’ve got your choice of:

Q: Why did the chicken cross the road?
A: To get to the other side.

or

Q: What is the answer to Life, the Universe and Everything?
A: 42

or of course both. Bonus points to anyone that can successully mesh the two questions together in a meaningful manner.

Now, I want to see the most complicated, obfuscated code you can muster up. Nothing but tokens, tokens, tokens. At the same, try to keep the code short and sweet. One last requirement…when “run”, the code must generate the correct answer.

PHP, Perl, ASP, Actionscripting, javscript, Java, etc. All are welcome.

Awww - no fair. I only do ColdFusion and Python and it’s really hard to write obfuscated code in those :slight_smile:

Might have to dust off my ancient (and pretty bad) Perl skills…

The classic ‘Life’ in INTERCAL…


	PLEASE NOTE BEGINNING OF BEGINNING
        DO WRITE IN .11
        DO WRITE IN .12
        DO ,1 <- .11 BY .12
        DO ,2 <- .11 BY .12
	DO WRITE IN .13
	DO .14 <- #0
	DO .1 <- .11
	DO (1020) NEXT
	DO .4 <- .1
	DO ,3 <- .4
	DO .2 <- #0
	PLEASE STASH .2

	PLEASE NOTE INITIALIZING ,1 TO ZEROES
	DO .1 <- .11
	PLEASE COME FROM (116)
	DO .2 <- .1
	DO .1 <- .12
	PLEASE COME FROM (113)
	DO ,1 SUB .2.1 <- #0
	DO (111) NEXT
(112)	DO (2010) NEXT
(113)	PLEASE FORGET #2
(111)   DO (112) NEXT
	DO (114) NEXT
(115)	DO .1 <- .2
	DO (2010) NEXT
(116)	PLEASE FORGET #3
(114)   DO (115) NEXT
	PLEASE FORGET #2

	PLEASE NOTE INITIAL POSITION INPUT
	PLEASE COME FROM (123)
	DO WRITE IN .1
	DO (121) NEXT
	DO WRITE IN .2
(123)	DO ,1 SUB .1.2 <- #1
(122)	DO RESUME "?!1~.1'$#1"~#3
(121)   DO (122) NEXT
	PLEASE FORGET #1

	PLEASE NOTE END OF BEGINNING, BEGINNING OF MIDDLE
	DO COME FROM (298)

	PLEASE NOTE PRINTING CURRENT POSITION
	DO (300) NEXT

	PLEASE NOTE PUTTING NEXT POSITION IN ,2
	DO .1 <- .11
	DO .9 <- .1
	DO (2000) NEXT
	DO .7 <- .1
	DO (2000) NEXT
	PLEASE COME FROM (216)
	DO .5 <- .1
	DO .1 <- .12
	DO .10 <- .1
	DO (2000) NEXT
	DO .8 <- .1
	DO (2000) NEXT
	PLEASE COME FROM (213)
	DO .6 <- .1

	DO .1 <- #0
	DO .2 <- ,1 SUB .5.6
	DO (2020) NEXT
	DO .2 <- ,1 SUB .5.8
	DO (2020) NEXT
	DO .2 <- ,1 SUB .5.10
	DO (2020) NEXT
	DO .2 <- ,1 SUB .7.6
	DO (2020) NEXT
	DO .2 <- ,1 SUB .7.10
	DO (2020) NEXT
	DO .2 <- ,1 SUB .9.6
	DO (2020) NEXT
	DO .2 <- ,1 SUB .9.8
	DO (2020) NEXT
	DO .2 <- ,1 SUB .9.10
	DO (2020) NEXT
	DO :2 <- #0$#65535
	DO .1 <- "?'"V.1$,1SUB.7.8"~:2'$#3"~:2
	DO ,2 SUB .7.8 <- "?!1~.1'$#1"~#1

	DO (211) NEXT
(212)   DO .10 <- .8
	DO .8 <- .6
	DO .1 <- .6
	DO (2010) NEXT
(213)	PLEASE FORGET #2
(211)   DO (212) NEXT
	DO (214) NEXT
(215)	DO .9 <- .7
	DO .7 <- .5
	DO .1 <- .5
	DO (2010) NEXT
(216)	PLEASE FORGET #3
(214)   DO (215) NEXT
	PLEASE FORGET #2

	PLEASE NOTE COPYING ,2 BACK INTO ,1
	DO .1 <- .11
	DO (2000) NEXT
	PLEASE COME FROM (226)
	DO .2 <- .1
	DO .1 <- .12
	DO (2000) NEXT
	PLEASE COME FROM (223)
	DO ,1 SUB .2.1 <- ,2 SUB .2.1
(223)	DO (221) NEXT
(222)	DO (2000) NEXT
	DO .3 <- "?.1$#1"~"#0$#65535"
	PLEASE RESUME '?"!3~.3'~#1"$#1'~#3
(221)   DO (222) NEXT
	PLEASE FORGET #1
(226)	DO (224) NEXT
(225)	DO .1 <- .2
	DO (2000) NEXT
	DO .3 <- "?.1$#1"~"#0$#65535"
	PLEASE RESUME '?"!3~.3'~#1"$#1'~#3
(224)   DO (225) NEXT
	PLEASE FORGET #1

	PLEASE NOTE INCREMENT TIMESTEP AND TEST
	DO .1 <- .14
	DO (1020) NEXT
	DO .14 <- .1
	DO (231) NEXT
	DO (299) NEXT
(232)	DO .3 <- "?.14$.13"~"#0$#65535"
	PLEASE RESUME '?"!3~.3'~#1"$#2'~#3
(231)	DO (232) NEXT
	DO FORGET #1

	PLEASE NOTE OVERFLOW TESTING
	DO .7 <- #0
	DO .8 <- #0
	DO .1 <- .11
	DO (2000) NEXT
	DO .5 <- .1
	DO .1 <- .12
	DO (2000) NEXT
	DO COME FROM (243)
	DO .6 <- .1
	DO .2 <- ,1 SUB #2.6
	DO .1 <- .7
	DO (500) NEXT
	DO .7 <- .1
	DO .2 <- ,1 SUB .5.6
	DO .1 <- .8
	DO (500) NEXT
	DO .8 <- .1
(243)	DO (241) NEXT
(242)	DO .1 <- .6
	DO (2000) NEXT
	DO .3 <- "?.1$#1"~"#0$#65535"
	PLEASE RESUME '?"!3~.3'~#1"$#1'~#3
(241)   DO (242) NEXT
	PLEASE FORGET #1

	DO .7 <- #0
	DO .8 <- #0
	DO .1 <- .12
	DO (2000) NEXT
	DO .6 <- .1
	DO .1 <- .11
	DO (2000) NEXT
	DO COME FROM (253)
	DO .5 <- .1
	DO .2 <- ,1 SUB .5#2
	DO .1 <- .7
	DO (500) NEXT
	DO .7 <- .1
	DO .2 <- ,1 SUB .5.6
	DO .1 <- .8
	DO (500) NEXT
	DO .8 <- .1
(253)	DO (251) NEXT
(252)	DO .1 <- .5
	DO (2000) NEXT
	DO .3 <- "?.1$#1"~"#0$#65535"
	PLEASE RESUME '?"!3~.3'~#1"$#1'~#3
(251)   DO (252) NEXT
(298)	PLEASE FORGET #1

(299)	DO FORGET #1
	PLEASE NOTE END OF MIDDLE, BEGINNING OF END

	PLEASE NOTE PRINTING FINAL POSITION
	DO (300) NEXT

	PLEASE NOTE END OF END
	PLEASE GIVE UP


(300)	PLEASE NOTE POSITION OUTPUT ROUTINE
	DO READ OUT .14
	PLEASE RETRIEVE .2
	DO .6 <- .12
	PLEASE COME FROM (316)
	DO .5 <- #1
	PLEASE COME FROM (313)
	DO .1 <- .2
	DO (301) NEXT
	DO .2 <- #242
	DO (303) NEXT
(302)	PLEASE RESUME "?',1 SUB .5.6'$#1"~#3
(301)   DO (302) NEXT
	DO .2 <- #116
(303)	PLEASE FORGET #1
	DO (1010) NEXT
	DO ,3 SUB .5 <- .3
(313)	DO (311) NEXT
(312)	DO .1 <- .5
	DO (1020) NEXT
	DO .5 <- .1
	DO .3 <- "?.5$.4"~"#0$#65535"
	PLEASE RESUME '?"!3~.3'~#1"$#1'~#3
(311)   DO (312) NEXT
	DO .1 <- .2
	DO .2 <- #80
	DO (1010) NEXT
	DO ,3 SUB .4 <- .3
	PLEASE READ OUT ,3
	DO (314) NEXT
(315)	DO .1 <- .6
	DO (2010) NEXT
	PLEASE FORGET #3
(316)	DO .6 <- .1
(314)   DO (315) NEXT
	DO PLEASE STASH .2
	PLEASE RESUME #3

(500)	DO (501) NEXT
	DO .1 <- #0
	PLEASE RESUME #1
(502)   PLEASE RESUME '?.2$#2'~#3
(501)	DO (502) NEXT
	DO (2020) NEXT
	DO (503) NEXT
	PLEASE RESUME #2
(504)	DO .2 <- "?.1$#3"~"#0$#65535"
	PLEASE RESUME '?"!2~.2'~#1"$#1'~#3
(503)	DO (504) NEXT
	PLEASE FORGET #3
	DO (299) NEXT

(2010)  PLEASE ABSTAIN FROM (2004)
(2000)  PLEASE STASH .2
        DO .2 <- #1
        DO (2001) NEXT
(2001)  PLEASE FORGET #1
        DO .1 <- '?.1$.2'~'#0$#65535'
        DO (2002) NEXT
        DO .2 <- !2$#0'~'#32767$#1'
        DO (2001) NEXT
(2003)  PLEASE RESUME "?!1~.2'$#1"~#3
(2002)  DO (2003) NEXT
        PLEASE RETRIEVE .2
(2004)	PLEASE RESUME #2
	PLEASE DO REINSTATE (2004)
	PLEASE RESUME '?"!1~.1'~#1"$#2'~#6

(2020)  PLEASE STASH .2 + .3
	DO (1021) NEXT

:lol:

:eek2:

So which answer does it give Sowen?

:eek:

that’s a language, sowen???

I think I just got a migrane. Sheesh :smiley:

Yep it’s a real language - called intercal. I saw an artical about it just a couple of days before creole posted this thread and it just seemed apt! The program (aparently!) is Life (the cell simulator).

I think this is more in line with what creole was looking for though.


using System;

namespace ItsLifeJim
{
	
	/// <summary>
	/// Discover the question
	/// </summary>
	class Class1
	{
		static void Main(string[] args)
		{
			const int theMeaningOfLife = 42;
			int chickens = 2;
			int chickenMomas = 0;
			long youHaveToBeKiddingThatManyChickens = 9999999999999999;
			Console.WriteLine("How fertile are you chickens! 1 is low 10 is rockin'");
			int howCoolAreYourCocks = Convert.ToInt32(Console.ReadLine());

			while (chickens < youHaveToBeKiddingThatManyChickens)
			{
				int chickenLove = howHornyAreOurChickens();
				chickens = chickens + chickensGetItOn(chickens, chickenLove, howCoolAreYourCocks);
				chickens = howThickAreChickens(chickens);//The chickens cross the road

				int haveWeFoundIt = chickens % theMeaningOfLife;
				if (haveWeFoundIt == 0)
				{
					Console.WriteLine("Your faithfull chickens found the meaning of life! It took {0} Chickens and {1} generations of Chickens to find", chickens, chickenMomas);
					break;
				}
				else
				{
					Console.WriteLine("It took {0} Chickens & {1} generations of Chickens NOT to find the meaning of life!", chickens, chickenMomas);
				}
				chickenMomas++;

			}
			
			Console.ReadLine();
		}
		static int aRandomNumberBetween1And10()
		{
			int itsRandom;
			Random randomNum = new Random();
			itsRandom = randomNum.Next(1,9);
			return itsRandom;
		}
		static int howHornyAreOurChickens()
		{
			int hubbaHubba = aRandomNumberBetween1And10();
			return hubbaHubba;
		}
		static int chickensGetItOn(int multiChickens, int hotOrColdDarlin, int howCoolAreYourCocks)
		{
			
			int studValue = howCoolAreYourCocks;
			int impregnationQuality = hotOrColdDarlin * studValue;
			int justWatchTheOffspring = multiChickens * impregnationQuality;
			return justWatchTheOffspring;
		}
		static int howThickAreChickens(int allDemChickens)
		{
			int aFewChickensLess;
			int chickenSlaughterValue = aRandomNumberBetween1And10() * 10;
			aFewChickensLess = allDemChickens-((chickenSlaughterValue*allDemChickens)/100);
			return aFewChickensLess;
		}
	
	}
}


It’s C# so anyone with the .NET sdk can compile and run it. I did this on holiday, during which I plastered 90% of the time, so the logic side of things is a little iffy, but you do get an answer now and then.

Have no idea what is does - came to me in a dream. Coded verbatim and undebugged. Seems to time out the PHP parser…


<?php
function ifAllElseFails($type, $msg, $file, $line, $context) {
   echo ( "Ah what the hell. Doesn't work. But the meaning of life is 42. And chickens or eggs? Nah. It was a mutant gecko." );
}
error_reporting(E_ALL);
set_error_handler("ifAllElseFails");

class TheMeaningOfLif {
     var $came_first;
	 var $the_answer;
	 var $aeons;
	 var $doubt;
	 var $uncertainty;
	
	 function TheMeaningOfLif() {
		  $this->aeons = "150";
		  $this->doubt = ceil ( 13.3 * $this->Life() );
		  $this->uncertainty = floor ( 132 / $this->theUniverse() );
		  $this->the_answer[whatisthemeaning] = $this->andEverything();
		  $this->came_first = array ( "The Chicken", "The Egg" );  	
          $this->came_first = arsort ( $this->came_first, SORT_NUMERIC );		
		  $this->the_answer[whichcamefirst] = whichCameFirst($this->came_first);
     }
	 function Life () {
        for ($x = 1; $x <= $this->aeons; $x++) {
            $r = 1 / ($x * $x);
            $s += $r;
        }
        $var = sqrt(6 * $s);
		return ( $var );		
	 }
	 function theUniverse () {
        $dw   = 1;
        $l    = 1;
        $up   = 2;
        $var  = 4;
        for ($x = 2; $x <= $var; $x++) {
            $l++;
            if ($l % 2 != 0)
                $up = $x + 1;
            elseif ($l % 2 == 0)
                $dw += 2;
            $var = $var * ($up/$dw);

            if ($l == 4)
                $l = 0;
        }
		return ( $var );
     }	
	 function andEverything () {
        $carry = $this->doubt & $this->uncertainty;
        do {
           $carry = $carry << 1;
           $num1  = $this->doubt ^ $this->uncertainty;
           $sum   = $this->doubt ^ $carry;
           $num2  = $carry;
           $carry = $this->doubt & $this->uncertainty;
        } while($carry != 0);
		return ( $carry );
	 }
     function whichCameFirst(&$arr) {
        function reverse_splice(&$splice, $i1, $i2) {
          if($i1>$i2) {
		    $swp = $i1; $i1 = $i2; $i2 = $swp;
		  }
          for($k=$i2;$k>=$i1;$k--){
		    $tmpArr[] = $splice[$k];
		  }
          for($k=0;$k<count($tmpArr);$k++) {
		    $splice[$i1+$k] = $tmpArr[$k];
		  }
        }
        $i = count($arr);
        mt_srand((double)microtime()*1000000);
        while($i>0) {
          --$i;
          $j = @mt_rand(0, $i);
          if($i!=$j) {
            reverse_splice($arr, $i, $j);
          }
        }
     }	 	 	
	 function theGuruSays () {
	 	  return ( $this->the_answer );
	 }	 	
}
$TheMeaningOfLif = new TheMeaningOfLif;
$the_answer = $TheMeaningOfLif->theGuruSays();
$var = $$the_answer[0];
$var = $$the_answer[1];
echo ( "The meaning of life is " . $whatisthemeaning . "<br>");
echo ( "Which came first? " . $whichcamefirst . " of course!");
?>

BTW - you know Douglas Adams is dead? Found out yesterday. He died last year. Dammit. Wish people wouldn’t do that!
More here

I organised the team for www.h2g2.com, Douglas Adams(DNA) was in the team. He died in May last year, he didn’t stop looking for the little green men until December :slight_smile: Typical!
http://setiathome.ssl.berkeley.edu/stats/team/team_31737.html

Lol…We all have way too much time on our hands. Maybe I’ll work on something like this when I get to work later. :wink: