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/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
... | #Wart | Wart | (rev "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... | #REXX | REXX | /*REXX program to demonstrate FIFO queue usage by some simple operations*/
call viewQueue
a="Fred"
push /*puts a "null" on top of queue.*/
push a 2 /*puts "Fred 2" on top of queue.*/
call viewQueue
queue "Toft 2" /*put "Toft 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 ... | #LDPL | LDPL | DATA:
A IS NUMBER VECTOR
C IS TEXT
N IS NUMBER
I IS NUMBER
J IS NUMBER
PROCEDURE:
SUB-PROCEDURE SHOWU
STORE 0 IN I
WHILE I IS LESS THAN N DO
DISPLAY " STORE "
DISPLAY A:I
DISPLAY " IN "
DISPLAY " A:"
DISPLAY I CRLF
ADD I AND 1 IN I
REPEAT
DI... |
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... | #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT,{}
MODE DATA
$$ numbers=*
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
$$ MODE TUSCRIPT
numbers=EXCHANGE (numbers,":,{0-00} :':")
unrangednrs=JOIN (numbers,"")
rangednrs=COMBINE (unrangednrs,"")
rangednrs=EXCHAN... |
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
... | #Wren | Wren | import "/str" for Str
import "/upc" for Graphemes
for (word in ["asdf", "josé", "møøse", "was it a car or a cat I saw", "😀🚂🦊"]) {
System.print(Str.reverse(word))
}
for (word in ["as⃝df̅", "ℵΑΩ 駱駝道 🤔 🇸🇧 🇺🇸 🇬🇧 👨👩👧👦🆗🗺"]) {
System.print(Graphemes.new(word).toList[-1..0].join())
} |
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... | #Ring | Ring |
# Project : Queue/Definition
load "stdlib.ring"
oQueue = new Queue
for n = 5 to 7
see "Push: " + n + nl
oQueue.add(n)
next
see "Pop: " + oQueue.remove() + nl
see "Push: 8" + nl
oQueue.add(8)
see "Pop: " + oQueue.remove() + nl
see "Pop: " + oQueue.remove() + nl
see "Pop: " + oQueue.remove() + nl
if len(... |
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 ... | #Liberty_BASIC | Liberty BASIC | s$ = "s$ = : Print Left$(s$, 5) + chr$(34) + s$ + chr$(34) + Mid$(s$, 5)" : Print Left$(s$, 5) + chr$(34) + s$ + chr$(34) + Mid$(s$, 5) |
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... | #TXR | TXR | (defun range-extract (numbers)
`@{(mapcar [iff [callf > length (ret 2)]
(ret `@[@1 0]-@[@1 -1]`)
(ret `@{@1 ","}`)]
(mapcar (op mapcar car)
(split [window-map 1 :reflect
(op list @2 (- @2 @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
... | #Wortel | Wortel | ; the @rev operator reverses strings and arrays
@rev "abc" ; returns "cba"
; or the same thing using a pointer expression
!~r "abc" |
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... | #Ruby | Ruby | require 'forwardable'
# A FIFO queue contains elements in first-in, first-out order.
# FIFO#push adds new elements to the end of the queue;
# FIFO#pop or FIFO#shift removes elements from the front.
class FIFO
extend Forwardable
# Creates a FIFO containing _objects_.
def self.[](*objects)
new.push(*objects... |
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 ... | #LIL | LIL | # reflect this
reflect this |
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... | #UNIX_Shell | UNIX Shell | #!/usr/bin/bash
range_contract () (
add_range () {
case $(( current - range_start )) in
0) ranges+=( $range_start ) ;;
1) ranges+=( $range_start $current ) ;;
*) ranges+=("$range_start-$current") ;;
esac
}
ranges=()
range_start=$1
curr... |
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
... | #XBS | XBS | log(string.reverse("Hello")) |
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... | #Rust | Rust | use std::collections::VecDeque;
fn main() {
let mut stack = VecDeque::new();
stack.push_back("Element1");
stack.push_back("Element2");
stack.push_back("Element3");
assert_eq!(Some(&"Element1"), stack.front());
assert_eq!(Some("Element1"), stack.pop_front());
assert_eq!(Some("Element2"), st... |
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 ... | #Lisp | Lisp | ((lambda (x) (list x (list 'quote x)))
'(lambda (x) (list x (list 'quote 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... | #Ursala | Ursala | #import std
#import int
x = <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>
f = mat`,+ ==?(~&l,^|T/~& :/`-)*bhPS+ %zP~~hzX*titZBPiNCSiNCQSL+ rlc ^|E/~& predecessor
#show+
t = <f x> |
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
... | #XPL0 | XPL0 | include c:\cxpl\codes; \intrinsic 'code' declarations
string 0; \use zero-terminated strings, instead of MSb terminated
func StrLen(Str); \Return the number of characters in an ASCIIZ string
char Str;
int I;
for I:= 0 to -1>>1-1 do
if Str(I) = 0 then return I;
func RevStr(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... | #Scala | Scala | class Queue[T] {
private[this] class Node[T](val value:T) {
var next:Option[Node[T]]=None
def append(n:Node[T])=next=Some(n)
}
private[this] var head:Option[Node[T]]=None
private[this] var tail:Option[Node[T]]=None
def isEmpty=head.isEmpty
def enqueue(item:T)={
val n=new Node(item)
if(is... |
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 ... | #Logo | Logo | make "a [ 116 121 112 101 32 34 124 109 97 107 101 32 34 97 32 91 124 10 102 111 114 101 97 99 104 32 58 97 32 91 32 116 121 112 101 32 119 111 114 100 32 34 124 32 124 32 63 32 93 10 112 114 105 110 116 32 34 124 32 93 124 10 102 111 114 101 97 99 104 32 58 97 32 91 32 116 121 112 101 32 99 104 97 114 32 63 32 93 10 9... |
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... | #VBA | VBA |
Public Function RangeExtraction(AList) As String
'AList is a variant that is an array, assumed filled with numbers in ascending order
Const RangeDelim = "-" 'range delimiter
Dim result As String
Dim InRange As Boolean
Dim Posn, ub, lb, rangestart, rangelen As Integer
result = ""
'find dimensions of AList
u... |
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
... | #Yorick | Yorick | strchar(strchar("asdf")(:-1)(::-1)) |
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... | #Scheme | Scheme | (define (make-queue)
(make-vector 1 '()))
(define (push a queue)
(vector-set! queue 0 (append (vector-ref queue 0) (list a))))
(define (empty? queue)
(null? (vector-ref queue 0)))
(define (pop queue)
(if (empty? queue)
(error "can not pop an empty queue")
(let ((ret (car (vector-ref queue 0)))... |
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 ... | #Lua | Lua | s=[[io.write('s=[','[',s,']','];',s)]];io.write('s=[','[',s,']','];',s) |
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... | #VBScript | VBScript | Function Range_Extraction(list)
num = Split(list,",")
For i = 0 To UBound(num)
startnum = CInt(num(i))
sum = startnum
Do While i <= UBound(num)
If sum = CInt(num(i)) Then
If i = UBound(num) Then
If startnum <> CInt(num(i)) Then
If startnum + 1 = CInt(num(i)) Then
Range_Extraction = Rang... |
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
... | #Z80_Assembly | Z80 Assembly | PrintChar equ $BB5A ;Amstrad CPC bios call
Terminator equ 0 ;null terminator for strings
org $8000
ld hl, StringA
call ReverseString
ld hl, StringA
call PrintString
ret ;return to basic
StringA:
byte "12345678",0
;;;; SUBROUTINES
GetStringLength:
;HL = STRING. RETURNS LENGTH IN B. LENGTH... |
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... | #SenseTalk | SenseTalk |
set myFoods to be an empty list
push "grapes" into myFoods
push "orange" into myFoods
push "apricot" into myFoods
put "The foods in my queue are: " & myFoods
pull from myFoods into firstThingToEat
put "The first thing to eat is: " & firstThingToEat
if myFoods is empty then
put "The foods list is empty!"... |
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 ... | #M2000_Interpreter | M2000 Interpreter |
Module Alfa {
Rem {This Program Show itself in Help Form}
inline "help "+quote$(module.name$)
}
Alfa
|
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... | #Wren | Wren | var extractRange = Fn.new { |list|
if (list.isEmpty) return ""
var sb = ""
var first = list[0]
var prev = first
var append = Fn.new { |index|
if (first == prev) {
sb = sb + prev.toString
} else if (first == prev - 1) {
sb = sb + first.toString + "," + prev.... |
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
... | #zkl | zkl | "this is a test".reverse() |
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... | #Sidef | Sidef | class FIFO(*array) {
method pop {
array.is_empty && die "underflow";
array.shift;
}
method push(*items) {
array += items;
self;
}
method empty {
array.len == 0;
}
} |
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 ... | #M4 | M4 | define(`quine',``$1(`$1')'')dnl
quine(`define(`quine',``$1(`$1')'')dnl
quine') |
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... | #zkl | zkl | fcn range(ns){
fcn(w){
if (w.atEnd) return(Void.Stop);
a:=b:=w.next(); n:=0;
while(b+1 == (c:=w.peekN(n))){ n+=1; b=c }
if(n>1){do(n){w.next()}; return("%d-%d".fmt(a,b)); }
a
} :
(0).pump(*,List,_.fp(ns.walker().tweak(Void,Void))).concat(",");
} |
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
... | #Zoea | Zoea |
program: reverse_string
input: xyzzy
output: yzzyx
|
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... | #Slate | Slate | collections define: #Queue &parents: {ExtensibleArray}.
q@(Queue traits) isEmpty [resend].
q@(Queue traits) push: obj [q addLast: obj].
q@(Queue traits) pop [q removeFirst].
q@(Queue traits) pushAll: c [q addAllLast: c].
q@(Queue traits) pop: n [q removeFirst: n]. |
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 ... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | a="Print[\"a=\",InputForm[a],\";\",a]";Print["a=",InputForm[a],";",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
... | #Zoea_Visual | Zoea Visual |
var s = "socat".*;
std.mem.reverse(u8, &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... | #Smalltalk | Smalltalk | OrderedCollection extend [
push: obj [ ^(self add: obj) ]
pop [
(self isEmpty) ifTrue: [
SystemExceptions.NotFound signalOn: self
reason: 'queue empty'
] ifFalse: [
^(self removeFirst)
]
]
]
|f|
f := OrderedCollection new.
f push: 'example'; push: 'ano... |
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 ... | #MATLAB_.2F_Octave | MATLAB / Octave | x='{>\(y>(((-y-(((<(^<ejtq)\{-y.2^*<';z=['x=''',x,''';'];disp([z,x-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
... | #Zig | Zig |
var s = "socat".*;
std.mem.reverse(u8, &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... | #Standard_ML | Standard ML |
signature QUEUE =
sig
type 'a queue
val empty_queue: 'a queue
exception Empty
val enq: 'a queue -> 'a -> 'a queue
val deq: 'a queue -> ('a * 'a queue)
val empty: 'a queue -> bool
end;
|
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... | #Stata | Stata | proc push {stackvar value} {
upvar 1 $stackvar stack
lappend stack $value
}
proc pop {stackvar} {
upvar 1 $stackvar stack
set value [lindex $stack 0]
set stack [lrange $stack 1 end]
return $value
}
proc size {stackvar} {
upvar 1 $stackvar stack
llength $stack
}
proc empty {stackvar} {
... |
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 ... | #Maxima | Maxima | /* Using ?format from the unerlying Lisp system */
lambda([],block([q:ascii(34),s:"lambda([],block([q:ascii(34),s:~A~A~A],print(?format(false,s,q,s,q))))()$"],print(?format(false,s,q,s,q))))()$ |
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... | #Tcl | Tcl | proc push {stackvar value} {
upvar 1 $stackvar stack
lappend stack $value
}
proc pop {stackvar} {
upvar 1 $stackvar stack
set value [lindex $stack 0]
set stack [lrange $stack 1 end]
return $value
}
proc size {stackvar} {
upvar 1 $stackvar stack
llength $stack
}
proc empty {stackvar} {
... |
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 ... | #MiniScript | MiniScript | s="s=;print s[:2]+char(34)+s+char(34)+s[2:]";print s[:2]+char(34)+s+char(34)+s[2:] |
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... | #UNIX_Shell | UNIX Shell | queue_push() {
typeset -n q=$1
shift
q+=("$@")
}
queue_pop() {
if queue_empty $1; then
print -u2 "queue $1 is empty"
return 1
fi
typeset -n q=$1
print "${q[0]}" # emit the value of the popped element
q=( "${q[@]:1}" ) # and remove the first element from the que... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #11l | 11l | T XorShiftStar
UInt64 state
F seed(seed_state)
.state = seed_state
F next_int() -> UInt32
V x = .state
x (+)= x >> 12
x (+)= x << 25
x (+)= x >> 27
.state = x
R (x * 2545'F491'4F6C'DD1D) >> 32
F next_float()
R Float(.next_int()) / 2.0^32
V random_gen =... |
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 ... | #Modula-2 | Modula-2 | MODULE Quine;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
CONST src = "MODULE Quine;\nFROM FormatString IMPORT FormatString;\nFROM Terminal IMPORT WriteString,ReadChar;\n\nCONST src = \x022%s\x022;\nVAR buf : ARRAY[0..2048] OF CHAR;\nBEGIN\n FormatString(src, buf, src);\n W... |
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... | #UnixPipes | UnixPipes | init() {echo > fifo}
push() {echo $1 >> fifo }
pop() {head -1 fifo ; (cat fifo | tail -n +2)|sponge fifo}
empty() {cat fifo | wc -l} |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Ada | Ada | with Interfaces; use Interfaces;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
const : constant Unsigned_64 := 16#2545_F491_4F6C_DD1D#;
state : Unsigned_64 := 0;
Unseeded_Error : exception;
procedure seed (num : Unsigned_64) is
begin
state := num;
end seed;
function Nex... |
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 ... | #MUMPS | MUMPS | QUINE
NEW I,L SET I=0
FOR SET I=I+1,L=$TEXT(+I) Q:L="" WRITE $TEXT(+I),!
KILL I,L
QUIT
SMALL
S %=0 F W $T(+$I(%)),! Q:$T(+%)="" |
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 ... | #NASM | NASM | %define a "%define "
%define b "db "
%define c "%deftok "
%define d "a, 97, 32, 34, a, 34, 10, a, 98, 32, 34, b, 34, 10, a, 99, 32, 34, c, 34, 10, a, 100, 32, 34, d, 34, 10, c, 101, 32, 100, 10, b, 101, 10"
%deftok e d
db e |
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... | #V | V | [fifo_create []].
[fifo_push swap cons].
[fifo_pop [[*rest a] : [*rest] a] view].
[fifo_empty? dup empty?]. |
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... | #VBA | VBA | Public queue As New Collection
Private Sub push(what As Variant)
queue.Add what
End Sub
Private Function pop() As Variant
If queue.Count > 0 Then
what = queue(1)
queue.Remove 1
Else
what = CVErr(461)
End If
pop = what
End Function
Private Function empty_()
empty_ = ... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #ALGOL_68 | ALGOL 68 | BEGIN # generate some pseudo random numbers using Xorshift star #
# note that although LONG INT is 64 bits in Algol 68G, LONG BITS is longer than 64 bits #
LONG BITS state;
LONG INT const = ABS LONG 16r2545f4914f6cdd1d;
LONG INT one shl 32 = ABS ( LONG 16r1 SHL 32 );
# sets the state to the s... |
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 ... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols nobinary
Q = "'"
S = "\\"
N = "\n"
A = "&"
code = [ -
'/* NetRexx */', -
'options replace format comments java crossref savelog symbols nobinary', -
'', -
'Q = "&QS"', -
'S = "&ESC"', -
'N = "&NL"', -
'A = "&"', -
'code = [... |
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... | #VBScript | VBScript | ' Queue Definition - VBScript
Option Explicit
Dim queue, i, x
Set queue = CreateObject("System.Collections.ArrayList")
If Not empty_(queue) Then Wscript.Echo queue.Count
push queue, "Banana"
push queue, "Apple"
push queue, "Pear"
push queue, "Strawberry"
Wscript.Echo "Count=" & queue.Count
Wscript.Echo pull(queue) & " ... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #C | C | #include <math.h>
#include <stdint.h>
#include <stdio.h>
static uint64_t state;
static const uint64_t STATE_MAGIC = 0x2545F4914F6CDD1D;
void seed(uint64_t num) {
state = num;
}
uint32_t next_int() {
uint64_t x;
uint32_t answer;
x = state;
x = x ^ (x >> 12);
x = x ^ (x << 25);
x = x ^... |
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 ... | #NewLISP | NewLISP | (lambda (s) (print (list s (list 'quote 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... | #Vlang | Vlang | const max_tail = 256
struct Queue<T> {
mut:
data []T
tail int
head int
}
fn (mut queue Queue<T>) push(value T) {
if queue.tail >= max_tail || queue.tail < queue.head {
return
}
println('push: $value')
queue.data << value
queue.tail++
}
fn (mut queue Queue<T>) pop() !T {
if queue.tail > 0 && queue.hea... |
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... | #Wart | Wart | def (queue seq)
(tag queue (list seq lastcons.seq len.seq))
def (enq x q)
do1 x
let (l last len) rep.q
rep.q.2 <- (len + 1)
if no.l
rep.q.1 <- (rep.q.0 <- list.x)
rep.q.1 <- (cdr.last <- list.x)
def (deq q)
let (l last len) rep.q
ret ans car.l
unless zero?.len
... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #C.2B.2B | C++ | #include <array>
#include <cstdint>
#include <iostream>
class XorShiftStar {
private:
const uint64_t MAGIC = 0x2545F4914F6CDD1D;
uint64_t state;
public:
void seed(uint64_t num) {
state = num;
}
uint32_t next_int() {
uint64_t x;
uint32_t answer;
x = state;
... |
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 ... | #Nim | Nim | |
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... | #Wren | Wren | import "/queue" for Queue
var q = Queue.new()
var item = q.pop()
if (item == null) {
System.print("ERROR: attempted to pop from an empty queue")
} else {
System.print("'%(item)' was popped")
} |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #D | D | import std.math;
import std.stdio;
class XorShiftStar {
private immutable MAGIC = 0x2545F4914F6CDD1D;
private ulong state;
public void seed(ulong num) {
state = num;
}
public uint nextInt() {
ulong x;
uint answer;
x = state;
x = x ^ (x >> 12);
... |
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 ... | #NS-HUBASIC | NS-HUBASIC | 10 LIST |
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... | #XLISP | XLISP | (define-class queue
(instance-variables vals))
(define-method (queue 'initialize)
(setq vals '())
self)
(define-method (queue 'push x)
(setq vals (nconc vals (cons x nil))))
(define-method (queue 'pop)
(define val (car vals))
(setq vals (cdr vals))
val)
(define-method (queue 'emptyp)... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Delphi | Delphi |
program Xorshift_star;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.Math;
type
TXorshiftStar = record
private
state: uint64;
const
k = $2545F4914F6CDD1D;
public
constructor Create(aState: uint64);
procedure Seed(aState: uint64);
function NextInt: uint32;
function NextF... |
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 ... | #Oberon-2 | Oberon-2 | MODULE M;
IMPORT O:=Out;
CONST
T=";PROCEDURE c*;BEGIN O.Char(22X);O.String(T) END c;BEGIN O.String('MODULE M;IMPORT O:=Out;CONST T=');c END M.";
PROCEDURE c*;
BEGIN
O.Char(22X);O.String(T)
END c;
BEGIN
O.String('MODULE M;IMPORT O:=Out;CONST T=');
c
END M. |
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method | Pseudo-random numbers/Middle-square method | Middle-square_method Generator
The Method
To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i... | #AArch64_Assembly | AArch64 Assembly |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program pRandom64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM6... |
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... | #XPL0 | XPL0 | include c:\cxpl\codes;
def Size=8;
int Fifo(Size);
int In, Out; \fill and empty indexes into Fifo
proc Push(A); \Add integer A to queue
int A; \(overflow not detected)
[Fifo(In):= A;
In:= In+1;
if In >= Size then In:= 0;
];
func Pop; \Return first integer in queue... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #F.23 | F# |
// Xorshift star. Nigel Galloway: August 14th., 2020
let fN=(fun(n:uint64)->n^^^(n>>>12))>>(fun n->n^^^(n<<<25))>>(fun n->n^^^(n>>>27))
let Xstar32=Seq.unfold(fun n->let n=fN n in Some(uint32((n*0x2545F4914F6CDD1DUL)>>>32),n))
let XstarF n=Xstar32 n|>Seq.map(fun n->(float n)/4294967296.0)
|
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Factor | Factor | USING: accessors kernel literals math math.statistics
prettyprint sequences ;
CONSTANT: mask64 $[ 1 64 shift 1 - ]
CONSTANT: mask32 $[ 1 32 shift 1 - ]
CONSTANT: const 0x2545F4914F6CDD1D
! Restrict seed value to positive integers.
PREDICATE: positive < integer 0 > ;
ERROR: seed-nonpositive seed ;
TUPLE: xorshift*... |
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 ... | #Objeck | Objeck | class Program { function : Main(args : String[]) ~ Nil { s := "class Program { function : Main(args : String[]) ~ Nil { s :=; IO.Console->Print(s->SubString(61))->Print(34->As(Char))->Print(s)->Print(34->As(Char))->PrintLine(s->SubString(61, 129)); } }"; IO.Console->Print(s->SubString(61))->Print(34->As(Char))->Print... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method | Pseudo-random numbers/Middle-square method | Middle-square_method Generator
The Method
To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
type long is range 0 .. 2**64;
Seed : long := 675_248;
function random return long is
begin
Seed := Seed * Seed / 1_000 rem 1_000_000;
return Seed;
end random;
begin
for I in 1 .. 5 loop
Put (long'Image (random));
end loop;
... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method | Pseudo-random numbers/Middle-square method | Middle-square_method Generator
The Method
To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i... | #ALGOL_68 | ALGOL 68 | BEGIN # generate random numbers by the middle-square method #
INT seed := 675248;
# returns the next middle-square random number #
PROC ms random = INT: seed := SHORTEN( ( ( LONG INT( seed ) * LONG INT( seed ) ) OVER 1000 ) MOD 1 000 000 );
# test the ms random procedure #
FOR i TO 5 DO
prin... |
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... | #zkl | zkl | class Queue{
var [const] q=List();
fcn push { q.append(vm.pasteArgs()) }
fcn pop { q.pop(0) }
fcn empty { q.len()==0 }
} |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Go | Go | package main
import (
"fmt"
"math"
)
const CONST = 0x2545F4914F6CDD1D
type XorshiftStar struct{ state uint64 }
func XorshiftStarNew(state uint64) *XorshiftStar { return &XorshiftStar{state} }
func (xor *XorshiftStar) seed(state uint64) { xor.state = state }
func (xor *XorshiftStar) nextInt() uint32 ... |
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 ... | #OCaml | OCaml | (fun p -> Printf.printf p (string_of_format p)) "(fun p -> Printf.printf p (string_of_format p)) %S;;\n";; |
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32 | Pseudo-random numbers/PCG32 | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #11l | 11l | T PCG32
UInt64 state, inc
F next_int()
V old = .state
.state = (old * 6364136223846793005) + .inc
V shifted = UInt32(((old >> 18) (+) old) >> 27)
V rot = UInt32(old >> 59)
R (shifted >> rot) [|] (shifted << (((-)rot + 1) [&] 31))
F seed(UInt64 seed_state, seed_sequence)
... |
http://rosettacode.org/wiki/Pythagorean_quadruples | Pythagorean quadruples |
One form of Pythagorean quadruples is (for positive integers a, b, c, and d):
a2 + b2 + c2 = d2
An example:
22 + 32 + 62 = 72
which is:
4 + 9 + 36 = 49
Task
For positive integers up 2,200 (inclusive), for all values of ... | #11l | 11l | F quad(top = 2200)
V r = [0B] * top
V ab = [0B] * (top * 2)^2
L(a) 1 .< top
L(b) a .< top
ab[a * a + b * b] = 1B
V s = 3
L(c) 1 .< top
(V s1, s, V s2) = (s, s + 2, s + 2)
L(d) c + 1 .< top
I ab[s1]
r[d] = 1B
s1 += s2
s2 += 2
R enumerate... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method | Pseudo-random numbers/Middle-square method | Middle-square_method Generator
The Method
To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i... | #AppleScript | AppleScript | on newGenerator(n, seed)
script generator
property seed : missing value
property p1 : 10 ^ (n div 2)
property p2 : 10 ^ n
on getRandom()
set seed to seed * seed div p1 mod p2
return seed div 1
end getRandom
end script
set generator's seed t... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Haskell | Haskell | import Data.Bits
import Data.Word
import System.Random
import Data.List
newtype XorShift = XorShift Word64
instance RandomGen XorShift where
next (XorShift state) = (out newState, XorShift newState)
where
newState = (\z -> z `xor` (z `shiftR` 27)) .
(\z -> z `xor` (z `shiftL` 25)) .... |
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 ... | #Oforth | Oforth | "dup 34 emit print 34 emit BL emit print" dup 34 emit print 34 emit BL emit print |
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32 | Pseudo-random numbers/PCG32 | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Ada | Ada | with Interfaces; use Interfaces;
package random_pcg32 is
function Next_Int return Unsigned_32;
function Next_Float return Long_Float;
procedure Seed (seed_state : Unsigned_64; seed_sequence : Unsigned_64);
end random_pcg32;
|
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32 | Pseudo-random numbers/PCG32 | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #ALGOL_68 | ALGOL 68 | BEGIN # generate some pseudo random numbers using PCG32 #
# note that although LONG INT is 64 bits in Algol 68G, LONG BITS is longer than 64 bits #
LONG BITS state := LONG 16r853c49e6748fea9b;
LONG INT inc := ABS LONG 16rda3e39cb94b95bdb;
LONG BITS mask 64 = LONG 16rfffffffffffffff... |
http://rosettacode.org/wiki/Pythagorean_quadruples | Pythagorean quadruples |
One form of Pythagorean quadruples is (for positive integers a, b, c, and d):
a2 + b2 + c2 = d2
An example:
22 + 32 + 62 = 72
which is:
4 + 9 + 36 = 49
Task
For positive integers up 2,200 (inclusive), for all values of ... | #ALGOL_68 | ALGOL 68 | BEGIN
# find values of d where d^2 =/= a^2 + b^2 + c^2 for any integers a, b, c #
# where d in [1..2200], a, b, c =/= 0 #
# max number to check #
INT max number = 2200;
INT max square = max number * max number;
# table of numbers that can be the sum of two squ... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method | Pseudo-random numbers/Middle-square method | Middle-square_method Generator
The Method
To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i... | #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI or android with termux */
/* program pRandom.s */
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constantes se... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Java | Java | public class XorShiftStar {
private static final long MAGIC = Long.parseUnsignedLong("2545F4914F6CDD1D", 16);
private long state;
public void seed(long num) {
state = num;
}
public int nextInt() {
long x;
int answer;
x = state;
x = x ^ (x >>> 12);
... |
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 ... | #Ol | Ol | ((lambda (s) (display (list s (list (quote quote) s)))) (quote (lambda (s) (display (list s (list (quote quote) s)))))) |
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32 | Pseudo-random numbers/PCG32 | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #C | C | #include <math.h>
#include <stdint.h>
#include <stdio.h>
const uint64_t N = 6364136223846793005;
static uint64_t state = 0x853c49e6748fea9b;
static uint64_t inc = 0xda3e39cb94b95bdb;
uint32_t pcg32_int() {
uint64_t old = state;
state = old * N + inc;
uint32_t shifted = (uint32_t)(((old >> 18) ^ old) >... |
http://rosettacode.org/wiki/Pythagorean_quadruples | Pythagorean quadruples |
One form of Pythagorean quadruples is (for positive integers a, b, c, and d):
a2 + b2 + c2 = d2
An example:
22 + 32 + 62 = 72
which is:
4 + 9 + 36 = 49
Task
For positive integers up 2,200 (inclusive), for all values of ... | #Amazing_Hopper | Amazing Hopper |
#include <flow.h>
DEF-MAIN(argv, argc)
SET(N, 2200)
DIM( MUL(MUL(N,N),2) ) AS-ZEROS( temp )
DIM( N ) AS-ZEROS( found )
MSET( a,T1,T2 )
TIC(T1)
SEQ-SPC(1,N,N,a), LET( a := MUL(a,a) )
SET(i,1), SET(r,0)
PERF-UP(i,N,1)
LET( r := ADD( [i] GET( a ), [i:end] CGET(a) ) )
SET-RANGE... |
http://rosettacode.org/wiki/Pythagorean_quadruples | Pythagorean quadruples |
One form of Pythagorean quadruples is (for positive integers a, b, c, and d):
a2 + b2 + c2 = d2
An example:
22 + 32 + 62 = 72
which is:
4 + 9 + 36 = 49
Task
For positive integers up 2,200 (inclusive), for all values of ... | #AppleScript | AppleScript | -- double :: Num -> Num
on double(x)
x + x
end double
-- powersOfTwo :: Generator [Int]
on powersOfTwo()
iterate(double, 1)
end powersOfTwo
on run
-- Two infinite lists, from each of which we can draw an arbitrary number of initial terms
set xs to powersOfTwo() -- {1, 2, 4, 8, 16, 32 ...
set... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method | Pseudo-random numbers/Middle-square method | Middle-square_method Generator
The Method
To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i... | #AWK | AWK |
# syntax: GAWK -f PSEUDO-RANDOM_NUMBERS_MIDDLE-SQUARE_METHOD.AWK
BEGIN {
seed = 675248
srand(seed)
for (i=1; i<=5; i++) {
printf("%2d: %s\n",i,main())
}
exit(0)
}
function main( s) {
s = seed ^ 2
while (length(s) < 12) {
s = "0" s
}
seed = substr(s,4,6)
return(seed... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method | Pseudo-random numbers/Middle-square method | Middle-square_method Generator
The Method
To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i... | #C | C | #include<stdio.h>
long long seed;
long long random(){
seed = seed * seed / 1000 % 1000000;
return seed;
}
int main(){
seed = 675248;
for(int i=1;i<=5;i++)
printf("%lld\n",random());
return 0;
} |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Julia | Julia | const mask32 = (0x1 << 32) - 1
const CONST = 0x2545F4914F6CDD1D
mutable struct XorShiftStar
state::UInt64
end
XorShiftStar(_seed=0x0) = XorShiftStar(UInt(_seed))
seed(x::XorShiftStar, num) = begin x.state = UInt64(num) end
"""return random int between 0 and 2**32"""
function next_int(x::XorShiftStar)
x... |
http://rosettacode.org/wiki/Pseudo-random_numbers/Xorshift_star | Pseudo-random numbers/Xorshift star | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #Kotlin | Kotlin | import kotlin.math.floor
class XorShiftStar {
private var state = 0L
fun seed(num: Long) {
state = num
}
fun nextInt(): Int {
var x = state
x = x xor (x ushr 12)
x = x xor (x shl 25)
x = x xor (x ushr 27)
state = x
return (x * MAGIC shr 32)... |
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 ... | #ooRexx | ooRexx | say sourceline(1) |
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32 | Pseudo-random numbers/PCG32 | Some definitions to help in the explanation
Floor operation
https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
Greatest integer less than or equal to a real number.
Bitwise Logical shift operators (c-inspired)
https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts
Binary bits of value shifted left or ri... | #C.2B.2B | C++ | #include <array>
#include <iostream>
class PCG32 {
private:
const uint64_t N = 6364136223846793005;
uint64_t state = 0x853c49e6748fea9b;
uint64_t inc = 0xda3e39cb94b95bdb;
public:
uint32_t nextInt() {
uint64_t old = state;
state = old * N + inc;
uint32_t shifted = (uint32_t)(((... |
http://rosettacode.org/wiki/Pythagorean_quadruples | Pythagorean quadruples |
One form of Pythagorean quadruples is (for positive integers a, b, c, and d):
a2 + b2 + c2 = d2
An example:
22 + 32 + 62 = 72
which is:
4 + 9 + 36 = 49
Task
For positive integers up 2,200 (inclusive), for all values of ... | #AWK | AWK |
# syntax: GAWK -f PYTHAGOREAN_QUADRUPLES.AWK
# converted from Go
BEGIN {
n = 2200
s = 3
for (a=1; a<=n; a++) {
a2 = a * a
for (b=a; b<=n; b++) {
ab[a2 + b * b] = 1
}
}
for (c=1; c<=n; c++) {
s1 = s
s += 2
s2 = s
for (d=c+1; d<=n; d++) {
if ... |
http://rosettacode.org/wiki/Pythagoras_tree | Pythagoras tree |
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem.
Task
Construct a Pythagoras tree of order 7 using only vectors (no rotation or ... | #Ada | Ada | with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Rectangles;
with SDL.Events.Events;
procedure Pythagoras_Tree is
Width : constant := 600;
Height : constant := 600;
Level : constant := 7;
type Point is record X, Y : Float; end record;
B1 : constant Point := (X => ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.