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/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
PRINT "Hello world!"
|
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #Elisa | Elisa | component FormalPowerSeries(Number);
type PowerSeries;
PowerSeries(Size = integer) -> PowerSeries;
+ PowerSeries -> PowerSeries;
- PowerSeries -> PowerSeries;
PowerSeries + PowerSeries -> PowerSeries;
PowerSeries - PowerSeries -> PowerSeries;
PowerSeries * PowerSeries ... |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #AWK | AWK | BEGIN {
r=7.125
printf " %9.3f\n",-r
printf " %9.3f\n",r
printf " %-9.3f\n",r
printf " %09.3f\n",-r
printf " %09.3f\n",r
printf " %-09.3f\n",r
} |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #BaCon | BaCon | ' Formatted numeric output
n = 7.125
PRINT n FORMAT "%09.3f\n" |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #Action.21 | Action! | DEFINE Bit="BYTE"
TYPE FourBit=[Bit b0,b1,b2,b3]
Bit FUNC Not(Bit a)
RETURN (1-a)
Bit FUNC MyXor(Bit a,b)
RETURN ((Not(a) AND b) OR (a AND Not(b)))
Bit FUNC HalfAdder(Bit a,b Bit POINTER c)
c^=a AND b
RETURN (MyXor(a,b))
Bit FUNC FullAdder(Bit a,b,c0 Bit POINTER c)
Bit s1,c1,s2,c2
s1=HalfAdder(a,c0,@c... |
http://rosettacode.org/wiki/Four_is_the_number_of_letters_in_the_... | Four is the number of letters in the ... | The Four is ... sequence is based on the counting of the number of
letters in the words of the (never─ending) sentence:
Four is the number of letters in the first word of this sentence, two in the second,
three in the third, six in the fourth, two in the fifth, seven in the sixth, ···
Definitions and... | #REXX | REXX | /*REXX pgm finds/shows the number of letters in the Nth word in a constructed sentence*/
@= 'Four is the number of letters in the first word of this sentence,' /*···*/
/* [↑] the start of a long sentence. */
parse arg N M ... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Pop11 | Pop11 | lvars ress;
if sys_fork(false) ->> ress then
;;; parent
printf(ress, 'Child pid = %p\n');
else
printf('In child\n');
endif; |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Python | Python | import os
pid = os.fork()
if pid > 0:
# parent code
else:
# child code |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #Maxima | Maxima | f(a, b):= a*b; |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #MAXScript | MAXScript | fn multiply a b =
(
a * b
) |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Uniface | Uniface |
message "Hello world!"
|
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #Go | Go | package main
import (
"fmt"
"math"
)
// Task: Formal power series type
//
// Go does not have a concept of numeric types other than the built in
// integers, floating points, and so on. Nor does it have function or
// operator overloading, or operator defintion. The type use to implement
// fps here is a... |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #BBC_BASIC | BBC BASIC | PRINT FNformat(PI, 9, 3)
PRINT FNformat(-PI, 9, 3)
END
DEF FNformat(n, sl%, dp%)
LOCAL @%
@% = &1020000 OR dp% << 8
IF n >= 0 THEN
= RIGHT$(STRING$(sl%,"0") + STR$(n), sl%)
ENDIF
= "-" + RIGHT$(STRING$(sl%,"0") + STR$(-n), sl%-1) |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #bc | bc | /*
* Print number n, using at least c characters.
*
* Different from normal, this function:
* 1. Uses the current ibase (not the obase) to print the number.
* 2. Prunes "0" digits from the right, so p(1.500, 1) prints "1.5".
* 3. Pads "0" digits to the left, so p(-1.5, 6) prints "-001.5".
* 4. Never prints a... |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #Ada | Ada |
type Four_Bits is array (1..4) of Boolean;
procedure Half_Adder (Input_1, Input_2 : Boolean; Output, Carry : out Boolean) is
begin
Output := Input_1 xor Input_2;
Carry := Input_1 and Input_2;
end Half_Adder;
procedure Full_Adder (Input_1, Input_2 : Boolean; Output : out Boolean; Carry : in out Boolean) is
... |
http://rosettacode.org/wiki/Four_is_the_number_of_letters_in_the_... | Four is the number of letters in the ... | The Four is ... sequence is based on the counting of the number of
letters in the words of the (never─ending) sentence:
Four is the number of letters in the first word of this sentence, two in the second,
three in the third, six in the fourth, two in the fifth, seven in the sixth, ···
Definitions and... | #Rust | Rust | struct NumberNames {
cardinal: &'static str,
ordinal: &'static str,
}
impl NumberNames {
fn get_name(&self, ordinal: bool) -> &'static str {
if ordinal {
return self.ordinal;
}
self.cardinal
}
}
const SMALL_NAMES: [NumberNames; 20] = [
NumberNames {
ca... |
http://rosettacode.org/wiki/Four_is_the_number_of_letters_in_the_... | Four is the number of letters in the ... | The Four is ... sequence is based on the counting of the number of
letters in the words of the (never─ending) sentence:
Four is the number of letters in the first word of this sentence, two in the second,
three in the third, six in the fourth, two in the fifth, seven in the sixth, ···
Definitions and... | #Wren | Wren | import "/fmt" for Fmt
var names = {
1: "one",
2: "two",
3: "three",
4: "four",
5: "five",
6: "six",
7: "seven",
8: "eight",
9: "nine",
10: "ten",
11: "eleven",
12: "twelve",
13: "thirteen",
14: "fourteen",
15: "fifteen",
16: "sixteen",
17: "... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #R | R |
p <- parallel::mcparallel({
Sys.sleep(1)
cat("\tChild pid: ", Sys.getpid(), "\n")
TRUE
})
cat("Main pid: ", Sys.getpid(), "\n")
parallel::mccollect(p)
p <- parallel:::mcfork()
if (inherits(p, "masterProcess")) {
Sys.sleep(1)
cat("\tChild pid: ", Sys.getpid(), "\n")
pa... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Racket | Racket |
#lang racket
(define-values [P _out _in _err]
(subprocess (current-output-port) (current-input-port) (current-error-port)
(find-executable-path "du") "-hs" "/usr/share"))
;; wait for process to end, print messages as long as it runs
(let loop () (unless (sync/timeout 10 P) (printf "Still running...\n"... |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #Mercury | Mercury | % Module ceremony elided...
:- func multiply(integer, integer) = integer.
multiply(A, B) = A * B. |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #Metafont | Metafont | primarydef a mult b = a * b enddef; |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Unison | Unison |
main = '(printLine "Hello world!")
|
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #Haskell | Haskell | newtype Series a = S { coeffs :: [a] } deriving (Eq, Show)
-- Invariant: coeffs must be an infinite list
instance Num a => Num (Series a) where
fromInteger n = S $ fromInteger n : repeat 0
negate (S fs) = S $ map negate fs
S fs + S gs = S $ zipWith (+) fs gs
S (f:ft) * S gs@(g:gt) = S $ f*g : coeffs (S ft *... |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #Beads | Beads | beads 1 program 'Formatted numeric output'
calc main_init
var num = 7.125
log to_str(num, min:9, zero_pad:Y) |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #C | C | #include <stdio.h>
main(){
float r=7.125;
printf(" %9.3f\n",-r);
printf(" %9.3f\n",r);
printf(" %-9.3f\n",r);
printf(" %09.3f\n",-r);
printf(" %09.3f\n",r);
printf(" %-09.3f\n",r);
return 0;
} |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #AutoHotkey | AutoHotkey | A := 13
B := 9
N := FourBitAdd(A, B)
MsgBox, % A " + " B ":`n"
. GetBin4(A) " + " GetBin4(B) " = " N.S " (Carry = " N.C ")"
return
Xor(A, B) {
return (~A & B) | (A & ~B)
}
HalfAdd(A, B) {
return {"S": Xor(A, B), "C": A & B}
}
FullAdd(A, B, C=0) {
X := HalfAdd(A, C)
Y := HalfAdd(B, X.S)
return {"S": Y.S, "C"... |
http://rosettacode.org/wiki/Four_is_the_number_of_letters_in_the_... | Four is the number of letters in the ... | The Four is ... sequence is based on the counting of the number of
letters in the words of the (never─ending) sentence:
Four is the number of letters in the first word of this sentence, two in the second,
three in the third, six in the fourth, two in the fifth, seven in the sixth, ···
Definitions and... | #zkl | zkl | // Built the sentence in little chucks but only save the last one
// Save the word counts
fcn fourIsThe(text,numWords){
const rmc="-,";
seq:=(text - rmc).split().apply("len").copy(); // (4,2,3,6...)
szs:=Data(numWords + 100,Int).howza(0).extend(seq); // bytes
cnt,lastWords := seq.len(),"";
total:=... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Raku | Raku | use NativeCall;
sub fork() returns int32 is native { ... }
if fork() -> $pid {
print "I am the proud parent of $pid.\n";
}
else {
print "I am a child. Have you seen my mommy?\n";
} |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #REXX | REXX | child = fork() |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #min | min | '* :multiply |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #MiniScript | MiniScript | multiply = function(x,y)
return x*y
end function
print multiply(6, 7) |
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #11l | 11l | V dif = s -> enumerate(s[1..]).map2((i, x) -> x - @s[i])
F difn(s, n) -> [Int]
R I n != 0 {difn(dif(s), n - 1)} E s
V s = [90, 47, 58, 29, 22, 32, 55, 5, 55, 73]
L(i) 10
print(difn(s, i)) |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #UNIX_Shell | UNIX Shell | #!/bin/sh
echo "Hello world!" |
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #J | J | Ai=: (i.@] =/ i.@[ -/ i.@>:@-)&#
divide=: [ +/ .*~ [:%.&.x: ] +/ .* Ai
diff=: 1 }. ] * i.@#
intg=: 0 , ] % 1 + i.@#
mult=: +//.@(*/)
plus=: +/@,:
minus=: -/@,: |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #C.23 | C# |
class Program
{
static void Main(string[] args)
{
float myNumbers = 7.125F;
string strnumber = Convert.ToString(myNumbers);
Console.WriteLine(strnumber.PadLeft(9, '0'));
Console.ReadLine();
}
}
|
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #C.2B.2B | C++ | #include <iostream>
#include <iomanip>
int main()
{
std::cout << std::setfill('0') << std::setw(9) << std::fixed << std::setprecision(3) << 7.125 << std::endl;
return 0;
} |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #AutoIt | AutoIt |
Func _NOT($_A)
Return (Not $_A) *1
EndFunc ;==>_NOT
Func _AND($_A, $_B)
Return BitAND($_A, $_B)
EndFunc ;==>_AND
Func _OR($_A, $_B)
Return BitOR($_A, $_B)
EndFunc ;==>_OR
Func _XOR($_A, $_B)
Return _OR( _
_AND( $_A, _NOT($_B) ), _
_AND( _NOT($_A), $_B) )
EndFunc ;==>_XOR
Func _HalfAdder($_A, $_B, ... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Ruby | Ruby | pid = fork
if pid
# parent code
else
# child code
end |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Run_BASIC | Run BASIC | run "someProgram.bas",#handle
render #handle ' this runs the program until it waits
' both the parent and child are running
' --------------------------------------------------------
' You can also call a function in the someProgram.bas program.
' For example if it had a DisplayBanner Funciton.
#... |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #MiniZinc | MiniZinc | function var int:multiply(a: var int,b: var int) =
a*b;
|
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #.D0.9C.D0.9A-61.2F52 | МК-61/52 | ИП0 ИП1 * В/О
|
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #Ada | Ada | with Ada.Text_Io;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.containers.Vectors;
procedure Forward_Difference is
package Flt_Vect is new Ada.Containers.Vectors(Positive, Float);
use Flt_Vect;
procedure Print(Item : Vector) is
begin
if not Item.Is_Empty then
Ada.Text_IO.Put('[')... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Unlambda | Unlambda | `r```````````````.G.o.o.d.b.y.e.,. .W.o.r.l.d.!i |
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #Java | Java | 1/(1+.) |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #Clojure | Clojure | (cl-format true "~9,3,,,'0F" 7.125) |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #COBOL | COBOL | IDENTIFICATION DIVISION.
PROGRAM-ID. NUMERIC-OUTPUT-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-EXAMPLE.
05 X PIC 9(5)V9(3).
PROCEDURE DIVISION.
MOVE 7.125 TO X.
DISPLAY X UPON CONSOLE.
STOP RUN. |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #BASIC | BASIC | 100 S$ = "1100 + 1100 = " : GOSUB 400
110 S$ = "1100 + 1101 = " : GOSUB 400
120 S$ = "1100 + 1110 = " : GOSUB 400
130 S$ = "1100 + 1111 = " : GOSUB 400
140 S$ = "1101 + 0000 = " : GOSUB 400
150 S$ = "1101 + 0001 = " : GOSUB 400
160 S$ = "1101 + 0010 = " : GOSUB 400
170 S$ = "1101 + 0011 = " : GOSUB 400
180 END
400 A0... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Rust | Rust | use nix::unistd::{fork, ForkResult};
use std::process::id;
fn main() {
match fork() {
Ok(ForkResult::Parent { child, .. }) => {
println!(
"This is the original process(pid: {}). New child has pid: {}",
id(),
child
);
}
... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Scala | Scala | import java.io.IOException
object Fork extends App {
val builder: ProcessBuilder = new ProcessBuilder()
val currentUser: String = builder.environment.get("USER")
val command: java.util.List[String] = java.util.Arrays.asList("ps", "-f", "-U", currentUser)
builder.command(command)
try {
val lines = scala.... |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #Modula-2 | Modula-2 | PROCEDURE Multiply(a, b: INTEGER): INTEGER;
BEGIN
RETURN a * b
END Multiply; |
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #ALGOL_68 | ALGOL 68 | main:(
MODE LISTREAL = [1:0]REAL;
OP - = (LISTREAL a,b)LISTREAL: (
[UPB a]REAL out;
FOR i TO UPB out DO out[i]:=a[i]-b[i] OD;
out
);
FORMAT real fmt=$zzz-d.d$;
FORMAT repeat fmt = $n(UPB s-1)(f(real fmt)",")f(real fmt)$;
FORMAT list fmt = $"("f(UPB s=1|real fmt|repeat fmt)")"$;
FLEX [1:0... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Ursa | Ursa | out "hello world!" endl console |
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #jq | jq | 1/(1+.) |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #Common_Lisp | Common Lisp | (format t "~9,3,,,'0F" 7.125) |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #D | D | import std.stdio;
void main() {
immutable r = 7.125;
writefln(" %9.3f", -r);
writefln(" %9.3f", r);
writefln(" %-9.3f", r);
writefln(" %09.3f", -r);
writefln(" %09.3f", r);
writefln(" %-09.3f", r);
} |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #Batch_File | Batch File |
@echo off
setlocal enabledelayedexpansion
:: ":main" is where all the non-logic-gate stuff happens
:main
:: User input two 4-digit binary numbers
:: There is no error checking for these numbers, however if the first 4 digits of both inputs are in binary...
:: The program will use them. All non-binary numbers are tre... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Sidef | Sidef | var x = 42;
{ x += 1; say x }.fork.wait; # x is 43 here
say x; # but here is still 42 |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Slate | Slate | p@(Process traits) forkAndDo: b
[| ret |
(ret := lobby cloneSystem)
first ifTrue: [p pipes addLast: ret second. ret second]
ifFalse: [[p pipes clear. p pipes addLast: ret second. b applyWith: ret second] ensure: [lobby quit]]
]. |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #Modula-3 | Modula-3 | PROCEDURE Multiply(a, b: INTEGER): INTEGER =
BEGIN
RETURN a * b;
END Multiply; |
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #ALGOL_W | ALGOL W | begin
% calculate forward differences %
% sets elements of B to the first order forward differences of A %
% A should have bounds 1 :: n, B should have bounds 1 :: n - 1 %
procedure FirstOrderFDifference ( integer array A( * )
; in... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Ursala | Ursala | #show+
main = -[Hello world!]- |
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #Julia | Julia | module FormalPowerSeries
using Printf
import Base.iterate, Base.eltype, Base.one, Base.show, Base.IteratorSize
import Base.IteratorEltype, Base.length, Base.size, Base.convert
_div(a, b) = a / b
_div(a::Union{Integer,Rational}, b::Union{Integer,Rational}) = a // b
abstract type AbstractFPS{T<:Number} end
Base.I... |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #DBL | DBL | D5=7125
A10=D5,'-ZZZZX.XXX' ; 7.125
A10=... |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #dc | dc | [*
* (n) (c) lpx
* Print number n, using at least c characters.
*
* Different from normal, this function:
* 1. Uses the current ibase (not the obase) to print the number.
* 2. Prunes "0" digits from the right, so [1.500 1 lxp] prints "1.5".
* 3. Pads "0" digits to the left, so [_1.5 6 lxp] prints "-001.5".
*... |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #C | C | #include <stdio.h>
typedef char pin_t;
#define IN const pin_t *
#define OUT pin_t *
#define PIN(X) pin_t _##X; pin_t *X = & _##X;
#define V(X) (*(X))
/* a NOT that does not soil the rest of the host of the single bit */
#define NOT(X) (~(X)&1)
/* a shortcut to "implement" a XOR using only NOT, AND and OR gates, a... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Smalltalk | Smalltalk | 'Here I am' displayNl.
|a|
a := [
(Delay forSeconds: 2) wait .
1 to: 100 do: [ :i | i displayNl ]
] fork.
'Child will start after 2 seconds' displayNl.
"wait to avoid terminating first the parent;
a better way should use semaphores"
(Delay forSeconds: 10) wait. |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Standard_ML | Standard ML | case Posix.Process.fork () of
SOME pid => print "This is the original process\n"
| NONE => print "This is the new process\n"; |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #MUMPS | MUMPS | MULTIPLY(A,B);Returns the product of A and B
QUIT A*B |
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #APL | APL | list ← 90 47 58 29 22 32 55 5 55 73
fd ← {⍺=0:⍵⋄(⍺-1)∇(1↓⍵)-(¯1↓⍵)}
1 fd list
¯43 11 ¯29 ¯7 10 23 ¯50 50 18
2 fd list
54 ¯40 22 17 13 ¯73 100 ¯32 |
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #AppleScript | AppleScript | -- forwardDifference :: Num a => [a] -> [a]
on forwardDifference(xs)
zipWith(my subtract, xs, rest of xs)
end forwardDifference
-- nthForwardDifference :: Num a => Int -> [a] -> [a]
on nthForwardDifference(xs, i)
|index|(iterate(forwardDifference, xs), 1 + i)
end nthForwardDifference
-------------------... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #.E0.AE.89.E0.AE.AF.E0.AE.BF.E0.AE.B0.E0.AF.8D.2FUyir | உயிர்/Uyir | முதன்மை என்பதின் வகை எண் பணி {{
("உலகத்தோருக்கு வணக்கம்") என்பதை திரை.இடு;
முதன்மை = 0;
}}; |
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #Kotlin | Kotlin | // version 1.2.10
fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
class Frac : Comparable<Frac> {
val num: Long
val denom: Long
companion object {
val ZERO = Frac(0, 1)
val ONE = Frac(1, 1)
}
constructor(n: Long, d: Long) {
require(d != 0L)
... |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #Delphi | Delphi |
program FormattedNumericOutput;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
fVal = 7.125;
begin
Writeln(FormatFloat('0000#.000',fVal));
Writeln(FormatFloat('0000#.0000000',fVal));
Writeln(FormatFloat('##.0000000',fVal));
Writeln(FormatFloat('0',fVal));
Writeln(FormatFloat('#.#E-0',fVal));
Writeln(... |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #C.23 | C# |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RosettaCodeTasks.FourBitAdder
{
public struct BitAdderOutput
{
public bool S { get; set; }
public bool C { get; set; }
public override string ToString ( )
{
return "S" + ( S ? "1" : "0" ) + "C" + ( C ? "1" :... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Symsyn | Symsyn |
| parent
ssx 'R child'
wait 'childevent'
'child is running...' []
'child will end...' []
post 'dieevent'
delay 5000
|
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Tcl | Tcl | package require Expect
# or
package require Tclx
for {set i 0} {$i < 100} {incr i} {
set pid [fork]
switch $pid {
-1 {
puts "Fork attempt #$i failed."
}
0 {
puts "I am child process #$i."
exit
}
default {
puts "The parent ... |
http://rosettacode.org/wiki/Four_is_magic | Four is magic | Task
Write a subroutine, function, whatever it may be called in your language, that takes an integer number and returns an English text sequence starting with the English cardinal representation of that integer, the word 'is' and then the English cardinal representation of the count of characters that made up the firs... | #11l | 11l | V Small = [‘zero’, ‘one’, ‘two’, ‘three’, ‘four’,
‘five’, ‘six’, ‘seven’, ‘eight’, ‘nine’,
‘ten’, ‘eleven’, ‘twelve’, ‘thirteen’, ‘fourteen’,
‘fifteen’, ‘sixteen’, ‘seventeen’, ‘eighteen’, ‘nineteen’]
V Tens = [‘’, ‘’, ‘twenty’, ‘thirty’, ‘forty’, ‘fifty’, ‘sixty’, ‘seventy’, ‘eighty’... |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #Nanoquery | Nanoquery | def multiply(a, b)
return a * b
end |
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #Arturo | Arturo | ; element-wise subtraction of two blocks. e.g.
; vsub [1 2 3] [1 2 3] ; [0 0 0]
vsub: function [u v][
map couple u v 'pair -> pair\0 - pair\1
]
differences: function [block][
order: attr "order"
if order = null -> order: 1
loop 1..order 'n -> block: vsub block drop block 1
return block
]
print d... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #V | V | "Hello world!" puts |
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #Lua | Lua | powerseries = setmetatable({
__add = function(z1, z2) return powerseries(function(n) return z1.coeff(n) + z2.coeff(n) end) end,
__sub = function(z1, z2) return powerseries(function(n) return z1.coeff(n) - z2.coeff(n) end) end,
__mul = function(z1, z2) return powerseries(function(n)
local ret = 0
for i = 0, n do
... |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #Eiffel | Eiffel |
note
description : "{
2 Examples are given.
The first example uses the standard library's FORMAT_DOUBLE class.
The second example uses the AEL_PRINTF class from the freely available
Amalasoft Eiffel Library (AEL).
See additional comments in the code.
}"
class APPLICATION
inherit
AEL_PRINTF -- Optional, see be... |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #C.2B.2B | C++ |
(ns rosettacode.adder
(:use clojure.test))
(defn xor-gate [a b]
(or (and a (not b)) (and b (not a))))
(defn half-adder [a b]
"output: (S C)"
(cons (xor-gate a b) (list (and a b))))
(defn full-adder [a b c]
"output: (C S)"
(let [HA-ca (half-adder c a)
HA-ca->sb (half-adder (first HA-ca) b)]
... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Toka | Toka | needs shell
getpid is-data PID
[ fork getpid PID = [ ." Child PID: " . cr ] [ ." In child\n" ] ifTrueFalse ] invoke |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #UNIX_Shell | UNIX Shell | i=0
(while test $i -lt 10; do
sleep 1
echo "Child process"
i=`expr $i + 1`
done) &
while test $i -lt 5; do
sleep 2
echo "Parent process"
i=`expr $i + 1`
done |
http://rosettacode.org/wiki/Four_is_magic | Four is magic | Task
Write a subroutine, function, whatever it may be called in your language, that takes an integer number and returns an English text sequence starting with the English cardinal representation of that integer, the word 'is' and then the English cardinal representation of the count of characters that made up the firs... | #8086_Assembly | 8086 Assembly | puts: equ 9h ; MS-DOS syscall to print a string
cpu 8086
bits 16
org 100h
section .text
;;; Read number from the MS-DOS command line
;;; The task says numbers up to 999999 need to be
;;; supported, so we can't get away with using MUL.
mov cl,[80h] ; Is there an argument?
test cl,cl
jnz havearg
mo... |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #Neko | Neko | var multiply = function(a, b) {
a * b
}
$print(multiply(2, 3)) |
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #AutoHotkey | AutoHotkey | MsgBox % diff("2,3,4,3",1)
MsgBox % diff("2,3,4,3",2)
MsgBox % diff("2,3,4,3",3)
MsgBox % diff("2,3,4,3",4)
diff(list,ord) { ; high order forward differences of a list
Loop %ord% {
L =
Loop Parse, list, `, %A_Space%%A_Tab%
If (A_Index=1)
p := A_LoopField
Else
L... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Vala | Vala | void main(){
stdout.printf("Hello world!\n");
} |
http://rosettacode.org/wiki/Formal_power_series | Formal power series | A power series is an infinite sum of the form
a
0
+
a
1
⋅
x
+
a
2
⋅
x
2
+
a
3
⋅
x
3
+
⋯
{\displaystyle a_{0}+a_{1}\cdot x+a_{2}\cdot x^{2}+a_{3}\cdot x^{3}+\cdots }
The ai are called the coefficients of the series. Such sums can be added, multiplied etc., where the new coefficients of ... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | cos = Series[Cos[x], {x, 0, 10}];
sin = Series[Sin[x], {x, 0, 8}];
sin - Integrate[cos, x] |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #Elixir | Elixir | n = 7.125
:io.fwrite "~f~n", [n]
:io.fwrite "~.3f~n", [n]
:io.fwrite "~9f~n", [n]
:io.fwrite "~9.3f~n", [n]
:io.fwrite "~9..0f~n", [n]
:io.fwrite "~9.3.0f~n", [n]
:io.fwrite "~9.3._f~n", [n]
:io.fwrite "~f~n", [-n]
:io.fwrite "~9.3f~n", [-n]
:io.fwrite "~9.3.0f~n", [-n]
:io.fwrite "~e~n", [n]
:io.fwrite "~12.4e~n", [n]... |
http://rosettacode.org/wiki/Formatted_numeric_output | Formatted numeric output | Task
Express a number in decimal as a fixed-length string with leading zeros.
For example, the number 7.125 could be expressed as 00007.125.
| #Emacs_Lisp | Emacs Lisp | (format "%09.3f" 7.125) ;=> "00007.125" |
http://rosettacode.org/wiki/Four_bit_adder | Four bit adder | Task
"Simulate" a four-bit adder.
This design can be realized using four 1-bit full adders.
Each of these 1-bit full adders can be built with two half adders and an or gate. ;
Finally a half adder can be made using an xor gate and an and gate.
The xor gate can be made using two nots, two ands ... | #Clojure | Clojure |
(ns rosettacode.adder
(:use clojure.test))
(defn xor-gate [a b]
(or (and a (not b)) (and b (not a))))
(defn half-adder [a b]
"output: (S C)"
(cons (xor-gate a b) (list (and a b))))
(defn full-adder [a b c]
"output: (C S)"
(let [HA-ca (half-adder c a)
HA-ca->sb (half-adder (first HA-ca) b)]
... |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #UnixPipes | UnixPipes | (echo "Process 1" >&2 ;sleep 5; echo "1 done" ) | (echo "Process 2";cat;echo "2 done") |
http://rosettacode.org/wiki/Fork | Fork | Task
Spawn a new process which can run simultaneously with, and independently of, the original parent process.
| #Visual_Basic_.NET | Visual Basic .NET | Module Module1
Sub Fork()
Console.WriteLine("Spawned Thread")
End Sub
Sub Main()
Dim t As New System.Threading.Thread(New Threading.ThreadStart(AddressOf Fork))
t.Start()
Console.WriteLine("Main Thread")
t.Join()
End Sub
End Module |
http://rosettacode.org/wiki/Four_is_magic | Four is magic | Task
Write a subroutine, function, whatever it may be called in your language, that takes an integer number and returns an English text sequence starting with the English cardinal representation of that integer, the word 'is' and then the English cardinal representation of the count of characters that made up the firs... | #APL | APL | magic←{
t20←'one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine'
t20←t20,'ten' 'eleven' 'twelve' 'thirteen' 'fourteen' 'fifteen' 'sixteen'
t20←t20,'seventeen' 'eighteen' 'nineteen'
tens←'twenty' 'thirty' 'forty' 'fifty' 'sixty' 'seventy' 'eighty' 'ninety'
spell←{
⍵=0:'zero'
... |
http://rosettacode.org/wiki/Four_is_magic | Four is magic | Task
Write a subroutine, function, whatever it may be called in your language, that takes an integer number and returns an English text sequence starting with the English cardinal representation of that integer, the word 'is' and then the English cardinal representation of the count of characters that made up the firs... | #AppleScript | AppleScript | (* Uses a Foundation number formatter for brevity. *)
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
on getNumberFormatter(localeID, numberStyle)
set formatter to current application's class "NSNumberFormatter"'s new()
tell formatter to setLocale:(current applicatio... |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #Nemerle | Nemerle | public Multiply (a : int, b : int) : int // this is either a class or module method
{
def multiply(a, b) { return a * b } // this is a local function, can take advantage of type inference
return multiply(a, b)
} |
http://rosettacode.org/wiki/Function_definition | Function definition | A function is a body of code that returns a value.
The value returned may depend on arguments provided to the function.
Task
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are ... | #NESL | NESL | function multiply(x, y) = x * y; |
http://rosettacode.org/wiki/Forward_difference | Forward difference | Task
Provide code that produces a list of numbers which is the nth order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
The first-order forward difference of a list of numbers A is a new list B, where Bn = An+1 - An.
List B should have one fewer elem... | #AWK | AWK | #!/usr/bin/awk -f
BEGIN {
if (p<1) {p = 1};
}
function diff(s, p) {
n = split(s, a, " ");
for (j = 1; j <= p; j++) {
for(i = 1; i <= n-j; i++) {
a[i] = a[i+1] - a[i];
}
}
s = "";
for (i = 1; i <= n-p; i++) s = s" "a[i];
return s;
}
{
print diff($0, p);
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.