|
Post by bluatigro on Jan 15, 2019 9:34:20 GMT
fount the next puzle in a magazin : acute = 30 blut = 25 boel = 17 cel = 18 clou = 26 club = 29 lat = 17 leut = 23 loep = 22 plat = 27 pol = 19 pub = 24 valt = 18 vla = 14 the char's are numbers added what is the char's value
|
|
|
Post by bluatigro on Jan 15, 2019 10:04:18 GMT
this wil take to long :
for a = 0 to 9 for b = 0 to 9 for c = 0 to 9 for e = 0 to 9 for l = 0 to 9 for o = 0 to 9 for p = 0 to 9 for t = 0 to 9 for u = 0 to 9 for v = 0 to 9 if a+c+u+t+e=30 _ and b+l+u+t=25 _ and b+o+e+l=17 _ and c+e+l=18 _ and c+l+o+u= 26 _ and c+l+u+b=29 _ and l+a+t=17 _ and l+e+u+t=23 _ and l+o+e+p=22 _ and p+l+a+t=27 _ and p+o+l=19 _ and p+u+b=24 _ and v+a+l+t=18 _ and v+l+a=14 then print "a = " ; a print "b = " ; b print "c = " ; c print "e = " ; e print "l = " ; l print "o = " ; o print "p = " ; p print "t = " ; t print "u = " ; u print "v = " ; v end end if next v next u next t next p next o next l next e next c next b next a
this can be done faster whit permutation's but i do not know how
|
|
|
Post by Rod on Jan 15, 2019 10:50:31 GMT
Answer is a=6 b=5 c=8 e=3 l=7 0=2 p=10 t=4 u=9 v=1
Like most folks a few minutes algebra brings the solution bubbling out.
How to code it? Interesting. My first thoughts are that you need two strategies. The first looks for single character differences between words and assigns the numeric difference. The second strategy would be a solve matrix. Here you would check repeatedly for single missing values as you store solutions. Again a single missing solution is the known sum deducted from the total.
e.g. VALT=18 ALT=17 so V=1 PLAT=27 ALT=17 so P=10
|
|
|
Post by Rod on Jan 15, 2019 12:15:09 GMT
Having thought a little more I would sort each “word” into alpha order. So reorder the letters of each word. Then sort the words, that will help find single character differences. When I do find a single character and obtain its value I would then remove it from every word and deduct its value from the total. That way the words get shorter and shorter and single character differences easier to find. Probably a single iteritive solution.
|
|
|
Post by B+ on Jan 15, 2019 21:29:20 GMT
OK here is a solution finder in code.
I used an anaCode$(letters$) function to arrange the letter counts of a word in alpha order into a 26 character string st that matching anaCodes are identical words or anagrams with same letter set.
I used a cycle of finding solutions then removing those solution letters and their values from the problem set until no new changes occurred.
'find letter values puzzle.txt for JB v2 B+ 2019-01-15
'first create a data$ from problem 14 items data$ = "acute = 30, blut = 25, boel = 17, cel = 18, clou = 26, club = 29, lat = 17, leut = 23, loep = 22, " data$ = data$ + "plat = 27, pol = 19, pub = 24, valt = 18, vla = 14"
' state problem and give choice of viewing intermediate calculations print "Problem: Find the value for each letter such that:" i = 1 while word$(data$, i, ",") <> "" print trim$(word$(data$, i, ",")) i = i + 1 wend print print "Do you want to see the interim calculations" print " as this program arrives at a solution set?" input " Enter y for yes, or n for no ";a$ if a$ = "y" then debug = 1 cls
'now separate words from values maxIndex = 14 dim words$(100), values(100), codes$(100), solutionValues(26) '< leave room for more words dim letters(26) 'this is for the anaCode$ funtion if debug then print : print "Original problem:" for i = 1 to maxIndex words$(i) = trim$(leftOf$(word$(data$, i, ","), "=")) values(i) = val(trim$(rightOf$(word$(data$, i, ","), "="))) codes$(i) = anaCode$(words$(i)) if debug then print words$(i), values(i), codes$(i) 'debug check data load next do scan 'look for 1 letter difference between one word and another, if so we can isolte a letter and it's value if debug then print : print "Solutions found:" for i = 1 to maxIndex - 1 for j = i + 1 to maxIndex d$ = oneLetterDifference$(codes$(i), codes$(j)) if d$ <> "" then v = abs(values(i) - values(j)) if debug then print d$; " = "; v solutionValues(asc(d$) - 96) = v end if next next
'now take these solutions and apply them back into the arrays for shorter words and smnaller values changes = 0 for i = 1 to 26 if solutionValues(i) then letter$ = chr$(i + 96) for w = 1 to maxIndex pos = instr(words$(w), letter$) if pos then 'rebuild word without letter, value without the letter's value and find new anaCode$ words$(w) = mid$(words$(w), 1, pos - 1) + mid$(words$(w), pos + 1) values(w) = values(w) - solutionValues(i) codes$(w) = anaCode$(words$(w)) changes = changes + 1 end if next end if next if debug and changes <> 0 then print print "After ";changes; " changes, letters and their values removed." print "The current state of problem:" for i = 1 to maxIndex print words$(i), values(i), codes$(i) next end if loop until changes = 0 print : print "The Solution Set is:" for i = 1 to 26 if solutionValues(i) then print chr$(i + 96); " = "; solutionValues(i) next
function oneLetterDifference$(ana1$, ana2$) for i = 1 to 26 'letters if mid$(ana1$, i, 1) <> mid$(ana2$, i, 1) then diff = diff + 1 saveLetter = i end if next if diff = 1 then oneLetterDifference$ = chr$(saveLetter + 96) end function
'create a function that counts a set of letters in word 'such that words with same counts are the same or anagrams of each other function anaCode$(s$) 'since letters is global, zero out letters s$ = lower$(s$) for i = 1 to 26 letters(i) = 0 next 'assuming s$ is just letters not digits or other stuff like punctuation for i = 1 to len(s$) letters(asc(mid$(s$, i, 1)) - 96) = letters(asc(mid$(s$, i, 1)) - 96) + 1 next for i = 1 to 26 b$ = b$ + str$(letters(i)) next anaCode$ = b$ end function
'some handy word tool functions FUNCTION leftOf$ (source$, of$) posOf = INSTR(source$, of$) IF posOf > 0 THEN leftOf$ = MID$(source$, 1, posOf - 1) END FUNCTION
FUNCTION rightOf$ (source$, of$) posOf = INSTR(source$, of$) IF posOf > 0 THEN rightOf$ = MID$(source$, posOf + LEN(of$)) END FUNCTION
|
|
|
Post by tsh73 on Jan 16, 2019 9:51:03 GMT
Nice solution, B+
|
|
|
Post by Rod on Jan 16, 2019 12:39:43 GMT
Beaten by B+ but I could not resist having a go. Here is where I got to, it finds the same solution more than once but that could be fixed.
dim d$(14,2) dim found$(50) dim found(50) d$(1,1)="blut" d$(1,2)="25" d$(2,1)="boel" d$(2,2)="17" d$(3,1)="cel" d$(3,2)="18" d$(4,1)="clou" d$(4,2)="26" d$(5,1)="club" d$(5,2)="29" d$(6,1)="lat" d$(6,2)="17" d$(7,1)="leut" d$(7,2)="23" d$(8,1)="loep" d$(8,2)="22" d$(9,1)="plat" d$(9,2)="27" d$(10,1)="pol" d$(10,2)="19" d$(11,1)="pub" d$(11,2)="24" d$(12,1)="valt" d$(12,2)="18" d$(13,1)="vla" d$(13,2)="14" oldfound=1
[start] 'first put letters within words in alpha order for n= 1 to 13 l=len(d$(n,1)) for m= 1 to l l$(m)=mid$(d$(n,1),m,1) next sort l$(,1,l w$="" for m= 1 to l w$=w$+l$(m) next d$(n,1)=w$ next sort d$(,1,13,1
'now match each word against every other word looking for a single character difference for m= 1 to 13 m$=d$(m,1) lm=len(m$) 'get the word we are matching to for n= 1 to m mm$=m$ n$=d$(n,1) ln=len(n$) 'get the word we are checking for o=1 to lm c$=mid$(m$,o,1) if instr(n$,c$,0)>0 then 'remove all matching characters n$=remchar$(n$,c$) mm$=remchar$(mm$,c$) end if 'print m$ , mm$,n$ next 'now see if we have a single character left in either word 'if so store it and deduce its value if mm$="" and len(n$)=1 then print "Found ";n$,abs(val(d$(n,2))-val(d$(m,2))) found=found+1 found$(found)=n$ found(found)=abs(val(d$(n,2))-val(d$(m,2))) end if if n$="" and len(mm$)=1 then print "Found ";mm$,abs(val(d$(n,2))-val(d$(m,2))) found=found+1 found$(found)=mm$ found(found)=abs(val(d$(n,2))-val(d$(m,2))) end if next next
'now clear out all found characters from all words and deduct its value from the total for f = oldfound to found for n= 1 to 13 if instr(d$(n,1),found$(f),1)>0 then d$(n,1)=remchar$(d$(n,1),found$(f)) d$(n,2)=str$(val(d$(n,2))-found(f)) end if next next 'remember where we ended last time oldfound=found
scan
'now loop back and do it all again if found<10 then goto [start]
'end
|
|
|
Post by B+ on Jan 16, 2019 16:18:04 GMT
Hi Rod,
I think your code is missing a remchar$ function after 'end.
And those sort lines like:
sort d$(,1,13,1
look wrong without the ) paired with the (, but probably right. I forgot that JB v2 has sort now.
|
|
|
Post by Rod on Jan 16, 2019 16:54:11 GMT
Away from home and B+ is correct. I used Liberty BASIC to code the routine and forgot that remchar$() is a new Liberty function. Will roll my own for Just BASIC when I get home. Or perhaps someone had one in their code bank?
|
|
|
Post by B+ on Jan 16, 2019 17:19:22 GMT
OK Rod, your code works with this addition (now that I understand it stands for remove character):
function remchar$(s$, c$) pos = instr(s$, c$) if pos then remchar$ = mid$(s$, 1, pos -1) + mid$(s$, pos + 1) else remchar$ = s$ end function
Oh! does work as:
sort d$(),1,13,1
So all JB v2 needs is the first ( to be able to tell it's an array type.
|
|
|
Post by Rod on Jan 17, 2019 14:26:05 GMT
Actually I didn't need all the sorting. The remchar$() function did not care. So it simplifies to:
dim d$(14,2) dim found$(50) dim found(50) d$(1,1)="blut" d$(1,2)="25" d$(2,1)="boel" d$(2,2)="17" d$(3,1)="cel" d$(3,2)="18" d$(4,1)="clou" d$(4,2)="26" d$(5,1)="club" d$(5,2)="29" d$(6,1)="lat" d$(6,2)="17" d$(7,1)="leut" d$(7,2)="23" d$(8,1)="loep" d$(8,2)="22" d$(9,1)="plat" d$(9,2)="27" d$(10,1)="pol" d$(10,2)="19" d$(11,1)="pub" d$(11,2)="24" d$(12,1)="valt" d$(12,2)="18" d$(13,1)="vla" d$(13,2)="14" oldfound=1 foundletters$=""
[start] scan
'match each word against every other word looking for a single character difference for m= 1 to 13 m$=d$(m,1) lm=len(m$) for n= 1 to m mm$=m$ n$=d$(n,1) ln=len(n$) for o=1 to lm c$=mid$(m$,o,1) if instr(n$,c$,0)>0 then n$=remchar$(n$,c$) mm$=remchar$(mm$,c$) end if next if mm$="" and len(n$)=1 and instr(foundletters$,n$,1)=0 then print "Found ";n$,abs(val(d$(n,2))-val(d$(m,2))) found=found+1 found$(found)=n$ found(found)=abs(val(d$(n,2))-val(d$(m,2))) foundletters$=foundletters$+n$ end if if n$="" and len(mm$)=1 and instr(foundletters$,mm$,1)=0 then print "Found ";mm$,abs(val(d$(n,2))-val(d$(m,2))) found=found+1 found$(found)=mm$ found(found)=abs(val(d$(n,2))-val(d$(m,2))) foundletters$=foundletters$+mm$ end if next next
' eliminate the found letters and their values from the array for f = oldfound to found for n= 1 to 13 if instr(d$(n,1),found$(f),1)>0 then d$(n,1)=remchar$(d$(n,1),found$(f)) d$(n,2)=str$(val(d$(n,2))-found(f)) end if next next oldfound=found
if found<10 then goto [start] end
function remchar$(s$, c$) pos = instr(s$, c$) if pos then remchar$ = mid$(s$, 1, pos -1) + mid$(s$, pos + 1) else remchar$ = s$ end function
|
|
|
Post by B+ on Jan 17, 2019 15:52:08 GMT
Oh I see you compare letter sets by comparing letters and removing like letters. Yes, then no need for sorting, just look for one letter left in one word and none left in the other.
I think bluatigro gave us a particularly easy puzzle. What if only 1 letter value could be discovered on first round, ie better = 28 and beer = 18 the difference is 2 t's = 10 st t = 5...
So instead of looking for 1 letter left, you'd see if all the letters left were the same. If so, divide the value difference of the 2 words by the number of like letters to solve for the letter.
|
|