My solution for a guessing algorithm where construction of "a" dictionary a 
result of forming words from splicing 2 variables in the js code,

a =: > ',' cut '"' -.~ wdclippaste '' NB. 
https://www.powerlanguage.co.uk/wordle/main.e65ce0a5.js dictionary section, 
must slice 2 sections together, excluding []

pD =: 1!:2&2 :(] [ 1!:2&2@:(,&<)) NB. utility printDebug but return y

ia =: 4 : 'x} y'

indiv1s =: (] # =/~@:i.@#)

legend =: \:~ (~. ;"0~ #/.~) ,a

dict =: (] \: 1 (#@~.@] * +/@:+)"1 (|. > {:"1 legend) i."1 ]) a NB. order dict 
by letter frequency * unique letters per word

score =: e.~ + = NB. compare candidate to secret word: 0: no match, 1: wrong 
pos 2:right pos

NB. score implies 1 means included somewhere + not in that position.
NB. for each next function score is x arg, remaining dictionary is y with {.y 
(first word) wnat was used to score

inp =: {.@] , }.@] ([ #~ 0 = {."1@rxmatch"1~(,@:) ) ('.....' ,: {.@]) ia~ 2 = [

expi =: {.@] , }.@] ([ #~ 0 -.@:= {."1@rxmatch"1~(,@:) ) ('.....' ,: {.@]) ia~ 
1 = [

exp =: ] ] F.: expi 1 indiv1s@:= [

inei =: ] ([ #~ +./@e."1~) {.@] #~ 1 = [

ine =: ] ] F.: inei 1 indiv1s@:= [

out =: {.@] , }.@] ([ #~ +./@e."1~(-.@:) ) {.@] #~ 0 = [

NB. out =: ] ] F.: outi 0 indiv1s@:= [

w =: ([ out^:(0 e. [) [ine^:(1 e. [) [ exp^:(1 e. [) inp^:(2 e. [))(}.@:)

wordle =: ((score {.) w ])^:(-.@:-: pD@:{.)^:_


the score funtion is what you are looking for.  is super elegant, but does not 
meet the spec of scoring 0 instead of 1 when there are extra copies of a 
candidate letter above and beyond the count in the secret.  The elegance.

score =: e.~ + = 


There is reason to hate the spec compared to elegant solution.  Which of 2 
extra wrong_place letters get scored 1 vs 0?  So huff+puff the spec is wrong is 
easy attitude to take.  But relenting with examining score in spec is "if 
candidate contains more copies of a letter than are present in secret, then 
score application with extra copies of letter replaced with space meets the 
spec. while avoiding replacing an extra copy with a candidate letter in right 
position in secret... is one way to do it.  Easier said than done enough that 
I'll work on this later.  








On Wednesday, February 16, 2022, 02:51:46 p.m. EST, Raul Miller 
<rauldmil...@gmail.com> wrote: 





https://rosettacode.org/wiki/Wordle_comparison

Wordle comparison compares a guess word to a reference word and
assigns green / yellow / gray values to each guess letter based on
some rules:

Matches which are in the right position are green.

Letters which do not occur in the reference are gray.

Letters which occur in the reference but not in the same position are
yellow or gray, depending on how many times the letter occurs.

At first glance, this might seem like a job for progressive index of.
But this is complicated by the fact that a later occurrence of an
exact match might deplete the "supply" of that letter.

For example, if the reference word was 'nomad' and the guess word was
'momma', the result should be 0 2 2 0 1 (which index ;:'gray yellow
green'). Similarly, if the reference word was 'momma' and the guess
word was 'nomad', the result should be 0 2 2 1 0.

Anyways, "progressive index of" seems to solve only a part of the problem here.

It seems like there ought to be a concise way of expressing this in J
-- some sort of double reverse progressive index of or a bitmask
shadow system or maybe a connected graph concept. Even nicer would be
if this approach were also space and time efficient. But I have not
figured any of that out yet.

Does anyone else want to take a stab at this?

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to