Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = <<<END
- 416 12 4
- So Isaac dwelt in Gerar and the men of the place asked him
- of his wife and he said, "She is my sister," for he feared to say
- "She is my wife", lest, said he, "the men of the place
- should kill me for Rebekah because she was fair to look upon"
- and it came to pass when he had been there a long time that Abimelech,
- king of the Philistines, looked out at a window and saw, and, behold,
- Isaac was sporting with Rebekah his wife and Abimelech called Isaac
- and said, "Behold of a surety she is thy wife and how saidst thou
- 'she is my sister'?" and Isaac said unto him, "Because, I said, lest I
- die for her."
- Genesis 26:6-9. King James version.
- END;
- $input = explode("\n", $input);
- $input_2 = explode(" ", array_shift($input)); //offset, cycle (distance), length
- $input = implode("\n", $input); //return to long string
- $input = str_split($input);
- $letters = array('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');
- $axed_string = str_replace($letters, '', strtolower(implode($input)));
- $axed_characters = str_split($axed_string);
- $new_input = str_replace($axed_characters, '', $input);
- //I'm going to do this the stupid way
- if($input_2[1] < 0){
- //going to have to work the other way
- $count = count($input);
- $disp_count = 0;
- $char_count = count($new_input);
- $str_out = null;
- while($count > 0){
- $current = $input[$count];
- $echoed = false;
- if(in_array(strtolower($current), $letters)){
- //current is a letter
- if(($char_count-$input_2[0]-1)%abs($input_2[1]) == 0 && $disp_count < $input_2[2] && $char_count < $input_2[0]+2){
- //display character with [] and add the character to the output string
- $disp_count++;
- $output[] = $current;
- $str_out[] = "[".$current."]";
- $echoed = true;
- }
- $char_count--;
- }
- if(!$echoed){
- $str_out[] = $current;
- }
- $count--;
- }
- $str_out = implode(array_reverse($str_out));
- $output = implode(array_reverse($output));
- echo $str_out;
- }else{
- $count = 0;
- $disp_count = 0;
- $char_count = 0;
- while($count < count($input)){
- $current = $input[$count];
- $echoed = false;
- if(in_array(strtolower($current), $letters)){
- //current is a letter
- if(($char_count-$input_2[0]+1)%abs($input_2[1]) == 0 && $disp_count < $input_2[2] && $char_count > $input_2[0]-2){
- //display character with [] and add the character to the output string
- $disp_count++;
- $output .= $current;
- echo "[".$current."]";
- $echoed = true;
- }
- $char_count++;
- }
- if(!$echoed){
- echo $current;
- }
- $count++;
- }
- }
- echo "\n\n$output";
Advertisement
Add Comment
Please, Sign In to add comment