Last active
August 29, 2015 14:16
-
-
Save G33kDude/ff2a4d3dde74f573791c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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