Can a machine write Shakespeare?
-
Tuesday, March 27, 2012 3:57 PM
Hi Folks.
I'm almost a comlpete beginner with Small Basic. I wote this code with the above question in mind. Any comments welcome!
Robin.
While 1=1 c=1 TextWindow.WriteLine("ENTER TARGET PHRASE") TextWindow.WriteLine("") Targetphrase=TextWindow.Read() Targetlength=text.GetLength(Targetphrase) While word<> Targetphrase word="" For i=1 to Targetlength n=31+math.GetRandomNumber(95) l=text.GetCharacter(n) word=word+l endfor c=c+1 endwhile TextWindow.Writeline(word) TextWindow.writeline("Total count: "+c) TextWindow.WriteLine("") endwhile
All Replies
-
Friday, April 27, 2012 10:05 AMAnswerer
I rewrote your program and gave more hints for a machine. Conclusion: A machine should learn more before writing Shakespeare.
While 1=1 c=0 TextWindow.WriteLine("ENTER TARGET PHRASE") TextWindow.WriteLine("") Targetphrase=TextWindow.Read() Targetlength=text.GetLength(Targetphrase) TextWindow.WriteLine("") AnalysePhrase() n=range r=Targetlength Permutation() TextWindow.WriteLine("Estimated count: P("+n+","+r+")="+ans) top=TextWindow.CursorTop While word<> Targetphrase c=c+1 word="" For i=1 to Targetlength n=min+Math.GetRandomNumber(range) l=Text.GetCharacter(n) word=word+l EndFor TextWindow.CursorLeft=0 TextWindow.CursorTop=top TextWindow.WriteLine("Generated: "+word+" "+c) EndWhile TextWindow.writeline("Total count: "+c) TextWindow.WriteLine("") EndWhile Sub AnalysePhrase min=1000 max=0 TextWindow.Write("Code: ") For i=1 To Targetlength char=Text.GetSubText(Targetphrase,i,1) code=Text.GetCharacterCode(char) TextWindow.Write(code+" ") If max<code Then max=code EndIf If code<min Then min=code EndIf EndFor TextWindow.WriteLine("") TextWindow.Write("Code range: "+min+"-"+max) min=min-1 range=max-min TextWindow.WriteLine("("+range+")") EndSub Sub Permutation ans=1 For i=n-r+1 To n ans=ans*i EndFor EndSub
Nonki Takahashi

