Skip to content

Commit dbdafb5

Browse files
committed
added day 1 part 2
1 parent f279967 commit dbdafb5

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

1_2.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/php
2+
<?php
3+
error_reporting( -1 );
4+
$file = trim( file_get_contents( '1_1.in' ) );
5+
$len = strlen( $file );
6+
$step = $len / 2;
7+
$sum = 0;
8+
$i = 0;
9+
for ( $j = 0; $j < $len; $j++ ) {
10+
$c1 = $file[$i];
11+
$k = ( $i + $step ) % $len;
12+
$c2 = $file[$k];
13+
$i++;
14+
if ( $c1 == $c2 ) $sum += $c1;
15+
}
16+
echo "sum: $sum\n";

foo

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/* Recursion via a self-yielding generator.
3+
*
4+
* Crashes all currently supported PHP versions that support generator delegation (7.0, 7.1).
5+
*
6+
* A generator delegating to itself, causing a recursion.
7+
*/
8+
function a()
9+
{
10+
yield from a();
11+
}
12+
foreach(a() as $v);

0 commit comments

Comments
 (0)