Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
56
Task/Word-wheel/Ada/word-wheel.ada
Normal file
56
Task/Word-wheel/Ada/word-wheel.ada
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
with Ada.Characters.Handling; use Ada.Characters.Handling;
|
||||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
|
||||
procedure Wordwheel is
|
||||
Compulsory_Ix : constant Positive := 5;
|
||||
Min_Length : constant Positive := 3;
|
||||
|
||||
function Char_Posn (Str : Unbounded_String; C : Character) return Natural is
|
||||
begin
|
||||
for Ix in 1 .. Length (Str) loop
|
||||
if Element (Str, Ix) = C then
|
||||
return Ix;
|
||||
end if;
|
||||
end loop;
|
||||
return 0;
|
||||
end Char_Posn;
|
||||
|
||||
procedure Search (Dict_Filename : String; Wheel : String) is
|
||||
Dict_File : File_Type;
|
||||
Allowed : constant String := To_Lower (Wheel);
|
||||
Required_Char : constant String (1 .. 1) := "" & Allowed (Compulsory_Ix);
|
||||
Available, Dict_Word : Unbounded_String;
|
||||
Dict_Word_Len : Positive;
|
||||
Matched : Boolean;
|
||||
Posn : Natural;
|
||||
begin
|
||||
Open (File => Dict_File, Mode => In_File, Name => Dict_Filename);
|
||||
while not End_Of_File (Dict_File) loop
|
||||
Dict_Word := Get_Line (Dict_File);
|
||||
Dict_Word_Len := Length (Dict_Word);
|
||||
if Dict_Word_Len >= Min_Length and then
|
||||
Dict_Word_Len <= Wheel'Length and then
|
||||
Ada.Strings.Unbounded.Count (Dict_Word, Required_Char) > 0
|
||||
then
|
||||
Available := To_Unbounded_String (Allowed);
|
||||
Matched := True;
|
||||
for i in 1 .. Dict_Word_Len loop
|
||||
Posn := Char_Posn (Available, Element (Dict_Word, i));
|
||||
if Posn > 0 then
|
||||
Delete (Source => Available, From => Posn, Through => Posn);
|
||||
else
|
||||
Matched := False;
|
||||
exit;
|
||||
end if;
|
||||
end loop;
|
||||
if Matched then
|
||||
Put_Line (Dict_Word);
|
||||
end if;
|
||||
end if;
|
||||
end loop;
|
||||
Close (Dict_File);
|
||||
end Search;
|
||||
begin
|
||||
Search ("unixdict.txt", "ndeokgelw");
|
||||
end Wordwheel;
|
||||
15
Task/Word-wheel/Lua/word-wheel-2.lua
Normal file
15
Task/Word-wheel/Lua/word-wheel-2.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
-- Algorithm is from Ruby implementation.
|
||||
local wheel = arg[1] or 'ndeoKgelw' -- wheel is 1st argument
|
||||
wheel = wheel:lower()
|
||||
local middle = wheel:sub(5, 5)
|
||||
assert(#middle == 1)
|
||||
for line in io.lines() do -- get dictionary from standard input
|
||||
local word = line:lower()
|
||||
if word:find(middle) and #word >= 3 then
|
||||
for wheel_char in wheel:gmatch('.') do
|
||||
word = word:gsub(wheel_char, '', 1)
|
||||
end -- for
|
||||
if #word == 0 then io.write(line:lower() .. ' ') end
|
||||
end -- if
|
||||
end -- for
|
||||
print ''
|
||||
Loading…
Add table
Add a link
Reference in a new issue