Found an interesting way to learn coding, that is by solving problems at

Solved till 13 by getting help from #ahk IRC and made a repertoire of the same will surely help in the long run.

Reached

http://projecteuler.net/problem=14

made the code for the same, i.e.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. compare := 0 count := 0 number := 2 Loop, 1000000 { K := number Loop, { if ( K = 1 ) { count := Count + 1 sofar .= ans k " " count "`n" ;MsgBox, %sofar% compare := compare > count ? compare : count MsgBox, %sofar%And the highest so far as per the requirement of the problem is %compare% Clipboard := compare TrayTip, %number%, %compare% count := 0 break } Loop { if ( K = 1 ) { ;MsgBox reached %ans% finally break } rem := mod(k, 2) ;MsgBox %k% leaves a remainder %rem% if ( rem = 0 ) { ans .= k "->" n := k//2 ;MsgBox %k% results in %n% K := N count := count + 1 } else { ans .= k "->" n := 3*k + 1 ;MsgBox %k% results %n% K := N count := count + 1 } } } ans := number := number + 1 }

that runs fine but i think to loop for 1000000 times will be something not elegant. so i think if the code could assign every number it's value like

eg. for 2 it is 2 ->1 2 ====> here if i could assign

2 for the number 2 &

1 for the number 1

for 3 it is 3->10->5->16->8->4->2->1 8 ====> here if i could assign

8 for the number 3,

7 for the number 10, ***

6 for the number 5,

5 for the number 16,

4 for the number 8,

3 for the number 4, **

2 for the number 2,

2 for the number 1,

So basically if the script could check for a number whether it's value is already cached somewhere then use that value and in case it's value is not assigned then generate it's value as per the current script. For example for 4, as the value of 4 has already been assigned ** 3 then use this value and move to 5, 5 also done which has the value 6, so move to 7, since 7 is not done it generates the value for 7 like 7->22->11->34->17->52->26->13->40->20->10 ( already generated so no need to move further just add 10 from ( 7->22->11->34->17->52->26->13->40->20 ) and add 7 from *** to get 17. so on forth.

In this manner there script can run through 1000000 times without hogging much resources. How to do that if possible? Thanks as usual in advance