TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Tips & Tricks (http://www.talkphp.com/tips-tricks/)
-   -   The most inventive way to get the number 8 (http://www.talkphp.com/tips-tricks/5477-most-inventive-way-get-number-8-a.html)

Arictos 07-05-2010 05:13 PM

The most inventive way to get the number 8
 
So, the other thread had a bit of fun behind it, so I figured maybe try starting another, similar thread? This one will be based around getting the number 8.

I'll follow the same structure from the other thread.

This would be the simplest method to get this answer, however be sure to read the rules!
PHP Code:

echo 3

As before, don't attempt the simplest method possible, but most inventive! See what you can come up with.
  1. eval and create_function functions are disallowed.
  2. 8 lines maximum but lines with only { and } on do not count towards that total. This does not include any echoes of the value.
  3. You must have only one semi-colon per line (;) unless of course it's used elsewhere apart from indicating the end of a line. Thus you're not allowed to fuse 2 lines together into 1. The exception is a for loop to where you're allowed 2.
  4. If PHP is going to store an integer in a variable (which I assume a lot of situations will) PHP will have to discover that number. An exception to this rule is the for loops first and last expressions. (Added this rule to make things a bit more entertaining)
  5. No PHP errors may be displayed. This includes Notices, Warnings, anything. error_reporting(-1); The only thing that can output is the number 8.
So however you end up doing it, the code must output the number 8.

I'll start off with two examples to show the diversity in which rules can be followed, although i'm sure many people will come up with their own interpretations!

PHP Code:

$var 'I\'m the cookie monster!';
$var strpos($var"cookie");

echo 
$var

PHP Code:

$string 'aardvark';
$count = (int) false;
for(
$i 0$i strlen($string); $i++)
$count++;

echo 
$count


Village Idiot 07-05-2010 06:03 PM

Assuming our file is this

PHP Code:

 <?php 
 $image 
'myfile.jpg';
 
$degrees 90;
 
header('Content-type: image/jpeg') ;
 
$source imagecreatefromjpeg($image) ;
 
$rotate imagerotate($source$degrees0) ;
 
imagejpeg($rotate) ;
?>


Arictos 07-05-2010 06:05 PM

Lol, that's just awesome, but it did break a rule ;) You defined degrees as a number ;)

But regardless, it was a great submission.

Village Idiot 07-05-2010 06:10 PM

Whoops, I'll fix that

Here we go:
Assuming our file is this

PHP Code:

  <?php 
 $image 
'myfile.jpg';
 
$degrees intval('90');
 
header('Content-type: image/jpeg') ;
 
$source imagecreatefromjpeg($image) ;
 
$rotate imagerotate($source$degrees0) ;
 
imagejpeg($rotate) ;
?>

ps. If you think that is a cheap way, my next alternitave would be to add 9 int typecast trues together.

Arictos 07-05-2010 07:39 PM

I don't think that's a cheap way at all x] You didn't directly assign the value, which is completely valid according to the original rules :)

But that being said, hopefully we can see some pretty crazy ways to get the numbers :)

I still like your idea though, it was very creative.

tony 07-05-2010 10:38 PM

I think I might have done some cheating, but this is my take.
php Code:
<?php
$val = substr(pi()."", ((int) false), intval('4'));
$val = str_split(implode("", explode(".", $val)));
$val = array_reduce($val, function ($x, $y) { return intval($x) + intval($y); });
echo $val;
?>
this is using php 5.3 of course

Arictos 07-06-2010 05:10 AM

You did awesome :) But you don't have to intval your $var's, they're already being interpreted by PHP. I'm excited to see what other methods, other than intval people can come up with :)

Salathe 07-06-2010 08:51 PM

I got bored.

PHP Code:

<?php
                                                                     
                                                                     
    
for(        $PHP      =FUNCTION(     $A,$AA){$Y     ="CHR";$XX   
      
=$A      .${           "AA"           };$N           =ord      
       
(${    "X"            ."X"           }[$A           [1]]      
        +
4-  +4)             ;$Z=           0x08           +$N;      
       return
$Y($Z        );},print(     $PHP (":)"     ,+8));0;);   
                                                                     
                                                                     
?>


Arictos 07-07-2010 02:46 AM

I don't want even to begin to understand what's going on.

But it looks fancy ;P

tony 07-07-2010 03:40 PM

awesome salathe, that is a great presentation.

Salathe 07-07-2010 07:01 PM

Quote:

Originally Posted by Arictos (Post 30778)
I don't want even to begin to understand what's going on.

What it's actually doing is very simple, it is just presented in an obfuscated way to get the VIII. Here's what it really does: print chr(56); :-)

adamdecaf 07-15-2010 11:00 PM

PHP Code:

if ($_GET['count'] == 8) {
   echo 
$_GET['count'];
} else {
    if (
$_GET['count'] > 8) {
       
header("Location: index.php?count=0");
    } else {
       
header("Location: index.php?count=" $_GET['count']++);
    }



Enfernikus 07-16-2010 01:49 AM

php Code:
$string = 'TalkPHP';
echo chr(str_replace(strlen($string), null, array_sum(array_map('ord', str_split(strtolower($string), (string)pow(pi(), pi() - pi()))))));

If you know your ASCII talkphp => 116 + 97 + 108 + 107 + 112 + 104 + 112 => 756, Drop the 7 and you have 56. 8's ascii code.


All times are GMT. The time now is 08:51 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0