Skip to content

Instantly share code, notes, and snippets.

View itsmee's full-sized avatar

Oleg Zaezdny itsmee

  • Tallinn, Estonia
View GitHub Profile
@itsmee
itsmee / sequencesThatSumToNumber.php
Last active December 11, 2015 18:08
A function in PHP that takes an integer and returns all sequences of numbers that sum to it. For example, 3 => (1, 1, 1), (1, 2), (2, 1), (3)
<?php
/**
* Returns an array containing all sequences of numbers that sum to $num,
* e.g. sequencesThatSumToNumber(3) => array(array(1, 1, 1), array(1, 2), array(2, 1), array(3))
*
* @param int $num
* @return array
*/
function sequencesThatSumToNumber($num) {