You looked!
![]()
Your question Mr anode
Sean![]()
| SitePoint Sponsor |
You looked!
![]()
Your question Mr anode
Sean![]()
Harry Potter
-- You lived inside my world so softly
-- Protected only by the kindness of your nature





I didn't, it popped up on one of the PHP sites' RSS feeds earlier today and I took note.
Ok...
Turn this array:
Apple =>Jobs
Microsoft =>Gates
Oracle => Ellison
Sun => McNealy
into this one
ylaencm => nus
nosille =>elcaro
setag => tfosorcim
sboj => elppa
Using the least lines of code possible
TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure
nah! I am PHP.![]()
SeanPHP Code:<?php
$firstArr = array ( 'Apple' => 'Jobs', 'Microsoft' => 'Gates', 'Oracle' => 'Ellison', 'Sun' => 'McNealy');
$firstArr = array_flip ( array_reverse ( $firstArr ) );
foreach ( $firstArr as $key => $val ) {
$key = strrev ( strtolower ( $key ) );
$secondArr[$key] = strrev ( strtolower ( $val ) );
}
?>![]()
Harry Potter
-- You lived inside my world so softly
-- Protected only by the kindness of your nature





I think it may be able to be just a bit shorter(I'm specifically thinking of all the Lisp-like array functions), but I'll accept that.
TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure
Did you come up with a way to do it? I'm sure it could be shorter
Anybody want to ask a question?
Sean![]()
Harry Potter
-- You lived inside my world so softly
-- Protected only by the kindness of your nature





When I have my coffee I will. I forget the specifics of working with array_map and friends, but I had a rough plan of how I'd do it when I came up with the question.
TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure
You said shortest number of lines right?PHP Code:$array = array_change_key_case(array_reverse(array_flip(array('Apple' => 'Jobs', 'Microsoft' => 'Gates', 'Oracle' => 'Ellison', 'Sun' => 'McNealy'))), CASE_LOWER);
foreach ($array as $key => $content) $new_array[strrev($key)] = strtolower(strrev($content));
![]()
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.





Now that you mention itOriginally Posted by cyborg from dh
PHP Code:foreach ((array_change_key_case(array_reverse(array_flip(array('Apple' => 'Jobs', 'Microsoft' => 'Gates', 'Oracle' => 'Ellison', 'Sun' => 'McNealy'))), CASE_LOWER)) as $key => $content) $new_array[strrev($key)] = strtolower(strrev($content));
In your face, Perl!
TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure
damn you!![]()
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
there. [img]images/smilies/tongue.gif[/img]PHP Code:foreach(array_reverse(array_flip(array('Apple'=>'Jobs','Microsoft'=>'Gates','Oracle'=>'Ellison','Sun'=>'McNealy')))as$k=>$c)$n[strtolower(strrev($k))]=strtolower(strrev($c));
Last edited by cyborg from dh; May 29, 2003 at 11:06.
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
Let's have a question from someone
Sean![]()
Harry Potter
-- You lived inside my world so softly
-- Protected only by the kindness of your nature
What's the output?PHP Code:define('C', 'f');
define('S' . strtoupper(str_rot13(C)), 'c', 0);
$d = '2.';
$q = 'S';
list ($x, $y) = array('p', 'gg');
$b = substr(str_rot13('a'.$x.'xy'.$y), 1, -4);
$c = ($e = 'a') . (25 / 2) . ($f = 22 | 45);
${'a1'.${((${'h'} = SS) ? ++$h : 0)}.'5'.(($g = 126 / 5) + ($g * 1.5))} = (float) ($d . ($f * 1.9047619047619));
$a = ${${$b}};
ob_start();
var_dump(${$e});
eval('${S'.$q.'} = substr(strrchr(ob_get_contents(), substr(\'(\',0)), 1, -(int) substr($c, 2, -2)) . round(floor($$b));');
ob_end_clean();
echo $$b;
Last edited by cyborg from dh; Jun 19, 2003 at 16:26.
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.





Oh, man... so tempting to simply run code... but I can resist. :-)
Good one, cyborg! Either really evil or there's a trick to it, I'm banking on the later as the former would require doing str_rot13 conversions by hand.
Man, I had never even heard of str_rot13 before. That's a wacky function.
Ok, I've stared at this for about five minutes, and I'm not coming up with a trick to it. Hopefully someone else is more devious than I. :-)
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?





Sam, do it on paper.
TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure





But wouldn't that be kind of like just running the script?
If I follow the documentation and do it by hand it'll essentially just execute like PHP would do it... only much much much slower.
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?





Sure, but it's a learning experience, as opposed to running it.Originally Posted by samsm
Personally, I got tripped up by the bitwise stuff and gave up. I'll try it if I ever read more Knuth![]()
TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure
There's no trick to it, I started out with a basic thing, and kept adding more and more stuff.
The bitwise thing is about the hardest part.
(Thought I'd revive this thread with something more difficult [img]images/smilies/wink.gif[/img], oh yeah, and doing it on paper's not cheating, you are still figuring it out, and the PHP Parser's not.)
Last edited by cyborg from dh; Jun 19, 2003 at 22:14.
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
I'll give you hint on what the value of the bitwise equation: It's half of double 6.3, that's all i'll say.
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.





Oh well, the lazy part of me was hoping that there was some part at the end that made most of the equation irrelevant.
Whoever gets this needs to show a proof to demonstrate that they did this by hand. :-)
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
bump. somebody's gotta do it....
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.





Crap. Ok, the whole thing is a bit daunting but none of the steps are THAT bad.
How about this. Each of use will simplify it one step and post the result and perhaps a brief rationalization for that simplification. We'll continue until it's solved.
I'll begin.
(Used this as help with the bitwise stuff)
There. Hope errors didn't slip in, as humans are prone to that sort of thing. I'm done for the evening as far as this thing is concerned, someone else pitch in a little and I'll get rid of a few more lines. :-)PHP Code:define('C', 'f');
define('SPc', 0);
$d = '2.';
$q = 'S';
$x = 'p';
$y = 'gg';
$b = 'c';
// $c = '1' . (25 / 2) . ($f = 22 | 45);
/*
22 / 2 == 11 r 0
11 / 2 == 5 r 1
5 / 2 == 2 r 1
2 / 2 == 1 r 0
1 / 2 == 0 r 1
10110 = 22
*/
/*
45 / 2 == 22 r 1
22 / 2 == 11 r 0
11 / 2 == 5 r 1
5 / 2 == 2 r 1
2 / 2 == 1 r 0
1 / 2 == 0 r 1
101101 = 45
*/
/*
bitwise or:
10110
101101
------
111111
1+2+4+8+16+32 == 63
so...
$c = '1' . 12.5 . 63;
so...
*/
$c = 112.563;
${'a1'.${((${'h'} = SS) ? ++$h : 0)}.'5'.(($g = 126 / 5) + ($g * 1.5))} = (float) ($d . ($f * 1.9047619047619));
$a = ${${$b}};
ob_start();
var_dump(${$e});
eval('${S'.$q.'} = substr(strrchr(ob_get_contents(), substr(\'(\',0)), 1, -(int) substr($c, 2, -2)) . round(floor($$b));');
ob_end_clean();
echo $$b;
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
the second define should be
You made another obvious mistake, however you've simplified it so much i'm not sure why you stopped, being so close and all....PHP Code:define('SS', 'c', 0);
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.

cyborg: I found the answer after quite a bit of work, but I got the wrong answer at first (I checked). After that I did manage to get the right result, but since I'd already seen the correct answer, it feels a bit like cheating.Originally Posted by cyborg from dh
![]()
I can post a complete solution if it's ok with everyone though.![]()
Please do. I would be interested in seeing it!Originally Posted by Azmo
![]()
ssegraves [at] gmail.com
On Image Use, Abuse, and Where We're Headed
stephan | XMLHttpRequest Basics
flickr | last.fm | Cogentas, LLC
Bookmarks