function WordBot_2_mzip % MATLAB zip file, a self-extracting MATLAB archive. % Usage: Run this file to recreate the original directory. fname = mfilename; fin = fopen([fname '.m'],'r'); dname = fname(1:find(fname=='_',1,'last')-1); mkdir(dname); mkdir([dname filesep 'lib']) addpath(dname) addpath([dname filesep 'lib']) L = fgetl(fin); while length(L) < 2 || ~isequal(L(1:2),'%%') L = fgetl(fin); end while ~isequal(L,'%% EOF') F = [dname filesep L(4:end)]; disp(F) fout = fopen(F,'w'); L = fgetl(fin); while length(L) < 2 || ~isequal(L(1:2),'%%') fprintf(fout,'%s\n',L); L = fgetl(fin); end fclose(fout); end fclose(fin) end %% WordBot.m function WordBot(W,C) % Copyright 2021-2023 Cleve Moler if nargin == 0 || isempty(get(gcf,'userdata')) wfigure H = winit; set(gcf,'userdata',H) if nargin == 0 return end end H = get(gcf,'userdata'); f = find([H(:,1).String],1,'last'); if isempty(f) f = 0; end f = f+1; for i = f:6 for j = 1:5 set(H(i,j),'backgroundcolor',[0 0 0]) end end for j = 1:length(W) set(H(f,j),'string',upper(W(j))) end colors = [0 0 0; .85*gold; green]; for j = 1:length(W) set(H(f,j),'backgroundColor', ... colors(str2double(C(j))+1,:)); set(H(f,j),'foregroundColor',white(1)); end end %% Words10.m function Words10 % Start = ['magic';'equal';'pause';'ratio';'guide';'minus']; C = char('A'+(0:25)); Gray = 'ATIO'; Green = 'R'; Gold = ''; Ok = C; for g = Gray Ok(Ok == g) = []; end list = wordlist; W = '*****'; cnt = 0; for r = 1 W(r) = Green(1); for p = 1:26 if any(C(p) == Ok) fp = find(W=='*',1,'first'); W(fp) = C(p); for q = 1:26 if any(C(q) == Ok) fq = find(W=='*',1,'first'); W(fq) = C(q); for s = 1:26 if any(C(s) == Ok) fs = find(W=='*',1,'first'); W(fs) = C(s); for t = 1:26 if any(C(t) == Ok) ft = find(W=='*',1,'first'); W(ft) = C(t); if any(W==list) disp(W) cnt = cnt+1; end W(ft) = '*'; end end W(fs) = '*'; end end W(fq) = '*'; end end W(fp) = '*'; end end end cnt end %% Words21.m function Words21 % Start = ['magic';'equal';'pause';'ratio';'guide';'minus']; C = char('A'+(0:25)); Gray = 'ATIOPMSCK'; Green = ['W' 'E']; Gold = 'R'; Ok = C; for g = Gray Ok(Ok == g) = []; end list = wordlist; W = '*****'; cnt = 0; for p = 1 W(p) = Green(p); for q = 3 W(q) = Green(2); for r = 4:5 if W(r) == '*' W(r) = Gold(1); for s = 1:26 if any(C(s) == Ok) fs = find(W=='*',1,'first'); W(fs) = C(s); for t = 1:26 if any(C(t) == Ok) ft = find(W=='*',1,'first'); W(ft) = C(t); if any(W==list) disp(W) cnt = cnt+1; end W(ft) = '*'; end end W(fs) = '*'; end end W(r) = '*'; end end end cnt end end %% gold.m function g = gold g = [212 175 55]/256; end %% gray.m function g = gray g = [.94 .94 .94]; end %% green.m function g = green g = [0 .75 0]; end %% trim_word.m function trim_word(c) H = get(gcf,'userdata'); delete(H(end-c+1:end,:)) end %% wfigure.m function wfigure clf reset shg % pos = get(0,'screensize'); pos = [100 100 400 300]; % pos = get(gcf,'pos'); set(gcf,'name','WordBot', ... 'color','w', ... 'numbertitle','off', ... 'toolbar','none', ... 'menubar','none', ... 'inverthardcopy','off', ... 'paperpositionmode','auto', ... 'position',pos) box on set(gca,'xtick',[],'ytick',[]) end %% winit.m function H = winit H = get(gcf,'userdata'); if ~isempty(H) delete(H) end u = 16; y = 12; x = 0; s = .9; H = repmat(uicontrol('vis','off'),6,5); for k = 1:6 for l = 1:5 H(k,l) = wpushbut('',[x+l+3 y-k s s]/u,[0 0 0],@wkey); end end set(gcf,'userdata',H) x = 10; wpushbut(" ", [ x y-3 s s]/u,green,@wcolor); wpushbut(" ", [ x y-2 s s]/u,.85*gold,@wcolor); wpushbut(" ", [ x y-1 s s]/u,[0 0 0],@wcolor); end %% wkey.m function wkey(arg,~) if isequal(arg.BackgroundColor,white(1)) arg.String = ''; else arg.BackgroundColor = white(1); end end %% wpushbut.m function pb = wpushbut(string,position,bgcolor,callback) sze = get(gcf,"Position"); fs = round(sze(3)/100+4); fgcolor = 1-bgcolor; pb = uicontrol(Style = "pushbutton", ... String = string, ... Units = "normalized", ... Position = position, ... Callback = callback, ... ForegroundColor = fgcolor, ... BackgroundColor = bgcolor, ... Fontsize = fs, ... Fontweight = "bold"); end %% EOF