Skip to content

Instantly share code, notes, and snippets.

@G33kDude
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save G33kDude/ff2a4d3dde74f573791c to your computer and use it in GitHub Desktop.

Select an option

Save G33kDude/ff2a4d3dde74f573791c to your computer and use it in GitHub Desktop.
#NoEnv
SetBatchLines, -1
Input := "13 743"
Start := A_TickCount
for each, Link in FindChain([2, 1], StrSplit(Input, " ")*)
Out .= ", " Link
Elapsed := A_TickCount - Start
MsgBox, % SubStr(Out, 3) "`n" Elapsed "ms"
FindChain(Chain, Length, Num)
{
if Chain.MaxIndex()-1 == Length
return (Chain[1] == Num) ? Chain : False
Performed := []
Biggest := Chain[1]
for each, BestLink in Chain
{
for each, Link in Chain
{
Sum := BestLink + Link
if (Sum <= Biggest || Sum > Num || Performed[Sum]) ; The chain only ever increases, we don't want to decrease or go over
continue
Performed[Sum] := True
if (Result := FindChain([Sum, Chain*], Length, Num))
return Result
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment