How to resolve the algorithm Look-and-say sequence step by step in the AutoHotkey programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Look-and-say sequence step by step in the AutoHotkey programming language

Table of Contents

Problem Statement

The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway.

The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   111221?   is sometimes referred to as the Cuckoo's Egg,   from a description of Morris in Clifford Stoll's book   The Cuckoo's Egg.

Sequence Definition

An example:

Write a program to generate successive members of the look-and-say sequence.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Look-and-say sequence step by step in the AutoHotkey programming language

Source code in the autohotkey programming language

AutoExecute:
    Gui, -MinimizeBox
    Gui, Add, Edit, w500 r20 vInput, 1
    Gui, Add, Button, x155 w100 Default, &Calculate
    Gui, Add, Button, xp+110 yp wp, E&xit
    Gui, Show,, Look-and-Say sequence
Return


ButtonCalculate:
    Gui, Submit, NoHide
    GuiControl,, Input, % LookAndSay(Input)
Return


GuiClose:
ButtonExit:
    ExitApp
Return


;---------------------------------------------------------------------------
LookAndSay(Input) {
;--------------------------------------------------------------------------- 
    ; credit for this function goes to AutoHotkey forum member Laslo 
    ; http://www.autohotkey.com/forum/topic44657-161.html
    ;-----------------------------------------------------------------------
    Loop, Parse, Input          ; look at every digit
        If (A_LoopField = d)    ; I've got another one! (of the same value)
            c += 1                  ; Let's count them ...
        Else {                  ; No, this one is different!
            r .= c d                ; remember what we've got so far
            c := 1                  ; It is the first one in a row
            d := A_LoopField        ; Which one is it?
        }
    Return, r c d
}


  

You may also check:How to resolve the algorithm Search in paragraph's text step by step in the 11l programming language
You may also check:How to resolve the algorithm Sorting algorithms/Gnome sort step by step in the Ruby programming language
You may also check:How to resolve the algorithm Cumulative standard deviation step by step in the Ring programming language
You may also check:How to resolve the algorithm A+B step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Radical of an integer step by step in the REXX programming language