aboutsummaryrefslogtreecommitdiff
path: root/challenge-004/abigail/lua
diff options
context:
space:
mode:
authorboblied <boblied@gmail.com>2021-03-09 07:52:31 -0600
committerboblied <boblied@gmail.com>2021-03-09 07:52:31 -0600
commitc897ab614e0a35455865bfe930df300bb854a03b (patch)
treea6a3527b8364196045a94ab49661bd2eb9c8fea6 /challenge-004/abigail/lua
parent199d363b79e769bf8dc150bf37228395bfbb4d16 (diff)
parentda7e149ecb3abdf29d3fb4f712427217d02f2fe1 (diff)
downloadperlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.tar.gz
perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.tar.bz2
perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-004/abigail/lua')
-rw-r--r--challenge-004/abigail/lua/ch-1.lua71
-rw-r--r--challenge-004/abigail/lua/ch-2.lua51
2 files changed, 122 insertions, 0 deletions
diff --git a/challenge-004/abigail/lua/ch-1.lua b/challenge-004/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..03a06fd74b
--- /dev/null
+++ b/challenge-004/abigail/lua/ch-1.lua
@@ -0,0 +1,71 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua
+--
+
+local pi = "%(uP7+Y`ME)gy(7')v?;%s^qc(Mj1}16idp'ONGs'2m.o,1HLY'}~P61@@Y-" ..
+ "*O/.v,Jc~D+ttA'&EPjR(zXxD$dr,M$P=-f*YQqe,GIZ`0x5oL1(mpl17en`" ..
+ ")Q$ge,L6_5.I;hj%yy6n,L_t')dtyy)[ugS&-3(c&lC:a&~8SP#+iis+WR&8" ..
+ "*Y;V3/+JD@-J>7u0$Nh<#2&:@+#=`/*YtP-0t8uf+tf/V&yjx>+]S=&%d}7z" ..
+ "0YXa9$SOyt$*mzv1&X(W(.{0G-Vya`0a}KI0pQD2,nV0:,WE0+#?F[>(i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+ "(}s.a0~]Zj*<*~%-~N27%$O,*/a,,c%<#@60On3z0~3@B13UOG/A^&K,GRHi" ..
+ ",S_:*&9I{_$nCM9&U^*9)WmPj+$TL8.]WpP)CWDR$u#7])K/Bi+,[B9(0~a&" ..
+ "&=aag,L-UG#HoAx/=@p,&ux{:0($3X*[J<4,eh{E1F&tE$cGo.&C}15*:u{Z" ..
+ ",:*H^'f,=~$,z%B)WZbL$DjA;/oFKa%.>ig/^o.90e/P=*Auex0TD}p/hncA" ..
+ "/%d87#/u19,r&sM(A+4V0%4u$.}F+P0o|4e.g(<[#5y<J++`sn,C6]p-t;&]" ..
+ "*wEcH.YA#C.|Tl$(2g>y*]3@5%II741/XZ>)Lm6e0``3L%.JF[+Z?8b(tj7C" ..
+ "'S/z}#vS|i)S9[=*/nCG)PMaY-{pML);vN?%kRcr#*.Tg,x;42'(1w.0dA)S" ..
+ ")-us%.#1$R-rkwf%m%B-(ctK8+4Sn^%*C1Y-wqsr%eNg11%$De&&07q+%1>-" ..
+ "+mCl2%)V#w%#y:[,?t*D$64`9.U+{`-SBX-+gi/o)0B$q#V$tW+#lmM)';EH" ..
+ "%yFPZ/Gy(~,dl@h)A&ju-Co2,-du++)[Awk&wE}p*H;._.[]4W+Eb7K#iiKB";
+
+local in_size = 5
+local out_size = 9
+local first_ord = string . byte ("#")
+local skip_ord = string . byte ("\\")
+local last_ord = string . byte ("~")
+local range = last_ord - first_ord
+local format = string . format ("%%0%dd", out_size)
+
+io . write ("3.")
+for i = 1, pi : len (), in_size do
+ local out = 0
+ for j = i, i + 4, 1 do
+ out = out * range
+ local n = pi : byte (j, j)
+ if n >= skip_ord
+ then n = n - 1
+ end
+ out = out + n - first_ord
+ end
+ io . write (string . format (format, out))
+end
+io . write ("\n")
+
+
+--
+-- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER
+-- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER
+-- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER
+-- FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER FODDER!
+--
diff --git a/challenge-004/abigail/lua/ch-2.lua b/challenge-004/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..c1214ac67d
--- /dev/null
+++ b/challenge-004/abigail/lua/ch-2.lua
@@ -0,0 +1,51 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua -f FILE < input-file
+--
+
+--
+-- Parse option, and exit if incorrect
+--
+
+local filename = ""
+if #arg == 2 and arg [1] == "-f"
+then filename = arg [2]
+end
+
+if file == ""
+then io . stderr : write ("Requires a '-f FILE' option\n")
+ os . exit (1)
+ end
+
+--
+-- Given a file name, and a set of letters, print
+-- the words from the file which can be made with the letters.
+--
+function extract_words (filename, letters)
+ for word in io . lines (filename) do
+ copy = word : gsub ("\n", "") : lower ()
+ for i = 1, letters : len () do
+ --
+ -- Remove each of the characters of 'letters' from
+ -- 'copy', after lowercasing, and only once.
+ --
+ copy = copy : gsub (letters : sub (i, i) : lower (), "", 1)
+ end
+ --
+ -- If we end up with the empty string, we have a winner.
+ --
+ if (copy : len () == 0)
+ then
+ print (word)
+ end
+ end
+end
+
+for line in io . lines () do
+ extract_words (filename, line : gsub ("\n", ""))
+end