"Hexadecimal Numbers"
In computers, everything is represented in 1s and 0s which is called a binary number.
There are numerous ways of representing any regular (decimal) number. One of those ways is called hexadecimal representation. This system uses the digits 0 thru 9 in addition to the letters A B C D E F (which represent 10 thru 15 respectively).
Given an input file of 500 decimal numbers (decimalsB.txt), how many times IN TOTAL does the letter D appear when each number is converted into hexadecimal format?
Note: This is NOT the same file as Problem 20.
The same as challenge 20 except this time convert to hex and remove everything that isn't D.
Awnser:
= 0
Source:
include(MISC.'fn.fetch.php'); function solution(){ $result = 0; $list = fetch('http://www.cstutoringcenter.com/problems/files/decimalsB.txt'); $lines = explode("\n", $list); foreach($lines as $decno) { // convert decimal to hex and remove everything except D $hexno = preg_replace('/[^D\-\._]/si' , '' , dechex($decno)); $result += strlen($hexno); // length of $hexno = no of D's } echo "= ".$result.""; }