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... | #NetRexx | NetRexx |
import java.text.SimpleDateFormat
say SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS").format(Date()) |
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]]
| #AutoHotkey | AutoHotkey | matrx :=[[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]]
sumA := sumB := sumD := sumAll := 0
for r, obj in matrx
for c, val in obj
sumAll += val
,sumA += r<c ? val : 0
,sumB += r>c ? val : 0
,sumD += r=c ? val : 0
MsgBox % result := "sum above diagonal = " sumA
. "`nsum b... |
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]]
| #AWK | AWK |
# syntax: GAWK -f SUM_OF_ELEMENTS_BELOW_MAIN_DIAGONAL_OF_MATRIX.AWK
BEGIN {
arr1[++n] = "1,3,7,8,10"
arr1[++n] = "2,4,16,14,4"
arr1[++n] = "3,1,9,18,11"
arr1[++n] = "12,14,17,18,20"
arr1[++n] = "7,1,3,9,5"
for (i=1; i<=n; i++) {
x = split(arr1[i],arr2,",")
if (x != n) {
pri... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Racket | Racket |
#lang racket
(define A (set "John" "Bob" "Mary" "Serena"))
(define B (set "Jim" "Mary" "John" "Bob"))
(set-symmetric-difference A B)
(set-subtract A B)
(set-subtract B A)
|
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Raku | Raku | my \A = set <John Serena Bob Mary Serena>;
my \B = set <Jim Mary John Jim Bob>;
say A ∖ B; # Set subtraction
say B ∖ A; # Set subtraction
say (A ∪ B) ∖ (A ∩ B); # Symmetric difference, via basic set operations
say A ⊖ B; # Symmetric difference, via dedicated operator |
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... | #PARI.2FGP | PARI/GP | f(x)=[x,x-273.15,1.8*x-459.67,1.8*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... | #Pascal | Pascal | program TemperatureConvert;
type
TemperatureType = (C, F, K, R);
var
kelvin: real;
function ConvertTemperature(temperature: real; fromType, toType: TemperatureType): real;
var
initial, result: real;
begin
(* We are going to first convert whatever we're given into Celsius.
... |
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... | #NewLISP | NewLISP | > (date)
"Sun Sep 28 20:17:55 2014" |
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... | #Nim | Nim | import times
echo getDateStr()
echo getClockStr()
echo getTime()
echo now() # shorthand for "getTime().local" |
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]]
| #BASIC | BASIC | arraybase 1
dim 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}}
ind = diag[?,]
sumDiag = 0
for x = 1 to diag[?,]
for y = 1 to diag[,?]-ind
sumDiag += diag[x, y]
next y
ind -= 1
next x
print "Sum of elements below main diagonal of matrix is "; sumDiag
end |
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]]
| #BQN | BQN | SumBelowDiagonal ← +´∘⥊⊢×(>⌜´)∘(↕¨≢)
matrix ← >⟨⟨ 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⟩⟩
SumBelowDiagonal matrix |
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... | #11l | 11l | F counter(arr)
DefaultDict[Int, Int] d
L(a) arr
d[a]++
R d
F decompose_sum(s)
R (2 .< Int(s / 2 + 1)).map(a -> (a, @s - a))
Set[(Int, Int)] all_pairs_set
L(a) 2..99
L(b) a + 1 .< 100
I a + b < 100
all_pairs_set.add((a, b))
V all_pairs = Array(all_pairs_set)
V product_counts = c... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #REBOL | REBOL | a: [John Serena Bob Mary Serena]
b: [Jim Mary John Jim Bob]
difference a b |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #REXX | REXX | /*REXX program finds symmetric difference and symmetric AND (between two lists). */
a= '["John", "Serena", "Bob", "Mary", "Serena"]' /*note the duplicate element: Serena */
b= '["Jim", "Mary", "John", "Jim", "Bob"]' /* " " " " Jim */
a.=0; SD.=0; SA.=0; SD=; SA= ... |
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... | #Perl | Perl | my %scale = (
Celcius => { factor => 1 , offset => -273.15 },
Rankine => { factor => 1.8, offset => 0 },
Fahrenheit => { factor => 1.8, offset => -459.67 },
);
print "Enter a temperature in Kelvin: ";
chomp(my $kelvin = <STDIN>);
die "No such temperature!\n" unless $kelvin > 0;
foreach (sor... |
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... | #Objeck | Objeck | function : Time() ~ Nil {
t := Time->New();
IO.Console->GetInstance()->Print(t->GetHours())->Print(":")->Print(t->GetMinutes())->Print(":")->PrintLine(t->GetSeconds());
} |
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... | #Objective-C | Objective-C | NSLog(@"%@", [NSDate date]); |
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]]
| #C | C |
#include<stdlib.h>
#include<stdio.h>
typedef struct{
int rows,cols;
int** dataSet;
}matrix;
matrix readMatrix(char* dataFile){
FILE* fp = fopen(dataFile,"r");
matrix rosetta;
int i,j;
fscanf(fp,"%d%d",&rosetta.rows,&rosetta.cols);
rosetta.dataSet = (int**)malloc(rosetta.rows*sizeof(int*));
for(i=0;i... |
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... | #AWK | AWK |
# syntax: GAWK -f SUM_AND_PRODUCT_PUZZLE.AWK
BEGIN {
for (s=2; s<=100; s++) {
if ((a=satisfies_statement3(s)) != 0) {
printf("%d (%d+%d)\n",s,a,s-a)
}
}
exit(0)
}
function satisfies_statement1(s, a) { # S says: P does not know the two numbers.
# Given s, for all pairs (a,b), a+b=s, 2 ... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Ring | Ring |
alist = []
blist = []
alist = ["john", "bob", "mary", "serena"]
blist = ["jim", "mary", "john", "bob"]
alist2 = []
for i = 1 to len(alist)
flag = 0
for j = 1 to len(blist)
if alist[i] = blist[j] flag = 1 ok
next
if (flag = 0) add(alist2, alist[i]) ok
next
blist2 = []
for j = 1 to len... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Ruby | Ruby | a = ["John", "Serena", "Bob", "Mary", "Serena"]
b = ["Jim", "Mary", "John", "Jim", "Bob"]
# the union minus the intersection:
p sym_diff = (a | b)-(a & b) # => ["Serena", "Jim"] |
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... | #Phix | Phix | atom K = prompt_number("Enter temperature in Kelvin >=0: ",{0,1e307})
printf(1," Kelvin: %5.2f\n Celsius: %5.2f\nFahrenheit: %5.2f\n Rankine: %5.2f\n\n",
{K, K-273.15, K*1.8-459.67, K*1.8})
|
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... | #OCaml | OCaml | #load "unix.cma";;
open Unix;;
let {tm_sec = sec;
tm_min = min;
tm_hour = hour;
tm_mday = mday;
tm_mon = mon;
tm_year = year;
tm_wday = wday;
tm_yday = yday;
tm_isdst = isdst} = localtime (time ());;
Printf.printf "%04d-%02d-%02d %02d:%02d:%02d\n" (year + 1900) (mon + 1) mday hou... |
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]]
| #C.2B.2B | C++ | #include <iostream>
#include <vector>
template<typename T>
T sum_below_diagonal(const std::vector<std::vector<T>>& matrix) {
T sum = 0;
for (std::size_t y = 0; y < matrix.size(); y++)
for (std::size_t x = 0; x < matrix[y].size() && x < y; x++)
sum += matrix[y][x];
return sum;
}
int m... |
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... | #C | C | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct node_t {
int x, y;
struct node_t *prev, *next;
} node;
node *new_node(int x, int y) {
node *n = malloc(sizeof(node));
n->x = x;
n->y = y;
n->next = NULL;
n->prev = NULL;
return n;
}
void free_node(node **n) ... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Run_BASIC | Run BASIC |
setA$ = "John,Bob,Mary,Serena"
setB$ = "Jim,Mary,John,Bob"
x$ = b$(setA$,setB$)
print word$(x$,1,",")
c$ = c$ + x$
x$ = b$(setB$,setA$)
print word$(x$,1,",")
print c$;x$
end
function b$(a$,b$)
i = 1
while word$(a$,i,",") <> ""
a1$ = word$(a$,i,",")
j = instr(b$,a1$)
if j <> 0 then b$ = left$(b$,j-1) + m... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Rust | Rust | use std::collections::HashSet;
fn main() {
let a: HashSet<_> = ["John", "Bob", "Mary", "Serena"]
.iter()
.collect();
let b = ["Jim", "Mary", "John", "Bob"]
.iter()
.collect();
let diff = a.symmetric_difference(&b);
println!("{:?}", diff);
}
|
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... | #PHP | PHP |
while (true) {
echo "\nEnter a value in kelvin (q to quit): ";
if ($kelvin = trim(fgets(STDIN))) {
if ($kelvin == 'q') {
echo 'quitting';
break;
}
if (is_numeric($kelvin)) {
$kelvin = floatVal($kelvin);
if ($kelvin >= 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... | #Oforth | Oforth | System.tick println
#[ #sqrt 1000000 seq map sum println ] bench |
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... | #Oz | Oz | {Show {OS.time}} %% posix time (seconds since 1970-01-01)
{Show {OS.gmTime}} %% current UTC as a record
{Show {OS.localTime}} %% current local time as record
%% Also interesting: undocumented module OsTime
%% When did posix time reach 1 billion?
{Show {OsTime.gmtime 1000000000}}
{Show {OsTime.localtime 100000... |
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]]
| #Excel | Excel | =LAMBDA(isUpper,
LAMBDA(matrix,
LET(
nCols, COLUMNS(matrix),
nRows, ROWS(matrix),
ixs, SEQUENCE(nRows, nCols, 0, 1),
x, MOD(ixs, nCols),
y, QUOTIENT(ixs, nRows),
IF(nCols=nRows,
LET(
p, LAMBDA(x, y,... |
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]]
| #F.23 | F# |
// Sum below leading diagnal. Nigel Galloway: July 21st., 2021
let _,n=[[ 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]]|>List.fold(fun(n,g) i->let i,_=i|>List.splitAt n in (n+1,g+(i|>List.sum)))(0,0) in printfn "%d" n
|
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... | #C.2B.2B | C++ | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
std::ostream &operator<<(std::ostream &os, std::vector<std::pair<int, int>> &v) {
for (auto &p : v) {
auto sum = p.first + p.second;
auto prod = p.first * p.second;
os << '[' << p.first << ", " << p.second << "] S=" ... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Scala | Scala | scala> val s1 = Set("John", "Serena", "Bob", "Mary", "Serena")
s1: scala.collection.immutable.Set[java.lang.String] = Set(John, Serena, Bob, Mary)
scala> val s2 = Set("Jim", "Mary", "John", "Jim", "Bob")
s2: scala.collection.immutable.Set[java.lang.String] = Set(Jim, Mary, John, Bob)
scala> (s1 diff s2) union (s2 d... |
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... | #PicoLisp | PicoLisp | (scl 2)
(de convertKelvin (Kelvin)
(for X
(quote
(K . prog)
(C (K) (- K 273.15))
(F (K) (- (*/ K 1.8 1.0) 459.67))
(R (K) (*/ K 1.8 1.0)) )
(tab (-3 8)
(car X)
(format ((cdr X) Kelvin) *Scl) ) ) ) |
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... | #PL.2FI | PL/I | *process source attributes xref;
/* PL/I **************************************************************
* 15.08.2013 Walter Pachl translated from NetRexx
* temperatures below 0K are considered invalid
*********************************************************************/
temperature: Proc Options(main);
Dcl sysin... |
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... | #PARI.2FGP | PARI/GP | system("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... | #Pascal | Pascal | type
timeStamp = packed record
dateValid: Boolean;
year: integer;
month: 1..12;
day: 1..31;
timeValid: Boolean;
hour: 0..23;
minute: 0..59;
second: 0..59;
end; |
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]]
| #Factor | Factor | USING: kernel math math.matrices prettyprint sequences ;
: sum-below-diagonal ( matrix -- sum )
dup square-matrix? [ "Matrix must be square." throw ] unless
0 swap [ head sum + ] each-index ;
{
{ 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-below-di... |
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]]
| #Go | Go | package main
import (
"fmt"
"log"
)
func main() {
m := [][]int{
{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 len(m) != len(m[0]) {
log.Fatal("Matrix must be square.")
}
sum := 0
for... |
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... | #C.23 | C# | using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
const int maxSum = 100;
var pairs = (
from X in 2.To(maxSum / 2 - 1)
from Y in (X + 1).To(maxSum - 2).TakeWhile(y => X + y <= maxSum)
select... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Scheme | Scheme |
(import (scheme base)
(scheme write))
;; -- given two sets represented as lists, return (A \ B)
(define (a-without-b a b)
(cond ((null? a)
'())
((member (car a) (cdr a)) ; drop head of a if it's a duplicate
(a-without-b (cdr a) b))
((member (car a) b) ; head of a is in b... |
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... | #Plain_English | Plain English | To run:
Start up.
Put 21 into a kelvin temperature.
Show the kelvin temperature in various temperature scales.
Wait for the escape key.
Shut down.
A temperature is a fraction.
A kelvin temperature is a temperature.
A celsius temperature is a temperature.
A rankine temperature is a temperature.
A fahrenheit temperatur... |
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... | #Perl | Perl | print scalar localtime, "\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... | #Phix | Phix | include timedate.e
?format_timedate(date(),"Dddd, Mmmm dth, YYYY, h:mm:ss pm")
atom t0 = time()
sleep(0.9)
?time()-t0
|
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]]
| #Haskell | Haskell | ----------------- UPPER OR LOWER TRIANGLE ----------------
matrixTriangle :: Bool -> [[a]] -> Either String [[a]]
matrixTriangle upper matrix
| upper = go drop id
| otherwise = go take pred
where
go f g
| isSquare matrix =
(Right . snd) $
foldr
(\xs (n, rows) -> (pred n, ... |
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... | #Common_Lisp | Common Lisp |
;;; Calculate all x's and their possible y's.
(defparameter *x-possibleys*
(loop for x from 2 to 49
collect (cons x (loop for y from (- 100 x) downto (1+ x)
collect y)))
"For every x there are certain y's, with respect to the rules of the puzzle")
(defun xys-operation (op x-possibleys)
"returns an ali... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const type: striSet is set of string;
enable_output(striSet);
const proc: main is func
local
const striSet: setA is {"John", "Bob" , "Mary", "Serena"};
const striSet: setB is {"Jim" , "Mary", "John", "Bob" };
begin
writeln(setA >< setB);
end func; |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Sidef | Sidef | var a = ["John", "Serena", "Bob", "Mary", "Serena"];
var b = ["Jim", "Mary", "John", "Jim", "Bob"];
a ^ b -> unique.dump.say; |
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... | #PowerShell | PowerShell | function temp($k){
try{
$c = $k - 273.15
$r = $k / 5 * 9
$f = $r - 459.67
} catch {
Write-host "Input error."
return
}
Write-host ""
Write-host " TEMP (Kelvin) : " $k
Write-host " TEMP (Celsius) : " $c
Write-host " TEMP (Fahrenheit): " ... |
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... | #Phixmonti | Phixmonti | def printList len for get print endfor enddef
time
"Actual time is " swap 1 get " hour, " rot 2 get " minutes, " rot 3 get nip " seconds, "
"and elapsed " msec " seconds of running time." 10 tolist printList |
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... | #PHP | PHP | echo 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]]
| #J | J | sum_below_diagonal =: [:+/@,[*>/~@i.@# |
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]]
| #JavaScript | JavaScript | (() => {
"use strict";
// -------- LOWER TRIANGLE OF A SQUARE MATRIX --------
// lowerTriangle :: [[a]] -> Either String [[a]]
const lowerTriangle = matrix =>
// Either a message, if the matrix is not square,
// or the lower triangle of the matrix.
isSquare(matrix) ? (
... |
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... | #D | D | void main() {
import std.stdio, std.algorithm, std.range, std.typecons;
const s1 = cartesianProduct(iota(1, 101), iota(1, 101))
.filter!(p => 1 < p[0] && p[0] < p[1] && p[0] + p[1] < 100)
.array;
alias P = const Tuple!(int, int);
enum add = (P p) => p[0] + p[1];
e... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Smalltalk | Smalltalk | |A B|
A := Set new.
B := Set new.
A addAll: #( 'John' 'Bob' 'Mary' 'Serena' ).
B addAll: #( 'Jim' 'Mary' 'John' 'Bob' ).
( (A - B) + (B - A) ) displayNl. |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #SQL.2FPostgreSQL | SQL/PostgreSQL | CREATE OR REPLACE FUNCTION arrxor(anyarray,anyarray) RETURNS anyarray AS $$
SELECT ARRAY(
(
SELECT r.elements
FROM (
(SELECT 1,unnest($1))
UNION ALL
(SELECT 2,unnest($2))
) AS r (arr, elements)
GROUP BY 1
HAVING M... |
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... | #Pure_Data | Pure Data | #N canvas 200 200 640 600 10;
#X floatatom 130 54 8 0 0 2 Kelvin chgk -;
#X obj 130 453 rnd2;
#X floatatom 130 493 8 0 0 1 K - -;
#X floatatom 251 54 8 0 0 2 Celsius chgc -;
#X obj 251 453 rnd2;
#X floatatom 251 493 8 0 0 1 °C - -;
#X floatatom 374 54 8 0 0 2 Fahrenheit chgf -;
#X obj 374 453 rnd2;
#X floatatom 374 493... |
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... | #PureBasic | PureBasic | Procedure.d Kelvin2Celsius(tK.d) : ProcedureReturn tK-273.15 : EndProcedure
Procedure.d Kelvin2Fahrenheit(tK.d) : ProcedureReturn tK*1.8-459.67 : EndProcedure
Procedure.d Kelvin2Rankine(tK.d) : ProcedureReturn tK*1.8 : EndProcedure
OpenConsole()
Repeat
Print("Temperatur Kelvin? ") : Kelvin.d = ValD... |
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... | #PicoLisp | PicoLisp | (stamp) |
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... | #Pike | Pike | write( ctime(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]]
| #jq | jq |
def add(s): reduce s as $x (null; . + $x);
# input: a square matrix
def sum_below_diagonal:
add( range(0;length) as $i | .[$i][:$i][] ) ;
|
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]]
| #Julia | Julia | using LinearAlgebra
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 ]
@show tril(A)
@show tril(A, -1)
@show sum(tril(A, -1)) # 69
|
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... | #Elixir | Elixir | defmodule Puzzle do
def sum_and_product do
s1 = for x <- 2..49, y <- x+1..99, x+y<100, do: {x,y}
s2 = Enum.filter(s1, fn p ->
Enum.all?(sumEq(s1,p), fn q -> length(mulEq(s1,q)) != 1 end)
end)
s3 = Enum.filter(s2, fn p -> only1?(mulEq(s1,p), s2) end)
Enum.filter(s3, fn p -> only1?(sumEq(s1,p)... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Swift | Swift | let setA : Set<String> = ["John", "Bob", "Mary", "Serena"]
let setB : Set<String> = ["Jim", "Mary", "John", "Bob"]
println(setA.exclusiveOr(setB)) // symmetric difference of A and B
println(setA.subtract(setB)) // elements in A that are not in B |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Tcl | Tcl | package require struct::set
set A {John Bob Mary Serena}
set B {Jim Mary John Bob}
set AnotB [struct::set difference $A $B]
set BnotA [struct::set difference $B $A]
set SymDiff [struct::set union $AnotB $BnotA]
puts "A\\B = $AnotB"
puts "B\\A = $BnotA"
puts "A\u2296B = $SymDiff"
# Of course, the library alr... |
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... | #Python | Python | >>> while True:
k = float(input('K ? '))
print("%g Kelvin = %g Celsius = %g Fahrenheit = %g Rankine degrees."
% (k, k - 273.15, k * 1.8 - 459.67, k * 1.8))
K ? 21.0
21 Kelvin = -252.15 Celsius = -421.87 Fahrenheit = 37.8 Rankine degrees.
K ? 222.2
222.2 Kelvin = -50.95 Celsius = -59.71 Fahrenheit ... |
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... | #PL.2FI | PL/I | put (datetime()); /* writes out the date and time */
/* The time is given to thousandths of a second, */
/* in the format hhmiss999 */
put (time()); /* gives the time in the format hhmiss999. */ |
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... | #PowerShell | PowerShell | Get-Date |
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]]
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | 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}};
Total[LowerTriangularize[m, -1], 2] |
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]]
| #MiniZinc | MiniZinc |
% Sum below leading diagnal. Nigel Galloway: July 22nd., 2021
array [1..5,1..5] of int: N=[|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|];
int: res=sum(n,g in 1..5 where n>g)(N[n,g]);
output([show(res)])
|
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... | #Factor | Factor | USING: combinators.short-circuit fry kernel literals math
math.ranges memoize prettyprint sequences sets tools.time ;
IN: rosetta-code.sum-and-product
CONSTANT: s1 $[
2 100 [a,b] dup cartesian-product concat
[ first2 { [ < ] [ + 100 < ] } 2&& ] filter
]
: quot-eq ( pair quot -- seq )
[ s1 ] 2dip tuck '[... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #TUSCRIPT | TUSCRIPT | $$ MODE TUSCRIPT
a="John'Bob'Mary'Serena"
b="Jim'Mary'John'Bob"
DICT names CREATE
SUBMACRO checknames
!var,val
PRINT val,": ",var
LOOP n=var
DICT names APPEND/QUIET n,num,cnt,val;" "
ENDLOOP
ENDSUBMACRO
CALL checknames (a,"a")
CALL checknames (b,"b")
DICT names UNLOAD names,num,cnt,val
LOOP n=names,v=val
... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #UNIX_Shell | UNIX Shell | uniq() {
u=("$@")
for ((i=0;i<${#u[@]};i++)); do
for ((j=i+1;j<=${#u[@]};j++)); do
[ "${u[$i]}" = "${u[$j]}" ] && unset u[$i]
done
done
u=("${u[@]}")
}
a=(John Serena Bob Mary Serena)
b=(Jim Mary John Jim Bob)
uniq "${a[@]}"
au=("${u[@]}")
uniq "${b[@]}"
bu=("${u[@]}")
ab=("${au[@]}")
for ((... |
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... | #Quackery | Quackery | [ $ "bigrat.qky" loadfile ] now!
[ 5 9 v* ] is r->k ( n/d --> n/d )
[ 1/v r->k 1/v ] is k->r ( n/d --> n/d )
[ 45967 100 v- ] is r->f ( n/d --> n/d )
[ -v r->f -v ] is f->r ( n/d --> n/d )
[ 5463 20 v- ] i... |
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... | #R | R | convert_Kelvin <- function(K){
if (!is.numeric(K))
stop("\n Input has to be numeric")
return(list(
Kelvin = K,
Celsius = K - 273.15,
Fahreneit = K * 1.8 - 459.67,
Rankine = K * 1.8
))
}
convert_Kelvin(21)
|
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... | #Prolog | Prolog | date_time(H). |
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... | #PureBasic | PureBasic | time=Date() ; Unix timestamp
time$=FormatDate("%mm.%dd.%yyyy %hh:%ii:%ss",time)
; following value is only reasonable accurate, on Windows it can differ by +/- 20 ms
ms_counter=ElapsedMilliseconds()
; could use API like QueryPerformanceCounter_() on Windows for more accurate values |
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]]
| #Nim | Nim | type SquareMatrix[T: SomeNumber; N: static Positive] = array[N, array[N, T]]
func sumBelowDiagonal[T, N](m: SquareMatrix[T, N]): T =
for i in 1..<N:
for j in 0..<i:
result += m[i][j]
const M = [[ 1, 3, 7, 8, 10],
[ 2, 4, 16, 14, 4],
[ 3, 1, 9, 18, 11],
[12, 14, 17... |
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]]
| #Perl | Perl | #!/usr/bin/perl
use strict;
use warnings;
use List::Util qw( sum );
my $matrix =
[[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]];
my $lowersum = sum map @{ $matrix->[$_] }[0 .. $_ - 1], 1 .. $#$matrix;
print "lower sum = $lowersum\n"; |
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... | #Go | Go | package main
import "fmt"
type pair struct{ x, y int }
func main() {
//const max = 100
// Use 1685 (the highest with a unique answer) instead
// of 100 just to make it work a little harder :).
const max = 1685
var all []pair
for a := 2; a < max; a++ {
for b := a + 1; b < max-a; b++ {
all = append(all, ... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Ursala | Ursala | a = <'John','Bob','Mary','Serena'>
b = <'Jim','Mary','John','Bob'>
#cast %sLm
main =
<
'a': a,
'b': b,
'a not b': ~&j/a b,
'b not a': ~&j/b a,
'symmetric difference': ~&jrljTs/a b> |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Wren | Wren | import "/set" for Set
var symmetricDifference = Fn.new { |a, b| a.except(b).union(b.except(a)) }
var a = Set.new(["John", "Bob", "Mary", "Serena"])
var b = Set.new(["Jim", "Mary", "John", "Bob"])
System.print("A = %(a)")
System.print("B = %(b)")
System.print("A - B = %(a.except(b))")
System.print("B - A = %... |
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... | #Racket | Racket | #lang racket
(define (converter temp init final)
(define to-k
(case init
('k temp)
('c (+ 273.15 temp))
('f (* (+ temp 459.67) 5/9))
('r (* temp 5/9))))
(case final
('k to-k)
('c (- to-k 273.15))
('f (- (* to-k 9/5) 459.67))
('r (* to-k 1.8))))
(define (kelvin-to-all te... |
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... | #Raku | Raku | my %scale =
Celcius => { factor => 1 , offset => -273.15 },
Rankine => { factor => 1.8, offset => 0 },
Fahrenheit => { factor => 1.8, offset => -459.67 },
;
my $kelvin = +prompt "Enter a temperature in Kelvin: ";
die "No such temperature!" if $kelvin < 0;
for %scale.sort {
printf "%12s:... |
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... | #Python | Python | import time
print time.ctime() |
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... | #Q | Q | q).z.D
2010.01.25
q).z.N
0D14:17:45.519682000
q).z.P
2010.01.25D14:17:46.962375000
q).z.T
14:17:47.817
q).z.Z
2010.01.25T14:17:48.711
q).z.z
2010.01.25T19:17:59.445 |
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]]
| #Phix | Phix | constant 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}}
atom res = 0
integer height = length(M)
for row=1 to height do
integer width = length(M[row])
if width!=height then crash("not squar... |
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... | #Haskell | Haskell | import Data.List (intersect)
s1, s2, s3, s4 :: [(Int, Int)]
s1 = [(x, y) | x <- [1 .. 100], y <- [1 .. 100], 1 < x && x < y && x + y < 100]
add, mul :: (Int, Int) -> Int
add (x, y) = x + y
mul (x, y) = x * y
sumEq, mulEq :: (Int, Int) -> [(Int, Int)]
sumEq p = filter (\q -> add q == add p) s1
mulEq p = filter (\q... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #XPL0 | XPL0 | def John, Bob, Mary, Serena, Jim; \enumerate set items (0..4)
proc SetOut(S); \Output the elements in set
int S;
int Name, I;
[Name:= ["John", "Bob", "Mary", "Serena", "Jim"];
for I:= 0 to 31 do
if S & 1<<I then
[Text(0, Name(I)); ChOut(0, ^ )];
CrLf(0);
];
int A, B;
[A:= 1<<John ! 1<<Bob ... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #Yabasic | Yabasic | lista1$ = "John Serena Bob Mary Serena"
lista2$ = "Jim Mary John Jim Bob"
lista1$ = quitadup$(lista1$)
lista2$ = quitadup$(lista2$)
res$ = quitacomun$(lista1$, lista2$)
res$ = res$ + quitacomun$(lista2$, lista1$)
print res$
sub quitadup$(l$)
l$ = l$ + " "
return quitarep$(l$)
end sub
sub quitacomun$(l1$, l2... |
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... | #REXX | REXX | /*REXX program converts temperatures for a number (8) of temperature scales. */
numeric digits 120 /*be able to support some huge numbers.*/
parse arg tList /*get the specified temperature list. */
do until tList='' ... |
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... | #Quackery | Quackery | time 1000000 / echo say " seconds since the Unix epoch." |
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... | #R | R | Sys.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]]
| #PL.2FI | PL/I |
trap: procedure options (main); /* 17 December 2021 */
declare n fixed binary;
get (n);
put ('The order of the matrix is ' || trim(n));
begin;
declare A (n,n) fixed binary;
declare sum fixed binary;
declare (i, j) fixed binary;
get (A);
sum = 0;
do i = 2 to 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]]
| #PL.2FM | PL/M | 100H: /* SUM THE ELEMENTS BELOW THE MAIN DIAGONAL OF A MATRIX */
/* CP/M BDOS SYSTEM CALL, IGNORE THE RETURN VALUE */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
... |
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... | #Java | Java | package org.rosettacode;
import java.util.ArrayList;
import java.util.List;
/**
* This program applies the logic in the Sum and Product Puzzle for the value
* provided by systematically applying each requirement to all number pairs in
* range. Note that the requirements: (x, y different), (x < y), and
* (x... |
http://rosettacode.org/wiki/Symmetric_difference | Symmetric difference | Task
Given two sets A and B, compute
(
A
∖
B
)
∪
(
B
∖
A
)
.
{\displaystyle (A\setminus B)\cup (B\setminus A).}
That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.
In other words:
(
A
∪
B
)
∖
(
A
∩
B
)
{\displaystyle (A\cup B)\setminus (A... | #zkl | zkl | fcn setCommon(list1,list2){ list1.filter(list2.holds); }
fcn sdiff(list1,list2)
{ list1.extend(list2).copy().removeEach(setCommon(list1,list2)) } |
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... | #Ring | Ring |
k = 21.0 c = 0 r = 0 f = 0
convertTemp(k)
see "Kelvin : " + k + nl +
"Celcius : " + c + nl +
"Rankine : " + r + nl +
"Fahrenheit : " + f + nl
func convertTemp k
c = k - 273.15
r = k * 1.8
f = r - 459.67
|
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... | #Racket | Racket | #lang racket
(require racket/date)
(date->string (current-date)) |
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.