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/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#OxygenBasic
OxygenBasic
    '========== Class Queue '==========   'FIRST IN FIRST OUT   bstring buf 'buffer to hold queue content int bg 'buffer base offset int i 'indexer int le 'length of buffer   method constructor() ==================== buf="" le=0 bg=0 i=0 end method   method destructor() =================== del buf le=0...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#PureBasic
PureBasic
Structure Quaternion a.f b.f c.f d.f EndStructure   Procedure.f QNorm(*x.Quaternion) ProcedureReturn Sqr(Pow(*x\a, 2) + Pow(*x\b, 2) + Pow(*x\c, 2) + Pow(*x\d, 2)) EndProcedure   ;If supplied, the result is returned in the quaternion structure *res, ;otherwise a new quaternion is created. A pointer to the ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Go
Go
package main   import "fmt"   func main() { a := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ta := %q\n\tfmt.Printf(a, a)\n}\n" fmt.Printf(a, a) }
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#PowerShell
PowerShell
  function range-extraction($arr) { if($arr.Count -gt 2) { $a, $b, $c, $arr = $arr $d = $e = $c if((($a + 1) -eq $b) -and (($b + 1) -eq $c)) { $test = $true while($arr -and $test) { $d = $e $e, $arr = $arr $test = ($d+1)...
http://rosettacode.org/wiki/Read_a_file_line_by_line
Read a file line by line
Read a file one line at a time, as opposed to reading the entire file at once. Related tasks Read a file character by character Input loop.
#XPL0
XPL0
int C; [repeat repeat C:= ChIn(1); \repeat until end-of-line ChOut(0, C); until C < $20; \CR, LF, or EOF until C = \EOF\ $1A; \repeat until end-of-file ]
http://rosettacode.org/wiki/Read_a_file_line_by_line
Read a file line by line
Read a file one line at a time, as opposed to reading the entire file at once. Related tasks Read a file character by character Input loop.
#zkl
zkl
foreach line in (File("foo.zkl")){print(line)}
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 ...
#Symsyn
Symsyn
  | reverse string   c : 'abcdefghijklmnopqrstuvwxyz' d : ' '   c [] i #c j - j if i < j c.i d 1 c.j c.i 1 d c.j - j + i goif endif c []  
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Oz
Oz
declare fun {NewQueue} Stream WritePort = {Port.new Stream} ReadPos = {NewCell Stream} in WritePort#ReadPos end   proc {Push WritePort#_ Value} {Port.send WritePort Value} end   fun {Empty _#ReadPos} %% the queue is empty if the value at the current %% read position is not...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Python
Python
from collections import namedtuple import math   class Q(namedtuple('Quaternion', 'real, i, j, k')): 'Quaternion type: Q(real=0.0, i=0.0, j=0.0, k=0.0)'   __slots__ = ()   def __new__(_cls, real=0.0, i=0.0, j=0.0, k=0.0): 'Defaults all parts of quaternion to zero' return super().__new__(_c...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Groovy
Groovy
s="s=%s;printf s,s.inspect()";printf s,s.inspect()
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Prolog
Prolog
range_extract :- L = [0, 1, 2, 4, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39] , writeln(L), pack_Range(L, LP), maplist(study_Range, R, LP), extract_Range(LA, R), atom_chars(A, LA), writeln(A).     %%%%%%%%%%%%%%%%%%%%%%%...
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 ...
#Tailspin
Tailspin
  templates reverse '$:[ $... ] -> $(last..first:-1)...;' ! end reverse   'asdf' -> reverse -> !OUT::write   ' ' -> !OUT::write   'as⃝df̅' -> reverse -> !OUT::write  
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Pascal
Pascal
program fifo(input, output);   type pNode = ^tNode; tNode = record value: integer; next: pNode; end;   tFifo = record first, last: pNode; end;   procedure initFifo(var fifo: tFifo); begin fifo.first := nil; fifo.last := nil end;   procedure pushFifo(v...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#R
R
  library(quaternions)   q <- Q(1, 2, 3, 4) q1 <- Q(2, 3, 4, 5) q2 <- Q(3, 4, 5, 6) r <- 7.0   display <- function(x){ e <- deparse(substitute(x)) res <- if(class(x) == "Q") paste(x$r, "+", x$i, "i+", x$j, "j+", x$k, "k", sep = "") else x cat(noquote(paste(c(e, " = ", res, "\n"), collapse=""))) invisible(res) }...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#GW-BASIC
GW-BASIC
10 LIST
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Hare
Hare
use fmt; const src: str = "use fmt; const src: str = {0}{1}{0}; export fn main() void = {{fmt::printfln(src, '{0}', src)!;}};"; export fn main() void = {fmt::printfln(src, '"', src)!;};
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#PureBasic
PureBasic
DataSection Data.i 33 ;count of elements to be read Data.i 0, 1, 2, 4, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 Data.i 25, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39 EndDataSection   NewList values() ;setup list Define elementCount, i Read.i elementCount For i = 1 To elementCount ...
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 ...
#Tcl
Tcl
package require Tcl 8.5 string reverse asdf
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Perl
Perl
use Carp; sub mypush (\@@) {my($list,@things)=@_; push @$list, @things} sub mypop (\@) {my($list)=@_; @$list or croak "Empty"; shift @$list } sub empty (@) {not @_}
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Racket
Racket
#lang racket   (struct quaternion (a b c d) #:transparent)   (define-match-expander quaternion: (λ (stx) (syntax-case stx () [(_ a b c d) #'(or (quaternion a b c d) (and a (app (λ(_) 0) b) (app (λ(_) 0) c) (app (λ(_) 0) d)))])))   (define (norm q) (match q [(quaternion: a b c d...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Haskell
Haskell
let q s = putStrLn (s ++ show s) in q "let q s = putStrLn (s ++ show s) in q "
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Python
Python
def range_extract(lst): 'Yield 2-tuple ranges or 1-tuple single elements from list of increasing ints' lenlst = len(lst) i = 0 while i< lenlst: low = lst[i] while i <lenlst-1 and lst[i]+1 == lst[i+1]: i +=1 hi = lst[i] if hi - low >= 2: yield (low, hi) ...
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 ...
#TI-83_BASIC
TI-83 BASIC
:Str1 :For(I,1,length(Ans)-1 :sub(Ans,2I,1)+Ans :End :sub(Ans,1,I→Str1
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Phix
Phix
with javascript_semantics sequence queue = {} procedure push_item(object what) queue = append(queue,what) end procedure function pop_item() object what = queue[1] queue = queue[2..$] return what end function function empty() return length(queue)=0 end function
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Raku
Raku
class Quaternion { has Real ( $.r, $.i, $.j, $.k );   multi method new ( Real $r, Real $i, Real $j, Real $k ) { self.bless: :$r, :$i, :$j, :$k; } multi qu(*@r) is export { Quaternion.new: |@r } sub postfix:<j>(Real $x) is export { qu 0, 0, $x, 0 } sub postfix:<k>(Real $x) is export { qu ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Hoon
Hoon
!:  :-  %say |= [^ [~ ~]] =+ ^= s ((list ,@tas) ~['!:  :-  %say |= [^ [~ ~]] =+ ^= s ((list ,@tas) ~[' 'x' '])  :-  %noun (,tape (turn s |=(a=@tas ?:(=(a %x) (crip `(list ,@tas)`(turn s |=(b=@tas =+([s=?:(=(b %x) " " "") m=(trip ~~~27.)] (crip :(welp s m (trip b) m s)))))) a))))'])  :-  %noun (,tape (turn...
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Qi
Qi
  (define make-range Start Start -> ["," Start] Start End -> ["," Start "," End] where (= End (+ Start 1)) Start End -> ["," Start "-" End])   (define range-extract-0 Start End [] -> (make-range Start End) Start End [A|As] -> (range-extract-0 Start A As) where (= (+ 1 End) A) Start End [A|As] -> (ap...
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 ...
#TMG
TMG
prog: parse(str); str: smark any(!<<>>) scopy str/done = { 1 2 }; done:  ;
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   def push /# l i -- l&i #/ 0 put enddef   def empty? /# l -- flag #/ len 0 == enddef   def pop /# l -- l-1 #/ empty? if "Empty" else head swap tail nip swap endif enddef     ( ) /# empty queue #/   1 push 2 push 3 push pop ? pop ? pop ? pop ?
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Red
Red
  quaternion: context [ quaternion!: make typeset! [block! hash! vector!] multiply: function [q [integer! float! quaternion!] p [integer! float! quaternion!]][ case [ number? q [collect [forall p [keep p/1 * q]]] number? p [collect [forall q [keep q/1 * p]]] 'else [ re...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#HQ9.2B
HQ9+
Q
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#R
R
extract.range = function(v) { r <- c(1, which(diff(v) != 1) + 1, length(v) + 1) paste0(collapse=",", v[head(r, -1)], ifelse(diff(r) == 1, "", paste0(ifelse(diff(r) == 2, ",", "-"), v[r[-1] - 1]))) }     print(extract.range(c( -6, -3, -2, -...
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 ...
#Tosh
Tosh
when flag clicked ask "Say something..." and wait set i to (length of answer) set inv to "" repeat until i = 0 set inv to (join (inv) (letter (i) of answer)) change i by -1 end say inv
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#PHP
PHP
class Fifo { private $data = array(); public function push($element){ array_push($this->data, $element); } public function pop(){ if ($this->isEmpty()){ throw new Exception('Attempt to pop from an empty queue'); } return array_shift($this->data); }   //Alias functions public function...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#REXX
REXX
/*REXX program performs some operations on quaternion type numbers and displays results*/ q = 1 2 3 4  ; q1 = 2 3 4 5 r = 7  ; q2 = 3 4 5 6 call qShow q , 'q' call qShow q1 ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#HTML
HTML
<!DOCTYPE html> <html> <head> <title>HTML/CSS Quine</title> <style type="text/css"> * { font: 10pt monospace; }   head, style { display: block; } style { white-space: pre; }   style:before { content: "\3C""!DOCTYPE html\3E" "\A\3Chtml\3E\A" "\3Chead\3E\A" "\9\3Ctitle\3E""HTML/CSS Quine""\3C/title\3E...
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Racket
Racket
  #lang racket   (define (list->ranges xs) (define (R lo hi) (if (= lo hi) (~a lo) (~a lo (if (= 1 (- hi lo)) "," "-") hi))) (let loop ([xs xs] [lo #f] [hi #f] [r '()]) (cond [(null? xs) (string-join (reverse (if lo (cons (R lo hi) r) r)) ",")] [(not hi) (loop (cdr xs) (car xs) (car xs) r)] ...
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 ...
#Transd
Transd
#lang transd   MainModule : { _start: (lambda (with s "as⃝df̅" (textout (reverse s))   // reversing user input (textout "\nPlease, enter a string: ") (textout "Input: " (reverse (read s))) )) }
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Picat
Picat
go => println("Test 1"), queue_test1, nl.   empty(Q) => Q = []. push(Queue, Value) = Q2 => Q2 = [Value] ++ Queue. pop(Q,_) = _, Q==[] ; var(Q) => throw $error(empty_queue,pop,'Q'=Q). pop(Queue,Q2) = Queue.last() => Q2 = [Queue[I] : I in 1..Queue.len-1].   queue_test1 =>    % create an empty queue ...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Ruby
Ruby
class Quaternion def initialize(*parts) raise ArgumentError, "wrong number of arguments (#{parts.size} for 4)" unless parts.size == 4 raise ArgumentError, "invalid value of quaternion parts #{parts}" unless parts.all? {|x| x.is_a?(Numeric)} @parts = parts end   def to_a; @parts; ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Huginn
Huginn
#! /bin/sh exec huginn --no-argv -E "${0}" #! huginn   main() { c = "#! /bin/sh{1}~" "exec huginn --no-argv -E {3}${{0}}{3}{1}#! huginn{1}{1}~" "main() {{{1}{2}c = {3}{0}{3};{1}{2}print({1}~" "{2}{2}copy( c ).replace( {3}{5}{3}, {3}{3} )~" ".format({1}{2}{2}{2}c.replace( {3}{5}{3}, ~" "{3}{5}{4}{3}{4}n{4}t{4...
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Raku
Raku
sub range-extraction (*@ints) { my $prev = NaN; my @ranges;   for @ints -> $int { if $int == $prev + 1 { @ranges[*-1].push: $int; } else { @ranges.push: [$int]; } $prev = $int; } join ',', @ranges.map: -> @r { @r > 2 ?? "@r[0]-@r[*-1]" ...
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 ...
#Turing
Turing
function reverse (s : string) : string var rs := "" for i : 0 .. length (s) - 1 rs := rs + s (length (s) - i) end for result rs end reverse   put reverse ("iterative example") put reverse (reverse ("iterative example"))
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#PicoLisp
PicoLisp
(off Queue) # Clear Queue (fifo 'Queue 1) # Store number '1' (fifo 'Queue 'abc) # an internal symbol 'abc' (fifo 'Queue "abc") # a transient symbol "abc" (fifo 'Queue '(a b c)) # and a list (a b c) Queue # Show the queue
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Rust
Rust
use std::fmt::{Display, Error, Formatter}; use std::ops::{Add, Mul, Neg};   #[derive(Clone,Copy,Debug)] struct Quaternion { a: f64, b: f64, c: f64, d: f64 }   impl Quaternion { pub fn new(a: f64, b: f64, c: f64, d: f64) -> Quaternion { Quaternion { a: a, b: b, ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Icon_and_Unicon
Icon and Unicon
procedure main();x:="write(\"procedure main();x:=\",image(x));write(x);end" write("procedure main();x:=",image(x));write(x);end
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#REXX
REXX
/*REXX program creates a range extraction from a list of numbers (can be negative.) */ old=0 1 2 4 6 7 8 11 12 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 35 36 37 38 39 #= words(old) /*number of integers in the number list*/ new= ...
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 ...
#TUSCRIPT
TUSCRIPT
$$ MODE TUSCRIPT SET input="was it really a big fat cat i saw" SET reversetext=TURN (input) PRINT "before: ",input PRINT "after: ",reversetext
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#PL.2FI
PL/I
  /* To push a node onto the end of the queue. */ push: procedure (tail); declare tail handle (node), t handle (node); t = new(:node:); get (t => value); if tail ^= bind(:null, node:) then tail => link = t; /* If the queue was non-empty, points the tail of the queue */ /* to the new node. ...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Scala
Scala
case class Quaternion(re: Double = 0.0, i: Double = 0.0, j: Double = 0.0, k: Double = 0.0) { lazy val im = (i, j, k) private lazy val norm2 = re*re + i*i + j*j + k*k lazy val norm = math.sqrt(norm2)   def negative = Quaternion(-re, -i, -j, -k) def conjugate = Quaternion(re, -i, -j, -k) def reciprocal = Quat...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Inform_7
Inform 7
R is a room. To quit: (- quit; -). When play begins: say entry 1 in Q; say Q in brace notation; quit. Q is a list of text variable. Q is {"R is a room. To quit: (- quit; -). When play begins: say entry 1 in Q; say Q in brace notation; quit. Q is a list of text variable. Q is "}
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Ring
Ring
  # Project : Range extraction   int = "0,1,2,4,6,7,8,11,12,14,15,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,35,36,37,38,39" int = str2list(substr(int, ",", nl)) sumint = [] intnew = 1 for n=1 to len(int) flag = 0 nr = 0 intnew = 0 for m=n to len(int)-1 if int[m] = int[m+1] - 1 ...
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 ...
#UNIX_Shell
UNIX Shell
  #!/bin/bash str=abcde   for((i=${#str}-1;i>=0;i--)); do rev="$rev${str:$i:1}"; done   echo $rev  
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#PostScript
PostScript
  % our queue is just [] and empty? is already defined. /push {exch tadd}. /pop {uncons exch}.  
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "float.s7i"; include "math.s7i";     # Define the quaternion number data type. const type: quaternion is new object struct var float: a is 0.0; var float: b is 0.0; var float: c is 0.0; var float: d is 0.0; end struct;     # Create a quaternion number from its rea...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#INTERCAL
INTERCAL
thisMessage print
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Ruby
Ruby
def range_extract(l) # pad the list with a big value, so that the last loop iteration will # append something to the range sorted, range = l.sort.concat([Float::MAX]), [] canidate_number = sorted.first   # enumerate over the sorted list in pairs of current number and next by index sorted.each_cons(2) do |cu...
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 ...
#Unlambda
Unlambda
``@c`d``s`|k`@c
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#PowerShell
PowerShell
  $Q = New-Object System.Collections.Queue   $Q.Enqueue( 1 ) $Q.Enqueue( 2 ) $Q.Enqueue( 3 )   $Q.Dequeue() $Q.Dequeue()   $Q.Count -eq 0 $Q.Dequeue() $Q.Count -eq 0   try { $Q.Dequeue() } catch [System.InvalidOperationException] { If ( $_.Exception.Message -eq 'Queue empty.' ) { 'Caught error' } }
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Sidef
Sidef
class Quaternion(r, i, j, k) {   func qu(*r) { Quaternion(r...) }   method to_s { "#{r} + #{i}i + #{j}j + #{k}k" } method reals { [r, i, j, k] } method conj { qu(r, -i, -j, -k) } method norm { self.reals.map { _*_ }.sum.sqrt }   method ==(Quaternion b) { self.reals == b.reals }   method +...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Io
Io
thisMessage print
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Rust
Rust
use std::ops::Add;   struct RangeFinder<'a, T: 'a> { index: usize, length: usize, arr: &'a [T], }   impl<'a, T> Iterator for RangeFinder<'a, T> where T: PartialEq + Add<i8, Output=T> + Copy { type Item = (T, Option<T>); fn next(&mut self) -> Option<Self::Item> { if self.index == self.length...
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 ...
#Ursala
Ursala
#import std   #cast %s   example = ~&x 'asdf'   verbose_example = reverse 'asdf'
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Prolog
Prolog
empty(U-V) :- unify_with_occurs_check(U, V).   push(Queue, Value, NewQueue) :- append_dl(Queue, [Value|X]-X, NewQueue).   % when queue is empty pop fails. pop([X|V]-U, X, V-U) :- \+empty([X|V]-U).   append_dl(X-Y, Y-Z, X-Z).  
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Swift
Swift
import Foundation   struct Quaternion { var a, b, c, d: Double   static let i = Quaternion(a: 0, b: 1, c: 0, d: 0) static let j = Quaternion(a: 0, b: 0, c: 1, d: 0) static let k = Quaternion(a: 0, b: 0, c: 0, d: 1) } extension Quaternion: Equatable { static func ==(lhs: Quaternion, rhs: Quaternion) -> Bool { ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#J
J
   
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Java
Java
(function(){print("("+arguments.callee.toString().replace(/\s/g,'')+")()");})()
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Scala
Scala
object Range { def spanRange(ls:List[Int])={ var last=ls.head ls span {x => val b=x<=last+1; last=x; b} }   def toRangeList(ls:List[Int]):List[List[Int]]=ls match { case Nil => List() case _ => spanRange(ls) match { case (range, Nil) => List(range) case (range, rest) => ...
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 ...
#Vala
Vala
int main (string[] args) { if (args.length < 2) { stdout.printf ("Please, input a string.\n"); return 0; } var str = new StringBuilder (); for (var i = 1; i < args.length; i++) { str.append (args[i] + " "); } stdout.printf ("%s\n", str.str.strip ().reverse ()); return 0; }
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#PureBasic
PureBasic
NewList MyStack()   Procedure Push(n) Shared MyStack() LastElement(MyStack()) AddElement(MyStack()) MyStack()=n EndProcedure   Procedure Pop() Shared MyStack() Protected n If FirstElement(MyStack()) ; e.g. Stack not empty n=MyStack() DeleteElement(MyStack(),1) Else Debug "Pop(), out of rang...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Tcl
Tcl
package require TclOO   # Support class that provides C++-like RAII lifetimes oo::class create RAII-support { constructor {} { upvar 1 { end } end lappend end [self] trace add variable end unset [namespace code {my destroy}] } destructor { catch { upvar 1 { end } end trace remove variable end ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#JavaScript
JavaScript
(function(){print("("+arguments.callee.toString().replace(/\s/g,'')+")()");})()
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Scheme
Scheme
  (define (make-range start end) (cond ((= start end) `("," ,start)) ((= end (+ start 1)) `("," ,start "," ,end)) (else `("," ,start "-" ,end))))   (define (range-extract-0 start end a) (cond ((null? a) (make-range start end)) ((= (+ 1 end) (car a)) ...
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 ...
#VBA
VBA
Public Function Reverse(aString as String) as String ' returns the reversed string dim L as integer 'length of string dim newString as string   newString = "" L = len(aString) for i = L to 1 step -1 newString = newString & mid$(aString, i, 1) next Reverse = newString End Function
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Python
Python
class FIFO(object): def __init__(self, *args): self.contents = list(args) def __call__(self): return self.pop() def __len__(self): return len(self.contents) def pop(self): return self.contents.pop(0) def push(self, item): self....
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#VBA
VBA
Option Base 1 Private Function norm(q As Variant) As Double norm = Sqr(WorksheetFunction.SumSq(q)) End Function   Private Function negative(q) As Variant Dim res(4) As Double For i = 1 To 4 res(i) = -q(i) Next i negative = res End Function   Private Function conj(q As Variant) As Variant ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Joy
Joy
"dup put putchars 10 putch." dup put putchars 10 putch.
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Jsish
Jsish
var code='var q=String.fromCharCode(39);puts("var code="+q+code+q+";eval(code)")';eval(code)
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func string: rangeExtraction (in array integer: numbers) is func result var string: rangeStri is ""; local var integer: index is 1; var integer: index2 is 1; begin while index <= length(numbers) do while index2 <= pred(length(numbers)) and numbers[succ(index...
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 ...
#VBScript
VBScript
  WScript.Echo StrReverse("asdf")  
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Quackery
Quackery
[ [] ] is queue ( --> [ )   [ [] = ] is empty? ( [ --> b )   [ nested join ] is push ( [ x --> [ )   [ dup empty? if [ $ "Queue unexpectedly empty." fail ] behead ] is pop ( ...
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#R
R
empty <- function() length(l) == 0 push <- function(x) { l <<- c(l, list(x)) print(l) invisible() } pop <- function() { if(empty()) stop("can't pop from an empty list") l[[1]] <<- NULL print(l) invisible() } l <- list() empty() # [1] TRUE push(3) # [[1]] # [1] 3 push("abc") # [[1]] # [1] 3 # [[2...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Visual_Basic_.NET
Visual Basic .NET
Option Compare Binary Option Explicit On Option Infer On Option Strict On   Structure Quaternion Implements IEquatable(Of Quaternion), IStructuralEquatable   Public ReadOnly A, B, C, D As Double   Public Sub New(a As Double, b As Double, c As Double, d As Double) Me.A = a Me.B = b Me...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Julia
Julia
x="println(\"x=\$(repr(x))\\n\$x\")" println("x=$(repr(x))\n$x")
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#SNOBOL4
SNOBOL4
* # Absolute value define('abs(n)') :(abs_end) abs abs = ~(abs = lt(n,0) -n) n :(return) abs_end   define('rangext(str)d1,d2') :(rangext_end) rangext num = ('+' | '-' | '') span('0123456789') rxt1 str ',' span(' ') = ' ' :s(rxt1) rxt2 str num . d1 ' ' num . d2 = + ...
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 ...
#Vedit_macro_language
Vedit macro language
Reg_Empty(10) for (BOL; !At_EOL; Char) { Reg_Copy_Block(10, CP, CP+1, INSERT) }
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Racket
Racket
  #lang racket   (define (make-queue) (mcons #f #f)) (define (push! q x) (define new (mcons x #f)) (if (mcar q) (set-mcdr! (mcdr q) new) (set-mcar! q new)) (set-mcdr! q new)) (define (pop! q) (define old (mcar q)) (cond [(eq? old (mcdr q)) (set-mcar! q #f) (set-mcdr! q #f)] [else (set-mcar! q (mcdr ol...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#Wren
Wren
class Quaternion { construct new(a, b, c, d ) { _a = a _b = b _c = c _d = d }   a { _a } b { _b } c { _c } d { _d }   norm { (a*a + b*b + c*c + d*d).sqrt }   - { Quaternion.new(-a, -b, -c, -d) }   conj { Quaternion.new(a, -b, -c, -d) }   + (q) { ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Kotlin
Kotlin
// version 1.1.2   const val F = """// version 1.1.2   const val F = %c%c%c%s%c%c%c   fun main(args: Array<String>) { System.out.printf(F, 34, 34, 34, F, 34, 34, 34) } """   fun main(args: Array<String>) { System.out.printf(F, 34, 34, 34, F, 34, 34, 34) }
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Swift
Swift
  import Darwin   func ranges(from ints:[Int]) -> [(Int, Int)] {   var range : (Int, Int)? var ranges = [(Int, Int)]() for this in ints { if let (start, end) = range { if this == end + 1 { range = (start, this) } else { ranges.append(range!) range = (this, this) } } else { range = (this...
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 ...
#Visual_Basic
Visual Basic
Debug.Print VBA.StrReverse("Visual Basic")
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#Raku
Raku
role FIFO { method enqueue ( *@values ) { # Add values to queue, returns the number of values added. self.push: @values; return @values.elems; } method dequeue ( ) { # Remove and return the first value from the queue. # Return Nil if queue is empty. ...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#XPL0
XPL0
proc QPrint(Q); \Display quaternion real Q; [RlOut(0, Q(0)); Text(0, " + "); RlOut(0, Q(1)); Text(0, "i + "); RlOut(0, Q(2)); Text(0, "j + "); RlOut(0, Q(3)); Text(0, "k"); CrLf(0); ]; func real QNorm(Q); \Return norm of a quaternion real Q; return sqrt( Q(0)*Q(0) + Q(1)*Q(1) + Q(2)...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Lambdatalk
Lambdatalk
{{lambda {:x} :x} '{lambda {:x} :x}} -> {lambda {:x} :x}
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Tailspin
Tailspin
  templates extract data start <"1">, end <"1"> local templates out when <{start: <=$.end>}> do '$.start;' ! when <{end: <=$.start+1>}> do '$.start;,$.end;' ! otherwise '$.start;-$.end;' ! end out @: {start: $(1), end: $(1)}; [ $(2..last)... -> #, $@ -> out ] -> '$...;' ! when <=$@.end+1> do @.e...
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 ...
#Visual_Basic_.NET
Visual Basic .NET
#Const REDIRECTOUT = True   Module Program Const OUTPATH = "out.txt"   ReadOnly TestCases As String() = {"asdf", "as⃝df̅", "Les Misérables"}   ' SIMPLE VERSION Function Reverse(s As String) As String Dim t = s.ToCharArray() Array.Reverse(t) Return New String(t) End Function  ...
http://rosettacode.org/wiki/Queue/Definition
Queue/Definition
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Illustration of FIFO behavior Task Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion. Operation...
#REBOL
REBOL
rebol [ Title: "FIFO" URL: http://rosettacode.org/wiki/FIFO ]   ; Define fifo class:   fifo: make object! [ queue: copy [] push: func [x][append queue x] pop: func [/local x][ ; Make 'x' local so it won't pollute global namespace. if empty [return none] x: first queue remove qu...
http://rosettacode.org/wiki/Quaternion_type
Quaternion type
Quaternions   are an extension of the idea of   complex numbers. A complex number has a real and complex part,   sometimes written as   a + bi, where   a   and   b   stand for real numbers, and   i   stands for the square root of minus 1. An example of a complex number might be   -3 + 2i,   wher...
#zkl
zkl
class Quat{ fcn init(real=0,i1=0,i2=0,i3=0){ var [const] vector= // Quat(r,i,j,k) or Quat( (r,i,j,k) ) (if(List.isType(real)) real else vm.arglist).apply("toFloat"); var r,i,j,k; r,i,j,k=vector; // duplicate data for ease of coding var [const] // properties: This is one way to do it ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Lasso
Lasso
var(a=(:10,39,118,97,114,40,97,61,40,58,39,10,36,97,45,62,106,111,105,110,40,39,44,39,41,10,39,41,41,39,10,118,97,114,40,98,61,98,121,116,101,115,41,10,36,97,45,62,102,111,114,101,97,99,104,32,61,62,32,123,32,36,98,45,62,105,109,112,111,114,116,56,98,105,116,115,40,35,49,41,32,125,10,36,98,45,62,97,115,83,116,114,105,1...
http://rosettacode.org/wiki/Range_extraction
Range extraction
A format for expressing an ordered list of integers is to use a comma separated list of either individual integers Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints) The range s...
#Tcl
Tcl
proc rangeExtract list { set result [lindex $list 0] set first [set last [lindex $list 0]] foreach term [lrange $list 1 end] { if {$term == $last+1} { set last $term continue } if {$last > $first} { append result [expr {$last == $first+1 ? "," : "-"}] $last } append result "," $term set...