Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 875 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

PHP Programming Challenge of the Day #1

Thread title: PHP Programming Challenge of the Day #1
Reply    
    Thread tools Search this thread Display Modes  
08-23-2011, 02:46 PM
#1
Arictos is offline Arictos
Status: Junior Member
Join date: Jan 2006
Location: Salt Lake City
Expertise:
Software:
 
Posts: 60
iTrader: 0 / 0%
 

Arictos is on a distinguished road

Send a message via AIM to Arictos Send a message via MSN to Arictos

  Old  PHP Programming Challenge of the Day #1

This is something that I find quite enjoyable that we do at work, it keeps us sharp :P See how you fair?

http://pastecode.com/1RC

We use the "Reply" button on PasteCode, and then paste it out to everyone at our work with our solutions at the end of the day.

08-23-2011, 04:55 PM
#2
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Pretty simple, replied.

edit: it seems to have gotten deleted from the paste so here it is
PHP Code:
<?
$a 
'Raphael';
$b 'Castiel';

echo 
"start $a $b <br />";

$a .= $b;
$b=substr($a,0,(strlen($a)-strlen($b)));
$a=substr($a,strlen($b));
echo 
"end $a $b <br />";
?>
This solution will work with any two strings regardless of length.

I'm interested in continuing with this so if you'd continue to post them that would be great. I'd also be happy to contribute if you want.

08-24-2011, 03:38 AM
#3
.Nick is offline .Nick
.Nick's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 1,159
iTrader: 3 / 100%
 

.Nick is on a distinguished road

  Old

PHP Code:
list($a$b) = array($b$a); 
Edit:

Originally Posted by Village Genius View Post
PHP Code:
<?
$a 
'Raphael';
$b 'Castiel';

echo 
"start $a $b <br />";

$a .= $b;
$b=substr($a,0,(strlen($a)-strlen($b)));
$a=substr($a,strlen($b));
echo 
"end $a $b <br />";
?>
In case anyone is interested, it occurred to me today that this is more or less an XOR swap.

08-25-2011, 08:13 PM
#4
Arictos is offline Arictos
Status: Junior Member
Join date: Jan 2006
Location: Salt Lake City
Expertise:
Software:
 
Posts: 60
iTrader: 0 / 0%
 

Arictos is on a distinguished road

Send a message via AIM to Arictos Send a message via MSN to Arictos

  Old

PasteCode doesn't modify the origional, but rather it gives you a new one :P

Good stuff so far though

Something one of my friends replied that isn't on this forum is:
http://pastecode.com/1eL

Reply With Quote
08-25-2011, 08:50 PM
#5
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Originally Posted by Arictos View Post
PasteCode doesn't modify the origional, but rather it gives you a new one :P

Good stuff so far though

Something one of my friends replied that isn't on this forum is:
http://pastecode.com/1eL
That method would run into issues if the string itself has a ~ in it. That isn't really part of the challenge though.

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed