Skip to content

Instantly share code, notes, and snippets.

@esase
esase / suffix_array.php
Last active May 29, 2016 08:54
Suffix array [algorithm]
<?php
/**
* A data type that computes the suffix array of a string
*/
class SuffixArray
{
/**
* Text
* @var string
@esase
esase / queens.php
Last active May 29, 2016 08:53
Queens [problem]
<?php
class Queens
{
/**
* Board size
* @var integer
*/
protected $boardSize;
@esase
esase / union_find.php
Last active June 5, 2016 04:16
Union find [algorithm]
<?php
class UnionFind
{
/**
* Elements
* @var array
*/
public $elements;
@esase
esase / array_shuffle.php
Last active May 29, 2016 08:53
Array shuffle (by Donald Knuth) [algorithm]
<?php
$input = [
1,
2,
3,
4,
5,
6,
7
@esase
esase / selection_sort.php
Last active May 29, 2016 08:53
Selection sort [algorithm]
<?php
/**
* Selection sort
*
* @param array $input
* @return array
*/
function selectionSort(array $input)
{
@esase
esase / stack.php
Last active May 29, 2016 08:52
Stack [data type]
<?php
class Stack
{
/**
* Items
*
* @var array
*/
protected $items = [];
@esase
esase / queue.php
Last active May 29, 2016 08:51
Queue [data type]
<?php
class Queue
{
/**
* Items
*
* @var array
*/
protected $items = [];
<?php
/**
* Insertion sort
*
* @param array $input
* @return array
*/
function insertionSort(array $input)
{
@esase
esase / binary_search.php
Last active May 29, 2016 08:56
Simple binary search [algorithm]
<?php
$input = [
1,
3,
5,
2,
4,
6,
8,
@esase
esase / time_to_string.php
Last active May 29, 2016 08:57
Transform the time in a string representation [problem at: https://www.hackerrank.com/challenges/the-time-in-words]
<?php
function getTime($hour, $minute)
{
$hour = (int) $hour;
$minute = (int) $minute;
// start time again
if ($hour == 12 && $minute > 30) {
$hour = 0;