TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-05-2010, 05:13 PM   #1 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default 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

Last edited by Arictos : 07-05-2010 at 05:44 PM.
Arictos is offline  
Reply With Quote
Old 07-05-2010, 06:03 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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) ;
?>
__________________

Village Idiot is offline  
Reply With Quote
Old 07-05-2010, 06:05 PM   #3 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default

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

But regardless, it was a great submission.
Arictos is offline  
Reply With Quote
Old 07-05-2010, 06:10 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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.
__________________

Village Idiot is offline  
Reply With Quote
Old 07-05-2010, 07:39 PM   #5 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default

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.
Arictos is offline  
Reply With Quote
Old 07-05-2010, 10:38 PM   #6 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

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
tony is offline  
Reply With Quote
Old 07-06-2010, 05:10 AM   #7 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default

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 :)
Arictos is offline  
Reply With Quote
Old 07-06-2010, 08:51 PM   #8 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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;);   
                                                                     
                                                                     
?>
Salathe is offline  
Reply With Quote
Old 07-07-2010, 02:46 AM   #9 (permalink)
The Wanderer
 
Join Date: Jul 2010
Posts: 17
Thanks: 0
Arictos is on a distinguished road
Default

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

But it looks fancy ;P
Arictos is offline  
Reply With Quote
Old 07-07-2010, 03:40 PM   #10 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

awesome salathe, that is a great presentation.
tony is offline  
Reply With Quote
Old 07-07-2010, 07:01 PM   #11 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Arictos View Post
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);
Salathe is offline  
Reply With Quote
Old 07-15-2010, 11:00 PM   #12 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

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']++);
    }

__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-16-2010, 01:49 AM   #13 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

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.
__________________
My Blog

Last edited by Enfernikus : 07-17-2010 at 03:42 PM.
Enfernikus is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
The most inventive way to switch 2 values Wildhoney Tips & Tricks 32 08-10-2010 05:10 AM
How to get row number from 2 top numberd rows ttmtake General 5 01-28-2009 11:16 PM
Sorting number reversed problem... Peuplarchie General 2 01-21-2009 08:04 PM
Unique random number? code_junkie Advanced PHP Programming 4 12-21-2008 12:01 AM
how to get the rows affected(not number of rows) kororo203 Absolute Beginners 2 04-23-2008 08:32 AM


All times are GMT. The time now is 01:23 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design