![]() |
The most inventive way to switch 2 values
OK! A little game for you all :-)
The only objective is to switch the values of $a and $b. The values of $a and $b are 1 and 2, respectively:php Code:
So for example this is an easy way to do it: php Code:
However! We're not looking for the simplest way to do it, or the fastest, but rather, the most inventive way to do it! There are a couple of rules and those are:
So basically $a must equal 2 and $b must equal 1 at the end of your code.I'll start us off: Put that mind to work! Oh, and just for Karl, you can't just set $a to 2 and $b to 1 ;-) You have to reference the first 2 variables set! |
PHP Code:
|
Lol at the last one :-) Very confusing!
|
ok, turns out I should have fully read the first post before I started on this - I completely missed the 8-lines rule until now *!*
As such, the code below isn't my entry - I'll be off to make an 8-line entry now - but since I wrote it, might as well post it :D I decided to use the Google Spreadsheet service to swap the values over (using the Zend Framework GData library) This code requires you have a valid google account, a spreadsheet created with the same name as $spreadsheet in the code and the Zend Framework installed in /library. PHP Code:
Alan |
Lol! Man, you're crazy :-) ! That's why I made the 8 line rule. To stop people wasting so much time on something like this.
|
Ok, my new attempt - using bitwise operators to swap the values about:
PHP Code:
|
Quote:
Alan |
Disclaimer: I hold no responsibility for any physical or mental injury to yourself or those in your immediate vicinity caused as a direct result of looking at my method of swapping the variables' values. You have been warned. :-P
PHP Code:
|
I made this...then read the rules, I broke the majority of the rules
PHP Code:
(I know, nearly everything there is useless) |
Wow, that's insane Salathe :D Followed the code about halfway through then I'm fairly certain I blacked out :D
Another way to do it (if in doubt, use a database!): PHP Code:
|
I'm fairly certain this thread will be counter-productive to all those who have started to learn PHP
fun non the less though |
Quote:
I'm not even going to attempt to read that haha |
Quote:
Quote:
Some really nice entries thus far, a couple that were to be expected but definitely lateral thinking being shown in others, great work. I'm looking forward to seeing more weird and wonderful approaches being used. :-) |
Quote:
|
A new one that conforms to the rules and such
I decided to follow Salath's setence bit. (btw..alot of this math is utterly useless) (and yes...it's hard to read) PHP Code:
|
list,array
Quote:
|
Quote:
|
What the hell TlcAndres. That's complete gibberish to me. :-P Maybe if I could format better, I could get a better context but I am sure it works. You're a real guru then it comes to that, aren't you? Hehe.
I have no idea how to do it, since Wildhoney already posted my initial thoughts for the script. That'll be; PHP Code:
|
Hope this makes it easier to understand the math - I think it only works for the year 2k7 though, hmm I could make it work for 2k8 though.
PHP Code:
--Edit nvm - it's 2k8 compliant going to make it work when ever though |
ok here is my code: :)
PHP Code:
|
| All times are GMT. The time now is 07:22 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0