Skip to content

Instantly share code, notes, and snippets.

View dahse89's full-sized avatar

Philipp Dahse dahse89

View GitHub Profile
@dahse89
dahse89 / stringSimilarity.php
Last active December 14, 2016 16:08
hackerrank stringSimilarity solution php
<?php
function stringSimilarity( $a) {
$a = trim($a);
$cutPrefix = $sum = 0;
$length = strlen($a);
do{
$count = 0;
while($a[$count] === substr($a,$cutPrefix+($count++), 1)){}
$sum += $count -1;
@dahse89
dahse89 / salesForceIdChecksum.func.php
Last active October 26, 2016 12:16
salesforce 15 digit to 18 digit id. Function to calculate the checksum.
<?php
function salesForceIdChecksum($id)
{
$map = implode('',array_merge(range('A', 'Z'), range(0, 9)));
$checksum = '';
foreach (str_split($id, 5) as $chunk) {
$checksum .= substr($map, bindec( strrev(array_reduce(str_split($chunk, 1),function($carry, $item){
$carry .= (!is_numeric($item) && $item == strtoupper($item)) ? '1' : '0';
@dahse89
dahse89 / TreeBuilder.php
Last active June 24, 2016 11:02 — forked from mistic100/TreeBuilder.php
[PHP] Recursive builder pattern
<?php
/**
* Recursive builder pattern
*
* Usage:
* $tree = \Tree\Builder::init()
* ->setName('parent')
* ->addChild()