WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sorting algorithms_Comb sort





Java: public static <E extends Comparable<? super E>> void sort(E[] input) {
    int gap = input.length;
    boolean swapped = true;
    while (gap > 1 || swapped) {
        if (gap > 1) {
            gap = (int) (gap / 1.3);
        }
        swapped = false;
        for (int i = 0; i + gap < input.length; i++) {
            if (input[i].compareTo(input[i + gap]) > 0) {
                E t = input[i];
                input[i] = input[i + gap];
                input[i + gap] = t;
                swapped = true;
            }
        }
    }
}





COBOL:        C-PROCESS SECTION.
       C-000.
           DISPLAY "SORT STARTING".

           MOVE WC-SIZE TO WC-GAP.

           PERFORM E-COMB UNTIL WC-GAP = 1 AND FINISHED.

           DISPLAY "SORT FINISHED".

       C-999.
           EXIT.

       E-COMB SECTION.
       E-000.
           IF WC-GAP > 1
              DIVIDE WC-GAP BY 1.3 GIVING WC-GAP
              IF WC-GAP = 9 OR 10
                 MOVE 11 TO WC-GAP.

           MOVE 1   TO WC-SUB-1.
           MOVE "Y" TO WF-FINISHED.

           PERFORM F-SCAN UNTIL WC-SUB-1 + WC-GAP > WC-SIZE.

       E-999.
           EXIT.

       F-SCAN SECTION.
       F-000.
           ADD WC-SUB-1 WC-GAP GIVING WC-SUB-2.
           IF WB-ENTRY(WC-SUB-1) > WB-ENTRY(WC-SUB-2)
              MOVE WB-ENTRY(WC-SUB-1) TO WC-TEMP
              MOVE WB-ENTRY(WC-SUB-2) TO WB-ENTRY(WC-SUB-1)
              MOVE WC-TEMP            TO WB-ENTRY(WC-SUB-2)
              MOVE "N"                TO WF-FINISHED.

           ADD 1 TO WC-SUB-1.

       F-999.
           EXIT.
Task: Sorting algorithms_Comb sort







Python: >>> def combsort(input):
    gap = len(input)
    swaps = True
    while gap > 1 or swaps:
        gap = max(1, int(gap / 1.25))  
        swaps = False
        for i in range(len(input) - gap):
            j = i+gap
            if input[i] > input[j]:
                input[i], input[j] = input[j], input[i]
                swaps = True

                
>>> y = [88, 18, 31, 44, 4, 0, 8, 81, 14, 78, 20, 76, 84, 33, 73, 75, 82, 5, 62, 70]
>>> combsort(y)
>>> assert y == sorted(y)
>>> y
[0, 4, 5, 8, 14, 18, 20, 31, 33, 44, 62, 70, 73, 75, 76, 78, 81, 82, 84, 88]
>>>



COBOL:        C-PROCESS SECTION.
       C-000.
           DISPLAY "SORT STARTING".

           MOVE WC-SIZE TO WC-GAP.

           PERFORM E-COMB UNTIL WC-GAP = 1 AND FINISHED.

           DISPLAY "SORT FINISHED".

       C-999.
           EXIT.

       E-COMB SECTION.
       E-000.
           IF WC-GAP > 1
              DIVIDE WC-GAP BY 1.3 GIVING WC-GAP
              IF WC-GAP = 9 OR 10
                 MOVE 11 TO WC-GAP.

           MOVE 1   TO WC-SUB-1.
           MOVE "Y" TO WF-FINISHED.

           PERFORM F-SCAN UNTIL WC-SUB-1 + WC-GAP > WC-SIZE.

       E-999.
           EXIT.

       F-SCAN SECTION.
       F-000.
           ADD WC-SUB-1 WC-GAP GIVING WC-SUB-2.
           IF WB-ENTRY(WC-SUB-1) > WB-ENTRY(WC-SUB-2)
              MOVE WB-ENTRY(WC-SUB-1) TO WC-TEMP
              MOVE WB-ENTRY(WC-SUB-2) TO WB-ENTRY(WC-SUB-1)
              MOVE WC-TEMP            TO WB-ENTRY(WC-SUB-2)
              MOVE "N"                TO WF-FINISHED.

           ADD 1 TO WC-SUB-1.

       F-999.
           EXIT.
Task: Sorting algorithms_Comb sort








VB: Function comb_sort(ByVal s As Variant) As Variant
    Dim gap As Integer: gap = UBound(s)
    Dim swapped As Integer
    Do While True
        gap = WorksheetFunction.Max(WorksheetFunction.Floor_Precise(gap / 1.3), 1)
        swapped = False
        For i = 0 To UBound(s) - gap
            si = Val(s(i))
            If si > Val(s(i + gap)) Then
                s(i) = s(i + gap)
                s(i + gap) = CStr(si)
                swapped = True
            End If
        Next i
        If gap = 1 And Not swapped Then Exit Do
    Loop
    comb_sort = s
End Function

Public Sub main()
    Dim s(9) As Variant
    For i = 0 To 9
        s(i) = CStr(Int(1000 * Rnd))
    Next i
    Debug.Print Join(s, ", ")
    Debug.Print Join(comb_sort(s), ", ")
End Sub


COBOL:        C-PROCESS SECTION.
       C-000.
           DISPLAY "SORT STARTING".

           MOVE WC-SIZE TO WC-GAP.

           PERFORM E-COMB UNTIL WC-GAP = 1 AND FINISHED.

           DISPLAY "SORT FINISHED".

       C-999.
           EXIT.

       E-COMB SECTION.
       E-000.
           IF WC-GAP > 1
              DIVIDE WC-GAP BY 1.3 GIVING WC-GAP
              IF WC-GAP = 9 OR 10
                 MOVE 11 TO WC-GAP.

           MOVE 1   TO WC-SUB-1.
           MOVE "Y" TO WF-FINISHED.

           PERFORM F-SCAN UNTIL WC-SUB-1 + WC-GAP > WC-SIZE.

       E-999.
           EXIT.

       F-SCAN SECTION.
       F-000.
           ADD WC-SUB-1 WC-GAP GIVING WC-SUB-2.
           IF WB-ENTRY(WC-SUB-1) > WB-ENTRY(WC-SUB-2)
              MOVE WB-ENTRY(WC-SUB-1) TO WC-TEMP
              MOVE WB-ENTRY(WC-SUB-2) TO WB-ENTRY(WC-SUB-1)
              MOVE WC-TEMP            TO WB-ENTRY(WC-SUB-2)
              MOVE "N"                TO WF-FINISHED.

           ADD 1 TO WC-SUB-1.

       F-999.
           EXIT.
Task: Sorting algorithms_Comb sort




Go: package main

import "fmt"

func main() {
    a := []int{170, 45, 75, -90, -802, 24, 2, 66}
    fmt.Println("before:", a)
    combSort(a)
    fmt.Println("after: ", a)
}

func combSort(a []int) {
    if len(a) < 2 {
        return
    }
    for gap := len(a); ; {
        if gap > 1 {
            gap = gap * 4 / 5
        }
        swapped := false
        for i := 0; ; {
            if a[i] > a[i+gap] {
                a[i], a[i+gap] = a[i+gap], a[i]
                swapped = true
            }
            i++
            if i+gap >= len(a) {
                break
            }
        }
        if gap == 1 && !swapped {
            break
        }
    }
}






COBOL:        C-PROCESS SECTION.
       C-000.
           DISPLAY "SORT STARTING".

           MOVE WC-SIZE TO WC-GAP.

           PERFORM E-COMB UNTIL WC-GAP = 1 AND FINISHED.

           DISPLAY "SORT FINISHED".

       C-999.
           EXIT.

       E-COMB SECTION.
       E-000.
           IF WC-GAP > 1
              DIVIDE WC-GAP BY 1.3 GIVING WC-GAP
              IF WC-GAP = 9 OR 10
                 MOVE 11 TO WC-GAP.

           MOVE 1   TO WC-SUB-1.
           MOVE "Y" TO WF-FINISHED.

           PERFORM F-SCAN UNTIL WC-SUB-1 + WC-GAP > WC-SIZE.

       E-999.
           EXIT.

       F-SCAN SECTION.
       F-000.
           ADD WC-SUB-1 WC-GAP GIVING WC-SUB-2.
           IF WB-ENTRY(WC-SUB-1) > WB-ENTRY(WC-SUB-2)
              MOVE WB-ENTRY(WC-SUB-1) TO WC-TEMP
              MOVE WB-ENTRY(WC-SUB-2) TO WB-ENTRY(WC-SUB-1)
              MOVE WC-TEMP            TO WB-ENTRY(WC-SUB-2)
              MOVE "N"                TO WF-FINISHED.

           ADD 1 TO WC-SUB-1.

       F-999.
           EXIT.
Task: Sorting algorithms_Comb sort






PHP: function combSort($arr){
	$gap = count($arr);
        $swap = true;
	while ($gap > 1 || $swap){
		if($gap > 1) $gap /= 1.25;
		
		$swap = false;
		$i = 0;
		while($i+$gap < count($arr)){
			if($arr[$i] > $arr[$i+$gap]){
				list($arr[$i], $arr[$i+$gap]) = array($arr[$i+$gap],$arr[$i]);
				$swap = true;
			}
			$i++;
		}
	}
	return $arr;
}
Task: Sorting algorithms_Comb sort






PHP: function combSort($arr){
	$gap = count($arr);
        $swap = true;
	while ($gap > 1 || $swap){
		if($gap > 1) $gap /= 1.25;
		
		$swap = false;
		$i = 0;
		while($i+$gap < count($arr)){
			if($arr[$i] > $arr[$i+$gap]){
				list($arr[$i], $arr[$i+$gap]) = array($arr[$i+$gap],$arr[$i]);
				$swap = true;
			}
			$i++;
		}
	}
	return $arr;
}






Ada: with Ada.Text_IO;
procedure Comb_Sort is
   generic
      type Element_Type is private;
      type Index_Type is range <>;
      type Array_Type is array (Index_Type range <>) of Element_Type;
      with function ">" (Left, Right : Element_Type) return Boolean is <>;
      with function "+" (Left : Index_Type; Right : Natural) return Index_Type is <>;
      with function "-" (Left : Index_Type; Right : Natural) return Index_Type is <>;
   procedure Comb_Sort (Data: in out Array_Type);

   procedure Comb_Sort (Data: in out Array_Type) is
      procedure Swap (Left, Right : in Index_Type) is
         Temp : Element_Type := Data(Left);
      begin
         Data(Left)  := Data(Right);
         Data(Right) := Temp;
      end Swap;
      Gap : Natural := Data'Length;
      Swap_Occured : Boolean;
   begin
      loop
         Gap := Natural (Float(Gap) / 1.25 - 0.5);
         if Gap < 1 then
            Gap := 1;
         end if;
         Swap_Occured := False;
         for I in Data'First .. Data'Last - Gap loop
            if Data (I) > Data (I+Gap) then
               Swap (I, I+Gap);
               Swap_Occured := True;
            end if;
         end loop;
         exit when Gap = 1 and not Swap_Occured;
      end loop;
   end Comb_Sort;

   type Integer_Array is array (Positive range <>) of Integer;
   procedure Int_Comb_Sort is new Comb_Sort (Integer, Positive, Integer_Array);
   Test_Array : Integer_Array := (1, 3, 256, 0, 3, 4, -1);
begin
   Int_Comb_Sort (Test_Array);
   for I in Test_Array'Range loop
      Ada.Text_IO.Put (Integer'Image (Test_Array (I)));
   end loop;
   Ada.Text_IO.New_Line;
end Comb_Sort;
Task: Sorting algorithms_Comb sort






PHP: function combSort($arr){
	$gap = count($arr);
        $swap = true;
	while ($gap > 1 || $swap){
		if($gap > 1) $gap /= 1.25;
		
		$swap = false;
		$i = 0;
		while($i+$gap < count($arr)){
			if($arr[$i] > $arr[$i+$gap]){
				list($arr[$i], $arr[$i+$gap]) = array($arr[$i+$gap],$arr[$i]);
				$swap = true;
			}
			$i++;
		}
	}
	return $arr;
}




COBOL:        C-PROCESS SECTION.
       C-000.
           DISPLAY "SORT STARTING".

           MOVE WC-SIZE TO WC-GAP.

           PERFORM E-COMB UNTIL WC-GAP = 1 AND FINISHED.

           DISPLAY "SORT FINISHED".

       C-999.
           EXIT.

       E-COMB SECTION.
       E-000.
           IF WC-GAP > 1
              DIVIDE WC-GAP BY 1.3 GIVING WC-GAP
              IF WC-GAP = 9 OR 10
                 MOVE 11 TO WC-GAP.

           MOVE 1   TO WC-SUB-1.
           MOVE "Y" TO WF-FINISHED.

           PERFORM F-SCAN UNTIL WC-SUB-1 + WC-GAP > WC-SIZE.

       E-999.
           EXIT.

       F-SCAN SECTION.
       F-000.
           ADD WC-SUB-1 WC-GAP GIVING WC-SUB-2.
           IF WB-ENTRY(WC-SUB-1) > WB-ENTRY(WC-SUB-2)
              MOVE WB-ENTRY(WC-SUB-1) TO WC-TEMP
              MOVE WB-ENTRY(WC-SUB-2) TO WB-ENTRY(WC-SUB-1)
              MOVE WC-TEMP            TO WB-ENTRY(WC-SUB-2)
              MOVE "N"                TO WF-FINISHED.

           ADD 1 TO WC-SUB-1.

       F-999.
           EXIT.
Task: Horizontal sundial calculations



C#: using System;

namespace RosettaCode
{
  internal sealed class Program
  {
    private static void Main()
    {
      Func<double> getDouble = () => Convert.ToDouble(Console.ReadLine());
      double h = 0, lat, lng, lme, slat, hra, hla;

      Console.Write("Enter latitude       => ");
      lat = getDouble();
      Console.Write("Enter longitude      => ");
      lng = getDouble();
      Console.Write("Enter legal meridian => ");
      lme = getDouble();

      slat = Math.Sin(lat*2*Math.PI/360);
      Console.WriteLine("\n    sine of latitude:   {0:0.000}", slat);
      Console.WriteLine("    diff longitude:     {0:0.000}\n", lng-lme);
      Console.WriteLine("Hour, sun hour angle, dial hour line angle from 6am to 6pm");
      for (h = -6; h<6; h++)
      {
        hra = 15*h;
        hra -= lng-lme;
        hla = Math.Atan(slat*Math.Tan(hra*2*Math.PI/360))*360/(2*Math.PI);
        Console.WriteLine("HR= {0,7:0.000}; HRA {1,7:0.000}; HLA= {2,7:0.000}", h, hra, hla);
      }
    }
  }
}









Ada: with Ada.Text_IO;
with Ada.Numerics.Elementary_Functions;
procedure Sundial is
   use Ada.Numerics.Elementary_Functions;
   use Ada.Numerics;
   package Float_IO is new Ada.Text_IO.Float_IO (Float);

   Latitude, Longitude, Meridian : Float;
   Latitude_Sine                 : Float;
begin
   Ada.Text_IO.Put ("Enter latitude:       ");
   Float_IO.Get (Latitude);
   Ada.Text_IO.Put ("Enter longitude:      ");
   Float_IO.Get (Longitude);
   Ada.Text_IO.Put ("Enter legal meridian: ");
   Float_IO.Get (Meridian);
   Ada.Text_IO.New_Line;

   Latitude_Sine := Sin (Latitude * Pi / 180.0);
   Ada.Text_IO.Put_Line
     ("   sine of latitude:" & Float'Image (Latitude_Sine));
   Ada.Text_IO.Put_Line
     ("   diff longitude:" & Float'Image (Longitude - Meridian));
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put_Line
     ("hour, sun hour angle, dial hour line angle from 6am to 6pm");
   for H in -6 .. 6 loop
      declare
         Hour_Angle : constant Float :=
            15.0 * Float (H) - (Longitude - Meridian);
         Line_Angle : constant Float :=
            Arctan (Latitude_Sine * Tan (Hour_Angle * Pi / 180.0)) * 180.0 /
            Pi;
      begin
         Ada.Text_IO.Put_Line
           ("HR=" &
            Integer'Image (H) &
            "; HRA=" &
            Float'Image (Hour_Angle) &
            "; HLA=" &
            Float'Image (Line_Angle));
      end;
   end loop;
end Sundial;
Task: Horizontal sundial calculations

C: #include <stdio.h>
#include <math.h>

#define PICKVALUE(TXT, VM) do {			\
    printf("%s: ", TXT);			\
    scanf("%lf", &VM);				\
  } while(0);

#if !defined(M_PI)
#define M_PI 3.14159265358979323846
#endif

#define DR(X) ((X)*M_PI/180.0)
#define RD(X) ((X)*180.0/M_PI)

int main()
{
  double lat, slat, lng, ref;
  int h;
  
  PICKVALUE("Enter latitude", lat);
  PICKVALUE("Enter longitude", lng);
  PICKVALUE("Enter legal meridian", ref);
  printf("\n");

  slat = sin(DR(lat));
  printf("sine of latitude: %.3f\n", slat);
  printf("diff longitude: %.3f\n\n", lng - ref);
  
  printf("Hour, sun hour angle, dial hour line angle from 6am to 6pm\n");
  
  for(h = -6; h <= 6; h++)
  {
    double hla, hra;
    hra = 15.0*h;
    hra = hra - lng + ref;
    hla = RD(atan(slat * tan(DR(hra))));
    printf("HR= %3d;  \t  HRA=%7.3f;  \t  HLA= %7.3f\n",
	   h, hra, hla);
  }

  return 0;
}











Ada: with Ada.Text_IO;
with Ada.Numerics.Elementary_Functions;
procedure Sundial is
   use Ada.Numerics.Elementary_Functions;
   use Ada.Numerics;
   package Float_IO is new Ada.Text_IO.Float_IO (Float);

   Latitude, Longitude, Meridian : Float;
   Latitude_Sine                 : Float;
begin
   Ada.Text_IO.Put ("Enter latitude:       ");
   Float_IO.Get (Latitude);
   Ada.Text_IO.Put ("Enter longitude:      ");
   Float_IO.Get (Longitude);
   Ada.Text_IO.Put ("Enter legal meridian: ");
   Float_IO.Get (Meridian);
   Ada.Text_IO.New_Line;

   Latitude_Sine := Sin (Latitude * Pi / 180.0);
   Ada.Text_IO.Put_Line
     ("   sine of latitude:" & Float'Image (Latitude_Sine));
   Ada.Text_IO.Put_Line
     ("   diff longitude:" & Float'Image (Longitude - Meridian));
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put_Line
     ("hour, sun hour angle, dial hour line angle from 6am to 6pm");
   for H in -6 .. 6 loop
      declare
         Hour_Angle : constant Float :=
            15.0 * Float (H) - (Longitude - Meridian);
         Line_Angle : constant Float :=
            Arctan (Latitude_Sine * Tan (Hour_Angle * Pi / 180.0)) * 180.0 /
            Pi;
      begin
         Ada.Text_IO.Put_Line
           ("HR=" &
            Integer'Image (H) &
            "; HRA=" &
            Float'Image (Hour_Angle) &
            "; HLA=" &
            Float'Image (Line_Angle));
      end;
   end loop;
end Sundial;
Task: Horizontal sundial calculations


C++: #include <cmath>
#include <iostream>
#include <numbers>


static const double DegreesPerHour = 15.0;
static const double DegreesPerRadian = 180.0 * std::numbers::inv_pi;


struct SundialCalculation
{
  double HourAngle;
  double HourLineAngle;
};


class Sundial
{
  
  double m_sinLatitude;
  double m_timeZoneCorrection;
    
public:
  Sundial(double latitude, double longitude, double legalMeridian) noexcept
    : m_sinLatitude(sin(latitude / DegreesPerRadian))
    , m_timeZoneCorrection(legalMeridian - longitude) {}

  SundialCalculation CalculateShadow(double hoursSinceNoon) const noexcept
  {
    double hourAngle = hoursSinceNoon * DegreesPerHour + m_timeZoneCorrection;
    double hourAngleRad = hourAngle / DegreesPerRadian;
    double hlaRad = atan2(m_sinLatitude * sin(hourAngleRad), cos(hourAngleRad));
    double hourLineAngle = hlaRad * DegreesPerRadian;
    return SundialCalculation {hourAngle, hourLineAngle};
  }
};

int main()
{
  double latitude, longitude, legalMeridian;
  std::cout << "Enter latitude:";
  std::cin >> latitude;
  std::cout << "Enter longitude:";
  std::cin >> longitude;
  std::cout << "Enter legal meridian:";
  std::cin >> legalMeridian;
  
  
  const Sundial sundial(latitude, longitude, legalMeridian);
  for(int hour = -6; hour < 7; ++hour)
  {
    
    auto result = sundial.CalculateShadow(hour);

    
    auto amOrPm = hour < 0 ? "am" : "pm";
    auto hourString = std::to_string(hour < 1 ? 12 + hour : hour);
    std::cout << hourString << amOrPm << 
    " - sun hour angle:" << result.HourAngle <<
    ", dial hour line angle:" << result.HourLineAngle << "\n";
  }
}










Ada: with Ada.Text_IO;
with Ada.Numerics.Elementary_Functions;
procedure Sundial is
   use Ada.Numerics.Elementary_Functions;
   use Ada.Numerics;
   package Float_IO is new Ada.Text_IO.Float_IO (Float);

   Latitude, Longitude, Meridian : Float;
   Latitude_Sine                 : Float;
begin
   Ada.Text_IO.Put ("Enter latitude:       ");
   Float_IO.Get (Latitude);
   Ada.Text_IO.Put ("Enter longitude:      ");
   Float_IO.Get (Longitude);
   Ada.Text_IO.Put ("Enter legal meridian: ");
   Float_IO.Get (Meridian);
   Ada.Text_IO.New_Line;

   Latitude_Sine := Sin (Latitude * Pi / 180.0);
   Ada.Text_IO.Put_Line
     ("   sine of latitude:" & Float'Image (Latitude_Sine));
   Ada.Text_IO.Put_Line
     ("   diff longitude:" & Float'Image (Longitude - Meridian));
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put_Line
     ("hour, sun hour angle, dial hour line angle from 6am to 6pm");
   for H in -6 .. 6 loop
      declare
         Hour_Angle : constant Float :=
            15.0 * Float (H) - (Longitude - Meridian);
         Line_Angle : constant Float :=
            Arctan (Latitude_Sine * Tan (Hour_Angle * Pi / 180.0)) * 180.0 /
            Pi;
      begin
         Ada.Text_IO.Put_Line
           ("HR=" &
            Integer'Image (H) &
            "; HRA=" &
            Float'Image (Hour_Angle) &
            "; HLA=" &
            Float'Image (Line_Angle));
      end;
   end loop;
end Sundial;
Task: Horizontal sundial calculations




Go: package main

import (
    "fmt"
    "math"
    "os"
)

func getnum(prompt string) (r float64) {
    fmt.Print(prompt)
    if _, err := fmt.Scan(&r); err != nil {
        fmt.Println(err)
        os.Exit(-1)
    }
    return
}

func main() {
    lat := getnum("Enter latitude       => ")
    lng := getnum("Enter longitude      => ")
    ref := getnum("Enter legal meridian => ")
    slat := math.Sin(lat * math.Pi / 180)
    diff := lng - ref
    fmt.Println("\n    sine of latitude:   ", slat)
    fmt.Println("    diff longitude:     ", diff)
    fmt.Println("\nHour, sun hour angle, dial hour line angle from 6am to 6pm")
    for h := -6.; h <= 6; h++ {
        hra := 15*h - diff
        s, c := math.Sincos(hra * math.Pi / 180)
        hla := math.Atan2(slat*s, c) * 180 / math.Pi
        fmt.Printf("%2.0f %8.3f %8.3f\n", h, hra, hla)
    }
}








Ada: with Ada.Text_IO;
with Ada.Numerics.Elementary_Functions;
procedure Sundial is
   use Ada.Numerics.Elementary_Functions;
   use Ada.Numerics;
   package Float_IO is new Ada.Text_IO.Float_IO (Float);

   Latitude, Longitude, Meridian : Float;
   Latitude_Sine                 : Float;
begin
   Ada.Text_IO.Put ("Enter latitude:       ");
   Float_IO.Get (Latitude);
   Ada.Text_IO.Put ("Enter longitude:      ");
   Float_IO.Get (Longitude);
   Ada.Text_IO.Put ("Enter legal meridian: ");
   Float_IO.Get (Meridian);
   Ada.Text_IO.New_Line;

   Latitude_Sine := Sin (Latitude * Pi / 180.0);
   Ada.Text_IO.Put_Line
     ("   sine of latitude:" & Float'Image (Latitude_Sine));
   Ada.Text_IO.Put_Line
     ("   diff longitude:" & Float'Image (Longitude - Meridian));
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put_Line
     ("hour, sun hour angle, dial hour line angle from 6am to 6pm");
   for H in -6 .. 6 loop
      declare
         Hour_Angle : constant Float :=
            15.0 * Float (H) - (Longitude - Meridian);
         Line_Angle : constant Float :=
            Arctan (Latitude_Sine * Tan (Hour_Angle * Pi / 180.0)) * 180.0 /
            Pi;
      begin
         Ada.Text_IO.Put_Line
           ("HR=" &
            Integer'Image (H) &
            "; HRA=" &
            Float'Image (Hour_Angle) &
            "; HLA=" &
            Float'Image (Line_Angle));
      end;
   end loop;
end Sundial;
Task: Horizontal sundial calculations





Java: import java.util.Scanner;

public class Sundial {
    public static void main(String[] args) {
        double lat, slat, lng, ref;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter latitude: ");
        lat = sc.nextDouble();
        System.out.print("Enter longitude: ");
        lng = sc.nextDouble();
        System.out.print("Enter legal meridian: ");
        ref = sc.nextDouble();
        System.out.println();

        slat = Math.sin(Math.toRadians(lat));
        System.out.printf("sine of latitude: %.3f\n", slat);
        System.out.printf("diff longitude: %.3f\n\n", lng - ref);

        System.out.printf("Hour, sun hour angle, dial hour line angle from 6am to 6pm\n");

        for (int h = -6; h <= 6; h++) {
            double hla, hra, hraRad;
            hra = 15.0 * h;
            hra = hra - lng + ref;
            hraRad = Math.toRadians(hra);
            hla = Math.toDegrees(Math.atan2(Math.sin(hraRad)*Math.sin(Math.toRadians(lat)), Math.cos(hraRad)));
            System.out.printf("HR= %3d;  \t  HRA=%7.3f;  \t  HLA= %7.3f\n",
                    h, hra, hla);
        }
    }
}







Ada: with Ada.Text_IO;
with Ada.Numerics.Elementary_Functions;
procedure Sundial is
   use Ada.Numerics.Elementary_Functions;
   use Ada.Numerics;
   package Float_IO is new Ada.Text_IO.Float_IO (Float);

   Latitude, Longitude, Meridian : Float;
   Latitude_Sine                 : Float;
begin
   Ada.Text_IO.Put ("Enter latitude:       ");
   Float_IO.Get (Latitude);
   Ada.Text_IO.Put ("Enter longitude:      ");
   Float_IO.Get (Longitude);
   Ada.Text_IO.Put ("Enter legal meridian: ");
   Float_IO.Get (Meridian);
   Ada.Text_IO.New_Line;

   Latitude_Sine := Sin (Latitude * Pi / 180.0);
   Ada.Text_IO.Put_Line
     ("   sine of latitude:" & Float'Image (Latitude_Sine));
   Ada.Text_IO.Put_Line
     ("   diff longitude:" & Float'Image (Longitude - Meridian));
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put_Line
     ("hour, sun hour angle, dial hour line angle from 6am to 6pm");
   for H in -6 .. 6 loop
      declare
         Hour_Angle : constant Float :=
            15.0 * Float (H) - (Longitude - Meridian);
         Line_Angle : constant Float :=
            Arctan (Latitude_Sine * Tan (Hour_Angle * Pi / 180.0)) * 180.0 /
            Pi;
      begin
         Ada.Text_IO.Put_Line
           ("HR=" &
            Integer'Image (H) &
            "; HRA=" &
            Float'Image (Hour_Angle) &
            "; HLA=" &
            Float'Image (Line_Angle));
      end;
   end loop;
end Sundial;