task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Raku
Raku
say DateTime.now; dd DateTime.now.Instant;
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#Python
Python
from numpy import array, tril, sum   A = [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]   print(sum(tril(A, -1))) # 69
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#R
R
mat <- rbind(c(1,3,7,8,10), c(2,4,16,14,4), c(3,1,9,18,11), c(12,14,17,18,20), c(7,1,3,9,5)) print(sum(mat[lower.tri(mat)]))
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#JavaScript
JavaScript
(function () { 'use strict';   // GENERIC FUNCTIONS   // concatMap :: (a -> [b]) -> [a] -> [b] var concatMap = function concatMap(f, xs) { return [].concat.apply([], xs.map(f)); },   // curry :: ((a, b) -> c) -> a -> b -> c curry = function curry(f) { retu...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Ruby
Ruby
module TempConvert   FROM_TEMP_SCALE_TO_K = {'kelvin' => lambda{|t| t}, 'celsius' => lambda{|t| t + 273.15}, 'fahrenheit' => lambda{|t| (t + 459.67) * 5/9.0}, 'rankine' => lambda{|t| t * 5/9.0}, 'delisle' => lambda{|t| 373.15 - t * 2/3.0}, 'newton' => lambda{|t| t * 100/33.0 + 273.1...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Raven
Raven
time dup print "\n" print int '%a %b %e %H:%M:%S %Y' date
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#REBOL
REBOL
now print rejoin [now/year "-" now/month "-" now/day " " now/time]
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#Raku
Raku
sub lower-triangle-sum (@matrix) { sum flat (1..@matrix).map( { @matrix[^$_]»[^($_-1)] } )»[*-1] }   say lower-triangle-sum [ [ 1, 3, 7, 8, 10 ], [ 2, 4, 16, 14, 4 ], [ 3, 1, 9, 18, 11 ], [ 12, 14, 17, 18, 20 ], [ 7, 1, 3, 9, 5 ] ];
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#REXX
REXX
/* REXX */ ml ='1 3 7 8 10 2 4 16 14 4 3 1 9 18 11 12 14 17 18 20 7 1 3 9 5' Do i=1 To 5 Do j=1 To 5 Parse Var ml m.i.j ml End End   l='' Do i=1 To 5 Do j=1 To 5 l=l right(m.i.j,2) End Say l l='' End   sum=0 Do i=2 To 5 Do j=1 To i-1 sum=sum+m.i.j End End Say 'Sum below main diag...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#jq
jq
  # For readability: def collect(c): map(select(c));   # stream-oriented checks: def hasMoreThanOne(s): [limit(2;s)] | length > 1;   def hasOne(s): [limit(2;s)] | length == 1;   def prod: .[0] * .[1];   ## A stream of admissible [x,y] values def xy: [range(2;50) as $x # 1 < X < Y < 100 | range($x+1; 101-$x) as $y...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Run_BASIC
Run BASIC
[loop] input "Kelvin Degrees";kelvin if kelvin <= 0 then end ' zero or less ends the program celcius = kelvin - 273.15 fahrenheit = kelvin * 1.8 - 459.67 rankine = kelvin * 1.8 print kelvin;" kelvin is equal to ";celcius; " degrees celcius and ";fahrenheit;" degrees fahrenheit and ";rankine; " degrees ...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Scala
Scala
object TemperatureConversion extends App {   def kelvinToCelsius(k: Double) = k + 273.15   def kelvinToFahrenheit(k: Double) = k * 1.8 - 459.67   def kelvinToRankine(k: Double) = k * 1.8   if (args.length == 1) { try { val kelvin = args(0).toDouble if (kelvin >= 0) { println(f"K $kelvin...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Retro
Retro
time putn
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#REXX
REXX
/*REXX program shows various ways to display the system time, including other options. */   say '════════════ Normal format of time' say 'hh:mm:ss ◄─────────────── hh= is 00 ──► 23' say 'hh:mm:ss ◄─────────────── hh= hour mm= minute ss= second' say time() say time('n') ...
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#Ring
Ring
  see "working..." + nl see "Sum of elements below main diagonal of matrix:" + nl diag = [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]   lenDiag = len(diag) ind = lenDiag sumDiag = 0   for n=1 to lenDiag for m=1 to lenDiag-ind sumDiag += diag[n][...
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#Ruby
Ruby
arr = [ [ 1, 3, 7, 8, 10], [ 2, 4, 16, 14, 4], [ 3, 1, 9, 18, 11], [12, 14, 17, 18, 20], [ 7, 1, 3, 9, 5] ] p arr.each_with_index.sum {|row, x| row[0, x].sum}  
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Julia
Julia
  using Primes   function satisfy1(x::Integer) prmslt100 = primes(100) for i in 2:(x ÷ 2) if i ∈ prmslt100 && x - i ∈ prmslt100 return false end end return true end   function satisfy2(x::Integer) once = false for i in 2:isqrt(x) if x % i == 0 j = ...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Rust
Rust
fn main() -> std::io::Result<()> { print!("Enter temperature in Kelvin to convert: "); let mut input = String::new(); std::io::stdin().read_line(&mut input)?; match input.trim().parse::<f32>() { Ok(kelvin) => { if kelvin < 0.0 { println!("Negative Kelvin values are no...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#11l
11l
print(sum((1..1000).map(x -> 1.0/x^2)))
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Ring
Ring
  /* Output: ** Sun abbreviated weekday name ** Sunday full weekday name ** May abbreviated month name ** May full month name ** 05/24/15 09:58:38 Date & Time ** 24 Day of the month ** 09 Hour (24) ** 09 ...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Ruby
Ruby
t = Time.now   # textual puts t # => 2013-12-27 18:00:23 +0900   # epoch time puts t.to_i # => 1388134823   # epoch time with fractional seconds puts t.to_f # => 1388134823.9801579   # epoch time as a rational (more precision): puts Time.now.to_r # 1424900671883862959/1000000000  
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#11l
11l
F sum_digits(=n, base) V r = 0 L n > 0 r += n % base n I/= base R r   print(sum_digits(1, 10)) print(sum_digits(1234, 10)) print(sum_digits(F'E, 16)) print(sum_digits(0F'0E, 16))
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local var integer: sum is 0; var integer: i is 0; var integer: j is 0; const array array integer: m is [] ([] ( 1, 3, 7, 8, 10), [] ( 2, 4, 16, 14, 4), [] ( 3, 1, ...
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#Wren
Wren
var m = [ [ 1, 3, 7, 8, 10], [ 2, 4, 16, 14, 4], [ 3, 1, 9, 18, 11], [12, 14, 17, 18, 20], [ 7, 1, 3, 9, 5] ] if (m.count != m[0].count) Fiber.abort("Matrix must be square.") var sum = 0 for (i in 1...m.count) { for (j in 0...i) { sum = sum + m[i][j] } } System.print("Sum of e...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Kotlin
Kotlin
// version 1.1.4-3   data class P(val x: Int, val y: Int, val sum: Int, val prod: Int)   fun main(args: Array<String>) { val candidates = mutableListOf<P>() for (x in 2..49) { for (y in x + 1..100 - x) { candidates.add(P(x, y, x + y, x * y)) } }   val sums = candidates.gr...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Scheme
Scheme
  (import (scheme base) (scheme read) (scheme write))   (define (kelvin->celsius k) (- k 273.15))   (define (kelvin->fahrenheit k) (- (* k 1.8) 459.67))   (define (kelvin->rankine k) (* k 1.8))   ;; Run the program (let ((k (begin (display "Kelvin  : ") (flush-output-port) (read)))) (when (num...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#360_Assembly
360 Assembly
* Sum of a series 30/03/2017 SUMSER CSECT USING SUMSER,12 base register LR 12,15 set addressability LR 10,14 save r14 LE 4,=E'0' s=0 LE 2,=E'1' i=1 DO WHILE=(CE,2,LE,=E'1000'...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Rust
Rust
// 20210210 Rust programming solution   extern crate chrono; use chrono::prelude::*;   fn main() { let utc: DateTime<Utc> = Utc::now(); println!("{}", utc.format("%d/%m/%Y %T")); }  
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Scala
Scala
println(new java.util.Date)
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#11l
11l
F sum35(limit) V sum = 0 L(i) 1 .< limit I i % 3 == 0 | i % 5 == 0 sum += i R sum   print(sum35(1000))
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#360_Assembly
360 Assembly
* Sum digits of an integer 08/07/2016 SUMDIGIN CSECT USING SUMDIGIN,R13 base register B 72(R15) skip savearea DC 17F'0' savearea STM R14,R12,12(R13) prolog ST R13,4(R15) " <- ST R15,8(R13) ...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#0815
0815
  {x{*%<:d:~$<:1:~>><:2:~>><:3:~>><:4:~>><:5:~>><:6:~>><:7: ~>><:8:~>><:9:~>><:a:~>><:b:~>><:c:~>><:ffffffffffffffff: ~>{x{*>}:8f:{x{*&{=+>{~>&=x<:ffffffffffffffff:/#:8f:{{~%  
http://rosettacode.org/wiki/Sum_of_elements_below_main_diagonal_of_matrix
Sum of elements below main diagonal of matrix
Task Find and display the sum of elements that are below the main diagonal of a matrix. The matrix should be a square matrix. ───   Matrix to be used:   ─── [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]
#XPL0
XPL0
int Mat, X, Y, Sum; [Mat:= [[1,3,7,8,10], [2,4,16,14,4], [3,1,9,18,11], [12,14,17,18,20], [7,1,3,9,5]]; Sum:= 0; for Y:= 0 to 4 do for X:= 0 to 4 do if Y > X then Sum:= Sum + Mat(Y,X); IntOut(0, Sum); ]
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Lua
Lua
function print_count(t) local cnt = 0 for k,v in pairs(t) do cnt = cnt + 1 end print(cnt .. ' candidates') end   function make_pair(a,b) local t = {} table.insert(t, a) -- 1 table.insert(t, b) -- 2 return t end   function setup() local candidates = {} for x = 2, 98 do ...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "float.s7i";   const func float: celsius (in float: kelvin) is return kelvin - 273.15;   const func float: fahrenheit (in float: kelvin) is return kelvin * 1.8 - 459.67;   const func float: rankine (in float: kelvin) is return kelvin * 1.8;   const proc: main is func local ...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Sidef
Sidef
var scale = Hash( Celcius => Hash.new(factor => 1 , offset => -273.15 ), Rankine => Hash.new(factor => 1.8, offset => 0 ), Fahrenheit => Hash.new(factor => 1.8, offset => -459.67 ), );   var kelvin = Sys.readln("Enter a temperature in Kelvin: ").to_n; kelvin >= 0 || die "No such temperature!"; ...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#11l
11l
F suffize(numstr, digits = -1, base = 10) V suffixes = [‘’, ‘K’, ‘M’, ‘G’, ‘T’, ‘P’, ‘E’, ‘Z’, ‘Y’, ‘X’, ‘W’, ‘V’, ‘U’, ‘googol’]   V exponent_distance = I base == 2 {10} E 3 V num_sign = I numstr[0] C ‘+-’ {numstr[0]} E ‘’   V num = abs(Float(numstr.replace(‘,’, ‘’)))   Int suffix_index I base == 10 ...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#ACL2
ACL2
(defun sum-x^-2 (max-x) (if (zp max-x) 0 (+ (/ (* max-x max-x)) (sum-x^-2 (1- max-x)))))
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Scheme
Scheme
(use posix) (seconds->string (current-seconds))
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "time.s7i";   const proc: main is func begin writeln(time(NOW)); end func;
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#8th
8th
  needs combinators/bi   : mul3or5? ( 3 mod 0 = ) ( 5 mod 0 = ) bi or ;   "The sum of the multiples of 3 or 5 below 1000 is " . 0 ( mul3or5? if I n:+ then ) 1 999 loop . cr   with: n   : >triangular SED: n -- n dup 1+ * 2 / ;   : sumdiv SED: n n -- n dup >r /mod nip >triangular r> * ;   : sumdiv_3,5 SED: n -- ...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#8086_Assembly
8086 Assembly
cpu 8086 org 100h section .text jmp demo ;;; Sum of digits of AX in base BX. ;;; Returns: AX = result ;;; CX, DX destroyed. digsum: xor cx,cx ; Result .loop: xor dx,dx ; Divide AX by BX div bx ; Quotient in AX, modulus in DX add cx,dx ; Add digit to sum test ax,ax ; Is the quotient now zero? jnz .loop ;...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#11l
11l
print(sum([1, 2, 3, 4, 5].map(x -> x^2)))
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#360_Assembly
360 Assembly
* Sum of squares 27/08/2015 SUMOFSQR CSECT USING SUMOFSQR,R12 LR R12,R15 LA R7,A a(1) SR R6,R6 sum=0 LA R3,1 i=1 LOOPI CH R3,N do i=1 to hbound(a) BH ELOOPI ...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Nim
Nim
import sequtils, sets, sugar, tables   var xycandidates = toSeq(2..98) sums = collect(initHashSet, for s in 5..100: {s}) # Set of possible sums. factors: Table[int, seq[(int, int)]] # Mapping product -> list of factors.   # Build the factor mapping. for i in 0..<xycandidates.high: let x = xycan...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Swift
Swift
  func KtoC(kelvin : Double)->Double{   return kelvin-273.15 }   func KtoF(kelvin : Double)->Double{   return ((kelvin-273.15)*1.8)+32 }   func KtoR(kelvin : Double)->Double{   return ((kelvin-273.15)*1.8)+491.67 }   var k// input print("\(k) Kelvin") var c=KtoC(kelvin : k) print("\(c) Celsius") var f=KtoF(...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Tcl
Tcl
proc temps {k} { set c [expr {$k - 273.15}] set r [expr {$k / 5.0 * 9.0}] set f [expr {$r - 459.67}] list $k $c $f $r }
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#Go
Go
package main   import ( "fmt" "math/big" "strconv" "strings" )   var suffixes = " KMGTPEZYXWVU" var ggl = googol()   func googol() *big.Float { g1 := new(big.Float).SetPrec(500) g1.SetInt64(10000000000) g := new(big.Float) g.Set(g1) for i := 2; i <= 10; i++ { g.Mul(g, g1) ...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Action.21
Action!
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit   PROC Calc(CARD n REAL POINTER res) CARD i,st BYTE perc REAL one,a,b   IntToReal(0,res) IF n=0 THEN RETURN FI   IntToReal(1,one) st=n/100 FOR i=1 TO n DO IF i MOD st=0 THEN PrintB(perc) Put('%) PutE() Put(28) perc==+1 FI   IntTo...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#SETL
SETL
$ Unix time print(tod);   $ Human readable time and date print(date);
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Sidef
Sidef
# textual say Time.local.ctime; # => Thu Mar 19 15:10:41 2015   # epoch time say Time.sec; # => 1426770641   # epoch time with fractional seconds say Time.micro_sec; # => 1426770641.68409
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#360_Assembly
360 Assembly
* Sum multiples of 3 and 5 SUM35 CSECT USING SUM35,R13 base register B 72(R15) skip savearea DC 17F'0' savearea STM R14,R12,12(R13) save previous context ST R13,4(R15) link backward ST R15,8(R...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Action.21
Action!
CARD FUNC SumDigits(CARD num,base) CARD res,a   res=0 WHILE num#0 DO res==+num MOD base num=num/base OD RETURN(res)   PROC Main() CARD ARRAY data=[ 1 10 1234 10 $FE 16 $F0E 16 $FF 2 0 2 2186 3 2187 3] BYTE i CARD num,base,res   FOR i=0 TO 15 STEP 2 DO num=data(i) ba...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#8086_Assembly
8086 Assembly
;;; Sum of squares cpu 8086 bits 16 section .text org 100h jmp demo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Calculate the sum of the squares of the array in SI. ;;; The array should contain 16-bit unsigned integers. ;;; The output will be 32-bit. ;;; Input: (DS:)SI = arr...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#ooRexx
ooRexx
all =.set~new Call time 'R' cnt.=0 do a=2 to 100 do b=a+1 to 100-2 p=a b if a+b>100 then leave b all~put(p) prd=a*b cnt.prd+=1 End End Say "There are" all~items "pairs where X+Y <=" max "(and X<Y)"   spairs=.set~new Do Until all~items=0 do p over all d=decompositions(p) If tak...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#UNIX_Shell
UNIX Shell
#!/bin/ksh # Temperature conversion typeset tt[1]=0.00 tt[2]=273.15 tt[3]=373.15 for i in {1..3} do ((t=tt[i])) echo $i echo "Kelvin: $t K" echo "Celsius: $((t-273.15)) C" echo "Fahrenheit: $((t*18/10-459.67)) F" echo "Rankine: $((t*18/10)) R" done
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#Julia
Julia
using Printf   const suf = Dict{BigInt, String}(BigInt(1) => "", BigInt(10)^100 => "googol", BigInt(10)^3 => "K", BigInt(10)^6 => "M", BigInt(10)^9 => "G", BigInt(10)^12 => "T", BigInt(10)^15 => "P", BigInt(10)^18 => "E", BigInt(10)^21 => "Z", BigInt(10)^24 => "Y", BigInt(10)^27 => "X", BigInt(10)^30 => "W"...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#Nim
Nim
import math, strutils   const Suffixes = ["", "K", "M", "G", "T", "P", "E", "Z", "Y", "X", "W", "V", "U", "googol"] None = -1   proc suffize(num: string; digits = None; base = 10): string =   let exponentDist = if base == 2: 10 else: 3 let num = num.strip().replace(",", "") let numSign = if num[0] in {'+', '-...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#Perl
Perl
use List::Util qw(min max first);   sub sufficate { my($val, $type, $round) = @_; $type //= 'M'; if ($type =~ /^\d$/) { $round = $type; $type = 'M' }   my $s = ''; if (substr($val,0,1) eq '-') { $s = '-'; $val = substr $val, 1 } $val =~ s/,//g; if ($val =~ m/e/i) { my ($m,$e) = split ...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#ActionScript
ActionScript
function partialSum(n:uint):Number { var sum:Number = 0; for(var i:uint = 1; i <= n; i++) sum += 1/(i*i); return sum; } trace(partialSum(1000));
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Smalltalk
Smalltalk
DateTime now displayNl.
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#SNOBOL4
SNOBOL4
OUTPUT = DATE() END
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Action.21
Action!
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit   PROC Main() REAL sum,r INT i   Put(125) PutE() ;clear the screen IntToReal(0,sum) FOR i=0 TO 999 DO IF i MOD 3=0 OR i MOD 5=0 THEN IntToReal(i,r) RealAdd(sum,r,sum) FI OD   PrintRE(sum) RETURN
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Ada
Ada
with Ada.Integer_Text_IO;   procedure Sum_Digits is -- sums the digits of an integer (in whatever base) -- outputs the sum (in base 10)   function Sum_Of_Digits(N: Natural; Base: Natural := 10) return Natural is Sum: Natural := 0; Val: Natural := N; begin while Val > 0 loop Sum :=...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#ACL2
ACL2
(defun sum-of-squares (xs) (if (endp xs) 0 (+ (* (first xs) (first xs)) (sum-of-squares (rest xs)))))
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Perl
Perl
use List::Util qw(none);   sub grep_unique { my($by, @list) = @_; my @seen; for (@list) { my $x = &$by(@$_); $seen[$x]= defined $seen[$x] ? 0 : join ' ', @$_; } grep { $_ } @seen; }   sub sums { my($n) = @_; my @sums; push @sums, [$_, $n - $_] for 2 .. int $n/2; @sums...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Ursa
Ursa
decl double k while true out "Temp. in Kelvin? " console set k (in double console) out "K\t" k endl "C\t" (- k 273.15) endl console out "F\t" (- (* k 1.8) 459.67) endl "R\t" (* k 1.8) endl endl console end while
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#VBA
VBA
  Option Explicit   Sub Main_Conv_Temp() Dim K As Single, Result As Single K = 21 Debug.Print "Input in Kelvin  : " & Format(K, "0.00") Debug.Print "Output in Celsius  : " & IIf(ConvTemp(Result, K, "C"), Format(Result, "0.00"), False) Debug.Print "Output in Fahrenheit : " & IIf(ConvTemp(Result, K,...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#Phix
Phix
include builtins/bigatom.e constant suffixes = "KMGTPEZYXWVU", anydp = 100 -- the "any dp" value (prevents nearest 1e-100, though) function suffize(sequence args) bigatom size = ba_abs(args[1]) integer sgn = iff(ba_compare(args[1],0)<0?-1:+1), la = length(args), dp = iff(la>...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Ada
Ada
with Ada.Text_Io; use Ada.Text_Io;   procedure Sum_Series is function F(X : Long_Float) return Long_Float is begin return 1.0 / X**2; end F; package Lf_Io is new Ada.Text_Io.Float_Io(Long_Float); use Lf_Io; Sum : Long_Float := 0.0; subtype Param_Range is Integer range 1..1000; begin for I ...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#SPL
SPL
hour,min,sec = #.now() day,month,year = #.today()   #.output(#.str(hour,"00:"),#.str(min,"00:"),#.str(sec,"00.000")) #.output(day,".",#.str(month,"00"),".",year)
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#SQL_PL
SQL PL
  SELECT CURRENT DATE, CURRENT TIME, CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY1;  
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Ada
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; ...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#ALGOL_68
ALGOL 68
  # operator to return the sum of the digits of an integer value in the # # specified base # PRIO SUMDIGITS = 1; OP SUMDIGITS = ( INT value, INT base )INT: IF base < 2 THEN # invalid base # print( ( "Base for digit sum must be at least 2...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Action.21
Action!
CARD FUNC SumOfSqr(BYTE ARRAY a BYTE count) BYTE i CARD res   IF count=0 THEN RETURN (0) FI   res=0 FOR i=0 TO count-1 DO res==+a(i)*a(i) OD RETURN (res)   PROC Test(BYTE ARRAY a BYTE count) BYTE i CARD res   res=SumOfSqr(a,count) Print("[") IF count>0 THEN FOR i=0 to count-1 D...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#ActionScript
ActionScript
function sumOfSquares(vector:Vector.<Number>):Number { var sum:Number = 0; for(var i:uint = 0; i < vector.length; i++) sum += vector[i]*vector[i]; return sum; }
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#11l
11l
V arr = [1, 2, 3, 4] print(sum(arr)) print(product(arr))
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Phix
Phix
with javascript_semantics function satisfies_statement1(integer s) -- S says: P does not know the two numbers. -- Given s, for /all/ pairs (a,b), a+b=s, 2<=a,b<=99, at least one of a or b is composite for a=2 to floor(s/2) do if is_prime(a) and is_prime(s-a) then return false end if ...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#VBScript
VBScript
  WScript.StdOut.Write "Enter the temperature in Kelvin:" tmp = WScript.StdIn.ReadLine   WScript.StdOut.WriteLine "Kelvin: " & tmp WScript.StdOut.WriteLine "Fahrenheit: " & fahrenheit(CInt(tmp)) WScript.StdOut.WriteLine "Celsius: " & celsius(CInt(tmp)) WScript.StdOut.WriteLine "Rankine: " & rankine(CInt(tmp))   Functio...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Visual_FoxPro
Visual FoxPro
#DEFINE ABSZC 273.16 #DEFINE ABSZF 459.67 LOCAL k As Double, c As Double, f As Double, r As Double, n As Integer, ; cf As String n = SET("Decimals") cf = SET("Fixed") SET DECIMALS TO 2 SET FIXED ON CLEAR DO WHILE .T. k = VAL(INPUTBOX("Degrees Kelvin:", "Temperature")) IF k <= 0 EXIT ENDIF  ? "K:",...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#Python
Python
  import math import os     def suffize(num, digits=None, base=10): suffixes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'X', 'W', 'V', 'U', 'googol']   exponent_distance = 10 if base == 2 else 3 num = num.strip().replace(',', '') num_sign = num[0] if num[0] in '+-' else ''   num = abs(float(num)...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Aime
Aime
real Invsqr(real n) { 1 / (n * n); }   integer main(void) { integer i; real sum;   sum = 0;   i = 1; while (i < 1000) { sum += Invsqr(i); i += 1; }   o_real(14, sum); o_byte('\n');   0; }
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Standard_ML
Standard ML
print (Date.toString (Date.fromTimeLocal (Time.now ())) ^ "\n")
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Stata
Stata
di c(current_date) di c(current_time)
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#ALGOL_68
ALGOL 68
# returns the sum of the multiples of 3 and 5 below n # PROC sum of multiples of 3 and 5 below = ( LONG LONG INT n )LONG LONG INT: BEGIN # calculate the sum of the multiples of 3 below n # LONG LONG INT multiples of 3 = ( n - 1 ) OVER 3; LONG LONG INT multiples of 5 = ( n - 1 ) OVER 5; ...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#AppleScript
AppleScript
----------------- SUM DIGITS OF AN INTEGER -----------------   -- baseDigitSum :: Int -> Int -> Int on baseDigitSum(base) script on |λ|(n) script go on |λ|(x) if 0 < x then Just({x mod base, x div base}) else ...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO;   procedure Test_Sum_Of_Squares is type Float_Array is array (Integer range <>) of Float;   function Sum_Of_Squares (X : Float_Array) return Float is Sum : Float := 0.0; begin for I in X'Range loop Sum := Sum + X (I) ** 2; end loop; return Su...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#360_Assembly
360 Assembly
* Sum and product of an array 20/04/2017 SUMPROD CSECT USING SUMPROD,R15 base register SR R3,R3 su=0 LA R5,1 pr=1 LA R6,1 i=1 DO WHILE=(CH,R6,LE,=AL2((PG-A)/4)) do i=1 to hbound(a) LR ...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Picat
Picat
  main => N = 98, PD = new_array(N*N), % PD[I] = no. of product decompositions of I foreach(I in 1..N*N) PD[I] = 0 end, foreach(X in 2..N-1, Y in X+1..N) PD[X * Y] := PD[X * Y] + 1 end,    % Fact 1: S says "P does not know X and Y.", i.e.  % For every possible sum decomposition of the number X+...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Wren
Wren
import "/fmt" for Fmt   var tempConv = Fn.new { |k| var c = k - 273.15 var f = c * 1.8 + 32 var r = f + 459.67 System.print("%(Fmt.f(7, k, 2))˚ Kelvin") System.print("%(Fmt.f(7, c, 2))˚ Celsius") System.print("%(Fmt.f(7, f, 2))˚ Fahrenheit") System.print("%(Fmt.f(7, r, 2))˚ Rankine") Sys...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#Raku
Raku
sub sufficate ($val is copy, $type is copy = 'M', $round is copy = Any) { if +$type ~~ Int { $round = $type; $type = 'M' } my $s = ''; if $val.substr(0,1) eq '-' { $s = '-'; $val.=substr(1) } $val.=subst(',', '', :g); if $val ~~ m:i/'e'/ { my ($m,$e) = $val.split(/<[eE]>/); $val = ($e < 0) ...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#ALGOL_68
ALGOL 68
MODE RANGE = STRUCT(INT lwb, upb);   PROC sum = (PROC (INT)LONG REAL f, RANGE range)LONG REAL:( LONG REAL sum := LENG 0.0; FOR i FROM lwb OF range TO upb OF range DO sum := sum + f(i) OD; sum );   test:( RANGE range = (1,1000); PROC f = (INT x)LONG REAL: LENG REAL(1) / LENG REAL(x)**2; print(("Sum of...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Swift
Swift
import Foundation   var ⌚️ = NSDate() println(⌚️)
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Tcl
Tcl
puts [clock seconds]
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#APL
APL
  Sum ← +/∘⍸1<15∨⍳  
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#APL
APL
sd←+/⊥⍣¯1
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Aime
Aime
real squaredsum(list l) { integer i; real s;   s = 0; i = -~l; while (i) { s += sq(l[i += 1]); }   s; }   integer main(void) { list l;   l = list(0, 1, 2, 3);   o_form("~\n", squaredsum(l)); o_form("~\n", squaredsum(list())); o_form("~\n", squaredsum(list(.5, -.5,...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#ALGOL_68
ALGOL 68
PROC sum of squares = ([]REAL argv)REAL:( REAL sum := 0; FOR i FROM LWB argv TO UPB argv DO sum +:= argv[i]**2 OD; sum ); test:( printf(($g(0)l$,sum of squares([]REAL(3, 1, 4, 1, 5, 9)))); )
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#4D
4D
ARRAY INTEGER($list;0) For ($i;1;5) APPEND TO ARRAY($list;$i) End for   $sum:=0 $product:=1 For ($i;1;Size of array($list)) $sum:=$var+$list{$i} $product:=$product*$list{$i} End for   // since 4D v13   $sum:=sum($list)  
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#ACL2
ACL2
(defun sum (xs) (if (endp xs) 0 (+ (first xs) (sum (rest xs)))))   (defun prod (xs) (if (endp xs) 1 (* (first xs) (prod (rest xs)))))