Reference · Tiles, Mexican Train and replay
longestRunfunction
The longest run of tiles from hand that can be laid one after another
against end, in the order they would be laid. A depth-first search over
the hand, bounded by PLAN_STEPS, preferring the heavier run of two the
same length: pips laid are pips that do not count.
Import it
import { longestRun } from "@johnmorrisdotca/domino";
Definition
function longestRun(hand: readonly Domino[], end: number): Domino[]
Parameters
| Name | Type | Description |
|---|---|---|
hand | readonly number[] | The canonical tile numbers in one hand. |
end | number | The pip value the next laid tile must match. |
Returns
number[]
The longest run of tiles from hand that can be laid one after another against end, in the order they would be laid. A depth-first search over the hand, bounded by PLAN_STEPS, preferring the heavier run of two the same length: pips laid are pips that do not count.
Examples
import { longestRun, tileOf } from "@johnmorrisdotca/domino";
console.log(longestRun([tileOf(1,2),tileOf(2,3),tileOf(3,4)],1));[ 18, 35, 52 ]What it prints (run when this page was built)