WeixiangYan/CodeTransOcean huggingface dataset:
Task: 21 game




Go: package main

import (
    "bufio"
    "fmt"
    "log"
    "math/rand"
    "os"
    "strconv"
    "time"
)

var scanner = bufio.NewScanner(os.Stdin)

var (
    total = 0
    quit  = false
)

func itob(i int) bool {
    if i == 0 {
        return false
    }
    return true
}

func getChoice() {
    for {
        fmt.Print("Your choice 1 to 3 : ")
        scanner.Scan()
        if scerr := scanner.Err(); scerr != nil {
            log.Fatalln(scerr, "when choosing number")
        }
        text := scanner.Text()
        if text == "q" || text == "Q" {
            quit = true
            return
        }
        input, err := strconv.Atoi(text)
        if err != nil {
            fmt.Println("Invalid number, try again")
            continue
        }
        newTotal := total + input
        switch {
        case input < 1 || input > 3:
            fmt.Println("Out of range, try again")
        case newTotal > 21:
            fmt.Println("Too big, try again")
        default:
            total = newTotal
            fmt.Println("Running total is now", total)
            return
        }
    }
}

func main() {
    rand.Seed(time.Now().UnixNano())
    computer := itob(rand.Intn(2))
    fmt.Println("Enter q to quit at any time\n")
    if computer {
        fmt.Println("The computer will choose first")
    } else {
        fmt.Println("You will choose first")
    }
    fmt.Println("\nRunning total is now 0\n")
    var choice int
    for round := 1; ; round++ {
        fmt.Printf("ROUND %d:\n\n", round)
        for i := 0; i < 2; i++ {
            if computer {
                if total < 18 {
                    choice = 1 + rand.Intn(3)
                } else {
                    choice = 21 - total
                }
                total += choice
                fmt.Println("The computer chooses", choice)
                fmt.Println("Running total is now", total)
                if total == 21 {
                    fmt.Println("\nSo, commiserations, the computer has won!")
                    return
                }
            } else {
                getChoice()
                if quit {
                    fmt.Println("OK, quitting the game")
                    return
                }
                if total == 21 {
                    fmt.Println("\nSo, congratulations, you've won!")
                    return
                }
            }
            fmt.Println()
            computer = !computer
        }
    }
}
Task: Sum multiples of 3 and 5



C#: using System;
using System.Collections.Generic;
using System.Numerics;

namespace RosettaCode
{
    class Program
    {
        static void Main()
        {
            List<BigInteger> candidates = new List<BigInteger>(new BigInteger[] { 1000, 100000, 10000000, 10000000000, 1000000000000000 });
            candidates.Add(BigInteger.Parse("100000000000000000000"));

            foreach (BigInteger candidate in candidates)
            {
                BigInteger c = candidate - 1;
                BigInteger answer3 = GetSumOfNumbersDivisibleByN(c, 3);
                BigInteger answer5 = GetSumOfNumbersDivisibleByN(c, 5);
                BigInteger answer15 = GetSumOfNumbersDivisibleByN(c, 15);

                Console.WriteLine("The sum of numbers divisible by 3 or 5 between 1 and {0} is {1}", c, answer3 + answer5 - answer15);
            }

            Console.ReadKey(true);
        }

        private static BigInteger GetSumOfNumbersDivisibleByN(BigInteger candidate, uint n)
        {
            BigInteger largest = candidate;
            while (largest % n > 0)
                largest--;
            BigInteger totalCount = (largest / n);
            BigInteger pairCount = totalCount / 2;
            bool unpairedNumberOnFoldLine = (totalCount % 2 == 1);
            BigInteger pairSum = largest + n;
            return pairCount * pairSum + (unpairedNumberOnFoldLine ? pairSum / 2 : 0);
        }

    }
}









Ada: with Ada.Text_IO;

procedure Sum_Multiples is

   type Natural is range 0 .. 2**63 - 1;

   function Sum_3_5 (Limit : in Natural) return Natural is
      Sum : Natural := 0;
   begin
      for N in 1 .. Limit - 1 loop
         if N mod 3 = 0 or else N mod 5 = 0 then
            Sum := Sum + N;
         end if;
      end loop;
      return Sum;
   end Sum_3_5;

begin
   Ada.Text_IO.Put_Line ("n=1000: " & Sum_3_5 (1000)'Image);
   Ada.Text_IO.Put_Line ("n=5e9 : " & Sum_3_5 (5e9)'Image);
end Sum_Multiples;
Task: Sum multiples of 3 and 5

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

unsigned long long sum35(unsigned long long limit)
{
    unsigned long long sum = 0;
    for (unsigned long long i = 0; i < limit; i++)
        if (!(i % 3) || !(i % 5))
            sum += i;
    return sum;
}

int main(int argc, char **argv)
{
    unsigned long long limit;

    if (argc == 2)
        limit = strtoull(argv[1], NULL, 10);
    else
        limit = 1000;

    printf("%lld\n", sum35(limit));
    return 0;
}











Ada: with Ada.Text_IO;

procedure Sum_Multiples is

   type Natural is range 0 .. 2**63 - 1;

   function Sum_3_5 (Limit : in Natural) return Natural is
      Sum : Natural := 0;
   begin
      for N in 1 .. Limit - 1 loop
         if N mod 3 = 0 or else N mod 5 = 0 then
            Sum := Sum + N;
         end if;
      end loop;
      return Sum;
   end Sum_3_5;

begin
   Ada.Text_IO.Put_Line ("n=1000: " & Sum_3_5 (1000)'Image);
   Ada.Text_IO.Put_Line ("n=5e9 : " & Sum_3_5 (5e9)'Image);
end Sum_Multiples;
Task: Sum multiples of 3 and 5


C++: #include <iostream>


typedef unsigned long long bigInt;

using namespace std;

class m35
{
public:
    void doIt( bigInt i )
    {
	bigInt sum = 0;
	for( bigInt a = 1; a < i; a++ )
	    if( !( a % 3 ) || !( a % 5 ) ) sum += a;

	cout << "Sum is " << sum << " for n = " << i << endl << endl;
    }
	
    
    void doIt_b( bigInt i )
    {
	bigInt sum = 0;
	for( bigInt a = 0; a < 28; a++ )
	{
	    if( !( a % 3 ) || !( a % 5 ) )
	    {
		sum += a;
		for( bigInt s = 30; s < i; s += 30 )
		    if( a + s < i ) sum += ( a + s );

	    }
	}
	cout << "Sum is " << sum << " for n = " << i << endl << endl;
    }
};

int main( int argc, char* argv[] )
{
    m35 m; m.doIt( 1000 );
    return system( "pause" );
}










Ada: with Ada.Text_IO;

procedure Sum_Multiples is

   type Natural is range 0 .. 2**63 - 1;

   function Sum_3_5 (Limit : in Natural) return Natural is
      Sum : Natural := 0;
   begin
      for N in 1 .. Limit - 1 loop
         if N mod 3 = 0 or else N mod 5 = 0 then
            Sum := Sum + N;
         end if;
      end loop;
      return Sum;
   end Sum_3_5;

begin
   Ada.Text_IO.Put_Line ("n=1000: " & Sum_3_5 (1000)'Image);
   Ada.Text_IO.Put_Line ("n=5e9 : " & Sum_3_5 (5e9)'Image);
end Sum_Multiples;
Task: Sum multiples of 3 and 5




Go: package main

import "fmt"

func main() {
    fmt.Println(s35(1000))
}

func s35(n int) int {
    n--
    threes := n / 3
    fives := n / 5
    fifteen := n / 15

    threes = 3 * threes * (threes + 1)
    fives = 5 * fives * (fives + 1)
    fifteen = 15 * fifteen * (fifteen + 1)

    n = (threes + fives - fifteen) / 2
	
    return n
}








Ada: with Ada.Text_IO;

procedure Sum_Multiples is

   type Natural is range 0 .. 2**63 - 1;

   function Sum_3_5 (Limit : in Natural) return Natural is
      Sum : Natural := 0;
   begin
      for N in 1 .. Limit - 1 loop
         if N mod 3 = 0 or else N mod 5 = 0 then
            Sum := Sum + N;
         end if;
      end loop;
      return Sum;
   end Sum_3_5;

begin
   Ada.Text_IO.Put_Line ("n=1000: " & Sum_3_5 (1000)'Image);
   Ada.Text_IO.Put_Line ("n=5e9 : " & Sum_3_5 (5e9)'Image);
end Sum_Multiples;
Task: Sum multiples of 3 and 5





Java: class SumMultiples {
	public static long getSum(long n) {
		long sum = 0;
		for (int i = 3; i < n; i++) {
			if (i % 3 == 0 || i % 5 == 0) sum += i;
		}
		return sum;
	}
	public static void main(String[] args) {
		System.out.println(getSum(1000));
	}
}







Ada: with Ada.Text_IO;

procedure Sum_Multiples is

   type Natural is range 0 .. 2**63 - 1;

   function Sum_3_5 (Limit : in Natural) return Natural is
      Sum : Natural := 0;
   begin
      for N in 1 .. Limit - 1 loop
         if N mod 3 = 0 or else N mod 5 = 0 then
            Sum := Sum + N;
         end if;
      end loop;
      return Sum;
   end Sum_3_5;

begin
   Ada.Text_IO.Put_Line ("n=1000: " & Sum_3_5 (1000)'Image);
   Ada.Text_IO.Put_Line ("n=5e9 : " & Sum_3_5 (5e9)'Image);
end Sum_Multiples;
Task: Sum multiples of 3 and 5







Python: def sum35a(n):
    'Direct count'
    
    return sum(x for x in range(n) if x%3==0 or x%5==0)

def sum35b(n): 
    "Count all the 3's; all the 5's; minus double-counted 3*5's"
    
    return sum(range(3, n, 3)) + sum(range(5, n, 5)) - sum(range(15, n, 15))
    
def sum35c(n):
    'Sum the arithmetic progressions: sum3 + sum5 - sum15'
    consts = (3, 5, 15)
    
    divs = [(n-1) // c for c in consts]
    sums = [d*c*(1+d)/2 for d,c in zip(divs, consts)]
    return sums[0] + sums[1] - sums[2]


for n in range(1001):
    sa, sb, sc = sum35a(n), sum35b(n), sum35c(n)
    assert sa == sb == sc  

print('For n = %7i -> %i\n' % (n, sc))


for p in range(7):
    print('For n = %7i -> %i' % (10**p, sum35c(10**p)))


p = 20
print('\nFor n = %20i -> %i' % (10**p, sum35c(10**p)))





Ada: with Ada.Text_IO;

procedure Sum_Multiples is

   type Natural is range 0 .. 2**63 - 1;

   function Sum_3_5 (Limit : in Natural) return Natural is
      Sum : Natural := 0;
   begin
      for N in 1 .. Limit - 1 loop
         if N mod 3 = 0 or else N mod 5 = 0 then
            Sum := Sum + N;
         end if;
      end loop;
      return Sum;
   end Sum_3_5;

begin
   Ada.Text_IO.Put_Line ("n=1000: " & Sum_3_5 (1000)'Image);
   Ada.Text_IO.Put_Line ("n=5e9 : " & Sum_3_5 (5e9)'Image);
end Sum_Multiples;
Task: Sum multiples of 3 and 5








VB: Private Function SumMult3and5VBScript(n As Double) As Double
Dim i As Double
    For i = 1 To n - 1
        If i Mod 3 = 0 Or i Mod 5 = 0 Then
            SumMult3and5VBScript = SumMult3and5VBScript + i
        End If
    Next
End Function




Ada: with Ada.Text_IO;

procedure Sum_Multiples is

   type Natural is range 0 .. 2**63 - 1;

   function Sum_3_5 (Limit : in Natural) return Natural is
      Sum : Natural := 0;
   begin
      for N in 1 .. Limit - 1 loop
         if N mod 3 = 0 or else N mod 5 = 0 then
            Sum := Sum + N;
         end if;
      end loop;
      return Sum;
   end Sum_3_5;

begin
   Ada.Text_IO.Put_Line ("n=1000: " & Sum_3_5 (1000)'Image);
   Ada.Text_IO.Put_Line ("n=5e9 : " & Sum_3_5 (5e9)'Image);
end Sum_Multiples;
Task: Sum multiples of 3 and 5

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

unsigned long long sum35(unsigned long long limit)
{
    unsigned long long sum = 0;
    for (unsigned long long i = 0; i < limit; i++)
        if (!(i % 3) || !(i % 5))
            sum += i;
    return sum;
}

int main(int argc, char **argv)
{
    unsigned long long limit;

    if (argc == 2)
        limit = strtoull(argv[1], NULL, 10);
    else
        limit = 1000;

    printf("%lld\n", sum35(limit));
    return 0;
}
Task: Sum multiples of 3 and 5



C#: using System;
using System.Collections.Generic;
using System.Numerics;

namespace RosettaCode
{
    class Program
    {
        static void Main()
        {
            List<BigInteger> candidates = new List<BigInteger>(new BigInteger[] { 1000, 100000, 10000000, 10000000000, 1000000000000000 });
            candidates.Add(BigInteger.Parse("100000000000000000000"));

            foreach (BigInteger candidate in candidates)
            {
                BigInteger c = candidate - 1;
                BigInteger answer3 = GetSumOfNumbersDivisibleByN(c, 3);
                BigInteger answer5 = GetSumOfNumbersDivisibleByN(c, 5);
                BigInteger answer15 = GetSumOfNumbersDivisibleByN(c, 15);

                Console.WriteLine("The sum of numbers divisible by 3 or 5 between 1 and {0} is {1}", c, answer3 + answer5 - answer15);
            }

            Console.ReadKey(true);
        }

        private static BigInteger GetSumOfNumbersDivisibleByN(BigInteger candidate, uint n)
        {
            BigInteger largest = candidate;
            while (largest % n > 0)
                largest--;
            BigInteger totalCount = (largest / n);
            BigInteger pairCount = totalCount / 2;
            bool unpairedNumberOnFoldLine = (totalCount % 2 == 1);
            BigInteger pairSum = largest + n;
            return pairCount * pairSum + (unpairedNumberOnFoldLine ? pairSum / 2 : 0);
        }

    }
}
Task: Sum multiples of 3 and 5


C++: #include <iostream>


typedef unsigned long long bigInt;

using namespace std;

class m35
{
public:
    void doIt( bigInt i )
    {
	bigInt sum = 0;
	for( bigInt a = 1; a < i; a++ )
	    if( !( a % 3 ) || !( a % 5 ) ) sum += a;

	cout << "Sum is " << sum << " for n = " << i << endl << endl;
    }
	
    
    void doIt_b( bigInt i )
    {
	bigInt sum = 0;
	for( bigInt a = 0; a < 28; a++ )
	{
	    if( !( a % 3 ) || !( a % 5 ) )
	    {
		sum += a;
		for( bigInt s = 30; s < i; s += 30 )
		    if( a + s < i ) sum += ( a + s );

	    }
	}
	cout << "Sum is " << sum << " for n = " << i << endl << endl;
    }
};

int main( int argc, char* argv[] )
{
    m35 m; m.doIt( 1000 );
    return system( "pause" );
}
Task: Sum multiples of 3 and 5





Java: class SumMultiples {
	public static long getSum(long n) {
		long sum = 0;
		for (int i = 3; i < n; i++) {
			if (i % 3 == 0 || i % 5 == 0) sum += i;
		}
		return sum;
	}
	public static void main(String[] args) {
		System.out.println(getSum(1000));
	}
}
Task: Sum multiples of 3 and 5







Python: def sum35a(n):
    'Direct count'
    
    return sum(x for x in range(n) if x%3==0 or x%5==0)

def sum35b(n): 
    "Count all the 3's; all the 5's; minus double-counted 3*5's"
    
    return sum(range(3, n, 3)) + sum(range(5, n, 5)) - sum(range(15, n, 15))
    
def sum35c(n):
    'Sum the arithmetic progressions: sum3 + sum5 - sum15'
    consts = (3, 5, 15)
    
    divs = [(n-1) // c for c in consts]
    sums = [d*c*(1+d)/2 for d,c in zip(divs, consts)]
    return sums[0] + sums[1] - sums[2]


for n in range(1001):
    sa, sb, sc = sum35a(n), sum35b(n), sum35c(n)
    assert sa == sb == sc  

print('For n = %7i -> %i\n' % (n, sc))


for p in range(7):
    print('For n = %7i -> %i' % (10**p, sum35c(10**p)))


p = 20
print('\nFor n = %20i -> %i' % (10**p, sum35c(10**p)))
Task: Sum multiples of 3 and 5








VB: Private Function SumMult3and5VBScript(n As Double) As Double
Dim i As Double
    For i = 1 To n - 1
        If i Mod 3 = 0 Or i Mod 5 = 0 Then
            SumMult3and5VBScript = SumMult3and5VBScript + i
        End If
    Next
End Function
Task: Sum multiples of 3 and 5




Go: package main

import "fmt"

func main() {
    fmt.Println(s35(1000))
}

func s35(n int) int {
    n--
    threes := n / 3
    fives := n / 5
    fifteen := n / 15

    threes = 3 * threes * (threes + 1)
    fives = 5 * fives * (fives + 1)
    fifteen = 15 * fifteen * (fifteen + 1)

    n = (threes + fives - fifteen) / 2
	
    return n
}
Task: Sum multiples of 3 and 5



C#: using System;
using System.Collections.Generic;
using System.Numerics;

namespace RosettaCode
{
    class Program
    {
        static void Main()
        {
            List<BigInteger> candidates = new List<BigInteger>(new BigInteger[] { 1000, 100000, 10000000, 10000000000, 1000000000000000 });
            candidates.Add(BigInteger.Parse("100000000000000000000"));

            foreach (BigInteger candidate in candidates)
            {
                BigInteger c = candidate - 1;
                BigInteger answer3 = GetSumOfNumbersDivisibleByN(c, 3);
                BigInteger answer5 = GetSumOfNumbersDivisibleByN(c, 5);
                BigInteger answer15 = GetSumOfNumbersDivisibleByN(c, 15);

                Console.WriteLine("The sum of numbers divisible by 3 or 5 between 1 and {0} is {1}", c, answer3 + answer5 - answer15);
            }

            Console.ReadKey(true);
        }

        private static BigInteger GetSumOfNumbersDivisibleByN(BigInteger candidate, uint n)
        {
            BigInteger largest = candidate;
            while (largest % n > 0)
                largest--;
            BigInteger totalCount = (largest / n);
            BigInteger pairCount = totalCount / 2;
            bool unpairedNumberOnFoldLine = (totalCount % 2 == 1);
            BigInteger pairSum = largest + n;
            return pairCount * pairSum + (unpairedNumberOnFoldLine ? pairSum / 2 : 0);
        }

    }
}








Fortran:       INTEGER*8 FUNCTION SUMI(N)	
Calculates as per the young Gauss: N*(N + 1)/2 = 1 + 2 + 3 + ... + N.
       INTEGER*8 N	
        IF (MOD(N,2).EQ.0) THEN	
          SUMI = N/2*(N + 1)		
         ELSE			
          SUMI = (N + 1)/2*N		
        END IF			
      END FUNCTION SUMI		

      INTEGER*8 FUNCTION SUMF(N,F)	
       INTEGER*8 N,F		
       INTEGER*8 L		
       INTEGER*8 SUMI		
        L = (N - 1)/F		
        SUMF = F*SUMI(L)	
      END FUNCTION SUMF		

      INTEGER*8 FUNCTION SUMBFI(N)	
       INTEGER*8 N	
       INTEGER*8 I,S	
        S = 0		
        DO I = 3,N - 1	
          IF (MOD(I,3).EQ.0 .OR. MOD(I,5).EQ.0) S = S + I	
        END DO		
        SUMBFI = S		
      END FUNCTION SUMBFI	

      INTEGER*8 SUMF,SUMBFI	
      INTEGER*8 N	
      WRITE (6,*) "Sum multiples of 3 and 5 up to N"
   10 WRITE (6,11)		
   11 FORMAT ("Specify N: ",$)	
      READ (5,*) N		
      IF (N.LE.0) STOP		
      WRITE (6,*) "By Gauss:",SUMF(N,3) + SUMF(N,5) - SUMF(N,15)
      WRITE (6,*) "BFI sum :",SUMBFI(N)		
      GO TO 10			
      END
Task: Sum multiples of 3 and 5


C++: #include <iostream>


typedef unsigned long long bigInt;

using namespace std;

class m35
{
public:
    void doIt( bigInt i )
    {
	bigInt sum = 0;
	for( bigInt a = 1; a < i; a++ )
	    if( !( a % 3 ) || !( a % 5 ) ) sum += a;

	cout << "Sum is " << sum << " for n = " << i << endl << endl;
    }
	
    
    void doIt_b( bigInt i )
    {
	bigInt sum = 0;
	for( bigInt a = 0; a < 28; a++ )
	{
	    if( !( a % 3 ) || !( a % 5 ) )
	    {
		sum += a;
		for( bigInt s = 30; s < i; s += 30 )
		    if( a + s < i ) sum += ( a + s );

	    }
	}
	cout << "Sum is " << sum << " for n = " << i << endl << endl;
    }
};

int main( int argc, char* argv[] )
{
    m35 m; m.doIt( 1000 );
    return system( "pause" );
}









Fortran:       INTEGER*8 FUNCTION SUMI(N)	
Calculates as per the young Gauss: N*(N + 1)/2 = 1 + 2 + 3 + ... + N.
       INTEGER*8 N	
        IF (MOD(N,2).EQ.0) THEN	
          SUMI = N/2*(N + 1)		
         ELSE			
          SUMI = (N + 1)/2*N		
        END IF			
      END FUNCTION SUMI		

      INTEGER*8 FUNCTION SUMF(N,F)	
       INTEGER*8 N,F		
       INTEGER*8 L		
       INTEGER*8 SUMI		
        L = (N - 1)/F		
        SUMF = F*SUMI(L)	
      END FUNCTION SUMF		

      INTEGER*8 FUNCTION SUMBFI(N)	
       INTEGER*8 N	
       INTEGER*8 I,S	
        S = 0		
        DO I = 3,N - 1	
          IF (MOD(I,3).EQ.0 .OR. MOD(I,5).EQ.0) S = S + I	
        END DO		
        SUMBFI = S		
      END FUNCTION SUMBFI	

      INTEGER*8 SUMF,SUMBFI	
      INTEGER*8 N	
      WRITE (6,*) "Sum multiples of 3 and 5 up to N"
   10 WRITE (6,11)		
   11 FORMAT ("Specify N: ",$)	
      READ (5,*) N		
      IF (N.LE.0) STOP		
      WRITE (6,*) "By Gauss:",SUMF(N,3) + SUMF(N,5) - SUMF(N,15)
      WRITE (6,*) "BFI sum :",SUMBFI(N)		
      GO TO 10			
      END
Task: Sum multiples of 3 and 5

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

unsigned long long sum35(unsigned long long limit)
{
    unsigned long long sum = 0;
    for (unsigned long long i = 0; i < limit; i++)
        if (!(i % 3) || !(i % 5))
            sum += i;
    return sum;
}

int main(int argc, char **argv)
{
    unsigned long long limit;

    if (argc == 2)
        limit = strtoull(argv[1], NULL, 10);
    else
        limit = 1000;

    printf("%lld\n", sum35(limit));
    return 0;
}










Fortran:       INTEGER*8 FUNCTION SUMI(N)	
Calculates as per the young Gauss: N*(N + 1)/2 = 1 + 2 + 3 + ... + N.
       INTEGER*8 N	
        IF (MOD(N,2).EQ.0) THEN	
          SUMI = N/2*(N + 1)		
         ELSE			
          SUMI = (N + 1)/2*N		
        END IF			
      END FUNCTION SUMI		

      INTEGER*8 FUNCTION SUMF(N,F)	
       INTEGER*8 N,F		
       INTEGER*8 L		
       INTEGER*8 SUMI		
        L = (N - 1)/F		
        SUMF = F*SUMI(L)	
      END FUNCTION SUMF		

      INTEGER*8 FUNCTION SUMBFI(N)	
       INTEGER*8 N	
       INTEGER*8 I,S	
        S = 0		
        DO I = 3,N - 1	
          IF (MOD(I,3).EQ.0 .OR. MOD(I,5).EQ.0) S = S + I	
        END DO		
        SUMBFI = S		
      END FUNCTION SUMBFI	

      INTEGER*8 SUMF,SUMBFI	
      INTEGER*8 N	
      WRITE (6,*) "Sum multiples of 3 and 5 up to N"
   10 WRITE (6,11)		
   11 FORMAT ("Specify N: ",$)	
      READ (5,*) N		
      IF (N.LE.0) STOP		
      WRITE (6,*) "By Gauss:",SUMF(N,3) + SUMF(N,5) - SUMF(N,15)
      WRITE (6,*) "BFI sum :",SUMBFI(N)		
      GO TO 10			
      END
Task: Sum multiples of 3 and 5




Go: package main

import "fmt"

func main() {
    fmt.Println(s35(1000))
}

func s35(n int) int {
    n--
    threes := n / 3
    fives := n / 5
    fifteen := n / 15

    threes = 3 * threes * (threes + 1)
    fives = 5 * fives * (fives + 1)
    fifteen = 15 * fifteen * (fifteen + 1)

    n = (threes + fives - fifteen) / 2
	
    return n
}







Fortran:       INTEGER*8 FUNCTION SUMI(N)	
Calculates as per the young Gauss: N*(N + 1)/2 = 1 + 2 + 3 + ... + N.
       INTEGER*8 N	
        IF (MOD(N,2).EQ.0) THEN	
          SUMI = N/2*(N + 1)		
         ELSE			
          SUMI = (N + 1)/2*N		
        END IF			
      END FUNCTION SUMI		

      INTEGER*8 FUNCTION SUMF(N,F)	
       INTEGER*8 N,F		
       INTEGER*8 L		
       INTEGER*8 SUMI		
        L = (N - 1)/F		
        SUMF = F*SUMI(L)	
      END FUNCTION SUMF		

      INTEGER*8 FUNCTION SUMBFI(N)	
       INTEGER*8 N	
       INTEGER*8 I,S	
        S = 0		
        DO I = 3,N - 1	
          IF (MOD(I,3).EQ.0 .OR. MOD(I,5).EQ.0) S = S + I	
        END DO		
        SUMBFI = S		
      END FUNCTION SUMBFI	

      INTEGER*8 SUMF,SUMBFI	
      INTEGER*8 N	
      WRITE (6,*) "Sum multiples of 3 and 5 up to N"
   10 WRITE (6,11)		
   11 FORMAT ("Specify N: ",$)	
      READ (5,*) N		
      IF (N.LE.0) STOP		
      WRITE (6,*) "By Gauss:",SUMF(N,3) + SUMF(N,5) - SUMF(N,15)
      WRITE (6,*) "BFI sum :",SUMBFI(N)		
      GO TO 10			
      END
Task: Sum multiples of 3 and 5





Java: class SumMultiples {
	public static long getSum(long n) {
		long sum = 0;
		for (int i = 3; i < n; i++) {
			if (i % 3 == 0 || i % 5 == 0) sum += i;
		}
		return sum;
	}
	public static void main(String[] args) {
		System.out.println(getSum(1000));
	}
}






Fortran:       INTEGER*8 FUNCTION SUMI(N)	
Calculates as per the young Gauss: N*(N + 1)/2 = 1 + 2 + 3 + ... + N.
       INTEGER*8 N	
        IF (MOD(N,2).EQ.0) THEN	
          SUMI = N/2*(N + 1)		
         ELSE			
          SUMI = (N + 1)/2*N		
        END IF			
      END FUNCTION SUMI		

      INTEGER*8 FUNCTION SUMF(N,F)	
       INTEGER*8 N,F		
       INTEGER*8 L		
       INTEGER*8 SUMI		
        L = (N - 1)/F		
        SUMF = F*SUMI(L)	
      END FUNCTION SUMF		

      INTEGER*8 FUNCTION SUMBFI(N)	
       INTEGER*8 N	
       INTEGER*8 I,S	
        S = 0		
        DO I = 3,N - 1	
          IF (MOD(I,3).EQ.0 .OR. MOD(I,5).EQ.0) S = S + I	
        END DO		
        SUMBFI = S		
      END FUNCTION SUMBFI	

      INTEGER*8 SUMF,SUMBFI	
      INTEGER*8 N	
      WRITE (6,*) "Sum multiples of 3 and 5 up to N"
   10 WRITE (6,11)		
   11 FORMAT ("Specify N: ",$)	
      READ (5,*) N		
      IF (N.LE.0) STOP		
      WRITE (6,*) "By Gauss:",SUMF(N,3) + SUMF(N,5) - SUMF(N,15)
      WRITE (6,*) "BFI sum :",SUMBFI(N)		
      GO TO 10			
      END