Anagrams

Post gaming related scripts
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

20 Jul 2017, 14:59

Yeah I saw some len4.txt ... when I tried it.
wl2.txt probably comes from the auto-complete thread I refered to recently. I think I renamed it for lazy typing :beard:
wolf_II wrote: I think when the permutation are taken care of I will get only 1/3 of the count, which equals your number .. looks promising :D
It would be nice if our numbers coincide, because we cannot easily calculate the correct number of anagrams. Getting the same result would be a nice inidcator. Although, since we discussed methods we might be biased to make similar mistakes ;)
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

20 Jul 2017, 15:18

Did you notice the last post on the previous page? I posted a fix to take care of permutations. And I got exactly 1/3 as I hoped. 1,105 :D
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

20 Jul 2017, 15:41

Happy days!
I was looking at it, thinking about how to avoid generating the permutations in the first place. It is a tricky one.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

21 Jul 2017, 06:43

version 2.07
Anagrams v2.07.zip
(13.78 KiB) Downloaded 694 times

This version is worth keeping. It contains all the features, all the fixes and works with up to 2 spaces (3-word solutions).
I plan to introduce some recursion next to deal with an arbitrary amount of spaces.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

21 Jul 2017, 06:59

version 2.08
Anagrams v2.08.zip
(13.79 KiB) Downloaded 263 times

Only two lines code have changed, one being the version number. :lol:
Now I need to do more testing.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

21 Jul 2017, 07:23

Code: Select all

--------------------------------------------------------------------------------
Input = "elevenplustwo", Skip = 5, 110k words
--------------------------------------------------------------------------------
Add spaces      Length      # of solutions      Time        Reference count
0               13          111                 0.009
1               14          2                   0.020       2
2               15          1105                0.944       1105
3               16          5458                3.609       9351
4               17          4472                10.905      8654
5               18          737                 20.048      892

6               19          0                   22.184
When I am comparing the results to Helgef's reference I suspect again some permutations interfering :(
Edit: I added Reference count to the table.
Edit2: I added missing relevant information.
Last edited by wolf_II on 21 Jul 2017, 08:01, edited 2 times in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

21 Jul 2017, 07:28

When I am comparing the results to Helgef's reference I suspect again some permutations interfering
:think: Did you compare the number of results to the reference list?
Regarding the spinner, try to put

Code: Select all

Gdip_SetSmoothingMode(pGraphics, 4)
after

Code: Select all

; setup Gdip
[...]
pGraphics := Gdip_GraphicsFromHDC(hDC)
To my eyes it improves the quality of the dots.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

21 Jul 2017, 07:40

Re: smooth spinner
Thanks :thumbup:

I edited the table above.
I expect a problem with the previous candidates which are stored (in principle). Maybe Previous[] could be a static?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

21 Jul 2017, 09:06

Quick answer, note that the so called reference list has not been verified to be free of duplicates, at least not by me. One could sort each line, D%A_Space%, and then sort with U option delimiter and `n.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

21 Jul 2017, 09:47

I see, thanks. I will write some diagnostic helper, this is unreliable to do manually.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

21 Jul 2017, 11:07

Here is the Diagnostics helper script. I manually produced 2.txt, ... 6.txt using the "Copy all items to clipboard" feature in Anagrams version 2.08. Those files are saved in a separate folder containg the "elevenplustwo.txt" and the following script. Then I ran the script.

Code: Select all

#NoEnv
#SingleInstance, Force


    ;---------------------------------------------------------------------------
    ; split elevenplustwo.txt	MD5 = 9e2d9e30887c75d12137fc5c076644f3
    ;---------------------------------------------------------------------------
    FileRead, TXT, elevenplustwo.txt

    Loop, Parse, TXT, `n, `r
    {
        Line := Trim(A_LoopField)
        StrReplace(Line, A_Space,, Count), Count++
        OUT%Count% .= Line "`r`n"
    }

    For each, Index in [2,3,4,5,6] {
        FileDelete, % "ref " Index ".txt"
        FileAppend, % RTrim(OUT%Index%, "`r`n"), % "ref " Index ".txt"
    }


    ;---------------------------------------------------------------------------
    ; sort "ref x.txt" for x = 2,3,4,5,6 as proposed by Helgef
    ;---------------------------------------------------------------------------
    For each, Index in [2,3,4,5,6] {
        FileDelete, % "ref " Index " sorted.txt"
        FileRead, TXT, % "ref " Index ".txt"
        Output := ""

        Loop, Parse, TXT, `n, `r
        {
            Line := A_LoopField
            Sort, Line, D%A_Space%
            Output .= Line "`r`n"
        }

        Output := RTrim(Output, "`n`r")
        Sort, Output
        FileAppend, %Output%, % "ref " Index " sorted.txt"
    }


    ;---------------------------------------------------------------------------
    ; sort "x.txt" for x = 2,3,4,5,6 as proposed by Helgef
    ;---------------------------------------------------------------------------
    For each, Index in [2,3,4,5,6] {
        FileDelete, % Index " sorted.txt"
        FileRead, TXT, % Index ".txt"
        Output := ""

        Loop, Parse, TXT, `n, `r
        {
            Line := A_LoopField
            Sort, Line, D%A_Space%
            Output .= Line "`r`n"
        }

        Output := RTrim(Output, "`n`r")
        Sort, Output
        FileAppend, %Output%, % Index " sorted.txt"
    }


ExitApp
Now I compare 2 sorted.txt with ref 2 sorted.txt and so on. My first observation when I compare 6 sorted.txt and ref 6 sorted: (used for brevity)

There are lines that all start with "el el " which come from Anagrams that are not present in the reference, all remaining differences are lines in the reference, but are missing from Anagrams output.

Needs further investigation, I just share my method here already, Maybe we can get an idea where to look next?

Edit: Second impression: all lines starting with "el el " are only present in Anagrams output, not present in the reference. 5 sorted.txt vs. ref 5 sorted.txt
Last edited by wolf_II on 21 Jul 2017, 11:20, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

21 Jul 2017, 11:20

Asuming your el el lines form valid anagrams, it seems there are missing anagrams in the so called reference :problem:
I will revisit my code later.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

22 Jul 2017, 03:55

I know why I didn't get the el el sentences. It's because combinations() doesn't return any duplicates. My brute-force method needs two el's to produce a combination containing two el's. I have made a modification, but I'm not sure it will ever finish :lol:
Edit: It didn't finish :(
I peeked in on its progress (debug vars) and saw that it had found el el combinations, so I interrupted it, it had found ~19000 results, I took out the el el ones,

Code: Select all

el el en put vows 
el el en puts vow 
el el en supt vow 
el el en tup vows 
el el en tups vow 
el el enow pus tv 
el el enow pus vt 
el el enow put vs 
el el enow sup tv 
el el enow sup vt 
el el enow tup vs 
el el enow tv ups 
el el enow ups vt 
el el es punt vow 
el el et pun vows 
el el et puns vow 
el el et spun vow 
el el ne put vows 
el el ne puts vow 
el el ne supt vow 
el el ne tup vows 
el el ne tups vow 
el el nest up vow 
el el net up vows 
el el nets up vow 
el el new opus tv 
el el new opus vt 
el el new pout vs 
el el new soup tv 
el el new soup vt 
el el news tov up 
el el nous pew tv 
el el nous pew vt 
el el now supe tv 
el el now supe vt 
el el now up vest 
el el now up vets 
el el nows up vet 
el el nu pest vow 
el el nu pet vows 
el el nu pets vow 
el el nu pews tov 
el el nu pow vest 
el el nu pow vets 
el el nu pows vet 
el el nu pts wove 
el el nu sept vow 
el el nu spew tov 
el el nu step vow 
el el nu swop vet 
el el nu tsp wove 
el el nu vest wop 
el el nu vet wops 
el el nu vets wop 
el el nut sp wove 
el el onus pew tv 
el el onus pew vt 
el el opus tv wen 
el el opus vt wen 
el el ow pun vest 
el el ow pun vets 
el el ow puns vet 
el el ow pus vent 
el el ow spun vet 
el el ow sup vent 
el el ow up vents 
el el ow ups vent 
el el owe puns tv 
el el owe puns vt 
el el owe punt vs 
el el owe spun tv 
el el owe spun vt 
el el owes pun tv 
el el owes pun vt 
el el own supe tv 
el el own supe vt 
el el own up vest 
el el own up vets 
el el owns up vet 
el el pen ut vows 
el el pens ut vow 
el el pent us vow 
el el pest un vow 
el el pet un vows 
el el pets un vow 
el el pew unto vs 
el el pews tov un 
el el pews ut von 
el el po tv unsew 
el el po unsew vt 
el el pout vs wen 
el el pow tune vs 
el el pow un vest 
el el pow un vets 
el el pow us vent 
el el pows un vet 
el el pts un wove 
el el pts unwove 
el el pun st wove 
el el pun tv woes 
el el pun vt woes 
el el puns tov we 
el el puns tv woe 
el el puns vt woe 
el el punt se vow 
el el punt vs woe 
el el punts wove 
el el put sn wove 
el el puton vs we 
el el puts von we 
el el puts woven 
el el sent up vow 
el el sept un vow 
el el sew tv upon 
el el sew upon vt 
el el sewn tov up 
el el sn tup wove 
el el snow up vet 
el el soup tv wen 
el el soup vt wen 
el el sow up vent 
el el sown up vet 
el el sp tun wove 
el el sp tune vow 
el el sp ut woven 
el el spew tov un 
el el spew ut von 
el el spun tov we 
el el spun tv woe 
el el spun vt woe 
el el st up woven 
el el step un vow 
el el stew up von 
el el supe tv won 
el el supe vt won 
el el supt von we 
el el supt woven 
el el swop un vet 
el el ten up vows 
el el tens up vow 
el el tov up wens 
el el tsp un wove 
el el tsp unwove 
el el tune vs wop 
el el tups von we 
el el tups woven 
el el un vest wop 
el el un vet wops 
el el un vets wop 
el el up vest won 
el el up vets won 
el el up von west 
el el up von wets 
el el upon vs wet 
el el us vent wop 
el el us von wept 
My guess is that there shouldn't be any more el el sentences than those. I shall ponder if I can (easily) filter the brute force method such that it actually manages to finish.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

22 Jul 2017, 12:47

Is it possible to get an output file for Input = foxtrot from your combine function? or maybe for input = go go go?
I'm looking for an easy short one, so analysing where the differences are should also be more straight forward. That's my hope at least.
I had a look at your function earlier on but I cant see how to get it to produce output into a file.

On the other hand, I might have reached the end of my ability to wrap my head around this topic. One more knot could cause permanent damage ;)
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

22 Jul 2017, 15:17

Well that was quick atleast,

Code: Select all

for to tx 
fox tort 
fox trot 
fro to tx 
of ort tx 
of rot tx 
of tor tx 
oft or tx 
ox rf tot 
rf too tx 
and

Code: Select all

go gogo
:D
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

22 Jul 2017, 16:15

Thanks for doing that. I only noticed that I am currently displaying the anagrams without sorting the words in each line. Should I sort the words as the last improvement and call it finished?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

22 Jul 2017, 17:15

Sorting might look better, I guess it will be quick.
If you feel that it is finished, I would like to congratulate you on a job well done! It turned out to be a very nice app, and I had fun discussing it with you, thank you very much for your efforts and time. :salute: :bravo:
Also, I think you should include v.2 in the first post.

Cheers!
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

23 Jul 2017, 11:32

Thank you for your kind words and your massive help with this! :salute:
I will shortly post an updated version. I also like to add my new spinner that signals to the user when something is going on, rather than just disabling the controls in the GUI.
I will also update the first post.

version 2.09
Anagrams v2.09.zip
(14.6 KiB) Downloaded 230 times
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Anagrams

23 Jul 2017, 15:04

Helgef wrote:If you feel that it is finished
I don't feel that the project is finished in a good way. More like: I am finished as I can not improve it further.
There still are some multi-word anagrams missing for sufficiently large inputs like eleven plus two.
There are plenty multi-word anagrams found and displayed, so that's a partial success.

More importantly: I feel like I should not be wasting any more of your precious time on this.
I can't thank you enough for your teaching, guidance and patience with me. And of course the time you spent. :beer:

I thoroughly enjoyed the experience. :dance: :superhappy: :wave:
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Anagrams

23 Jul 2017, 16:03

I feel like I should not be wasting any more of your precious time on this.
You can not and you have not, I shall waste my own time, as I see fit ;)

2.09
My only critisism is that the mulit-word anagrams are dependent on the amount of spaces typed in the edit. It would be more intuitive, and user friendly, to have an optional count of how many words to have per line in the listview.
The default would be 1, which would show the one-word anagrams. So if I type elvenplustwo, and then select 3 words per line, I get the eleven plus two set. Basically, it would be the equivalent of how it is now if you type elevenplustwo and starts adding spaces after that. 1 space two words, 2 spaces three words ...

Cheers.
I do not see the spinner unless I make it parentless, as mentioned in the spinner thread. A very nice addition though.

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 12 guests