--!name Cryptogram
--!icon puzzle
--!category Puzzles
local aD=[[
C##age)resi#,nce+f#4, mas#$y*f#4, >abs#i*f#4<
Al#Hs#> r#e. T#n#ygratif#^#&$J0astonish%rest<
Man#d$*animal=blushes. Or n#Fs#=<
$xf##;#0#E#j#Qgry, sw#4<
Few /s~h#7er+put up$( #z%annoy#v#J#l example<
Get$/facts first,0]n6c#(d#Cort ]m#.6please<
9re#{*my $4$" #(exaggera{<
Wrinkl#"$<$K5dicate#0e#%smil#"#hZen<
Be c#;l#-5$/dr#- if6must_#~2tidy#Iul<
Let us #Weavor#I+#o=when#1 c#&+die even%$,takXw#DZ#Irry<
I#b resi#*e#j/$L tempta{4
Ex#2i#i#dname e#j ` gives+]ir $@s4
We~#<5%gut#$_s#&*us~look7 at%#,rs4
To #q `#k#d$I*a$'#u rom#v4
9#Kth)r#;ly pure0#f$2e4
Nowa#Os$J #g%pr#M*e#j/#Qd%value*no/4
$.>y#Ug $?+#g e#j/4
9$*#H+get rid#Jtempta{#S yield+it4
Life)far#=o im#{ant2/ ever+talk seri#@ly ab#L4
Ambi{$c#sfailure4
MenZc#& old_#R#fbec#& #l4
We#!d`$GQwe#!said1
Early+bed0#4ly+r#:, #cs2m#(healthy,#1althy,0w#:1
T$3may #~2$B, if two*]m~dead1
Fish0visitors#Zink5 t$3#Os1
He=li#"down$(#>g#`sha#!r#: up$( fleas1
The#%#fwas2#l war,#[2bad peace1
Glas#`china,0reputa{~easily cracked,0#fwe#!m#Wed1
Love$/enemies,$+#Rt#X6y###\ults1
In t#n$$#8/#bZ said#tcert#5,$L $40taxes1
9$*#H+#h2$>#SZ `3
No/ g#)t$" #Vachieved$(#L #3husiasm3
ToZ g#)t#SZ mis$,stood3
A foolish#msi#?ncy#dhobgoblin*$: m#6s3
Adopt%pace*$C: hX$B)pati#i3
What)a#1ed? A#wnt#0ose $8#"#h >yetZ#Ediscove#B3
9rew#7#J/#1#!d`#S #h d`}3
Our$')frit#$ed a#H by detail. Simplify, $2ify8
Ra]rQ#q,Qm`y,Qfame, give me #Kth8
It)#ftoo late+give up ## prejud#Ms8
9mass*m#Elead #os*quiet des#2a{8
Bew#;*a#!en#$pr#:s=requi#%new clo]s8
Not until#1~lo#*do#1Zgin+$,#,nd ##$=8
A h#@e divided ag#5st}#k#b>#,nd$v
Wi#_mal#M#=w#7 n`,$( charity$+#<$v
All%$$'s2#,ge,0#<%men0w#&n$K#wyers(
9c##se*#Ke #q #fdid run smooth(
We #g$)#1 #;_#g >what#1 mayZ(
T$F/ eithX#l#[ bad_$17 mak#"it#I(
Love #<, #Kst2few,#> wrong+n`(
Cow#7s die#ay #ps$7]ir $4s;%valiant #fta#?*$4$# once(
9fool#>#_$1 he)w#:,$#%w#:#a #gs#x#k+be2fool(
BettXt$3h##s#=o#IonQa minute#=o late(
How#\r=$:#bdle th#9s hisZams! So shines2#l d#F52naughty $$(
NeithXa bor#9Xnor2l#WXbe(
Uneasy lies%head=w#4s2c#9n(
If#GsicZ%food*#q,#wy on(
9bettXpart*val##)discre{(
Love looks >with%eyes_with%m#6(
W#:ly0slow; #Rstum#Y=run#\st(
When2man)ti#B*London, he)ti#B*life$m
Patriotism$c#Jsc#Udrel$m
No#a$#2blockhead #Vwrote,$L$+m`y$m
Curiosity)`#s#2man#30cert#5 charac#$#Cics#Jvigor#@ m#6$m
A $: l#4n7#]danger#@ /$g
Fools rush5#0e#%angels f#4+t#)d$g
Hope spr7s e#$nal5$Eb#)st$g
Bl#-ed)h$9expects#8/,$+he sha#!#fb$aed$g
Angels#b fly$H#R$% ]mselv#"l#ely^
9poets #hZ#Emys#$i#@l#^il#3 on%subject*cheese^
There~no unin#$est7 /#`$*unin#$e#?d$J^
An adv#3ure)$*an5conveni#i r#ely#m$&#B^
9travel$esees,%tripp$ehas c#&+see^
H$9can,#>es. H$9cannot, teaches${
T$F #q sincerX#z%#q*food${
Bew#;*false #gledge;})mo#%danger#@Qignor#v${
E#j/)funny,#. #u#.})#ren7+s#&body els#'$W
Ev#Eif6a#%on%r#e track,6#yget run ovXif6ju#*sit ]r#'$W
$.>a member*any#[ganized $S$5y. I am2Democrat.|$W
Genius)` #2c#35spira{0ninety-nine #2c#3 #2spira{$NEdi#/
T$F substitute$+h#7 #+k$NEdi#/
Failure)$2y%op#{unity+begin ag#5, t#n#p more5t#Xig#3ly.|Henry Ford
Speak#Iftly0carry2big#Zick;6#ygo#\r.|$w
Do$)6can,$($)6#h,#0ere6ar#'$w
Doubt)>a pleasant#mdi{_cert#5ty)absurd$Y
If God did >ex#C,} $A nec#-ary+inv#3#x$Y
9j##ney#Jth#@and milesZgins$(2s7le #?p$O
H$9#gs #|)w#:; h$9#gs#x#k)enl#eened$O
Natu#%do#">hurry, yet e#j/)$Xed$O
Thos$9#g#> >$-. Thos$9$-#> >#g$O
To see$))r#e0not+do})want*c##ag#'$Q
9su#2ior#a)modest5 #nspeech_exc#Fs5 #nac{s.|$Q
Real #gledge#S #g%ext#3*`#Aignoranc#'$Q
One sw#<ow#>#">#c2summer$[
Man)by $C2$S#Qimal$[
9$I#dmo#*im#{ant$5#s#+k.|Plato
9unexamined$')>#+#_liv7.|Socrates
While#1~postpon7,$' sp#Fs b$P
As #u#.6#o, #~ $Zliv#'Seneca
Difficulti#"streng]n%m#6,#. labor#>es%bod$P
We suffXmo#%often5 imagina{Qin #)lit$P
Wa#?#8 mo#%#p argu7$)2#l#a $<Z. Be `$t
Very $:)n#Fed+#c2#ry$'$t
9be#*#H*aveng7 thy#k)not+bec#& #}%wrongdoer$t
Men~d#Curbed >by /s_by%views#0i#P#R$%*/s$]
No#a)free#0o)>mas#$*him#k$]
Fir#*say+y###k$)6$A;0]n#>$)6#h+do$]
It#]bad#wn=admits*no modifica{$u
Pract#M#dbest*#<5s#Kctors$u
Read7 #cth2$!#a;#mfer#i2#)dy#a;0writ7 #(exact#a$j
S#& books #;#tta#?d, #|#tsw#<owed,0s#& few#tchewed0dige#?d$j
A w#:#a #y#c mo#%op#{unitiesQhe f#6s$j
Hope#]#l b#)kfast_it#]bad sup#2$j
Vision#dart*see7 /s5visi#Y$o
May6#o #<%#Os*y##$'$o
E#j#a desires+#o #u_no#a $A old$o
H`sty#dfir#*chaptXin%book*wisdom$^
N#Vput off ti#!tomor#9$)6c#(do#=#O$^
$xtenZ#Ne6$-; if #j#Qgry,2hund#B$^
It$"%best*#ps,}$"%#+st*#ps$p
No `)#Tl#-5 t#n$$#0o l#eens%burden*it$+any ` else$p
T$F/5%$$#I irres#Cibly#mtagi#@#. laugh#$0#l hum##$p
T$F charm equal+t#Wern#-*h#4t.$`
I decla#%aftXa#!t$F enjoym#3 #} #)d7!$`
One half#s$$#b>$,#,nd%pleasur#"of%o]r.$`
Why, $MI'veZlieved#.#ay#. six $V /s$7b#)kfast$i
It's#8 #T go7 back+yes#$#O,$HI$"2differ#3 #2#/ ]n$i
Begin at%$I,0go on t#D6c#&#=%#W: ]n#Zop$i
E#j/#Agot2moral, if only6c#(f#6}$i
Take ca#%of%sense,#Qd%s#Uds #y$% c#;*]m$=$i
To travel hope$!y)aZttX/ #z+arrive[
T$F duty#1#I#G#P$,rate#.%duty*be7 #ry[
E#j` liv#"b#^#X7 s#&/[
9$$)so $!#Jnumber*/#`I'm su#%we $< #<Z#. #ry#. k7s[
Know$dapply. W#D$ddo.$}]
No/)#+#_moreQt#n#O.$}]
LaughtXis%sun=driv#"wintXfrom$Efac#'$\
H$9opens2school#>or, closes2pri#/.|$\
Music expr#-es=which#b>be said0on#0ich})$V#tsil#3.|$\
Happy#\milies~a#!a#}; e#j un#ry#\mily)un#ry5}s own #H.|$_
9two $fwarriors~pati#i0tim#'$_
Pati#i:2minor #Nm*despair, disgu#:d#.2$8e@
Bore:2#2#/#0o talks#0en6wish#x+li#?n@
Egot#C:2#2#/*low ta#?, more5#$e#?d5#x#kQin me@
Calamiti#"#;*two k#6s: $U+##$=,0#l #Ntune+#|@
Admira{: ## polite recogni{*ano]r#Aresembl#v+##$=@
Y#4:2#2iod*t$3hund#B0sixty-fiv$am#3s@
Apologize:+lay%f#Uda{ #N2futu#%offense@
Nobody #V#Ngets#0e#%he buried2hatch$k
9safe#*#H+dou#Y$/m`y#S fold} ovXonce0put}5$/pock$k
Con$&r%po#,ge #,mp:}s #Tfuln#-#ms#Cs5%ability+stick+` / ti#!it gets ]r#'Josh B#D7s
Do >$%$'#=o seri#@ly. You #y#fget #L*it a#o$n
A $>)on$9#gs a#!ab#L you0#}s6just$0$n
Positive#Qy/$GQnegative#8/$n
9g#)te#*$@6c#(#c5$'#SZ#mtinu#<y f#476#y#c `$n
A m#&nt's5s#e)$M#+th2life#Aex#2i#i.|OlivXW#We#!Holmes
Time #,ys #u $?$+anyon$9#y#T}$y
Iron rusts$6 dis#T; #,gnant watXlos#"its purity$y
Bl#-ed)h$9has f#Ud #n#+k; let#x#.k#8 othXbl#-edn#-$T
Sil#i)mo#%eloqu#3Q#+ds$T
A#a#0o d#;s+wa#? ` h##*#p has >discove#B%value*lif#'Charl#"Darwin
To $X g#)t /s#1#G#*>$*act_also d#)m; >$*plan_alsoZliev#'Anatole Fr#v
9$B*succ#-)con#,ncy+purpos#'Benjamin Disraeli
Do$s? Very#1#!]n$s, $.large, I#mt#5#Gltitudes.|Walt Whitman
Hope#d/$( fea]rs=#2ches5%soul$r
That} #y#fc#& ag#5)what mak#"life#I sweet$r
Wisdom#dsupreme$5*#rin#-.|Sophocles
Seize%#O, put#8 #Kst5%mor#9.|Horace
They#b$H#R$1 ]y#b.|Virgil
If6#h2g#7en5$/library,#8/ w#DZ lack7.|C#Mro
It)al#Hs darke#*justZ#Ne%#O dawneth$NFuller
He=#os5 hope d#vth$(#L#Gsic$RHerbert
No#a)#(island, #3ire*it#k.|John Donne
9m#6)its own#wce,0in}#k#b #c2heaven*h#X,2h#X*heaven.|John Milton
'TisZt#$+#h #qd0lostQnever+#h #qd at #<.|Alf#B Tenny#/
Ah_a#a#A#)#P$< exc#F #ngrasp,#[$)'s2heav#E#N?|Robert B#9n7
Words #;,*c##se,%$fdrug #Td by#ak#6$h
I #~ six h`#*serv7-men; #Rtaught me a#!I knew$h
You#b >cross%sea by$K #,nd70#,r7 at%wa#$$|
Faith#dbird=feels%l#e#0en%dawn)sti#!dark$|
If t$F s#Kggle, t$F progr#-.|F#Berick Douglass
I attribute m#^ucc#-+this: I #fgave#[#=ok#Qy excus#'Flor#i N#e7ale
No/5$'#SZ f#4ed,})only#t$,stood.|Marie Curie
$.>$D*storms,$+$.$Zsail m#^hip.|Louisa May Alcott
Isn't} n#M+$1=tomor#9#]new #O$(#8 $@s5} yet?|L. M. Montg#&ry
To die w#DZ #(aw$!y big adv#3ur#'$b
Thos$9br7 sunshine5to%#os*#|#b>#~}$6 ]m$=.|$b
T$F/ half#I#G#P#+th#>7#. $2y m#-7 ab#L5 boats.|Kenne#_Grahame
A $:5accuracy $Msav#"tons*explana{.|Saki
I #} #+k:}#\scinat#"me. I#b sit0look at}$+h##s.|Jer#& K. Jer#&
When6#h eliminated%$V,$)#Vrem#5#`how#Vimproba#Y,#GstZ%#Kth$z
It#]capital $@+]orize$7` has data$z
Adapt#[ #2ish,#8w#. ever,)$C's5exora#Y im#2ativ#'H. G. W#Xs
Animals~su#Pagreea#Y $>s: ]y#.k#8 ques{#`#Rpass#8 criticisms$REliot
No/)so p#5ful#=$Em#6#.2g#)t0sudd#Echang#'Mary Sh#Xey
All=we see#[ seem)but2d#)m$(in2d#)m.|Edgar All#(Poe
It$G+fail5#[iginality #z+succ#F5 imita{.|Herm#(Melv#De
A sharp#=ngue#d$*edged#=ol=g#9s keenXwith#m#,nt us#'Wash7ton Irv7
Into each$' s#& r#5#G#*f#<.$~low
Lives*g#)t m#Ea#!rem#6 us#1#b #c ## liv#"sublime.$~low
It$G+offXno exc#TQa bad `$RWash7ton
I $*regret=I #h$# `$'+lose$+my c#Utry.|Nath#(Hale
These #;%#ps=try men#Asouls$NP#5e
9h#7er%conflict,%mo#%glori#@%triumph$NP#5e
No#a #V#?ps5$0 rivXtwic#'Heraclitus
Talk70eloqu#i~not$0:+$-,#Qd+$-#1ll,~two /s.|B#EJon#/
We a#!#h#Zreng#_$?+#Wure%$Us*#|.|$q
Hypocrisy#dhomage#0i#Pv#M pays+$8#'$q
I #h made t#nlettX#uerQusual,$HI lack%#p+#c} short$l
9h#4t has}s #)#/s#0i#P#)#/ #gs#8/ of$l
My$' hasZ#E$!*#$ri#Y $U#`most*whi#P#f#rened.|Michel de Montaigne
9proof#spudd7)in%eat7.|Miguel de Cervantes
Pati#i)bit#$_its fruit)sweet.|Jean-Jacqu#"R#@seau
In%land#sbl#6,%`-eyed#a)k7.|De$&rius Erasmus
9pen)m#eiX#z%s#+d.|Edw#7 Bulwer-Lytton
Beauty)in%eye#sbeholder.|Marg#;t Wolfe Hunger#Nd
If at first6don't succ#F, try, try ag#5.|W#Diam Edw#7 Hick#/
Be >$D*g#97 slowly,Z $D only*#,nd7#Z#D&
$;c#Ut$/chickens$7]y~hatched&
Empty v#-els #c%mo#*no#:&
Abs#i #cs%h#4t g#9 fonder&
You#b lead2horse+wa#$,$#6can't #c} drink&
$;put a#!y## eggs5 ` basket&
When%cat#Aa#H,%m#M #yplay&
A bird5%hand)#+#_two5%bush&
Birds#JfeathXflock#=ge]r&
$;cross%bridge t#D6c#&+it&
Nec#-ity#dmo]r*inven{&
Peopl$9#o5 glass h#@#"$< >th#9#Z`s&
G#)t oaks$6 $: acorns g#9&
A ch#5)$*as#Zrong#.}s#1ake#*link&
9grass)al#Hs greenXon%othX$&#sf#i&
A $>5 n#F#]$>5d#F&
9squeaky#0eel gets%g#)se&
One#a#Ameat)anothXman#Apoi#/&
Fools0]ir m`y~soon$5ed&
Half2loaf$GQno b#)d&
9road+h#X)paved$( #l5ten{s&
$;bite%hand=f#Fs you&
An empt#^ack#b>#,nd upr#e&
It)no #T cry7 ovXspilt milk&
9cob#Yr#Achildr#Ego b#;foot&
What#b'tZ cu#B#GstZ #Wu#B&
Good fenc#"#c #l neighb##s&
$;th#9%baby #L$(%bathwa#$&
You#b't tea#P#(old#>g new tricks&
9apple #ff#<s#\r$6%tree&
N#Vlook2gift horse5%m#Lh&
L#en7 #fstrik#"tw#M5$0#wce&
It#A#(i#!w#6=blows#8body#Qy #l&
Many2#Ke #+d)spoken5 jest&
A leop#7#b>change}s spots&
$;#c2m#Ut#5 #L#Jmoleh#D&
H#6s#e$GQ#Nes#e&]]local a0=[[
 the 
.|Proverb
.|William Shakespeare
 is 
 of 
 to 
thing
 and 
.|Benjamin Franklin
 a 
.|Ralph Waldo Emerson
.|Oscar Wilde
 in
 you 
ing
.|Henry David Thoreau
The 
.|Mark Twain
 that 
not 
.|Ambrose Bierce
 than 
er 
 be
.|Robert Louis Stevenson
the
.|G. K. Chesterton
, but 
one
tion
 it
 are ]]local a1=[[
ll es ourterre omee.|an reast worstaess asson wh weperentearainindard norowiseareall to dosteous's redistillen eed muway so*a truouticefordaych  an]y )touseounevXendellble st or fa)a y sth s,  man canmake is%ightnevXknowhaveenceveryselfgood conhis livetimelovehapp of%+be longance pla himwi#!thanporto]rslikekeepfull was but#+ldtakeside life with whatonly  for underspeakI am  y## %samethinksimplhree death part fromZfo#%virtue who littleDon't shouldselvesfriendenoughmi#,kewouldZsecretnatureafraid%hum#(here)no)betterZcause beginn7 people merely excepts#&tim#".|Thomas .|Lao Tzuy.|SenecaConfucius.|George political$NCarlylemisfortuneimpossibleWi#!Rogersaccomplish.|Voltairel#4n7 how+.|Ar#CotleVictor Hugo.|Epictetus$NJeffersonLeo Tolstoy|Jane Austene disappointJ. M. Barrie#dla#*refuge7)>$?;#1#G#*Xse#"what he mo#*powerful .|AlexandXPope.|Rudy#7 Kipl7.|Lewis Carroll.|Francis Baconet.|Kin Hubbard.|Blaise Pascal.|Samuel Johnson.|Elbert Hubbard.|Jonathan Swift.|Charl#"DickensLa Rochefoucauld.|Emily Dickin#/ I#mtradict my#k.|Marcus Aurelius.|Publilius Syrus.|Abraham LincolnTheodo#%RooseveltWhen angry, count .|Leonardo da Vinci.|Arthur Con#(Doyle.|George Bernard Shaw.|Rabindranath Tagore|Johann Wolfgang von Goe|Henry Wadsworth Longfel]]local a3={0,0,64,36,18,13,7,1,7,7,4,5,2,2,4,7,4,1,2,0,2,0,0,2}local aH,aE="%&()*+/0123456789<=>@QXZ[]^_`{}~","#$"local ao=""for a=33,126 do ao=ao..string.char(a)end local function aQ(r)return"["..r:gsub("%p","%%%0").."]"end local a5,a4=aQ(aE)..".",aQ(aH)local ap={}for bh in(a0.."\n"):gmatch("(.-)\n")do ap[#ap+1]=bh end local function bi(C)local n,V=1,1 for M,u in ipairs(a3)do if C<u then return a1:sub(n+C*V,n+C*V+V-1)end C,n,V=C-u,n+u*V,V+1 end return""end local ak local function bu(W)return ak(bi((aE:find(W:sub(1,1),1,true)-1)*94+ao:find(W:sub(2),1,true)-1))end local function bt(W)return ak(ap[aH:find(W,1,true)])end function ak(r)return(r:gsub(a5,bu):gsub(a4,bt))end local function bp(r,d)local A=1 for M=2,d do A=r:find("\n",A,true)+1 end local a8=r:find("\n",A,true)return r:sub(A,(a8 or 0)-1)end local m=1 for M in aD:gmatch("\n")do m=m+1 end local function aX(d)return ak(bp(aD,d)):match("^(.-)|(.*)$")end local s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"local a_="abcdefghijklmnpqrstuvwxyz12345"local O={"QWERTYUIOP","ASDFGHJKL<","ZXCVBNM?!"}local _,aC=16,3 local function ba(d)local ax=d*7919+12345 local p={}for a=1,26 do p[a]=a end for a=26,2,-1 do ax=(ax*1103515245+12345)%2147483648 local C=(ax>>8)%a+1 p[a],p[C]=p[C],p[a]end for a=1,26 do if p[a]==a then local C=a%26+1 p[a],p[C]=p[C],p[a]end end return p end local function bs(ae)local E,H={},""for Z in ae:gmatch("%S+")do if H==""then H=Z elseif#H+1+#Z<=_ then H=H.." "..Z else E[#E+1]=H;H=Z end end if H~=""then E[#E+1]=H end return E end local a2=os.time({year=2026,month=1,day=1,hour=12})//86400 local function L()local c=os.time()if not c or c<1700000000 then return nil end local e=os.date("*t",c)return os.time({year=e.year,month=e.month,day=e.day,hour=12})//86400 end local function U(e)return(e-a2)%m+1 end local j={solved=0,perfect=0,streak=0,best=0,last=0,hints=0,psolved=0}local aq={"solved","perfect","streak","best","last","hints","psolved"}local K=string.rep(".",m)local o={day=0,g=nil}local G=nil local ad,h=nil,nil local aF,aB,E,x,p,ab,am=nil,nil,nil,nil,nil,nil,nil local n,t,D,z,w=1,1,1,false,nil local q,F,v="menu",1,1 local function aU(I)return{idx=I,guess=string.rep(".",26),hints=0,checks=0,at=1,done=false}end local function aP(g)if not g then return""end return table.concat({g.idx,g.guess,g.hints,g.checks,g.at,g.done and 1 or 0},",")end local function X(r)return math.tointeger(tonumber(r))or 0 end local function aO(r)local l={}for aA in((r or"")..","):gmatch("([^,]*),")do l[#l+1]=aA end local I=X(l[1])if I<1 or I>m or#l<6 or not l[2]:match("^[%.a-zA-Z]+$")or#l[2]~=26 then return nil end return{idx=I,guess=l[2],hints=X(l[3]),checks=X(l[4]),at=math.max(1,X(l[5])),done=l[6]=="1"}end local function aY()local c={"C1"}for M,d in ipairs(aq)do c[#c+1]=j[d]end c[#c+1]=K c[#c+1]=o.day c[#c+1]=aP(o.g)c[#c+1]=aP(G)snail.save(table.concat(c,";"))end local function bn()local r=snail.load()if type(r)~="string"or r:sub(1,3)~="C1;"then return end local l={}for aA in(r..";"):gmatch("([^;]*);")do l[#l+1]=aA end for a,d in ipairs(aq)do j[d]=X(l[a+1])end local u=#aq+1 local bq=(l[u+1]or""):gsub("[^.osp]",".")K=(bq..string.rep(".",m)):sub(1,m)o.day=X(l[u+2])o.g=aO(l[u+3])G=aO(l[u+4])end local aG={["."]=0,o=1,s=2,p=3}local function aR(a,b)if aG[b]>aG[K:sub(a,a)]then K=K:sub(1,a-1)..b..K:sub(a+1)end end local function ay()local M,u=K:gsub("[sp]","")return u end local function az()local e=L()if e and j.last>=e-1 then return j.streak end return 0 end local function B(f)local b=h.guess:sub(f,f)if b=="."then return 0,false end return s:find(b:upper(),1,true),b:match("%u")~=nil end local function Y(f,i,R)local b=i==0 and"."or s:sub(i,i)if i>0 and not R then b=b:lower()end h.guess=h.guess:sub(1,f-1)..b..h.guess:sub(f+1)end local function N()return x[n].x end local function aN()local P,S=0,0 for f=1,26 do if am[f]then S=S+1 if B(f)>0 then P=P+1 end end end return P,S end local function av(W,g)ad,h=W,g aF,aB=aX(g.idx)E=bs(aF:upper())p,ab,am,x=ba(g.idx),{},{},{}for a=1,26 do ab[p[a]]=a end for ac,al in ipairs(E)do for b=1,#al do local i=s:find(al:sub(b,b),1,true)if i then x[#x+1]={l=ac,c=b,x=p[i]}am[p[i]]=true end end end n=math.min(g.at,#x)z,w,t,D=false,nil,1,1 q="game"aR(g.idx,"o")aY()end local function aw()local e=L()if not e then q="noclock";return end if o.day~=e or not o.g then o.day,o.g=e,aU(U(e))end av("daily",o.g)end local function aW(I)local e=L()if e and I==U(e)then return aw()end if not(G and G.idx==I)then G=aU(I)end av("practice",G)end local function bj()h.done=true local aM=h.hints==0 and h.checks==0 aR(h.idx,aM and"p"or"s")if ad=="daily"then j.solved=j.solved+1 j.hints=j.hints+h.hints if aM then j.perfect=j.perfect+1 end j.streak=j.last==o.day-1 and j.streak+1 or 1 j.last=o.day if j.streak>j.best then j.best=j.streak end else j.psolved=j.psolved+1 end w=nil end local function aL()local P,S=aN()if P<S then return end for f=1,26 do if am[f]and B(f)~=ab[f]then w="All filled in, but something's wrong"return end end bj()end local function aI()for d=1,#x do local a=(n+d-1)%#x+1 if B(x[a].x)==0 then n=a;return end end end local function a7(i)local f=N()local M,R=B(f)if R then w="A hint gave that letter";return false end for T=1,26 do local g,ac=B(T)if T~=f and g==i then if ac then w=s:sub(i,i).." is already placed by a hint";return false end Y(T,0)end end Y(f,i)return true end local function bl()local f=N()local M,R=B(f)if R then w="That letter is already shown";return end local i=ab[f]for T=1,26 do if T~=f and B(T)==i then Y(T,0)end end Y(f,i,true)h.hints=h.hints+1 w="Revealed: "..s:sub(f,f).." is "..s:sub(i,i)end local function a9()local ag=0 for f=1,26 do local g=B(f)if g>0 and g~=ab[f]then Y(f,0);ag=ag+1 end end h.checks=h.checks+1 if ag==0 then w="Every letter so far is right"else w=ag..(ag==1 and" wrong letter taken out"or" wrong letters taken out")end end local function aT(e)local i=x[n]local ar,aJ=nil,99 for a,ae in ipairs(x)do if ae.l==i.l+e and math.abs(ae.c-i.c)<aJ then ar,aJ=a,math.abs(ae.c-i.c)end end if ar then n=ar;return true end return false end local function bo()local e=L()for d=1,m do local a=(h.idx+d-1)%m+1 local b=K:sub(a,a)if b~="s"and b~="p"and not(e and a==U(e))then return aW(a)end end q="menu"end local function at(J,b)return O[J]:sub(b,b)end local function bk(d)if h.done then if d=="ok"and ad=="practice"then bo()elseif d=="ok"or d=="top"then q,F="menu",1 end return end w=nil if not z then if d=="top"then q,F="menu",1;return end if d=="left"then n=(n-2)%#x+1 elseif d=="right"then n=n%#x+1 elseif d=="up"then aT(-1)elseif d=="down"then if not aT(1)then z=true end elseif d=="ok"then z=true local g=B(N())if g>0 then for J=1,3 do local b=O[J]:find(s:sub(g,g),1,true)if b then t,D=J,b end end end end h.at=n return end if d=="top"then z=false elseif d=="up"then if t==1 then z=false else t=t-1 end elseif d=="down"then t=math.min(3,t+1)elseif d=="left"then D=(D-2)%#O[t]+1 elseif d=="right"then D=D%#O[t]+1 elseif d=="ok"then local k=at(t,D)if k=="<"then local M,R=B(N())if R then w="A hint gave that letter"else Y(N(),0)end z=false elseif k=="?"then bl();z=false;aL();if not h.done then aI()end elseif k=="!"then a9();z=false elseif a7(s:find(k,1,true))then z=false aL()if not h.done then aI()end end h.at=n aY()end D=math.min(D,#O[t])end local function aS()local c={}local e=L()if e then local au="Today's quotation #"..U(e)if o.day==e and o.g then au=au..(o.g.done and" - solved"or" - carry on")end c[#c+1]={au,"daily"}else c[#c+1]={"Today's quotation: needs the clock","noclock"}end if G and not G.done then c[#c+1]={"Carry on: quotation #"..G.idx,"prac"}end c[#c+1]={"All quotations","list"}c[#c+1]={"Statistics","stats"}c[#c+1]={"How to play","help"}return c end function key(d)if q=="game"then return bk(d)end if q=="menu"then local Q=aS()if d=="up"then F=(F-2)%#Q+1 elseif d=="down"then F=F%#Q+1 elseif d=="ok"then local A=Q[F][2]if A=="daily"then aw()elseif A=="prac"then av("practice",G)elseif A=="list"then local e=L()v=h and h.idx or(e and U(e))or 1 q="list"else q=A end end return end if q=="list"then if d=="top"then q="menu"elseif d=="up"then v=(v-2)%m+1 elseif d=="down"then v=v%m+1 elseif d=="left"then v=math.max(1,v-10)elseif d=="right"then v=math.min(m,v+10)elseif d=="ok"then aW(v)end return end if d=="top"or d=="ok"then q="menu"end end local function ah(a)return a_:sub(a,a)end local function aK()local y,bb,aj={},N(),h.done local a=0 for ac,al in ipairs(E)do if ac>1 and(#E<=5 or aj)then y[#y+1]=string.rep(".",_)end local aa,ai={},{}for b=1,_ do local k=al:sub(b,b)local i=s:find(k,1,true)if k==""or k==" "then aa[b],ai[b]=".","."elseif i then a=a+1 local f=p[i]local g=B(f)if a==n and not aj then aa[b]=g>0 and ah(g)or"#"else aa[b]=g>0 and"{"..s:sub(g,g).."}"or"o"end ai[b]=f==bb and ah(f)or s:sub(f,f)else aa[b],ai[b]=k=="."and ah(30)or k,"."end end y[#y+1]=table.concat(aa)if not aj then y[#y+1]=table.concat(ai)end end if aj then return table.concat(y,"/")end y[#y+1]=string.rep(".",_)for J=1,3 do local c={string.rep(".",aC)}for b=1,#O[J]do local k=at(J,b)if z and J==t and b==D then local i=s:find(k,1,true)c[#c+1]=ah(i or(("<?!"):find(k,1,true)+26))else c[#c+1]="{"..k.."}"end end c[#c+1]=string.rep(".",_-aC-#O[J])y[#y+1]=table.concat(c)end return table.concat(y,"/")end local function an(u,Z)return u.." "..Z..(u==1 and""or"s")end local function bd()local as,b=h.hints,h.checks if as==0 and b==0 then snail.status("Solved! No hints, no checks")else local c={}if as>0 then c[#c+1]=an(as,"hint")end if b>0 then c[#c+1]=an(b,"check")end snail.status("Solved with "..table.concat(c," and "))end snail.board(aK())snail.text("- "..aB)snail.rule()if ad=="daily"then snail.small("Streak: "..an(az(),"day")..", best "..j.best..". A new quotation tomorrow.")snail.hint("BACK OK done")else snail.small(ay().." of "..m.." quotations solved.")snail.hint("BACK OK next quotation")end end local function be()snail.title((ad=="daily"and"Today's quotation #"or"Quotation #")..h.idx)if h.done then return bd()end local P,S=aN()snail.status(w or("Letters "..P.." of "..S.."   Hints "..h.hints))snail.board(aK())if not z then snail.hint("BACK OK keyboard")return end local k=at(t,D)local br=k=="<"and"clear letter"or k=="?"and"reveal letter"or k=="!"and"check letters"or s:sub(N(),N()).."="..k snail.hint("BACK quote OK "..br)end local a6={o=" - started",s=" - solved",p=" - solved, no hints"}local function bf()snail.title("All quotations")local e=L()local bc=e and U(e)local aV=13 local aZ=math.max(1,math.min(v-6,m-aV+1))for a=aZ,math.min(m,aZ+aV-1)do local b=K:sub(a,a)local af=a6[b]or""if a==bc then af=" - today"..af:gsub(" %- ",", ")end if b=="s"or b=="p"then local M,A=aX(a)af=af.." ("..A..")"end snail.row("Quotation "..a..af,a==v)end snail.small(ay().." of "..m.." solved.")snail.hint("BACK back OK play L/R jump 10 UP/DN move")end local function bg()snail.title("Statistics")snail.text("Daily quotations solved: "..j.solved)snail.text("Streak: "..an(az(),"day")..", best "..j.best)snail.text("Solved with no hints or checks: "..j.perfect)snail.text("Hints used on daily quotations: "..j.hints)snail.rule()snail.small("Practice quotations solved: "..j.psolved)snail.small("Quotations solved so far: "..ay().." of "..m..".")snail.hint("BACK back OK back")end function draw()if q=="game"then return be()end if q=="list"then return bf()end if q=="stats"then return bg()end if q=="menu"then snail.title("Cryptogram")local e=L()if e then snail.status(os.date("%A, %B ")..tonumber(os.date("%d")).." - streak "..az())else snail.status("Every quotation works any time")end local Q=aS()if F>#Q then F=#Q end for a,bm in ipairs(Q)do snail.row(bm[1],a==F)end snail.gap()snail.small(m.." quotations, each in its own letter code.")snail.hint("BACK leave OK choose UP/DN move")return end if q=="help"then snail.title("How to play")snail.text("Each letter of the quotation is swapped for another. The code letters sit under the boxes.")snail.text("The black box is your cursor. Arrows move it; OK opens the keyboard.")snail.text("Pick the real letter: it fills every box with the same code letter.")snail.text("On the keyboard: < clears a letter, ? reveals one, ! takes out wrong letters.")snail.text("No letter stands for itself. The author shows when you solve it.")snail.hint("BACK back OK back")return end snail.title("Today's quotation")snail.text("The daily quotation needs the date.")snail.text("Connect to Wi-Fi once so the clock gets set, then come back.")snail.text("Every quotation can still be played from All quotations.")snail.hint("BACK back OK back")end function start()bn()local e=L()if e and not(o.day==e and o.g and o.g.done)then aw()end end
