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.
teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: Code Puzzle Thread

Post by teadrinker » 21 Jan 2023, 05:33

Hi!
Not quite got it, is my solution incorrect?

Code: Select all

_unset(v*) => (e := v.__Enum(1), c := (*) => (e(&a), !%a% := unset), StrGet(Buffer(v.Length*2, 1)) ~= '.(?Cc)')

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

Re: Code Puzzle Thread

Post by Helgef » 21 Jan 2023, 09:32

That solution is not acceptable, you are not allowed to assign unset as that was not possible at the time of the puzzle start. Moreover, I think !%a% := unset is undefined and should probably throw.

The foreach oneliner should use the * operator instead of the regex callout thingy. See :arrow: Variadic function call

Cheers.

teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: Code Puzzle Thread

Post by teadrinker » 21 Jan 2023, 09:53

Helgef wrote: you are not allowed to assign unset as that was not possible at the time of the puzzle start.
Ok, I dont mind. :)
But you must have forgotten to mention this rule in the puzzle statement:
Helgef wrote: Puzzle rules:Your solution must consist of only one line, i.e., write _unset(v*) => .... You can assume that v.has(n) is true for n = 1,..,v.length. Edit: you may not call _unset from within _unset.
Helgef wrote: Moreover, I think !%a% := unset is undefined and should probably throw.
Really? Why didn't I notice it.
Helgef wrote: However, once a variable has been assigned a value, there is no obvious way to make it uninitialised again
Why not:

Code: Select all

myvar := 3
myvar := unset
MsgBox 'OK'
MsgBox myvar  ; <——— Error: This variable has not been assigned a value.

teadrinker
Posts: 4295
Joined: 29 Mar 2015, 09:41
Contact:

Re: Code Puzzle Thread

Post by teadrinker » 21 Jan 2023, 09:59

Or was it a condition of the task? :)
Oh, I read this:
Helgef wrote: Edit: This puzzle must not use changes made in beta 12 since these makes the unsetting part of the puzzle trivial
Now I'm starting to figure things out.

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

Re: Code Puzzle Thread

Post by Helgef » 16 May 2023, 12:39

Send in your solution as a private message to me, so that everyone gets a chance to consider the problem before solutions are posted.
Puzzle 17 - A pseudo-pseudo-array
Puzzle description: Doing repeated string concatenations with variables is very fast, but with array elements it is borderline useless in some cases. Hence, sometimes pseudo-arrays are useful. But since, in v2 we cannot create a variable like var%expr% := ..., we have to explicitly define each variable in the pseudo-array beforehand. This might not be feasible in some cases, why we need another solution.
Problem example,

Code: Select all

N := 100000
; normal array
a:=['a']
t1 := A_TickCount
loop N
	a[1] .= 'a'
t2 := A_TickCount
;pseudo-array
b1:='b'
t3 := A_TickCount
loop N
	b%'1'% .= 'b'
t4 := A_TickCount
msgbox 'a:`t' t2-t1 '`nb:`t' t4-t3
Puzzle objective: Create a substitute for the pseudo-array which has similar flexibility and performance. Define c in the code below and complete the code in the the loop body

Code: Select all

c[1] := 'c' ; define c

t5 := A_TickCount
loop N
	; complete the loop
t6 := A_TickCount
When you put the code in the first example you should get something like,

Code: Select all

a:	906
b:	0
c:	16
Puzzle rules: You must perform N number of .= 'c' such that c reference a string of length N+1 of c:s. The index and name 1 is just an example, your code should work for any reasonable amount of indices/names, even if they are not known when writing the script.

Note1: Puzzle 15 is still unsolved, please consider it too :)

Cheers.

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

Re: Code Puzzle Thread

Post by Helgef » 20 May 2023, 10:38

@teadrinker has provided a nice solution for puzzle 17 and will be awarded one point. But there is still some room for improvement, so do not hesitate to give it a try. I will post teadrinkers solution (much) later.

Cheers.

Post Reply

Return to “General Discussion”