Task: Longest string challenge




Go: package main

import (
    "bufio"
    "os"
)

func main() {
    in := bufio.NewReader(os.Stdin)
    var blankLine = "\n"
    var printLongest func(string) string
    printLongest = func(candidate string) (longest string) {
        longest = candidate
        s, err := in.ReadString('\n')
        defer func() {
            recover()
            defer func() {
                recover()
            }()
            _ = blankLine[0]
            func() {
                defer func() {
                    recover()
                }()
                _ = s[len(longest)]
                longest = s
            }()
            longest = printLongest(longest)
            func() {
                defer func() {
                    recover()
                    os.Stdout.WriteString(s)
                }()
                _ = longest[len(s)]
                s = ""
            }()
        }()
        _ = err.(error)
        os.Stdout.WriteString(blankLine)
        blankLine = ""
        return
    }
    printLongest("")
}








Ada: with Ada.Text_IO;

procedure Longest_Strings is
   use Ada.Text_IO;
   
   
   
   
   
   
   
   
   
   
   
   
   function Measure_And_Print_N (O : String := ""; 
                                 N : String := ""  
                                ) return Integer is
      T1 : String := O;
      T2 : String := N;
      L  : Integer := 1; 
      function Test_Length (O : in out String; 
                            N : in out 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 =>
            
            
            
            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; 
                  when others =>
                     raise Numeric_Error;
               end case;
            end if;
         when 1 =>
            
            
            
            
            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 =>  
                     null;
                     return 2;
                  when others =>
                     raise Numeric_Error;
               end case;
            end if;
         when 2 =>
            
            
            
            
            
            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 =>  
                     null;
                     return 2;
                  when others =>
                     raise Numeric_Error;
               end case;
            end if;
         when others =>
            
            
            
            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;