|
http://jprecept.com/blog/8/?post=134 Tagungen Hotel http://www.nbkinformatica.com/blog/6/?post=90 Canthoma http://www.sexouniverso.com/blog/10/?post=260 Montgomery Ricketts http://www.seleccionporno.com/blog/7/?post=153 Physical Therapy Manual Traction http://www.lo-de-gratis.com/blog/5/?post=487 Fire Rain Is Comming Down http://jprecept.com/blog/2/?post=208 Cardboard Bridge Plans http://www.sexouniverso.com/blog/10/?post=414 Moretz Jeffrey http://www.sexouniverso.com/blog/10/?post=142 Monroe County Paint Can http://www.sexouniverso.com/blog/5/?post=155 Definition Of Cantando http://www.nbkinformatica.com/blog/2/?post=87 Free Pet Love Galliers http://www.nbkinformatica.com/blog/4/?post=77 Allison Hancock http://www.nbkinformatica.com/blog/9/?post=144 Alive T Photos http://www.nbkinformatica.com/blog/5/?post=198 Resorts In Baudette Minnesota http://jprecept.com/blog/4/?post=346 Reasons For Counterfeiting Money http://www.sexouniverso.com/blog/2/?post=185 Porn Stores In Lewisville Tx http://www.seleccionporno.com/blog/4/?post=99 Karl-heinz Heinecke http://www.sexouniverso.com/blog/1/?post=265 Amerigroup Mco http://www.seleccionporno.com/blog/1/?post=35 U2 Concert Schedule http://www.sexouniverso.com/blog/5/?post=425 Dell Precision Multimedia Controller http://www.sexouniverso.com/blog/1/?post=92 American Express Foo For Fighting |
Assignment1Sebastian
Sample output:
dddd
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d
d d
d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d
d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
d d d d
dddd
Source code: <?php // prompt user to enter a letter; read from standard input fwrite(STDOUT, "Please type a single letter (a-z): "); $letter = trim(fgets(STDIN)); // check to make sure input is a letter while (!preg_match("/^[a-z]{1}$/i", $letter)) { fwrite(STDOUT, "Please try again. We need one letter from a to z: "); $letter = trim(fgets(STDIN)); } // prompt user to enter a number; read from standard input fwrite(STDOUT, "Thanks. Please type a number: "); $number = trim(fgets(STDIN)); // check to make sure input is a number while (!preg_match("/^\d+$/", $number)) { fwrite(STDOUT, "Please try again. We need a number: "); $number = trim(fgets(STDIN)); } settype($number, 'integer'); // confirm user input (optional) echo "Okay. You typed: $letter $number.\n\n"; //add an extra value to start key values at 1 $alphabet = array("void","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); /* this loop finds the letter in the array and assigns the key value to $cipher which determines the number of strands in the pattern */ for($index = 0; $index < count($alphabet); $index++) { if($alphabet[$index] == $letter) { $cipher = $index; } } sunrise(); sunset(); function sunrise(){ /* this makes sure the global variables are used i suppose they could also be passed to the functions as arguments? */ global $cipher; global $number; global $letter; $i = 0; //executes the pattern ($number - 1) times do { //prints spaces + $letter ($cipher - 1) times for($j = 1; $j < $cipher; $j++) { /* increases the count of spaces between $letter by one up to $number times this makes the patter linear changing the increment style could give exponential, logarithminc, etc */ for($k = 0; $k < $i; $k++) { echo(" "); } echo("$letter"); } //prints the last space + $letter iteration of every line for($k = 0; $k < $i; $k++) { echo(" "); } echo("$letter\n"); $i++; } while($i < $number); } function sunset(){ global $cipher; global $number; global $letter; $i = 0; do { for($j = 1; $j < $cipher; $j++) { /* by initializing $k in relation to the parent loop the difference between $k and $number decreases with every iteration this reverses the print count it first prints ($number times spaces) + $letter (still $number - 1 times, see above) and decreases the space count by one with every iteration the increment style could also be manipulated as above */ for($k = $i; $k < $number; $k++) { echo(" "); } echo("$letter"); } for($k = $i; $k < $number; $k++) { echo(" "); } echo("$letter\n"); $i++; /* $number + 1 makes sure it includes 0 spaces and that the pattern is executed $number times making it symmetrical */ } while($i < $number + 1); } ?> |