Code Puzzle Thread

Discuss Autohotkey related topics here. Not a place to share code.
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Code Puzzle Thread

27 Sep 2017, 18:57

wolf_II wrote:The puzzle is: Can someone fix the bug?
It took me a while, but I think it's that __Delete won't work with a function expecting two or more mandatory arguments. Changing the parameters to add default values appears to work: Watchdog(wParam := 0, lParam := 0) Watchdog(wParam, lParam := 0)

(And thanks, I found two one functions of my own where it wasn't being cleaned up because of not knowing this...)

EDIT: Wait, you said three characters. Because we're in object land, an implicit this is passed to __Delete() as the first parameter, so only the second parameter needs a default argument. (EDIT: I think)
derz00 wrote:Wow, good job qwerty12
Oh, thanks, derz00 :oops:
wolf_II wrote::D The answer by qwerty12 is correct! Well done! :thumbup:
Oh, awesome, thanks!
Helgef wrote:Puzzle submition is open for anyone again (assuming qwerty12 declines the privilege ;) ).
I will have to do so again, sorry...
Last edited by qwerty12 on 28 Sep 2017, 08:47, edited 3 times in total.
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: Code Puzzle Thread

27 Sep 2017, 20:22

Wow, good job qwerty12
try it and see
...
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Code Puzzle Thread

27 Sep 2017, 23:26

qwerty12 wrote:Watchdog(wParam, lParam := 0)
This is close to the answer I found too (https://autohotkey.com/boards/viewtopic ... 45#p156945).

:D The answer by qwerty12 is correct! Well done! :thumbup:

The three characters answer I was thinking of was: lParam=""
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Code Puzzle Thread

28 Sep 2017, 01:28

Great! :thumbup:
qwerty12 is now in the lead with 3 points :clap:
Puzzle submition is open for anyone again (assuming qwerty12 declines the privilege ;) ).
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Code Puzzle Thread

01 Nov 2017, 06:39

It took me 20 minutes .. :think: and luck

Code: Select all


#SingleInstance, force

I:=imread()	; Reads in the distorted image

; Code to restore the image
txt2arr_inverse(txt) ; applied to line 156
{
	rows:=StrSplit(txt,"`n")
	arr:=[]
	for m, row in rows
		for n, num in StrSplit(row,"`t")
			arr[n,m]:=num  ; here inverted the array
	return arr
}

imshow(I)	; Shows the image


return

; You may add any functions or labels here:

return
GuiClose:
esc::exitapp

; Below is not to be modified - You do not need to look at this code to solve the puzzle. The image is not distorted in this code.
imshow(im)
{
	static scale:=12, w:=32, h:=32
	p:=w/2!=w//2
	VarSetCapacity(lpvBits,3*(w+p)*h,0)
	o:=0,i:=0
	Loop, % w*h
		j:=mod(A_Index-1,w)+1, j==1?++i:"" , NumPut(im[i,j,3], lpvBits, o, "Uchar"), NumPut(im[i,j,2], lpvBits, o+1, "Uchar"), NumPut(im[i,j,1], lpvBits, o+2, "Uchar"), o+=3+(j=w?p:0)
	hBitmap := DllCall("gdi32.dll\CreateBitmap", "Int", w, "Int", h, "UInt", 1, "Uint", 24, "Ptr", 0)
    hBmp := DllCall("user32.dll\CopyImage", "Uint", hBitmap, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008)
    DllCall("gdi32.dll\SetBitmapBits", "Uint", hBmp, "UInt", 3*(w+p)*h, "Uint", &lpvBits)		
	
	Gui, new
	Gui, margin,0,0
	Gui, add,picture, % "w" w*scale " h" h*scale  " 0x4E hwndpicId"
	Gui, show,, % "Imshow: " w*scale "-by-" h*scale " pixels."
	SendMessage, 0x172, 0x0, hBmp,, % "ahk_id " picId
	return
}

imread()
{
A=
(
0	1	1	1	1	1	1	1	1	1	1	1	1	1	1	0	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	38	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	38	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	38	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	38	91	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	45	0	0	0	0	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	66	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	177	0	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	177	0	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	80	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	46	0	0	0	0	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	170	0	0	0	0	170	170	170	170	170	38	92	171	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	0	0	206	204	0	0	170	170	170	170	38	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	0	200	200	200	200	0	172	170	170	170	38	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	170	170	170	170	0	200	200	200	200	0	172	170	170	170	38	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	7	7	7	0	0	200	200	200	200	0	0	7	8	8	2	6	9	9	9	9	18	170	170	170	170	12	7	7	7	7	0	
0	70	70	70	70	85	200	200	200	200	98	70	70	70	70	15	43	59	59	59	39	0	170	170	170	170	0	51	59	59	59	0	
0	200	200	200	200	200	200	200	200	200	200	200	200	200	200	44	125	170	170	170	177	0	170	170	170	170	0	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	200	200	200	44	125	170	170	170	179	0	170	170	170	172	0	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	200	200	200	44	125	170	170	170	170	0	0	177	149	0	0	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	200	205	207	12	125	170	170	170	170	170	0	0	0	81	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	0	0	0	0	141	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	0	0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	0	174	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	36	0	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	0	0	0	0	131	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	200	200	200	30	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	200	200	200	44	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	200	200	200	44	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	200	200	200	200	200	200	200	200	200	200	200	200	200	200	44	125	170	170	170	170	170	170	170	170	170	170	170	170	170	170	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
)
B=
(
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	160	57	255	255	255	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	160	57	255	255	255	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	160	57	255	255	255	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	160	39	255	255	255	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	167	0	0	0	0	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	0	47	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	221	0	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	0	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	216	0	0	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	216	216	216	216	216	216	216	216	216	180	0	0	0	0	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	216	105	0	0	0	216	216	216	216	216	160	15	255	255	255	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	0	0	118	141	0	0	216	216	216	216	160	57	255	255	255	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	0	136	135	135	135	0	227	216	216	216	160	57	255	255	255	255	255	255	255	255	255	255	255	255	255	255	0	
0	216	216	216	216	0	135	135	135	135	0	224	216	216	216	160	57	255	255	255	255	255	255	255	255	255	255	255	255	255	255	0	
0	74	74	74	64	0	135	135	135	135	0	50	74	74	74	55	19	90	90	90	90	118	255	255	255	255	106	90	90	90	90	0	
0	5	5	5	5	10	135	135	135	135	15	7	7	7	7	5	1	6	6	5	0	0	255	255	255	255	0	0	5	5	5	0	
0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	99	29	135	135	135	137	0	255	255	255	255	0	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	99	29	135	135	135	137	0	255	255	255	255	0	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	99	29	135	135	135	135	0	0	255	255	0	0	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	73	29	135	135	135	135	135	0	0	0	0	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	0	0	0	0	36	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	63	0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	0	141	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	0	141	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	52	0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	0	0	0	0	36	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	71	29	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	99	29	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	99	29	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	135	135	135	135	135	135	135	135	135	135	135	135	135	135	99	29	135	135	135	135	135	135	135	135	135	135	135	135	135	135	0	
0	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	0	1	1	1	1	1	1	1	1	1	1	1	1	1	1	0	
)
C=
(
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	98	98	98	98	98	98	98	98	98	98	98	98	98	98	22	165	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	98	98	98	22	165	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	98	98	98	22	165	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	98	98	98	15	165	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	0	0	0	0	172	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	18	0	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	0	230	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	0	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	0	0	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	0	0	0	0	187	224	224	224	224	224	224	224	224	224	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	98	100	101	5	165	224	224	224	224	224	0	0	0	108	224	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	98	98	98	22	165	224	224	224	224	0	0	0	0	0	0	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	98	98	98	22	165	224	224	224	235	0	0	0	0	0	0	224	224	224	224	0	
0	98	98	98	98	98	98	98	98	98	98	98	98	98	98	22	165	224	224	224	233	0	0	0	0	0	0	224	224	224	224	0	
0	35	35	35	35	41	98	98	98	98	47	35	35	35	35	8	57	77	77	77	51	0	0	0	0	0	0	67	77	77	77	0	
0	10	10	10	0	0	98	98	98	98	0	0	10	10	10	2	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	0	98	98	98	98	0	213	210	210	210	46	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	0	98	98	98	98	0	213	210	210	210	46	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	0	0	101	100	0	0	210	210	210	210	46	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	0	0	0	0	210	210	210	210	210	46	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	57	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	218	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	219	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	210	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	56	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	46	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	46	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	46	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	210	210	210	210	210	210	210	210	210	210	210	210	210	210	46	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	2	2	2	2	2	2	2	2	2	2	2	2	2	2	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
)
	A:=txt2arr(A), B:=txt2arr(B), C:=txt2arr_inverse(C)
	I:=[]
	for l, plane in [A,B,C]
		for m, row in plane
			for n, num in row
				I[m,n,l]:=num
	return I
}

txt2arr(txt)
{
	rows:=StrSplit(txt,"`n")
	arr:=[]
	for m, row in rows
		for n, num in StrSplit(row,"`t")
			arr[m,n]:=num
	return arr
}
ops sorry didn't see there are more pages ..... it has been solved already :headwall:
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Code Puzzle Thread

01 Nov 2017, 06:54

Hello Xeo786 :wave:
ops sorry didn't see there are more pages
No problems, I'm glad to see more suggestions on solutions. Your solution is not quite correct, although you have right Idea :thumbup:

A note to all:
Please feel free to submit a new puzzle :) You are also welcome to PM me if you have doubts or questions about a puzzle idea.

Cheers.
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: Code Puzzle Thread

01 Nov 2017, 07:39

May a puzzle be in Python? :P lol
Helgef wrote:No
All right, it's here. https://autohotkey.com/boards/viewtopic ... 23&t=39267
Last edited by derz00 on 01 Nov 2017, 10:03, edited 1 time in total.
try it and see
...
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Code Puzzle Thread

01 Nov 2017, 07:46

so Here is new Puzzle ............. its is a Loop Parse Puzzle :

Its a Traveling Script posted below.... Places are defined as A B C D , and D is connected to Place A so script choose randomly to travel forward or backward but can't jump from A to C it has to travel B then C so all places are connect as loop/circle;

You can only change two line to make this script work, lines with [editable line] Tag :trollface:

Required: You can't travel to Same Place and Script has to travel trough all places.

trick is hidden inside these two lines you have to figure out :think:

Code: Select all

; Loop Parse Puzzle---only two lines are editable
xxxxxx = Something 			;[editable line] you can only define one variable in this line  
;Defining places & Destinations
Place_A =
(
Place_B
Place_D
)
Place_B =
(
Place_C
Place_A
)
Place_C =
(
Place_D
Place_B
)
Place_D =
(
Place_A
Place_C
)
;Non stop Traveling
loop
{
	Random, Random_place, 1, 2  
	loop, parse, pasring_Text, `n, `r   ;[editable line] you can only define pasring Text variable here
		if( a_index = Random_place)
			Travel_to := A_LoopField
	MsgBox, You have arrived at %Travel_to%
}	
esc::
ExitApp
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Code Puzzle Thread

01 Nov 2017, 09:47

derz00 wrote:May a puzzle be in Python? :P lol
No :D (Maybe in the Other Programming Languages forum)
Xeo786 wrote:so Here is new Puzzle ............. its is a Loop Parse Puzzle :
Great! :thumbup:
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Code Puzzle Thread

01 Nov 2017, 11:40

Code: Select all

; Loop Parse Puzzle---only two lines are editable
xxxxxx = Something 			;[editable line] you can only define one variable in this line  
;Defining places & Destinations
Place_A =
(
Place_B
Place_D
)
Place_B =
(
Place_C
Place_A
)
Place_C =
(
Place_D
Place_B
)
Place_D =
(
Place_A
Place_C
)
;Non stop Traveling
loop
{
	Random, Random_place, 1, 2  
	loop, parse, % pasring_Text := A_Index=1?(Random_place=1?Place_D:Place_B):A_Index=2?(Random_place=1?Place_A:Place_C):A_Index=3?(Random_place=1?Place_B:Place_D):A_Index=4?(Random_place=1?Place_C:Place_A):"", `n, `r   ;[editable line] you can only define pasring Text variable here
		if( a_index = Random_place)
			Travel_to := A_LoopField
	MsgBox, You have arrived at %Travel_to%
}	
esc::
ExitApp
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Code Puzzle Thread

01 Nov 2017, 13:35

So we are suposed to go A->B->C->D->A->B->... ?
Edit 1: Minor adjustment of Xtra's code,

Code: Select all

; Loop Parse Puzzle---only two lines are editable
i = -1 			;[editable line] you can only define one variable in this line  
;Defining places & Destinations
Place_A =
(
Place_B
Place_D
)
Place_B =
(
Place_C
Place_A
)
Place_C =
(
Place_D
Place_B
)
Place_D =
(
Place_A
Place_C
)
;Non stop Traveling
loop
{
	Random, Random_place, 1, 2  
	;loop, parse, % pasring_Text := A_Index=1?(Random_place=1?Place_D:Place_B):A_Index=2?(Random_place=1?Place_A:Place_C):A_Index=3?(Random_place=1?Place_B:Place_D):A_Index=4?(Random_place=1?Place_C:Place_A):"", `n, `r   ;[editable line] you can only define pasring Text variable here
	loop, parse, % pasring_Text := i++ != "" ? ((mod(i,4)+1)=1?(Random_place=1?Place_D:Place_B):(mod(i,4)+1)=2?(Random_place=1?Place_A:Place_C):(mod(i,4)+1)=3?(Random_place=1?Place_B:Place_D):(mod(i,4)+1)=4?(Random_place=1?Place_C:Place_A):""):"", `n, `r   ;[editable line] you can only define pasring Text variable here
		if( a_index = Random_place)
			Travel_to := A_LoopField
	MsgBox, You have arrived at %Travel_to%
}	
esc::
ExitApp
Edit 2:
Another way would be to ignore the variables Place_X, and just define the appropriate strings, a bit of cheat I guess,

Code: Select all

; Loop Parse Puzzle---only two lines are editable
i = 0 			;[editable line] you can only define one variable in this line  
;Defining places & Destinations
Place_A =
(
Place_B
Place_D
)
Place_B =
(
Place_C
Place_A
)
Place_C =
(
Place_D
Place_B
)
Place_D =
(
Place_A
Place_C
)
;Non stop Traveling
loop
{
	Random, Random_place, 1, 2  
	loop, parse, % parsing_text := (Random_place == 2 ? "`n" : "") . "Place_" . (["A","B","C","D"][mod(i++,4)+1]), `n, `r   ;[editable line] you can only define pasring Text variable here
		if( a_index = Random_place)
			Travel_to := A_LoopField
	MsgBox, You have arrived at %Travel_to%
}	
esc::
ExitApp
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Code Puzzle Thread

02 Nov 2017, 00:07

Xtra's Code stop working at place_D and keep traveling to same place ;)
Helgef wrote:So we are suposed to go A->B->C->D->A->B->... ?
No no as defined destination and connection (A connected to B & D) (B connected to A & C) (C connected to B&D) (D connected to A & C)
so script choose randomly to travel forward or backward. i.e. from A it can randomly choose to travel back to D or forward to B

Code: Select all

loop, parse, % pasring_Text := i++ != "" ? ((mod(i,4)+1)=1?(Random_place=1?Place_D:Place_B):(mod(i,4)+1)=2?(Random_place=1?Place_A:Place_C):(mod(i,4)+1)=3?(Random_place=1?Place_B:Place_D):(mod(i,4)+1)=4?(Random_place=1?Place_C:Place_A):""):"", `n, `r   ;[editable line] you can only define pasring Text variable here

This can be solved by above way :angel: but as line said "you can only define parsing Text variable" not variables and conditions :terms:

this can be solved by defining single variable "loop, parse, here, `n, `r"
I bet solution will blow your mind.... you would say WT* how is it even working.... :HeHe:
Image
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Code Puzzle Thread

02 Nov 2017, 01:34

Code: Select all

; Loop Parse Puzzle---only two lines are editable
Travel_To := 1 ;[editable line] you can only define one variable in this line  
;Defining places & Destinations
Places := [ [2, 4], [1, 3], [2, 4], [1, 3] ]
;Non stop Traveling
loop
{
	Random, Random_place, 1, 2  
	Travel_to := Places[Travel_To, Random_Place]
	MsgBox % "You have arrived at  Place_" chr( Travel_To + 64 )
}	
esc::
ExitApp
My solution. ( The code I changed is equivalent to what you wrote before )
BTW in your code:

Code: Select all

; Loop Parse Puzzle---only two lines are editable
Travel_To = Place_A		;[editable line] you can only define one variable in this line  
;Defining places & Destinations
Place_A =
(
Place_B
Place_D
)
Place_B =
(
Place_C
Place_A
)
Place_C =
(
Place_D
Place_B
)
Place_D =
(
Place_A
Place_C
)
;Non stop Traveling
loop
{
	Random, Random_place, 1, 2  
	loop, parse, %Travel_To%, `n, `r   ;[editable line] you can only define pasring Text variable here
		if( a_index = Random_place)
			Travel_to := A_LoopField
	MsgBox, You have arrived at %Travel_to%
}	
esc::
ExitApp
Recommends AHK Studio
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Code Puzzle Thread

02 Nov 2017, 02:14

nnnik you have changed the whole code ....but how your half post is not visible :wtf: ?...... where you mentioned these hidden/blur variable :bravo: .
Now I can see the 2nd half :P
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Code Puzzle Thread

02 Nov 2017, 02:30

I see, cool one. :thumbup:
Xeo786, am I correct to interpret your last post as nnnik's last code is the solution and should be credited a point?
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Code Puzzle Thread

02 Nov 2017, 02:47

Helgef wrote:I see, cool one. :thumbup:
Xeo786, am I correct to interpret your last post as nnnik's last code is the solution and should be credited a point?
Yah One point goes for nnnik. :D
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Code Puzzle Thread

02 Nov 2017, 03:04

Excellent, I have updated the score. Now, if you want nnnik, it is your privilege to submit a new puzzle for an additonal point, within some unspecified time frame ;)

Cheers.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Code Puzzle Thread

04 Dec 2017, 18:36

Puzzle 8 - Minimise the min
Puzzle objective: Modify the function Min(List*) such that it runs about 50 % faster in the special test case in the code box below.
Puzzle rules: You are only allowed to edit the function Min(List*), you cannot modify any of the marked lines in the function. The marked lines, that is the for-loop, must run and determine the result. You are not allowed to modify the contents of the object refered to by the variable List. The function must work in any case the original does, but only needs to be faster in the test case.
Code:

Code: Select all

; Read the full puzzle description and rules.
; You are only allowed to modify the function Min.
; You cannot modify any of the marked lines, the for-loop has to run and determine the minimum.
; You are not allowed to modify the contents of the object refered to by the variable List. The function must work in any case the original does.
Min(List*)
{	; https://autohotkey.com/boards/viewtopic.php?f=6&t=40898 by FanaticGuru
	List._NewEnum().Next(,X)
	for key, element in List	; This line is not allowed to be modified.
		if (element < X)        ; This line is not allowed to be modified.
			X := element        ; This line is not allowed to be modified.
	return X
}
; Benchmarking for Min function. Do not modify.
#noenv
setbatchlines -1
listlines off

p := []
N := 50
str := "abcd"
loop 19			; Make a large string
	str.=str	; strlen = 2097152
p[1] := str
loop % N
	p[A_Index+1] := "abcd " A_Index


t1:=QPC()
m := Min(p*)	; find min in array p
t2:=QPC()
msgbox % "time taken: " round(t2-t1,3) "`t" m

;-------------------------------------------------------------------------------
QPC() { ; microseconds precision, borrowed from wolf_II
;-------------------------------------------------------------------------------
    static Freq, init := DllCall("QueryPerformanceFrequency", "Int64P", Freq)

    DllCall("QueryPerformanceCounter", "Int64P", Count)
    Return (Count / Freq)*1000
}
Original function credits: [Function] Min/Max including with Associative Arrays

For reference, on my PC, the test case takes about 16 ms. PC performance vary so please submit any improvements.

Cheers.
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Code Puzzle Thread

07 Dec 2017, 02:04

Puzzle8:
Replacing the line List._NewEnum().Next(element, X) with

Code: Select all

List._NewEnum().Next(, !X ? X : "")
I gain ~8% on speed, replacing it with

Code: Select all

	for k, l in List
		k>50 ? x:=l : ""
I gain ~25%, well still far away from the goal, but at least I tried!
Bye!
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Code Puzzle Thread

07 Dec 2017, 13:20

Hello rommmcek :wave: . Your second try is good, but not quite there, you should think about why that improves the performance, then you will find a way to improve it further.

Cheers.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 11 guests