Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Five Challenges to do in an Hour


  • Please log in to reply
1 reply to this topic
Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

A few months ago I came across this webpage: https://blog.svpino....ess-than-1-hour. Don't worry, you don't need to follow it as it is an unknown site. I'll quote in the spoiler below what challenges the blog says someone should be able to do if they are competent as a software engineer. I was curious how well AHK can do these challenges. I was able to solve the first four I Believe, but got stuck on number five. Anyhow, here are the challenges. To the practiced and experienced coders (AHK and otherwise), how would you solve these?

 

(Edit: Not entirely sure if this was the best forum to toss them into. But I guess I am seeking help on Challenge 5.)

 

Challenge 1:

Spoiler

 

Challenge 2:

Spoiler

 

Challenge 3:

Spoiler

 

Challenge 4:

Spoiler

 

Challenge 5:

Spoiler


kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

Here's one way to do #5.

SetBatchLines, -1
global Matches
AllPossibilities100()
MsgBox, % Matches
ExitApp

AllPossibilities100(n := 1, S := "") {
    if (n = 1)                                      ; First call
        AllPossibilities100(n + 1, 1)               ; Recurse
    else if (n < 10) {
        AllPossibilities100(n + 1, S ",+" n)        ; Recurse. Concatenate S, +, and n 
        AllPossibilities100(n + 1, S ",-" n)        ; Recurse. Concatenate S, -, and n
        AllPossibilities100(n + 1, S n)             ; Recurse. Concatenate S and n
    }
    else {                                          ; 10th level recursion
        Loop, Parse, S, CSV                         ; Total the values of S and check if equal to 100
        {
            if (A_Index = 1) {
                Total := A_LoopField
                continue
            }
            SubS := SubStr(A_LoopField, 2)          ; The number portion of A_LoopField
            if (SubStr(A_LoopField, 1, 1) = "+")    ; If the first character is + add, else subtract
                Total += SubS
            else
                Total -= SubS
        }
        if (Total = 100)
            Matches .= StrReplace(S, ",") "`r`n"
    }
}

For those who are interested, Computerphile has some nice YouTube videos on recursion. [Link]