From 7a6f5de4b2748e8297dc214ab7eb09476d0fd198 Mon Sep 17 00:00:00 2001 From: Grant Regimbal Date: Wed, 23 Jul 2014 18:32:11 -0700 Subject: [PATCH 1/4] finished strpos --- challenges/strpos/strpos.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/challenges/strpos/strpos.php b/challenges/strpos/strpos.php index 0a4a756..fd7b640 100755 --- a/challenges/strpos/strpos.php +++ b/challenges/strpos/strpos.php @@ -1,8 +1,28 @@ Date: Wed, 23 Jul 2014 19:25:36 -0700 Subject: [PATCH 2/4] THE-BOX --- challenges/THE BOX/index.html | 17 +++++++++++ challenges/THE BOX/style.css | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 challenges/THE BOX/index.html create mode 100644 challenges/THE BOX/style.css diff --git a/challenges/THE BOX/index.html b/challenges/THE BOX/index.html new file mode 100644 index 0000000..e132ce0 --- /dev/null +++ b/challenges/THE BOX/index.html @@ -0,0 +1,17 @@ + + + + THE BOX + + + +
+
+
+
+
+
+
+ + + diff --git a/challenges/THE BOX/style.css b/challenges/THE BOX/style.css new file mode 100644 index 0000000..adc4c58 --- /dev/null +++ b/challenges/THE BOX/style.css @@ -0,0 +1,56 @@ +div { + position: absolute; +} + +#orange { + background-color: #F1AB3c; + width: 400px; + height: 400px; + left: 160px; + top: 10px; +} + +#dark_green { + background-color: #68884b; + width: 140px; + height: 190px; + top: 10px; +} + +#light_green { + background-color: #7fBB4d; + width: 140px; + height: 190px; + top: 220px; +} + +#dark_blue { + background-color: #2669A4; + width: 290px; + height: 90px; + top: 420px; +} + +#medium_dark_blue { + background-color: #4994DC; + width: 90px; + height: 90px; + left: 310px; + top: 420px; +} + +#medium_light_blue { + background-color: #87BFF4; + width: 150px; + height: 40px; + top: 420px; + left: 410px; +} + +#light_blue { + background-color: #B6DBFE; + width: 150px; + height: 40px; + top: 470px; + left: 410px; +} \ No newline at end of file From b9838fe94b2d39837eb195880eb55be4b2e703de Mon Sep 17 00:00:00 2001 From: Grant Regimbal Date: Mon, 28 Jul 2014 08:01:07 -0700 Subject: [PATCH 3/4] code comprehension --- challenges/comprehension/explanation.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/challenges/comprehension/explanation.txt b/challenges/comprehension/explanation.txt index e69de29..7d39bdc 100755 --- a/challenges/comprehension/explanation.txt +++ b/challenges/comprehension/explanation.txt @@ -0,0 +1,13 @@ + +@ defines an array or list or something of that nature + +% defines a variable + +$ defines an array or something + +The while loop takes a line from a text file and splits it by " " into an array. +Then the for each takes a chunk from that array and checks if it matches some string or regexp ( I have never used regexp's). If a match exists it then puts the chunk into an array or stack called storage. If a match does not exist it just shoves it into the second slot in the array assuming it starts at 0. + +The for each at the bottom prints the index and chunk from the array in storage with some pretty printing. + + From 98553cb5359c1561c25a14ef8351c15e554693a1 Mon Sep 17 00:00:00 2001 From: Grant Regimbal Date: Mon, 28 Jul 2014 11:33:42 -0700 Subject: [PATCH 4/4] fixed problem with multiple charachters false postives --- challenges/strpos/strpos.php | 49 ++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/challenges/strpos/strpos.php b/challenges/strpos/strpos.php index fd7b640..a236fa9 100755 --- a/challenges/strpos/strpos.php +++ b/challenges/strpos/strpos.php @@ -2,27 +2,46 @@ function my_strpos($whole_string, $chunk_string, $position_check=false) { - $chunk_string_char = str_split($chunk_string)[0]; + $chunk_string_char_array = str_split($chunk_string); $whole_string_array = str_split($whole_string); - if ($position_check != false) { - if ($chunk_string_char == $whole_string_array[$position_check]) { + if ($position_check !== false) { // This works and checks out + if ($chunk_string_char_array[0] == $whole_string_array[$position_check]) { return true; } - return false; } + $count = count($chunk_string_char_array); $array_position = 0; - foreach ($whole_string_array as $character) { - if ($character == $chunk_string_char) { - return $array_position; - } - $array_position = $array_position + 1; - } - return false; + $whole_position = 0; + + foreach ($whole_string_array as $character) { //Go through the alphabet + if ($character == $chunk_string_char_array[0]) { //Check the first character + + if ($count > 1) { // If array is larger than one char + $whole_peek = 1; + $still_matching = true; + + for ($chunk_index=1; $chunk_index < $count && $array_position + $whole_peek < count($whole_string_array); $chunk_index++,$whole_peek++) { + if ($chunk_string_char_array[$chunk_index] != $whole_string_array[$array_position + $whole_peek]) { + $still_matching = false; + continue; + } + } + if ($still_matching) { + return $array_position; + } + } else { + return $array_position; + } + } + $array_position++; + $whole_position++; + } + return false; } $alphabet = 'abcdefghijklmnopqrstuvwxyz'; @@ -33,10 +52,14 @@ function my_strpos($whole_string, $chunk_string, $position_check=false) # Should print "6" print(my_strpos($alphabet, 'ghi') . "\n"); +print(my_strpos($alphabet, 'gh!') . "\n"); +print(my_strpos($alphabet, 'g!i') . "\n"); + +var_dump(my_strpos($alphabet, 'a', 0)); + + # Should print "bool(false)" var_dump(my_strpos($alphabet, 'u', 22)); # Should print "bool(false)" var_dump(my_strpos($alphabet, 'A')); - -