Pzulze 13: Uamcsblrne!
A stiicnfiec sdtuy at an egisnlh uisitrveny has swhon that we can qitue elisay read text wehre all lrettes expcet the frist and the last in ecah word has been smeaclrbd. The oebijcvtes of tihs puzlze is to wrtie a fnitocun f, wchih unbcmlarses the enirte text of this psot. Ecah wrod, in odrer from first to last, in this txet has been scambreld by tihs fitcuonn,
slmarbce(wrod) {
lacol
wl := srlten(wrod) ; wl - wrod ltegnh
if (wl > 3) {
li := 2 ; li - lteetr iendx
count := wl - 2
loop %cuont% {
radonm np, 2, wl-1 ; np - new pisooitn
sl(word, li, np) ; sl - swap ltetres. You have to wrtie this fntioucn too, it swpas ltretes in wrod gievn by two psnooitis, li and np.
li++
}
}
rturen wrod
}
For rdoburiiatlcepy, Rdaonm,, 37 is uesd. Nruebms msut not be smacelbrd. Your code sulohd wrok for any simlriaily faotemrtd text. You can wrtie any aunmot of help fitunnocs. The fuicontn f msut be on the form,
out := f(str, fn)
wehre out is the poesrecsd text, str is the txet to pcseros, fn is a ftncioun objcet. It msut fiflul the flnwoolig citindoon
f(f(str, func("ucsrnlbmae")), fnuc("samrclbe")) == str
Bonus oicvetjbe, susgegt a sbtlaiue nmae for the ftinucon f, and epilaxn the bineetfs of the fn patremear.
Psaele sned yuor code (and bonus aesnwr) to me via PM but do not psot any stiolnous or hnits in tihs terahd. The fsrit one to copletme the task will rivecee two pniots, annoye who clteoemps the task aetfr taht but bofree a motnh from now, will recveie one ponit.
Dacilsiemr, the ogiianrl text mgiht cotiann silelpng eorrrs.
Crehes.
Code Puzzle Thread
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
Discuss Autohotkey related topics here. Not a place to share code.
Re: Code Puzzle Thread
We have a winner for Pzulze 13! boiler have submitted a great solution and will be awarded two points
. Anyone who wants, can still send their solution to me for one point. The solution will be available around the 25th of May.
Cheers.

Cheers.
Re: Code Puzzle Thread
This is boiler's solution for Pzulze 13,
. It is now boiler's privilege to submit the next puzzle, if boiler wants.
Cheers.
And the bonus questions,boiler wrote:Code: Select all
str = (% Pzulze 13: Uamcsblrne! A stiicnfiec sdtuy at an egisnlh uisitrveny has swhon that we can qitue elisay read text wehre all lrettes expcet the frist and the last in ecah word has been smeaclrbd. The oebijcvtes of tihs puzlze is to wrtie a fnitocun f, wchih unbcmlarses the enirte text of this psot. Ecah wrod, in odrer from first to last, in this txet has been scambreld by tihs fitcuonn, slmarbce(wrod) { lacol wl := srlten(wrod) ; wl - wrod ltegnh if (wl > 3) { li := 2 ; li - lteetr iendx count := wl - 2 loop %cuont% { radonm np, 2, wl-1 ; np - new pisooitn sl(word, li, np) ; sl - swap ltetres. You have to wrtie this fntioucn too, it swpas ltretes in wrod gievn by two psnooitis, li and np. li++ } } rturen wrod } For rdoburiiatlcepy, Rdaonm,, 37 is uesd. Nruebms msut not be smacelbrd. Your code sulohd wrok for any simlriaily faotemrtd text. You can wrtie any aunmot of help fitunnocs. The fuicontn f msut be on the form, out := f(str, fn) wehre out is the poesrecsd text, str is the txet to pcseros, fn is a ftncioun objcet. It msut fiflul the flnwoolig citindoon f(f(str, func("ucsrnlbmae")), fnuc("samrclbe")) == str Bonus oicvetjbe, susgegt a sbtlaiue nmae for the ftinucon f, and epilaxn the bineetfs of the fn patremear. Psaele sned yuor code (and bonus aesnwr) to me via PM but do not psot any stiolnous or hnits in tihs terahd. The fsrit one to copletme the task will rivecee two pniots, annoye who clteoemps the task aetfr taht but bofree a motnh from now, will recveie one ponit. Dacilsiemr, the ogiianrl text mgiht cotiann silelpng eorrrs. Crehes. ) MsgBox, % out := f(str, func("unscramble")) ; unscramble the input MsgBox, % out2 := f(out, func("scramble")) ; scramble the previous unscrambled output MsgBox, % f(out2, func("unscramble")) ; re-unscramble the previous scrambled output MsgBox, % (f(f(str, func("unscramble")), func("scramble")) == str) ? "Success!" : "Failed :(" return f(str, fn) { Random,, 37 index := 1 loop { if RegExMatch(SubStr(str, index), "^[a-zA-Z]+", word) { newStr .= %fn%(word) index := index + StrLen(word) } else { newStr .= SubStr(str, index, 1) index++ } } until index > StrLen(str) return newStr } scramble(word) { local wl := strlen(word) ; wl - word length if (wl > 3) { li := 2 ; li - letter index count := wl - 2 loop %count% { random np, 2, wl-1 ; np - new position sl(word, li, np) ; sl - swap letters. You have to write this function too, it swaps letters in word given by two positions, li and np. li++ } } return word } unscramble(word) { local swaps := [] wl := strlen(word) ; wl - word length if (wl > 3) { li := 2 ; li - letter index count := wl - 2 loop %count% { random np, 2, wl-1 ; np - new position swaps.Push({pos1: li, pos2: np}) li++ } loop, %count% sl(word, swaps[swaps.Count() - A_Index + 1].pos1, swaps[swaps.Count() - A_Index + 1].pos2) } return word } sl(ByRef word, li, np) { t := SubStr(word, li, 1) word := SubStr(word, 1, li - 1) . SubStr(word, np, 1) . SubStr(word, li + 1) word := SubStr(word, 1, np - 1) . t . SubStr(word, np + 1) }
Well done and thanks for participatingBoiler wrote: My suggested name for the function f is processWords, because it will perform a process on each of the words in a string, and that process can be anything that the identified function might perform on those words. In this case, it scrambles and unscrambles them, but it could also be provided a function encrypt, decrypt, reverse or capitalize or any number of other processes. This is the benefit of the fn parameter. It makes the function f very flexible in that it is set up to process all words in the provided string with the provided process.


Cheers.
Re: Code Puzzle Thread
Thanks, Helgef. I do have a new puzzle:
Puzzle 14: Earn your stripes by being first to find the hidden message, and your fellow puzzle solvers will be green with envy. Add the missing function HiddenMsg to the script below. A correct function will result in the message appearing in the GUI.
Puzzle 14: Earn your stripes by being first to find the hidden message, and your fellow puzzle solvers will be green with envy. Add the missing function HiddenMsg to the script below. A correct function will result in the message appearing in the GUI.
Code: Select all
Gui, -Caption
Gui, Margin, 0, 0
Gui, Add, Picture, x0 y0, ahk.png
Gui, Add, Progress, xm w217 h26 BackgroundD4D4D4
Gui, Add, Progress, xp+2 yp+2 wp-4 hp-4 Background202020
Gui, Font, cWhite
Gui, Add, Text, xp hp wp hp Center +0x200 vMsg BackgroundTrans
Gui, Show
GuiControl,, Msg, % HiddenMsg()
return
Esc::ExitApp
Re: Code Puzzle Thread
Since we haven’t seen any solutions to Puzzle 14 yet, I thought perhaps I should make my hints a little more obvious:
And I’ll add:
It’s really not complicated code to extract the info from the image. I hope to see someone solve it!
Earn your stripes by being first to find the hidden message, and your fellow puzzle solvers will be green with envy.
And I’ll add:
If you’re able to solve it, you’ll reveal an important component of your character.
It’s really not complicated code to extract the info from the image. I hope to see someone solve it!
Re: Code Puzzle Thread
Congratulations to Helgef for providing the solution to Puzzle 14!
Helgef has won two points for being first with the solution. Anyone who also sends the correct solution by June 25th will be awarded one point. Please PM me with your proposed solution.

Helgef has won two points for being first with the solution. Anyone who also sends the correct solution by June 25th will be awarded one point. Please PM me with your proposed solution.
Re: Code Puzzle Thread
Here is Helgef's solution to Puzzle 14:
When added to the main script and run with the image in the folder, it produces this, including the hidden message displayed at the bottom:
It may be a little cheesy, but it's hard to fit a profound message into a few stripes.
Good job, Helgef!
I'm looking forward to seeing what you come up with for Puzzle 15, if you choose to create one.
Code: Select all
HiddenMsg() {
coordmode pixel, window
x := 156
y := 20
s := ""
loop 9 {
pixelgetcolor col, x,y
green := (col & 0x0000ff00) >> 8
s .= chr(green)
y += 10
}
return s
}

Good job, Helgef!

Re: Code Puzzle Thread
Thank you @boiler, great puzzle
. I'll put it in my mental stack of todos to come up with a new puzzle
.
Cheers.


Cheers.
Return to “General Discussion”
Who is online
Users browsing this forum: No registered users and 2 guests