Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,144 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Longest_Strings is
|
||||
use Ada.Text_IO;
|
||||
|
||||
-- first, in order to strictly use integer, I use integer in
|
||||
-- place of an enumeration type: -1 => not-equal
|
||||
-- 0 => shorter - ignore, no print current string
|
||||
-- 1 => equal - print current and up-stream
|
||||
-- 2 => longer - no print upstream, only current and equal subsequent
|
||||
-- others => null; -- must never happen.
|
||||
--
|
||||
-- Anything else that is tested or used that is not a string or integer
|
||||
-- is not used explicitly by me, but is a standard part of the language
|
||||
-- as provided in the standard libraries (like boolean "End_Of_File").
|
||||
|
||||
function Measure_And_Print_N (O : String := ""; -- original/old string
|
||||
N : String := "" -- next/new string
|
||||
) return Integer is
|
||||
T1 : String := O;
|
||||
T2 : String := N;
|
||||
L : Integer := 1; -- Length defaults to the same;
|
||||
function Test_Length (O : in out String; -- original/old string
|
||||
N : in out String) -- new/test-subject string
|
||||
return Integer is
|
||||
function Test_Equal (O : in out String; N : in out String)
|
||||
return Integer is
|
||||
begin
|
||||
O := N;
|
||||
return 1;
|
||||
exception
|
||||
when Constraint_Error =>
|
||||
return -1;
|
||||
end;
|
||||
begin
|
||||
case Test_Equal (O, N) is
|
||||
when -1 =>
|
||||
O (N'Range) := N;
|
||||
return 0;
|
||||
when 1 =>
|
||||
return 1;
|
||||
when others =>
|
||||
return -1;
|
||||
end case;
|
||||
exception
|
||||
when Constraint_Error =>
|
||||
return 2;
|
||||
end;
|
||||
begin
|
||||
case Test_Length (T1, T2) is
|
||||
when 0 =>
|
||||
|
||||
-- N < O, so return "shorter" do not print N
|
||||
|
||||
if End_Of_File
|
||||
then
|
||||
return 0;
|
||||
else
|
||||
case Measure_And_Print_N (O, Get_Line) is
|
||||
when 0 =>
|
||||
return 0;
|
||||
when 1 =>
|
||||
return 0;
|
||||
when 2 =>
|
||||
return 2; -- carry up any subsequent canceling of print.
|
||||
when others =>
|
||||
raise Numeric_Error;
|
||||
end case;
|
||||
end if;
|
||||
when 1 =>
|
||||
|
||||
-- O = N, so return "equal" print N if all subsequent values are
|
||||
-- less than or equal to N
|
||||
|
||||
if End_Of_File
|
||||
then
|
||||
Put_Line (N);
|
||||
return 1;
|
||||
else
|
||||
case Measure_And_Print_N (O, Get_Line) is
|
||||
when 0 =>
|
||||
Put_Line (N);
|
||||
return 1;
|
||||
when 1 =>
|
||||
Put_Line (N);
|
||||
return 1;
|
||||
when 2 => -- carry up the subsequent canceling of print.
|
||||
null;
|
||||
return 2;
|
||||
when others =>
|
||||
raise Numeric_Error;
|
||||
end case;
|
||||
end if;
|
||||
when 2 =>
|
||||
|
||||
-- N > O, so return "longer" to cancel printing all previous values
|
||||
-- and print N if it is also equal to or greater than descendant
|
||||
-- values.
|
||||
|
||||
if End_Of_File
|
||||
then
|
||||
Put_Line (N);
|
||||
return 2;
|
||||
else
|
||||
case Measure_And_Print_N (N, Get_Line) is
|
||||
when 0 =>
|
||||
Put_Line (N);
|
||||
return 2;
|
||||
when 1 =>
|
||||
Put_Line (N);
|
||||
return 2;
|
||||
when 2 => -- printing N cancelled by subsequent input.
|
||||
null;
|
||||
return 2;
|
||||
when others =>
|
||||
raise Numeric_Error;
|
||||
end case;
|
||||
end if;
|
||||
when others =>
|
||||
|
||||
-- This should never happen - raise exception
|
||||
|
||||
raise Numeric_Error;
|
||||
end case;
|
||||
end;
|
||||
begin
|
||||
if End_Of_File
|
||||
then
|
||||
null;
|
||||
else
|
||||
case Measure_And_Print_N ("", Get_Line) is
|
||||
when 0 =>
|
||||
Put_Line (Current_Error,
|
||||
"Error, Somehow the input line is calculated as less than zero!");
|
||||
when 1 =>
|
||||
Put_Line (Current_Error,
|
||||
"All input lines appear to be blank.");
|
||||
when 2 =>
|
||||
null;
|
||||
when others =>
|
||||
raise Numeric_Error;
|
||||
end case;
|
||||
end if;
|
||||
end;
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
with Ada.Text_IO, Ada.Characters.Latin_1;
|
||||
|
||||
procedure Longest_String_Challenge is
|
||||
function "+"(S: String) return Unbounded_String renames To_Unbounded_String;
|
||||
Separator: constant Character := Ada.Characters.Latin_1.NUL;
|
||||
|
||||
procedure Funny_Stuff(B, L: in out Unbounded_String; N: Unbounded_String) is
|
||||
-- B holds a list of all longest strings, separated by Separator
|
||||
-- L holds longest string so far
|
||||
-- N is the next string to be considered
|
||||
Nat: Natural;
|
||||
begin
|
||||
Nat := Length(N) - Length(L);
|
||||
-- (1) this raises exception if L longer then N
|
||||
declare
|
||||
Pos: Positive;
|
||||
begin
|
||||
Pos := Nat; -- (2) this raises exception if L at least as long as N
|
||||
-- at this point, we know N is longer then L
|
||||
B := N;
|
||||
L := N;
|
||||
exception
|
||||
when Constraint_Error -- come from (2)
|
||||
-- at this point, we know L and N are of the same length
|
||||
=> B := B & Separator & N; -- add N to the set of solutions
|
||||
end;
|
||||
exception
|
||||
when Constraint_Error => null; -- come from (1)
|
||||
-- at this point, we know L is longer then N
|
||||
end Funny_Stuff;
|
||||
|
||||
Buffer: Unbounded_String := +"";
|
||||
Longest: Unbounded_String := +"";
|
||||
Next: Unbounded_String;
|
||||
|
||||
begin
|
||||
while True loop
|
||||
Next := + Ada.Text_IO.Get_Line;
|
||||
-- (3) raises exception when trying to read beyond the end of file
|
||||
Funny_Stuff(Buffer, Longest, Next);
|
||||
end loop;
|
||||
exception
|
||||
when others => -- come from (3)
|
||||
for I in To_String(Buffer)'Range loop
|
||||
if To_String(Buffer)(I) = Separator then
|
||||
Ada.Text_IO.New_Line;
|
||||
else
|
||||
Ada.Text_IO.Put(To_String(Buffer)(I));
|
||||
end if;
|
||||
end loop;
|
||||
end Longest_String_Challenge;
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
with Ada.Text_IO, Ada.Characters.Latin_1;
|
||||
|
||||
procedure Longest_String_Challenge is
|
||||
function "+"(S: String) return Unbounded_String renames To_Unbounded_String;
|
||||
function "-"(U: Unbounded_String) return String renames To_String;
|
||||
Separator: constant Character := Ada.Characters.Latin_1.NUL;
|
||||
|
||||
procedure Funny_Stuff(B, L: in out Unbounded_String;
|
||||
N: Unbounded_String;
|
||||
S, T: String) is
|
||||
C: Character;
|
||||
begin
|
||||
C:= T(T'First); -- (1) raises Constraint_Error if T is empty
|
||||
begin
|
||||
C := S(S'First); -- (2) raises Constraint_Error if S is empty
|
||||
-- at this point, we know that neither S nor T are empty
|
||||
Funny_Stuff(B,L,N,S(S'First+1 .. S'Last), T(T'First+1..T'Last));
|
||||
exception
|
||||
when Constraint_Error => -- come from (2), S is empty, T is not empty!
|
||||
B := N;
|
||||
L := N;
|
||||
end;
|
||||
exception
|
||||
when Constraint_Error => -- come from (1), T is empty
|
||||
begin
|
||||
C := S(S'First); -- (3) raises Constraint_Error if S is empty
|
||||
-- at this point, we know that T is empty and S isn't
|
||||
null;
|
||||
exception
|
||||
when Constraint_Error => -- come from (3); both S and T are empty
|
||||
B := B & Separator & N;
|
||||
end;
|
||||
end Funny_Stuff;
|
||||
|
||||
Buffer: Unbounded_String := +"";
|
||||
Longest: Unbounded_String := +"";
|
||||
Next: Unbounded_String;
|
||||
|
||||
begin
|
||||
while True loop
|
||||
Next := + Ada.Text_IO.Get_Line;
|
||||
-- (4) raises exception when trying to read beyond end of file
|
||||
Funny_Stuff(Buffer, Longest, Next, -Longest, -Next);
|
||||
end loop;
|
||||
exception
|
||||
when others => -- come from (4)
|
||||
for I in To_String(Buffer)'Range loop
|
||||
if To_String(Buffer)(I) = Separator then
|
||||
Ada.Text_IO.New_Line;
|
||||
else
|
||||
Ada.Text_IO.Put(To_String(Buffer)(I));
|
||||
end if;
|
||||
end loop;
|
||||
end Longest_String_Challenge;
|
||||
|
|
@ -1,28 +1,26 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #000080;font-style:italic;">--integer fn = open(command_line()[2],"r") -- (reading the source file)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">()[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">40</span><span style="color: #0000FF;">]&-</span><span style="color: #000000;">1</span>
|
||||
with javascript_semantics
|
||||
--integer fn = open(command_line()[2],"r") -- (reading the source file)
|
||||
sequence fn = unix_dict()[1..40]&-1
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">allx</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">line</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">line</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'x'</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">line</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function allx(string line)
|
||||
line[1..-1] = 'x'
|
||||
return line
|
||||
end function
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">longest</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">mask</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000080;font-style:italic;">-- object line = gets(fn)</span>
|
||||
<span style="color: #004080;">object</span> <span style="color: #000000;">line</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">fn</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">];</span> <span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">fn</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$];</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #004080;">atom</span><span style="color: #0000FF;">(</span><span style="color: #000000;">line</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #000000;">mask</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #004080;">string</span> <span style="color: #000000;">newmask</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">allx</span><span style="color: #0000FF;">(</span><span style="color: #000000;">line</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mask</span><span style="color: #0000FF;">,</span><span style="color: #000000;">newmask</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #000000;">longest</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mask</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">mask</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">longest</span><span style="color: #0000FF;">(</span><span style="color: #000000;">newmask</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mask</span><span style="color: #0000FF;">,</span><span style="color: #000000;">newmask</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000080;font-style:italic;">-- puts(1,line)</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">line</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">mask</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function longest(string mask)
|
||||
-- object line = gets(fn)
|
||||
object line = fn[1]; fn = fn[2..$];
|
||||
if atom(line) then return mask end if
|
||||
string newmask = allx(line)
|
||||
if not match(mask,newmask) then return longest(mask) end if
|
||||
mask = longest(newmask)
|
||||
if match(mask,newmask) then
|
||||
-- puts(1,line)
|
||||
printf(1,"%s\n",line)
|
||||
end if
|
||||
return mask
|
||||
end function
|
||||
|
||||
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">longest</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"x"</span><span style="color: #0000FF;">)</span>
|
||||
{} = longest("x")
|
||||
|
||||
<span style="color: #000080;font-style:italic;">--close(fn)</span>
|
||||
<!--
|
||||
--close(fn)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">longest</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">object</span> <span style="color: #000000;">line</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">gets</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">line</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #000000;">l</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">></span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">line</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #000000;">longest</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">longest</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">line</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">line</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">line</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">l</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function longest(integer l)
|
||||
object line = gets(fn)
|
||||
if line=-1 then return l end if
|
||||
if l>length(line) then return longest(l) end if
|
||||
l = longest(length(line))
|
||||
if l=length(line) then
|
||||
puts(1,line)
|
||||
end if
|
||||
return l
|
||||
end function
|
||||
|
||||
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">longest</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
|
||||
<!--
|
||||
{} = longest(0)
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
# Get-Content strips out any type of line break and creates an array of strings
|
||||
# We'll join them back together and put a specific type of line break back in
|
||||
$File = ( Get-Content C:\Test\File.txt ) -join "`n"
|
||||
|
||||
$LongestString = $LongestStrings = ''
|
||||
|
||||
# While the file string still still exists
|
||||
While ( $File )
|
||||
{
|
||||
# Set the String to the first string and File to any remaining strings
|
||||
$String, $File = $File.Split( "`n", 2 )
|
||||
|
||||
# Strip off characters until one or both strings are zero length
|
||||
$A = $LongestString
|
||||
$B = $String
|
||||
While ( $A -and $B )
|
||||
{
|
||||
$A = $A.Substring( 1 )
|
||||
$B = $B.Substring( 1 )
|
||||
}
|
||||
|
||||
# If A is zero length...
|
||||
If ( -not $A )
|
||||
{
|
||||
# If $B is not zero length (and therefore String is longer than LongestString)...
|
||||
If ( $B )
|
||||
{
|
||||
$LongestString = $String
|
||||
$LongestStrings = $String
|
||||
}
|
||||
# Else ($B is also zero length, and therefore String is the same length as LongestString)...
|
||||
Else
|
||||
{
|
||||
$LongestStrings = $LongestStrings, $String -join "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Output longest strings
|
||||
$LongestStrings.Split( "`n" )
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
@'
|
||||
a
|
||||
bb
|
||||
ccc
|
||||
ddd
|
||||
ee
|
||||
f
|
||||
ggg
|
||||
'@ -split "`r`n" |
|
||||
Group-Object -Property Length |
|
||||
Sort-Object -Property Name -Descending |
|
||||
Select-Object -Property Count, @{Name="Length"; Expression={[int]$_.Name}}, Group -First 1
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
'Read the input file. This assumes that the file is in the same
|
||||
'directory as the script.
|
||||
Set objfso = CreateObject("Scripting.FileSystemObject")
|
||||
Set objfile = objfso.OpenTextFile(objfso.GetParentFolderName(WScript.ScriptFullName) &_
|
||||
"\input.txt",1)
|
||||
|
||||
list = ""
|
||||
previous_line = ""
|
||||
l = Len(previous_line)
|
||||
|
||||
Do Until objfile.AtEndOfStream
|
||||
current_line = objfile.ReadLine
|
||||
If Mid(current_line,l+1,1) <> "" Then
|
||||
list = current_line & vbCrLf
|
||||
previous_line = current_line
|
||||
l = Len(previous_line)
|
||||
ElseIf Mid(current_line,l,1) <> "" And Mid(current_line,(l+1),1) = "" Then
|
||||
list = list & current_line & vbCrLf
|
||||
End If
|
||||
Loop
|
||||
|
||||
WScript.Echo list
|
||||
|
||||
objfile.Close
|
||||
Set objfso = Nothing
|
||||
Loading…
Add table
Add a link
Reference in a new issue