-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday8.php
More file actions
executable file
·61 lines (45 loc) · 1.66 KB
/
day8.php
File metadata and controls
executable file
·61 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
ini_set("memory_limit","256M");
$inputFile = fopen("input8.txt",'r');
function tokenizeString($string){
$string = str_replace('\"', '+', $string);
$string = str_replace('\\\\', '-', $string);
$matches = array();
preg_match_all("/\\\x[0-9a-fA-F]{2}/", $string, $matches);
// var_dump($matches);
foreach ($matches[0] as $match) {
// $replace = str_replace('\\', '0', $match);
// var_dump($replace);
$string =str_replace($match, '*', $string);
}
return $string;
}
function encodeString($string) {
$string = str_replace('"', '++', $string);
$string = str_replace('\\', '--', $string);
return '"'.$string.'"';
}
// $s = '\\x15sa\\';
// $s = trim(fgets($inputFile));
// var_dump($s);
// var_dump(tokenizeString($s));
// exit;
$numberOfChars = 0;
$numberOfCharsInMemory = 0;
$numberOfencodedChars = 0;
while ($row = trim(fgets($inputFile))) {
// var_dump($row);
$tokenizedString = tokenizeString($row);
// var_dump($tokenizedString);
$encodedString = encodeString($row);
// var_dump($encodedString);
$numberOfChars = $numberOfChars + strlen($row);
$numberOfCharsInMemory = $numberOfCharsInMemory + strlen($tokenizedString) - 2;
$numberOfencodedChars = $numberOfencodedChars + strlen($encodedString);
}
var_dump('numberOfChars: ' . $numberOfChars);
var_dump('numberOfCharsInMemory: ' . $numberOfCharsInMemory);
var_dump('numberOfChars - numberOfCharsInMemory: ' . ($numberOfChars - $numberOfCharsInMemory));
var_dump('numberOfencodedChars: '. $numberOfencodedChars);
var_dump('numberOfencodedChars - numberOfChars: ' . ($numberOfencodedChars - $numberOfChars));
fclose($inputFile);