AIAIYS

Young Engineering

Mutewatch - Good Vibrations

Tshirts for everyone!

Hi Norse Projects, Welcome onboard Y/S!

Bike By Y/S

WeSC + Y/S = <3

Frank Dandy Superweb

Go up
Go down
Updated: 19.01.12
Some of our Clients
Go up
Go down
Updated: 08.11.11
Twitter
Go up
Go down
Updated: 19.01.12
Calendar
Previous month
JAN 2012
sun
mon
tue
wed
thu
fri
sat
SEP OCT NOV DEC » JAN « FEB MAR APR MAY JUN
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
Next month
Updated: N/A
Documents
Go up
Go down
Updated: 02.07.10
14.12.11
Friday Challenge – Numbers without magic numbers

We tend to have something we call Friday Challenges at Y/S. It's basically a small hackathon with a specific goal and a reward of some sort. The fun thing with these challenges tend to be the discussions afterwards and while doing the code review you can clearly see the differences in approach. You can also earn extra points if you do something spectacular or easteregg-ish.

Last week we had the following task:

"Numbers without magic numbers
Create a function that returns our office number: 4687203333

Extreme: Not using any standard constants nor strings/numbers.
Hard: Only using standard-functions/constants.
Medium: Without using any strings nor numbers. Think outside the box...
Easy: Only using the number 1.

You can use Javascript, Python or PHP.

The function should be called get_office_number() and should return the value as a string.

Good luck."

And, here's the results and solutions that we came up with.

1. David went with the extreme solution not using any contants/numbers nor strings.

<?
function get_office_number(){
$one = pi()/pi();
$two = $one+$one;
$four = $two*$two;
$base = floor(getrandmax()*(pi()-$one));
$base += str_repeat(($four*$two), $two).str_repeat(($one-$one), (($four*$two)-$two));
$base += pow($four, ($four*$two) + ($one) ) / $two;
$base += pow($four, ($four*$two) ) / $two;
$base += (pow($four, ($four + $two)));
$base += (pow($four, ($four-$one))) * ($two+$one);
$base += ($two + $one);
return $base;
}
echo get_office_number();
die;

2. Frans went insane and created a jibberish version of combined constants ad infinitum. He motivated it with "but it's an oneliner!", not sure that counts though...

<?
function get_office_number() {
return (PHP_INT_MAX+PHP_INT_MAX+((((((PHP_INT_MAX-UPLOAD_ERR_PARTIAL)/PHP_MINOR_VERSION/PHP_MINOR_VERSION)-E_ERROR)/PHP_MINOR_VERSION)-E_ERROR)/PHP_MINOR_VERSION*UPLOAD_ERR_PARTIAL))-PHP_VERSION_ID*PHP_RELEASE_VERSION*PHP_MINOR_VERSION*PHP_RELEASE_VERSION-PHP_VERSION_ID-PHP_VERSION_ID-PHP_VERSION_ID-PHP_VERSION_ID-PHP_VERSION_ID-PHP_VERSION_ID-PHP_VERSION_ID-(PHP_VERSION_ID/PHP_MINOR_VERSION)+E_USER_NOTICE+E_USER_ERROR+E_COMPILE_WARNING+E_CORE_WARNING-E_PARSE-UPLOAD_ERR_PARTIAL;
}
echo get_office_number();

3. Fredrik did a HAXX0R version. I think the code says it all...or does it?

<?
function get_office_number(){
$hax=@hax; $__=ord($hax)-ord($hax);
@$_[]=(@${__}); $__=((++$__)+$__++); $_[]=@${__}; $___=$__/$__;
$_[++$_[$___]]=$_[$___]+(($___<<$___<<$___)-($___<<$___)-$___); $_[$_[($_[($___<<$___<<$___)-$___]/($___<<$___<<$___))]]=@${__};
$_[$_[$___/$___]*$_[($___<<$___)+$___]]=--$__; $_[$_[(@${__})]+$__]=(count(@${_})); $_[$_[(@${__})]+(++$__)]=(((--$__)<<($__<<$__<<$__))/((@${__})+$__));
return ($_[($___<<$___<<$___)].($_[($___<<$___<<$___)+@${__}]-(++$__)).($_[($__<<$__)>>$___]*($___<<$___)).(($__<<$__<<$__>>($___<<$___))-(--$__)).($___<<$___).(--$__).str_repeat($_[($__++)+$___],$___<<($___<<$___)));
}
echo get_office_number();

4. Mathias did a bit shifting scenario, but actually failed, since he missed the last digit in our office number :<

<?
//IF not running >5.3
#define ('PHP_ROUND_HALF_UP', 1);
#define ('PHP_ROUND_HALF_DOWN', 2);
#define ('PHP_ROUND_HALF_EVEN', 3);
#define ('PHP_ROUND_HALF_ODD', 4);
function get_office_number(){
return ((PHP_ROUND_HALF_UP<<(((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP) * PHP_ROUND_HALF_ODD)+(PHP_ROUND_HALF_ODD * PHP_ROUND_HALF_DOWN)))^(PHP_ROUND_HALF_UP<<(((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP)+PHP_ROUND_HALF_ODD) * PHP_ROUND_HALF_EVEN))^(PHP_ROUND_HALF_UP<<((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP) * (PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP)))^(PHP_ROUND_HALF_UP<<((PHP_ROUND_HALF_DOWN * PHP_ROUND_HALF_EVEN) * PHP_ROUND_HALF_ODD))^(PHP_ROUND_HALF_UP<<(((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP) * PHP_ROUND_HALF_ODD) + PHP_ROUND_HALF_EVEN))^(PHP_ROUND_HALF_UP<<(((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP) * PHP_ROUND_HALF_ODD) + PHP_ROUND_HALF_DOWN))^(PHP_ROUND_HALF_UP<<((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_EVEN) * PHP_ROUND_HALF_EVEN))^(PHP_ROUND_HALF_UP<<((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP) * PHP_ROUND_HALF_ODD))^(PHP_ROUND_HALF_UP<<(PHP_ROUND_HALF_ODD * PHP_ROUND_HALF_EVEN))^(PHP_ROUND_HALF_UP<<((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP) + (PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP) + PHP_ROUND_HALF_UP))^(PHP_ROUND_HALF_UP<<((PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_UP)+PHP_ROUND_HALF_ODD))^(PHP_ROUND_HALF_UP<<(PHP_ROUND_HALF_ODD + PHP_ROUND_HALF_EVEN))^(PHP_ROUND_HALF_UP<<(PHP_ROUND_HALF_DOWN * PHP_ROUND_HALF_EVEN))^(PHP_ROUND_HALF_UP< }
echo get_office_number();

He also made an easteregg. If you count the characters in the function, it's 1337... nice one!

5. Richard/Desmond did a coder's collab. They followed the rules but the code required you to create a file named as the number you wanted as the output. Smallest amount of code, but required extra effort!
Place a file named '4687203333' inside the the same directory as the file below.

<?php echo get_office_number(); function get_office_number(){ $arr=scandir(getcwd()); array_shift($arr); array_shift($arr); $arr2=array_shift($arr); return $arr2; }

Together we announced Fredrik as the winner of the challenge. Congrats Fredrik!

Levi Print
Updated: 14.12.11RSS +