Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php
  2. // get the base frequency
  3. $startingFrequency = 0;
  4.  
  5. // get the contents given by the advent_of_code website
  6. $fContents = file_get_contents("external_contents/day_1.txt");
  7.  
  8. // loop through each line of the contents (delimit by new line)
  9. foreach((array) explode(PHP_EOL, $fContents) as $number) {
  10.     // make sure the number is numeric
  11.     if(is_numeric($number)) {
  12.         // add the number to the starting frequency
  13.         $startingFrequency += $number;
  14.     }
  15. }
  16.  
  17. // return the end result
  18. echo "End result: " . $startingFrequency;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement