This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Payroll | |
def update(changed_employee) | |
puts("I cut a check for #{changed_employee.name}") | |
puts("His salary is now #{changed_employee.salary}") | |
end | |
end | |
class TaxMan | |
def update(changed_employee) | |
puts("I will send a new invoice to #{changed_employee.name}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 愚直なパターン | |
function powmod($a, $k, $m) | |
{ | |
$t = 1; | |
foreach (range(1, $k) as $r) { | |
$t = $t * $a; | |
} | |
return $t % $m; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function contains($v, Array $vs) | |
{ | |
if (count($vs) === 0) return false; | |
$left = 0; | |
$right = count($vs) - 1; | |
while (($left + 1) < $right) { | |
$mid = $left + ($right - $left) / 2; | |
if ($v < $vs[$mid]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$exec_num = 1000; | |
$ar = new SplFixedArray(10); | |
$cnt = 0; | |
for ($i = 0; $i < $exec_num; $i++) { | |
if ($ar->valid() === false) { | |
// 配列作成 & コピー | |
$ar = getArray($ar); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TreeNode | |
{ | |
public $value; | |
public $left; | |
public $right; | |
public function __construct($value) | |
{ | |
$this->value = $value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = range(1, 20); | |
shuffle($array); | |
var_dump($array); | |
var_dump(bubblesort($array)); | |
function bubblesort($array) | |
{ | |
$size = count($array); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = range(1, 20); | |
shuffle($array); | |
var_dump($array); | |
var_dump(selectionsort($array)); | |
function selectionsort($array) | |
{ | |
$size = count($array); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$Cart = new Cart(); | |
$Cart->setSetMenu(new SetMenu1()); | |
$Cart->add(new Hamburger(), 2)->add(new Popato(), 2)->add(new Drink(), 2); | |
printf("合計は %d になります。", $Cart->total()); | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[xdebug] | |
zend_extension="/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so" | |
xdebug.remote_enable=On | |
xdebug.remote_host=“localhost” | |
xdebug.remote_port=9000 | |
xdebug.remote_handler=dbgp | |
xdebug.remote_autostart=Off | |
xdebug.profiler_enable = On | |
xdebug.collect_vars=on | |
xdebug.collect_params=4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mergesort(&$array) | |
{ | |
_mergesort($array, 0, count($array)); | |
} | |
function _mergesort(&$array, $left, $right) | |
{ | |
if ($right - $left <= 1) return; |