snippet challenge 2 : suggest words starting with TE..

Wow, snippet challenge 1, saw an array of entries everything from c to php, but a special callout to junkiedogg's entry in hold your breath... assembly :)

Keep them coming in, i'm suprised we hav' nt seen any functional programming language entry. ( will probably post my entry to snippet challenge 2 in erlang!)

With that, let's continue the fun exercise with our next snippet challenge....

Bosky, had a bunch of diwali crackers and too lazy to decide which once to burst first. So, he decided that he would only pick the starting letters of the one he wanted, and his program should take care of the rest.

Your misson:

To take an array [ "technology" , "tandoori", "techeclave", "challenge", "technotrance", "teach","te" ] . (add your own elements into this array if you wish to ) . Take a string in lowe case as input , and if you find that there are other words that begin with this string , then print those .

eg:

"c" -> challenge

"t" -> technology, tandoori, techenclave, technotrance, te

"tech" -> technology , techenclave, technotrance

"teche"-> techenclave

hack! 8 )
 
PHP:

Code:
<?php

function wordStartingWith($str)

{

    $arr = array("technology" , "tandoori", "techeclave", "challenge", "technotrance", "teach","te");

     $regex = '/^'.$str.'/';

     foreach($arr as $a)

     {

         if(preg_match($regex,$a))echo $a."\n";

     }

}

?>

This will fail if there are special characters that messes with the regular expressions.

Don't you just LOVE regular expressions??

Assembly? Yea .. maybe tomorrow :) .. now too sleepy.
 
Back
Top