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/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Perl
Perl
use POSIX; # for floor() and ceil()   exp(1); # e 4 * atan2(1, 1); # pi sqrt($x); # square root log($x); # natural logarithm; log10() available in POSIX module exp($x); # exponential abs($x); # absolute value floor($x); # floor ceil($x); # ceiling $x ** $y; # power   use Math::Trig; pi; # alternate way to get pi   use ...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#R
R
fname <- "notes.txt" contents <- readChar(fname, file.info(fname)$size)
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Racket
Racket
(file->string "foo.txt")
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#F.23
F#
  // Reverse a string. Nigel Galloway: August 14th., 2019 let strRev α=let N=System.Globalization.StringInfo.GetTextElementEnumerator(α) List.unfold(fun n->if n then Some(N.GetTextElement(),N.MoveNext()) else None)(N.MoveNext())|>List.rev|>String.concat ""  
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Zsh
Zsh
function printroman () { local -a conv local number=$1 div rom num out conv=(I 1 IV 4 V 5 IX 9 X 10 XL 40 L 50 XC 90 C 100 CD 400 D 500 CM 900 M 1000) for num rom in ${(Oa)conv}; do (( div = number / num, number = number % num )) while (( div-- > 0 )); do out+=$rom done done echo $out }
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Objective-C
Objective-C
@interface NSString (RosettaCodeAddition) - (NSString *) repeatStringByNumberOfTimes: (NSUInteger) times; @end   @implementation NSString (RosettaCodeAddition) - (NSString *) repeatStringByNumberOfTimes: (NSUInteger) times { return [@"" stringByPaddingToLength:[self length]*times withString:self startingAtIndex:0];...
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
DeleteDuplicates[{0, 2, 1, 4, 2, 0, 3, 1, 1, 1, 0, 3}]
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#Seed7
Seed7
const type: matrix is array array float;   const proc: toReducedRowEchelonForm (inout matrix: mat) is func local var integer: numRows is 0; var integer: numColumns is 0; var integer: row is 0; var integer: column is 0; var integer: pivot is 0; var float: factor is 0.0; begin numRows := l...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Phix
Phix
?E -- Euler number ?PI -- pi ?log(E) -- natural logarithm ?log10(10) -- base 10 logarithm ?exp(log(5)) -- exponential ?sqrt(5) -- square root ?abs(-1.2) -- absolute value ?floor(-1.2) -- floor, -2 ?ceil(-1.2) -- ceiling, ...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Raku
Raku
my $string = slurp 'sample.txt';
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Raven
Raven
'myfile.txt' read as $content_as_string
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#Factor
Factor
"hello" reverse
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#OCaml
OCaml
let string_repeat s n = let s = Bytes.of_string s in let len = Bytes.length s in let res = Bytes.create (n * len) in for i = 0 to pred n do Bytes.blit s 0 res (i * len) len done; (Bytes.to_string res) ;;
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#MATLAB
MATLAB
>> unique([1 2 6 3 6 4 5 6])   ans =   1 2 3 4 5 6
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#Sidef
Sidef
func rref (M) { var (j, rows, cols) = (0, M.len, M[0].len)   for r in (^rows) { j < cols || return M   var i = r while (!M[i][j]) { ++i == rows || next i = r ++j == cols && return M }   M[i, r] = M[r, i] if (r != i) M[r] = (M[r]...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#PHP
PHP
M_E; //e M_PI; //pi sqrt(x); //square root log(x); //natural logarithm--log base 10 also available (log10) exp(x); //exponential abs(x); //absolute value floor(x); //floor ceil(x); //ceiling pow(x,y); //power
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#REALbasic
REALbasic
  Function readFile(theFile As FolderItem, txtEncode As TextEncoding = Nil) As String Dim fileContents As String Dim tis As TextInputStream tis = tis.Open(theFile) fileContents = tis.ReadAll(txtEncode) tis.Close Return fileContents   Exception err As NilObjectException MsgBox("File Not Found.") End Functi...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#REBOL
REBOL
read %my-file ; read as text read/binary %my-file ; preserve contents exactly
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#FALSE
FALSE
1_ [^$1_=~][]#% [$1_=~][,]#
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Oforth
Oforth
StringBuffer new "abcd" <<n(5)
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Maxima
Maxima
unique([8, 9, 5, 2, 0, 7, 0, 0, 4, 2, 7, 3, 9, 6, 6, 2, 4, 7, 9, 8, 3, 8, 0, 3, 7, 0, 2, 7, 6, 0]); [0, 2, 3, 4, 5, 6, 7, 8, 9]
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#Swift
Swift
  var lead = 0 for r in 0..<rows { if (cols <= lead) { break } var i = r while (m[i][lead] == 0) { i += 1 if (i == rows) { i = r lead += 1 if (cols == lead) { ...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Picat
Picat
main => println(math.e), println(math.pi), nl,   println(sqrt(2)), nl,   println(log(10)),  % base e println(log(math.pi,10)),  % some base, here pi println(log2(10)),  % base 2 println(exp(2.302585092994046)), nl,   println(abs(- math.e)), nl, println(floor(sq...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Retro
Retro
  here 'input.txt file:slurp
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#REXX
REXX
/*REXX program reads an entire file line-by-line and stores it as a continuous string.*/ parse arg iFID . /*obtain optional argument from the CL.*/ if iFID=='' then iFID= 'a_file' /*Not specified? Then use the default.*/ $= ...
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#Fancy
Fancy
"hello world!" reverse
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#OpenEdge.2FProgress
OpenEdge/Progress
MESSAGE FILL( "ha", 5 ) VIEW-AS ALERT-BOX.
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#MAXScript
MAXScript
uniques = #(1, 2, 3, "a", "b", "c", 2, 3, 4, "b", "c", "d") for i in uniques.count to 1 by -1 do ( id = findItem uniques uniques[i] if (id != i) do deleteItem uniques i )
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#Tcl
Tcl
package require Tcl 8.5 namespace path {::tcl::mathop ::tcl::mathfunc}   proc toRREF {m} { set lead 0 lassign [size $m] rows cols for {set r 0} {$r < $rows} {incr r} { if {$cols <= $lead} { break } set i $r while {[lindex $m $i $lead] == 0} { incr i ...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#PicoLisp
PicoLisp
(scl 12) # 12 places after decimal point (load "@lib/math.l")   (prinl (format (exp 1.0) *Scl)) # e, exp (prinl (format pi *Scl)) # pi   (prinl (format (pow 2.0 0.5) *Scl)) # sqare root (prinl (format (sqrt 2.0 1.0) *Scl))   (prinl (format (log 2.0) *Scl)) # logarithm (prinl (format (exp...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Ring
Ring
  # Read the file cStr = read("myfile.txt") # print the file content See cStr  
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Ruby
Ruby
# Read entire text file. str = IO.read "foobar.txt"   # It can also read a subprocess. str = IO.read "| grep ftp /etc/services"
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#FBSL
FBSL
FUNCTION StrRev1(BYVAL $p1) DIM $b = "" REPEAT LEN(p1) b = b & RIGHT(p1,1) p1 = LEFT(p1,LEN(p1)-1) END REPEAT RETURN b END FUNCTION  
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#OxygenBasic
OxygenBasic
    'REPEATING A CHARACTER   print string 10,"A" 'result AAAAAAAAAA   'REPEATING A STRING   function RepeatString(string s,sys n) as string sys i, le=len s if le=0 then exit function n*=le function=nuls n ' for i=1 to n step le mid function,i,s next end function   print RepeatString "ABC",3 'result AB...
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Microsoft_Small_Basic
Microsoft Small Basic
  ' Set the data. dataArray[1] = 1 dataArray[2] = 2 dataArray[3] = 2 dataArray[4] = 3 dataArray[5] = 4 dataArray[6] = 5 dataArray[7] = 5   resultArray[1] = dataArray[1] lastResultIndex = 1 position = 1 While position < Array.GetItemCount(dataArray) position = position + 1 isNewNumber = 1 ' logical 1 resultIndex =...
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#TI-83_BASIC
TI-83 BASIC
rref([[1,2,-1,-4][2,3,-1,-11][-2,0,-3,22]])
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#PL.2FI
PL/I
/* e not available other than by using exp(1q0).*/ /* pi not available other than by using a trig function such as: pi=4*atan(1) */ y = sqrt(x); y = log(x); y = log2(x); y = log10(x); y = exp(x); y = abs(x); y = floor(x); y = ceil(x); a = x**y; /* power */ /* extra functions: */ y = erf(x); /* the error functi...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Run_BASIC
Run BASIC
open DefaultDir$ + "/public/test.txt" for binary as #f fileLen = LOF(#f) a$ = input$(#f, fileLen) print a$ close #f
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Rust
Rust
use std::fs::File; use std::io::Read;   fn main() { let mut file = File::open("somefile.txt").unwrap();   let mut contents: Vec<u8> = Vec::new(); // Returns amount of bytes read and append the result to the buffer let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", resul...
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#Forth
Forth
: exchange ( a1 a2 -- ) 2dup c@ swap c@ rot c! swap c! ; : reverse ( c-addr u -- ) 1- bounds begin 2dup > while 2dup exchange -1 /string repeat 2drop ;   s" testing" 2dup reverse type \ gnitset
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Oz
Oz
declare fun {Repeat Xs N} if N > 0 then {Append Xs {Repeat Xs N-1}} else nil end end in {System.showInfo {Repeat "Ha" 5}}
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#PARI.2FGP
PARI/GP
repeat(s,n)={ if(n, Str(repeat(s, n-1), s), "") };
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#MiniScript
MiniScript
items = [1, 2, 3, "a", "b", "c", 2, 3, 4, "b", "c", "d"] d = {} for i in items d.push i end for print d.indexes
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#ML
ML
fun mem (x, []) = false | (x eql a, a :: as) = true | (x, _ :: as) = mem (x, as) ; fun remdup ([], uniq) = rev uniq | (h :: t, uniq) = if mem(h, uniq) then remdup (t, uniq) else remdup (t, h :: uniq) | L = remdup (L, [])   ; println ` implode ` remdup ` explode "the quick brown fox jumped...
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#TI-89_BASIC
TI-89 BASIC
rref([1,2,–1,–4; 2,3,–1,–11; –2,0,–3,22])
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Pop11
Pop11
pi  ;;; Number Pi sqrt(x)  ;;; Square root log(x)  ;;; Natural logarithm exp(x)  ;;; Exponential function abs(x)  ;;; Absolute value x ** y  ;;; x to the power y
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#PowerShell
PowerShell
Write-Host ([Math]::E) Write-Host ([Math]::Pi) Write-Host ([Math]::Sqrt(2)) Write-Host ([Math]::Log(2)) Write-Host ([Math]::Exp(2)) Write-Host ([Math]::Abs(-2)) Write-Host ([Math]::Floor(3.14)) Write-Host ([Math]::Ceiling(3.14)) Write-Host ([Math]::Pow(2, 3))
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Scala
Scala
object TextFileSlurper extends App { val fileLines = try scala.io.Source.fromFile("my_file.txt", "UTF-8").mkString catch { case e: java.io.FileNotFoundException => e.getLocalizedMessage() } }
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Scheme
Scheme
(with-input-from-file "foo.txt" (lambda () (reverse-list->string (let loop ((char (read-char)) (result '())) (if (eof-object? char) result (loop (read-char) (cons char result)))))))
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#Fortran
Fortran
PROGRAM Example   CHARACTER(80) :: str = "This is a string" CHARACTER :: temp INTEGER :: i, length   WRITE (*,*) str length = LEN_TRIM(str) ! Ignores trailing blanks. Use LEN(str) to reverse those as well DO i = 1, length/2 temp = str(i:i) str(i:i) = str(length+1-i:length+1-i) str(length+1-i:...
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Pascal
Pascal
"ha" x 5
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Perl
Perl
"ha" x 5
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Modula-2
Modula-2
  MODULE RemoveDuplicates;   FROM STextIO IMPORT WriteLn; FROM SWholeIO IMPORT WriteInt;   TYPE TArrayRange = [1 .. 7]; TArray = ARRAY TArrayRange OF INTEGER;   VAR DataArray, ResultArray: TArray; ResultIndex, LastResultIndex, Position: CARDINAL; IsNewNumber: BOOLEAN;   BEGIN (* Set the data. *); Data...
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#Ursala
Ursala
#import std #import flo   pivot = -<x fleq+ abs~~bh descending = ~&a^&+ ^|ahPathS2fattS2RpC/~& reflect = ~&lxPrTSx+ *iiD ~&l-~brS+ zipp0 row_reduce = ^C/vid*hhiD *htD minus^*p/~&r times^*D/vid@bh ~&l rref = reflect+ (descending row_reduce)+ reflect+ descending row_reduce+ pivot   #show+   test =   printf...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#PureBasic
PureBasic
Debug #E Debug #PI Debug Sqr(f) Debug Log(f) Debug Exp(f) Debug Log10(f) Debug Abs(f) Debug Pow(f,f)
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Python
Python
import math   math.e # e math.pi # pi math.sqrt(x) # square root (Also commonly seen as x ** 0.5 to obviate importing the math module) math.log(x) # natural logarithm math.log10(x) # base 10 logarithm math.exp(x) # e raised to the power of x abs(x) # absolute value math.floor(x) ...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "getf.s7i";   const proc: main is func local var string: fileContent is ""; begin fileContent := getf("text.txt"); end func;
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#SenseTalk
SenseTalk
Put file "~/Documents/myFile.txt" into TestFile put testFile
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Function ReverseString(s As Const String) As String If s = "" Then Return s Dim length As Integer = Len(s) Dim r As String = Space(length) For i As Integer = 0 To length - 1 r[i] = s[length - 1 - i] Next Return r End Function   Dim s As String = "asdf" Print "'"; s; "' reversed is '...
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Phix
Phix
?repeat('*',5) ?join(repeat("ha",5),"")
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Phixmonti
Phixmonti
def rep /# s n -- s #/ "" swap for drop over chain endfor nip enddef   "ha" 5 rep print
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#MUMPS
MUMPS
REMDUPE(L,S)  ;L is the input listing  ;S is the separator between entries  ;R is the list to be returned NEW Z,I,R FOR I=1:1:$LENGTH(L,S) SET Z($PIECE(L,S,I))=""  ;Repack for return SET I="",R="" FOR SET I=$O(Z(I)) QUIT:I="" SET R=$SELECT($L(R)=0:I,1:R_S_I) KILL Z,I QUIT R
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Nanoquery
Nanoquery
items = {1, 2, 3, "a", "b", "c", 2, 3, 4, "b", "c", "d"} unique = {}   for item in items if not item in unique unique.append(item) end end
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#VBA
VBA
Private Function ToReducedRowEchelonForm(M As Variant) As Variant Dim lead As Integer: lead = 0 Dim rowCount As Integer: rowCount = UBound(M) Dim columnCount As Integer: columnCount = UBound(M(0)) Dim i As Integer For r = 0 To rowCount If lead >= columnCount Then Exit For ...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#R
R
exp(1) # e pi # pi sqrt(x) # square root log(x) # natural logarithm log10(x) # base 10 logarithm log(x, y) # arbitrary base logarithm exp(x) # exponential abs(x) # absolute value floor(x) # floor ceiling(x) #...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Racket
Racket
(exp 1)  ; e pi  ; pi (sqrt x)  ; square root (log x)  ; natural logarithm (exp x)  ; exponential (abs x)  ; absolute value (floor x)  ; floor (ceiling x)  ; ceiling (expt x y)  ; power
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Sidef
Sidef
var file = File.new(__FILE__); var content = file.open_r.slurp; print content;
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Smalltalk
Smalltalk
(StandardFileStream oldFileNamed: 'foo.txt') contents
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#Frink
Frink
println[reverse["abcdef"]]
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#PHP
PHP
str_repeat("ha", 5)
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#PicoLisp
PicoLisp
(pack (need 5 "ha")) -> "hahahahaha"
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Neko
Neko
/** Remove duplicate elements, in Neko */   var original = $array(1, 2, 1, 4, 5, 2, 15, 1, 3, 4)   /* Create a table with only unique elements from the array */ var dedup = function(a) { var size = $asize(a) var hash = $hnew(size) while size > 0 { var v = a[size - 1] var k = $hkey(v) ...
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#Visual_FoxPro
Visual FoxPro
  CLOSE DATABASES ALL LOCAL lnRows As Integer, lnCols As Integer, lcSafety As String LOCAL ARRAY matrix[1] lcSafety = SET("Safety") SET SAFETY OFF CLEAR CREATE CURSOR results (c1 B(6), c2 B(6), c3 B(6), c4 B(6)) CREATE CURSOR curs1(c1 I, c2 I, c3 I, c4 I) INSERT INTO curs1 VALUES (1,2,-1,-4) INSERT INTO curs1 VALUES (2...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Raku
Raku
say e; # e say π; # or pi # pi say τ; # or tau # tau   # Common mathmatical function are availble # as subroutines and as numeric methods. # It is a matter of personal taste and # programming style as to which is used. say sqrt 2; # Square root say 2.sqrt; # Square root   # If you omit a bas...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#SNOBOL4
SNOBOL4
input(.inbin,21,"filename.txt [-r524288]")  :f(end) rdlp buf = inbin  :s(rdlp) * * now process the 'buf' containing the file * end
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Sparkling
Sparkling
let contents = readfile("foo.txt");
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#SPL
SPL
text = #.readtext("filename.txt")
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#Futhark
Futhark
  fun main(s: []i32) = s[::-1]  
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Pike
Pike
"ha"*5;
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#PL.2FI
PL/I
  /* To repeat a string a variable number of times: */   s = repeat('ha', 4);   /* or */   s = copy('ha', 5);   /* To repeat a single character a fixed number of times: */   s = (5)'h'; /* asigns 'hhhhh' to s. */  
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Nemerle
Nemerle
using System.Console;   module RemDups { Main() : void { def nums = array[1, 4, 6, 3, 6, 2, 7, 2, 5, 2, 6, 8]; def unique = $[n | n in nums].RemoveDuplicates(); WriteLine(unique); } }
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#Wren
Wren
import "/matrix" for Matrix import "/fmt" for Fmt   var m = Matrix.new([ [ 1, 2, -1, -4], [ 2, 3, -1, -11], [-2, 0, -3, 22] ])   System.print("Original:\n") Fmt.mprint(m, 3, 0) System.print("\nRREF:\n") m.toReducedRowEchelonForm Fmt.mprint(m, 3, 0)
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#REXX
REXX
a=abs(y) /*takes the absolute value of y.*/
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Ring
Ring
  See "Mathematical Functions" + nl See "Sin(0) = " + sin(0) + nl See "Sin(90) radians = " + sin(90) + nl See "Sin(90) degree = " + sin(90*3.14/180) + nl   See "Cos(0) = " + cos(0) + nl See "Cos(90) radians = " + cos(90) + nl See "Cos(90) degree = " + cos(90*3.14/180) + nl   See "Tan(0) = " + tan(0) + nl See "Tan(90) r...
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Standard_ML
Standard ML
fun readFile path = (fn strm => TextIO.inputAll strm before TextIO.closeIn strm) (TextIO.openIn path)
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Stata
Stata
mata f = fopen("somedata.txt", "r") fseek(f, 0, 1) n = ftell(f) fseek(f, 0, -1) s = fread(f, n) fclose(f) end
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Swift
Swift
import Foundation   let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) // print contents of file }
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#FutureBasic
FutureBasic
void local fn DoIt CFStringRef s1 = @"asdf", s2 = @"" long index for index = len(s1) - 1 to 0 step -1 s2 = fn StringByAppendingString( s2, mid(s1,index,1) ) next print s1,s2 end fn   window 1   fn DoIt   HandleEvents
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Plain_English
Plain English
To run: Start up. Put "ha" into a string. Append the string to itself given 5. Write the string on the console. Fill another string with the asterisk byte given 5. Write the other string on the console. Wait for the escape key. Shut down.   To append a string to itself given a number: If the number is less than 1, exit...
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   -- Note: Task requirement is to process "arrays". The following converts arrays into simple lists of words: -- Putting the resulting list back into an array is left as an exercise for the reader. a1 = [2, 3, 5, 7, 11, 13, 17, 19, 'cat...
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#Yabasic
Yabasic
// Rosetta Code problem: https://rosettacode.org/wiki/Reduced_row_echelon_form // by Jjuanhdez, 06/2022   dim matrix (3, 4) matrix(1, 1) = 1 : matrix(1, 2) = 2 : matrix(1, 3) = -1 : matrix(1, 4) = -4 matrix(2, 1) = 2 : matrix(2, 2) = 3 : matrix(2, 3) = -1 : matrix(2, 4) = -11 matrix(3, 1) = -2 : matrix(3, 2) = 0 : ma...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#RLaB
RLaB
>> const e euler ln10 ln2 lnpi log10e log2e pi pihalf piquarter rpi sqrt2 sqrt2r sqrt3 sqrtpi tworpi
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Ruby
Ruby
x.abs #absolute value x.magnitude #absolute value x.floor #floor x.ceil #ceiling x ** y #power include Math E #e PI #pi sqrt(x) #square root log(x) #natural logarithm log(x, y) #logarithm base y log10(x) #base 10 logarithm exp(x) #exponential  
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#Tcl
Tcl
set f [open $filename] set data [read $f] close $f
http://rosettacode.org/wiki/Read_entire_file
Read entire file
Task Load the entire contents of some text file as a single string variable. If applicable, discuss: encoding selection, the possibility of memory-mapping. Of course, in practice one should avoid reading an entire file at once if the file is large and the task can be accomplished incrementally instead (in which case...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT ERROR/STOP OPEN ("rosetta.txt",READ,-std-) var=FILE ("rosetta.txt")  
http://rosettacode.org/wiki/Reverse_a_string
Reverse a string
Task Take a string and reverse it. For example, "asdf" becomes "fdsa". Extra credit Preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa". Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting ...
#Gambas
Gambas
Public Sub Main() Dim sString As String = "asdf" Dim sOutput As String Dim siCount As Short   For siCount = Len(sString) DownTo 1 sOutput &= Mid(sString, siCount, 1) Next   Print sOutput   End
http://rosettacode.org/wiki/Repeat_a_string
Repeat a string
Take a string and repeat it some number of times. Example: repeat("ha", 5)   =>   "hahahahaha" If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****"). Other tasks re...
#Plorth
Plorth
"ha" 5 *
http://rosettacode.org/wiki/Remove_duplicate_elements
Remove duplicate elements
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#NewLISP
NewLISP
(unique '(1 2 3 a b c 2 3 4 b c d))
http://rosettacode.org/wiki/Reduced_row_echelon_form
Reduced row echelon form
Reduced row echelon form You are encouraged to solve this task according to the task description, using any language you may know. Task Show how to compute the reduced row echelon form (a.k.a. row canonical form) of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this wil...
#zkl
zkl
var [const] GSL=Import("zklGSL"); // libGSL (GNU Scientific Library) fcn toReducedRowEchelonForm(M){ // in place lead,rows,columns := 0,M.rows,M.cols; foreach r in (rows){ if (columns<=lead) return(M); i:=r; while(M[i,lead]==0){ // not a great check to use with real numbers i+=1; if(i==row...
http://rosettacode.org/wiki/Real_constants_and_functions
Real constants and functions
Task Show how to use the following math constants and functions in your language   (if not available, note it):   e   (base of the natural logarithm)   π {\displaystyle \pi }   square root   logarithm   (any base allowed)   exponential   (ex )   absolute value   (a.k.a. "magnitude")   floor   (largest ...
#Run_BASIC
Run BASIC
print "exp:";chr$(9); EXP(1) print "PI:";chr$(9); 22/7 print "Sqr2:";chr$(9); SQR(2) print "Log2:";chr$(9); LOG(2) : REM Base 10 print "Exp2:";chr$(9); EXP(2) print "Abs2:";chr$(9); ABS(-2) print "Floor:";chr$(9); INT(1.534) print "ceil:";chr$(9); val(using("###",1.534)) print "Power:";chr$(9); 1.23^4