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/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Rust | Rust |
fn generic_swap<'a, T>(var1: &'a mut T, var2: &'a mut T) {
std::mem::swap(var1, var2)
}
|
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Sather | Sather | class SWAP{T} is
swap(inout a, inout b:T) is
t ::= a;
a := b;
b := t;
end;
end; |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #WDTE | WDTE | let s => import 'stream';
let a => import 'arrays';
let max list =>
a.stream list
-> s.extent 1 >
-> at 0
; |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #Wortel | Wortel | @maxl [1 6 4 6 4 8 6 3] ; returns 8 |
http://rosettacode.org/wiki/Generator/Exponential | Generator/Exponential | A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the objec... | #C.2B.2B | C++ | #include <iostream>
using namespace std;
template<class T>
class Generator
{
public:
virtual T operator()() = 0;
};
// Does nothing unspecialized
template<class T, T P>
class PowersGenerator: Generator<T> {};
// Specialize with other types, or provide a generic version of pow
template<int P>
class PowersGenerat... |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Ring | Ring |
see gcd (24, 32)
func gcd gcd, b
while b
c = gcd
gcd = b
b = c % b
end
return gcd
|
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Ruby | Ruby |
40902.gcd(24140) # => 34 |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #Action.21 | Action! | DEFINE BOARDSIZE="64"
DEFINE EMPTY="'."
BYTE FUNC AbsDist(BYTE a,b)
IF a>b THEN RETURN (a-b) FI
RETURN (b-a)
BYTE FUNC GetPiece(BYTE ARRAY board BYTE x,y)
RETURN (board(x+y*8))
PROC PutPiece(BYTE ARRAY board BYTE x,y,piece)
board(x+y*8)=piece
RETURN
PROC PrintBoard(BYTE ARRAY board)
BYTE i,j,c
FOR j=0... |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #C | C | #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
typedef int bool;
char grid[8][8];
void placeKings() {
int r1, r2, c1, c2;
for (;;) {
r1 = rand() % 8;
c1 = rand() % 8;
r2 = rand() % 8;
c2 = rand... |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #11l | 11l | F genfizzbuzz(factorwords, numbers)
V sfactorwords = sorted(factorwords, key' p -> p[0])
[String] lines
L(num) numbers
V words = sfactorwords.filter2((fact, wrd) -> (@num % fact) == 0).map2((fact, wrd) -> wrd).join(‘’)
lines.append(I words != ‘’ {words} E String(num))
R lines.join("\n")
print(... |
http://rosettacode.org/wiki/Hailstone_sequence | Hailstone sequence | The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
If n is 1 then the sequence ends.
If n is even then the next n of the sequence = n/2
If n is odd then the next n of the sequence = (3 * n) + 1
The (unproven) Collatz conje... | #Scheme | Scheme | (define (collatz n)
(if (= n 1) '(1)
(cons n (collatz (if (even? n) (/ n 2) (+ 1 (* 3 n)))))))
(define (collatz-length n)
(let aux ((n n) (r 1)) (if (= n 1) r
(aux (if (even? n) (/ n 2) (+ 1 (* 3 n))) (+ r 1)))))
(define (collatz-max a b)
(let aux ((i a) (j 0) (k 0))
(if (> i b) (list j k)
(let ((h (collatz-length ... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #6502_Assembly | 6502 Assembly | ASCLOW: PHA ; push contents of registers that we
TXA ; shall be using onto the stack
PHA
LDA #$61 ; ASCII "a"
LDX #$00
ALLOOP: STA $2000,X
INX
CLC
ADC #$01
CMP #$7B ; have we got beyond ASCII "z"?
BNE A... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #68000_Assembly | 68000 Assembly |
Ascii_Low:
MOVEM.L D0/A0,-(SP) ;store D0 and A0 on stack
LEA $00100000,A0 ;could also have used MOVE.L since the address is static
MOVE.B #$61,D0 ;ascii "a"
loop_AsciiLow:
MOVE.B D0,(A0)+ ;store letter in address and increment pointer by 1
ADDQ.B #1,D0 ;add 1 to D0 to get the next letter
CMP.B #$7B,D0 ;Are we... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Nanoquery | Nanoquery | println "Hello world!" |
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Scala | Scala | def swap[A,B](a: A, b: B): (B, A) = (b, a) |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #Wren | Wren | var max = Fn.new { |a| a.reduce { |m, x| (x > m) ? x : m } }
var a = [42, 7, -5, 11.7, 58, 22.31, 59, -18]
System.print(max.call(a)) |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #XPL0 | XPL0 | include c:\cxpl\codes; \include 'code' declarations
def Tab=$09, LF=$0A, CR=$0D, EOF=$1A;
int CpuReg, Hand;
char CmdTail($80);
int I, Max, C;
[\Copy file name on command line, which is in the Program Segment Prefix (PSP)
\ ES=CpuReg(11), to the CmdTail array, which is in our Data Segment = Cpu... |
http://rosettacode.org/wiki/Generator/Exponential | Generator/Exponential | A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the objec... | #Clojure | Clojure | (defn powers [m] (for [n (iterate inc 1)] (reduce * (repeat m n)))))
(def squares (powers 2))
(take 5 squares) ; => (1 4 9 16 25) |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Run_BASIC | Run BASIC | print abs(gcd(-220,160))
function gcd(gcd,b)
while b
c = gcd
gcd = b
b = c mod b
wend
end function |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Rust | Rust | extern crate num;
use num::integer::gcd; |
http://rosettacode.org/wiki/Generate_Chess960_starting_position | Generate Chess960 starting position | Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
as in the standard chess game, all eight white pawns must be placed on the second rank.
W... | #11l | 11l | F random960()
V start = [‘R’, ‘K’, ‘R’]
L(piece) [‘Q’, ‘N’, ‘N’]
start.insert(random:(start.len + 1), piece)
V bishpos = random:(start.len + 1)
start.insert(bishpos, Char(‘B’))
start.insert(random:(bishpos + 1), Char(‘B’))
R start
print(random960()) |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #C.2B.2B | C++ |
#include <ctime>
#include <iostream>
#include <string>
#include <algorithm>
class chessBoard {
public:
void generateRNDBoard( int brds ) {
int a, b, i; char c;
for( int cc = 0; cc < brds; cc++ ) {
memset( brd, 0, 64 );
std::string pieces = "PPPPPPPPNNBBRRQKppppppppnnbbrrq... |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #Action.21 | Action! | DEFINE MAX_NUMBERS="200"
DEFINE MAX_LEN="20"
DEFINE MAX_FACTORS="5"
DEFINE PTR="CARD"
PROC PrintResult(BYTE max,n BYTE ARRAY factors PTR ARRAY texts)
BYTE i,j,t
BYTE ARRAY values(MAX_FACTORS)
FOR j=0 TO n-1
DO
values(j)=1
OD
FOR i=1 TO max
DO
t=0
FOR j=0 TO n-1
DO
IF values(j)=... |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #Ada | Ada |
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Containers.Generic_Array_Sort;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
procedure Main is
type map_element is record
... |
http://rosettacode.org/wiki/Hailstone_sequence | Hailstone sequence | The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
If n is 1 then the sequence ends.
If n is even then the next n of the sequence = n/2
If n is odd then the next n of the sequence = (3 * n) + 1
The (unproven) Collatz conje... | #Scilab | Scilab | function x=hailstone(n)
// iterative definition
// usage: global verbose; verbose=%T; hailstone(27)
global verbose
x=0; loop=%T
while(loop)
x=x+1
if verbose then
printf('%i ',n)
end
if n==1 then
loop=%F
elseif modulo(n,2)==1 then
... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #8080_Assembly | 8080 Assembly | org 100h
jmp test
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Store the lowercase alphabet as a CP/M string
;; ($-terminated), starting at HL.
;; Destroys: b, c
alph: lxi b,611ah ; set B='a' and C=26 (counter)
aloop: mov m,b ; store letter in memory
inr b ; next letter
inx h ; next memory position
... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #8086_Assembly | 8086 Assembly | bits 16
cpu 8086
org 100h
section .text
jmp demo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Store the lowercase alphabet starting at [ES:DI]
;;; Destroys AX, CX, DI
alph: mov cx,13 ; 2*13 words = 26 bytes
mov ax,'ab' ; Do two bytes at once
.loop: stosw ; Store AX at ES:DI and add 2 t... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Neat | Neat | void main() writeln "Hello world!"; |
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Scheme | Scheme | ; swap elements of a vector
; vector-swap! is not part of r5rs, so we define it
(define (vector-swap! v i j)
(let ((a (vector-ref v i)) (b (vector-ref v j)))
(vector-set! v i b)
(vector-set! v j a)))
(let ((vec (vector 1 2 3 4 5)))
(vector-swap! vec 0 4)
vec)
; #(5 2 3 4 1)
; we can swap also in lists
(define... |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #XSLT | XSLT | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="/*/*">
<!-- without data-type="number", items are sorted alphabetically -->
<xsl:sort data-type="number" order="descending"/>
<xsl:if test="position()... |
http://rosettacode.org/wiki/Generator/Exponential | Generator/Exponential | A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the objec... | #Common_Lisp | Common Lisp | (defun take (seq &optional (n 1))
(values-list (loop repeat n collect (funcall seq))))
(defun power-seq (n)
(let ((x 0))
(lambda () (expt (incf x) n))))
(defun filter-seq (s1 s2) ;; remove s2 from s1
(let ((x1 (take s1)) (x2 (take s2)))
(lambda ()
(tagbody g
(if (= x1 x2)
(progn (setf x1 ... |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Sass.2FSCSS | Sass/SCSS |
@function gcd($a,$b) {
@while $b > 0 {
$c: $a % $b;
$a: $b;
$b: $c;
}
@return $a;
}
|
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Sather | Sather | class MATH is
gcd_iter(u, v:INT):INT is
loop while!( v.bool );
t ::= u; u := v; v := t % v;
end;
return u.abs;
end;
gcd(u, v:INT):INT is
if v.bool then return gcd(v, u%v); end;
return u.abs;
end;
private swap(inout a, inout b:INT) is
t ::= a;
a := b;
b := t;
end... |
http://rosettacode.org/wiki/Generate_Chess960_starting_position | Generate Chess960 starting position | Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
as in the standard chess game, all eight white pawns must be placed on the second rank.
W... | #Action.21 | Action! | DEFINE MAX_NUMBERS="200"
DEFINE MAX_LEN="20"
DEFINE MAX_FACTORS="5"
DEFINE PTR="CARD"
PROC PrintResult(BYTE max,n BYTE ARRAY factors PTR ARRAY texts)
BYTE i,j,t
BYTE ARRAY values(MAX_FACTORS)
FOR j=0 TO n-1
DO
values(j)=1
OD
FOR i=1 TO max
DO
t=0
FOR j=0 TO n-1
DO
IF values(j)=... |
http://rosettacode.org/wiki/Generate_Chess960_starting_position | Generate Chess960 starting position | Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
as in the standard chess game, all eight white pawns must be placed on the second rank.
W... | #AutoHotkey | AutoHotkey | Loop, 5
Out .= Chess960() "`n"
MsgBox, % RTrim(Out, "`n")
Chess960() {
P := {}
P[K := Rand(2, 7)] := Chr(0x2654) ; King
P[Rand(1, K - 1)] := Chr(0x2656) ; Rook 1
P[Rand(K + 1, 8)] := Chr(0x2656) ; Rook 2
Loop, 8
Remaining .= P[A_Index] ? "" : A_Index "`n"
Sort, Remaining, Random N
P[Bishop1 := SubStr(Remain... |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #Crystal | Crystal | def hasNK(board, a, b)
(-1..1).each do |g|
(-1..1).each do |f|
aa = a + f; bb = b + g
if (0..7).includes?(aa) && (0..7).includes?(bb)
p = board[aa + 8 * bb]
return true if p == "K" || p == "k"
end
end
end
return false
end
... |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #ALGOL_68 | ALGOL 68 | BEGIN # generalised FizzBuzz #
# prompts for an integer, reads it and returns it #
PROC read integer = ( STRING prompt )INT:
BEGIN
print( ( prompt ) );
INT result;
read( ( result, newline ) );
result
... |
http://rosettacode.org/wiki/Hailstone_sequence | Hailstone sequence | The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
If n is 1 then the sequence ends.
If n is even then the next n of the sequence = n/2
If n is odd then the next n of the sequence = (3 * n) + 1
The (unproven) Collatz conje... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const func array integer: hailstone (in var integer: n) is func
result
var array integer: hSequence is 0 times 0;
begin
while n <> 1 do
hSequence &:= n;
if odd(n) then
n := 3 * n + 1;
else
n := n div 2;
end if;
end while;
hSequence ... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #8th | 8th |
"" ( 'a n:+ s:+ ) 0 25 loop
. cr
|
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #ABAP | ABAP | REPORT lower_case_ascii.
WRITE: / to_lower( sy-abcde ). |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Neko | Neko | $print("Hello world!"); |
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Seed7 | Seed7 | const proc: generate_swap (in type: aType) is func
begin
const proc: swap (inout aType: left, inout aType: right) is func
local
var aType: temp is aType.value;
begin
temp := left;
left := right;
right := temp;
end func;
end func; |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #Yabasic | Yabasic | l$ = "1,1234,62,234,12,34,6"
dim n$(1)
n = token(l$, n$(), ", ")
for i = 1 to n
t$ = n$(i)
if t$ > m$ then m$ = t$ end if // or: if t$ > m$ m$ = t$
if val(t$) > m then m = val(t$) end if // or: if val(t$) > m m = val(t$)
next
print "Alphabetic order: ", m$, ", numeric order: ", m |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #Yacas | Yacas | Max({1, 3, 3, 7})
Max({Pi,Exp(1)+2/5,17*Cos(6)/5,Sqrt(91/10)})
Max({1,6,Infinity})
Max({}) |
http://rosettacode.org/wiki/Generator/Exponential | Generator/Exponential | A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the objec... | #D | D | void main() {
import std.stdio, std.bigint, std.range, std.algorithm;
auto squares = 0.sequence!"n".map!(i => i.BigInt ^^ 2);
auto cubes = 0.sequence!"n".map!(i => i.BigInt ^^ 3);
squares.setDifference(cubes).drop(20).take(10).writeln;
} |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #S-BASIC | S-BASIC |
rem - return p mod q
function mod(p, q = integer) = integer
end = p - q * (p / q)
rem - return greatest common divisor of x and y
function gcd(x, y = integer) = integer
var r, temp = integer
if x < y then
begin
temp = x
x = y
y = temp
end
r = mod(x, y)
while r <> 0 do
begin
... |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Scala | Scala | def gcd(a: Int, b: Int): Int = if (b == 0) a.abs else gcd(b, a % b) |
http://rosettacode.org/wiki/Generate_Chess960_starting_position | Generate Chess960 starting position | Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
as in the standard chess game, all eight white pawns must be placed on the second rank.
W... | #BASIC | BASIC | for i = 1 to 10
inicio$ = "RKR"
pieza$ = "QNN"
for n = 1 to length(pieza$)
posic = int(rand*(length(inicio$) + 1)) + 1
inicio$ = left(inicio$, posic-1) + mid(pieza$, n, 1) + right(inicio$, length(inicio$) - posic + 1)
next n
posic = int(rand*(length(inicio$) + 1)) + 1
inicio$ = left(inicio$, posic... |
http://rosettacode.org/wiki/Generate_Chess960_starting_position | Generate Chess960 starting position | Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
as in the standard chess game, all eight white pawns must be placed on the second rank.
W... | #Befunge | Befunge | #.#.#.#.065*0#v_1-\>>?1v
v,":".:%*8"x"$<^!:\*2<+<
>48*,:4%2*1#v+#02#\3#g<<
v"B"*2%4:/4p<vg0:+1<\-1<
>\0p4/:6%0:0g>68*`#^_\:|
v"RKRNN"p11/6$p0\ "Q" \<
>"NRNKRRNNKRNRKNRRNKNR"v
v"NRNKRNRKNRNRKRNRNNKR"<
>"RKRNN"11g:!#v_\$\$\$\v
v _v#!`*86:g0:<^!:-1$\$<
>$\>,1+ :7`#@_^> v960v < |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #Factor | Factor | USING: combinators.short-circuit grouping io kernel math
math.parser math.ranges math.vectors prettyprint random
sequences sets splitting.monotonic strings ;
IN: rosetta-code.random-chess-position
<PRIVATE
CONSTANT: pieces "RNBQBNRPPPPPPPPrnbqbnrpppppppp"
CONSTANT: empty CHAR: .
: <empty-board> ( -- seq ) 64 [ em... |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #FreeBASIC | FreeBASIC |
Dim Shared As Byte grid(8, 8), r, c
Sub placeKings()
Dim As Byte r1, r2, c1, c2
Do
r1 = Int(Rnd*8)
c1 = Int(Rnd*8)
r2 = Int(Rnd*8)
c2 = Int(Rnd*8)
If (r1 <> r2 And Abs(r1 - r2) > 1 And Abs(c1 - c2) > 1) Then
grid(r1, c1) = Asc("K")
grid(r2, c... |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #AppleScript | AppleScript | --------------------- GENERAL FIZZBUZZ -------------------
-- fizzEtc :: [(Int, String)] -> [Symbol]
on fizzEtc(rules)
-- A non-finite sequence of fizzEtc symbols,
-- as defined by the given list of rules.
script numberOrNoise
on |λ|(n)
script ruleMatch
on |λ|(a, mk)
... |
http://rosettacode.org/wiki/Hailstone_sequence | Hailstone sequence | The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
If n is 1 then the sequence ends.
If n is even then the next n of the sequence = n/2
If n is odd then the next n of the sequence = (3 * n) + 1
The (unproven) Collatz conje... | #Sidef | Sidef | func hailstone (n) {
var sequence = [n]
while (n > 1) {
sequence << (
n.is_even ? n.div!(2)
: n.mul!(3).add!(1)
)
}
return(sequence)
}
# The hailstone sequence for the number 27
var arr = hailstone(var nr = 27)
say "#{nr}: #{arr.first(4)} ... #{arr.las... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #Action.21 | Action! | byte X
Proc Main()
For X=97 To 122
Do
Put(x)
Od
Return |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #Ada | Ada | type Lower_Case is new Character range 'a' .. 'z'; |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Nemerle | Nemerle |
class Hello
{
static Main () : void
{
System.Console.WriteLine ("Hello world!");
}
}
|
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #SenseTalk | SenseTalk |
set [x,y] to [13,"Hello"] -- assign values to two variables
put x,y
put
set [x,y] to [y,x] -- swap the variable values
put x,y
|
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Sidef | Sidef | func swap(Ref a, Ref b) {
var tmp = *a;
*a = *b;
*b = tmp;
} |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #Yorick | Yorick | > foo = [4, 3, 2, 7, 8, 9]
> max(foo)
9 |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #zkl | zkl | (1).max(1,2,3) //-->3
(66).max(1,2,3.14) //-->66 |
http://rosettacode.org/wiki/Generator/Exponential | Generator/Exponential | A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the objec... | #E | E | def genPowers(exponent) {
var i := -1
return def powerGenerator() {
return (i += 1) ** exponent
}
}
def filtered(source, filter) {
var fval := filter()
return def filterGenerator() {
while (true) {
def sval := source()
while (sval > fval) {
f... |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Scheme | Scheme | (define (gcd a b)
(if (= b 0)
a
(gcd b (modulo a b)))) |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Sed | Sed | #! /bin/sed -nf
# gcd.sed Copyright (c) 2010 by Paweł Zuzelski <pawelz@pld-linux.org>
# dc.sed Copyright (c) 1995 - 1997 by Greg Ubben <gsu@romulus.ncsc.mil>
# usage:
#
# echo N M | ./gcd.sed
#
# Computes the greatest common divisor of N and M integers using euclidean
# algorithm.
s/^/|P|K0|I10|O10|?~... |
http://rosettacode.org/wiki/Generate_Chess960_starting_position | Generate Chess960 starting position | Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
as in the standard chess game, all eight white pawns must be placed on the second rank.
W... | #C | C | #include<stdlib.h>
#include<locale.h>
#include<wchar.h>
#include<stdio.h>
#include<time.h>
char rank[9];
int pos[8];
void swap(int i,int j){
int temp = pos[i];
pos[i] = pos[j];
pos[j] = temp;
}
void generateFirstRank(){
int kPos,qPos,bPos1,bPos2,rPos1,rPos2,nPos1,nPos2,i;
for(i=0;i<8;i++){
rank[i] =... |
http://rosettacode.org/wiki/Gapful_numbers | Gapful numbers | Numbers (positive integers expressed in base ten) that are (evenly) divisible by the number formed by the
first and last digit are known as gapful numbers.
Evenly divisible means divisible with no remainder.
All one─ and two─digit numbers have this property and are trivially excluded. Only
numb... | #11l | 11l | L(start, n) [(100, 30), (1'000'000, 15), (1'000'000'000, 10)]
print("\nFirst "n‘ gapful numbers from ’start)
[Int] l
L(x) start..
I x % (Int(String(x)[0]) * 10 + (x % 10)) == 0
l.append(x)
I l.len == n
L.break
print(l) |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #Go | Go | package main
import (
"fmt"
"math/rand"
"strconv"
"strings"
"time"
)
var grid [8][8]byte
func abs(i int) int {
if i >= 0 {
return i
} else {
return -i
}
}
func createFen() string {
placeKings()
placePieces("PPPPPPPP", true)
placePieces("pppppppp", true... |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #Arturo | Arturo | maxNum: to :integer strip input "Set maximum number: "
facts: map 1..3 'x -> split.words strip input ~"Enter factor |x|: "
loop 1..maxNum 'i [
printNum: true
loop facts 'fact ->
if zero? i % to :integer fact\0 [
prints fact\1
printNum: false
]
print (printNum)? -> i -... |
http://rosettacode.org/wiki/Hailstone_sequence | Hailstone sequence | The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
If n is 1 then the sequence ends.
If n is even then the next n of the sequence = n/2
If n is odd then the next n of the sequence = (3 * n) + 1
The (unproven) Collatz conje... | #Smalltalk | Smalltalk | Object subclass: Sequences [
Sequences class >> hailstone: n [
|seq|
seq := OrderedCollection new.
seq add: n.
(n = 1) ifTrue: [ ^seq ].
(n even) ifTrue: [ seq addAll: (Sequences hailstone: (n / 2)) ]
ifFalse: [ seq addAll: (Sequences hailstone: ( (3*n) + 1 ) ) ].
^... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #ALGOL_68 | ALGOL 68 | # in ALGOL 68, a STRING is an array of characters with flexible bounds #
# so we can declare an array of 26 characters and assign a string #
# containing the lower-case letters to it #
[ 26 ]CHAR lc := "abcdefghijklmnopqrstuvwxyz"
|
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #ALGOL_W | ALGOL W | % set lc to the lower case alphabet %
string(26) lc;
for c := 0 until 25 do lc( c // 1 ) := code( decode( "a" ) + c ); |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #NetRexx | NetRexx | say 'Hello world!' |
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Slate | Slate | x@(Syntax LoadVariable traits) swapWith: y@(Syntax LoadVariable traits) &environment: env
"A macro that expands into simple code swapping the values of two variables
in the current scope."
[
env ifNil: [error: 'Cannot swap variables outside of a method'].
tmpVar ::= env addVariable.
{tmpVar store: x variable load... |
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Smalltalk | Smalltalk | OrderedCollection extend [
swap: a and: b [
|t|
t := self at: a.
self at: a put: (self at: b).
self at: b put: t
]
] |
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #Zoea | Zoea |
program: max
case: 1
input: [7,3,5,9,2,6]
output: 9
case: 2
input: [1,5,3,2,7]
output: 7
|
http://rosettacode.org/wiki/Greatest_element_of_a_list | Greatest element of a list | Task
Create a function that returns the maximum value in a provided set of values,
where the number of values may not be known until run-time.
| #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 PRINT "Values"''
20 LET z=0
30 FOR x=1 TO INT (RND*10)+1
40 LET y=RND*10-5
50 PRINT y
60 LET z=(y AND y>z)+(z AND y<z)
70 NEXT x
80 PRINT '"Max. value = ";z |
http://rosettacode.org/wiki/Generator/Exponential | Generator/Exponential | A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the objec... | #EchoLisp | EchoLisp |
(lib 'tasks) ;; for make-generator
;; generator of generators
(define (gen-power power)
(make-generator
(lambda(n) (yield (expt n power)) (1+ n)) 1))
(define powers-2 (gen-power 2))
(define powers-3 (gen-power 3))
(take powers-3 10)
→ (1 8 27 64 125 216 343 512 729 1000)
;; generators substraction
;; ... |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Seed7 | Seed7 | const func integer: gcd (in var integer: a, in var integer: b) is func
result
var integer: gcd is 0;
local
var integer: help is 0;
begin
while a <> 0 do
help := b rem a;
b := a;
a := help;
end while;
gcd := b;
end func; |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #SequenceL | SequenceL | gcd(a, b) :=
a when b = 0
else
gcd(b, a mod b); |
http://rosettacode.org/wiki/Generate_Chess960_starting_position | Generate Chess960 starting position | Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
as in the standard chess game, all eight white pawns must be placed on the second rank.
W... | #C.2B.2B | C++ | #include <iostream>
#include <string>
#include <time.h>
using namespace std;
namespace
{
void placeRandomly(char* p, char c)
{
int loc = rand() % 8;
if (!p[loc])
p[loc] = c;
else
placeRandomly(p, c); // try again
}
int placeFirst(char* p, char c, int loc = 0)
{
while (p[loc]) ++lo... |
http://rosettacode.org/wiki/Gapful_numbers | Gapful numbers | Numbers (positive integers expressed in base ten) that are (evenly) divisible by the number formed by the
first and last digit are known as gapful numbers.
Evenly divisible means divisible with no remainder.
All one─ and two─digit numbers have this property and are trivially excluded. Only
numb... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
procedure Gapful_Numbers is
function Divisor (N : in Positive) return Positive is
NN : Positive := N;
begin
while NN >= 10 loop
NN := NN / 10;
end loop;
return 10 * NN + (N mod 10);
end Divisor;
function Is_Gapful (N : in Positive) r... |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #Haskell | Haskell | {-# LANGUAGE LambdaCase, TupleSections #-}
module RandomChess
( placeKings
, placePawns
, placeRemaining
, emptyBoard
, toFen
, ChessBoard
, Square (..)
, BoardState (..)
, getBoard
)
where
import Control.Monad.State (State, get, gets, put)
import Data.List (find, sortBy)
import System.Random (Random, RandomGen, St... |
http://rosettacode.org/wiki/Gauss-Jordan_matrix_inversion | Gauss-Jordan matrix inversion | Task
Invert matrix A using Gauss-Jordan method.
A being an n × n matrix.
| #11l | 11l | V Eps = 1e-10
F transformToRref(&mat)
V lead = 0
L(r) 0 .< mat.len
I lead >= mat[0].len
R
V i = r
L mat[i][lead] == 0
i++
I i == mat.len
i = r
lead++
I lead == mat[0].len
R
swap(&mat[i], &mat[r])
V ... |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #AutoHotkey | AutoHotkey | ; Test parameters
max := 20, fizz := 3, buzz := 5, baxx := 7
Loop % max {
output := ""
if (Mod(A_Index, fizz) = 0)
output .= "Fizz"
if (Mod(A_Index, buzz) = 0)
output .= "Buzz"
if (Mod(A_Index, baxx) = 0)
output .= "Baxx"
if (output = "")
FileAppend %A_Index%`n, *
else
FileAppend %output%`n, *
}
|
http://rosettacode.org/wiki/Hailstone_sequence | Hailstone sequence | The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
If n is 1 then the sequence ends.
If n is even then the next n of the sequence = n/2
If n is odd then the next n of the sequence = (3 * n) + 1
The (unproven) Collatz conje... | #SNUSP | SNUSP | /@+@@@+++# 27
| halve odd /===count<<\ /recurse\ #/?\ zero
$>@/===!/===-?\==>?!/-<+++\ \!/=!\@\>?!\@/<@\.!\-/
/+<-\!>\?-<+>/++++<\?>+++/*6+4 | | \=/ \=itoa=@@@+@+++++#
\=>?/<=!=\ | | ! /+ !/+ !/+ !/+ \ mod10
|//!==/========\ | /<+> -\!?-\!?-... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #APL | APL | ⎕UCS 96+⍳26 |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #AppleScript | AppleScript | -------------------- ALPHABETIC SERIES -------------------
on run
unlines(map(concat, ¬
({enumFromTo("a", "z"), ¬
enumFromTo("🐟", "🐐"), ¬
enumFromTo("z", "a"), ¬
enumFromTo("α", "ω")})))
end run
-------------------- GENERIC FUNCTIONS -------------------
-- concat ::... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #Never | Never | func main() -> int {
prints("Hello world!\n");
0
} |
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #SNOBOL4 | SNOBOL4 | * SWAP(.V1, .V2) - Exchange the contents of two variables.
* The variables must be prefixed with the name operator
* when the function is called.
DEFINE('SWAP(X,Y)TEMP') :(SWAP_END)
SWAP TEMP = $X
$X = $Y
$Y = TEMP :(RETURN)
SWAP_END |
http://rosettacode.org/wiki/Generic_swap | Generic swap | Task
Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types.
If your solution language is statically typed please describe the way your language provides genericity.
If variables are typed in t... | #Standard_ML | Standard ML | fun swap (x, y) = (y, x) |
http://rosettacode.org/wiki/Generator/Exponential | Generator/Exponential | A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the objec... | #Elixir | Elixir | defmodule Generator do
def filter( source_pid, remove_pid ) do
first_remove = next( remove_pid )
spawn( fn -> filter_loop(source_pid, remove_pid, first_remove) end )
end
def next( pid ) do
send(pid, {:next, self})
receive do
x -> x
end
end
def power( m ), do: spawn( fn -> power_l... |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #SETL | SETL | a := 33; b := 77;
print(" the gcd of",a," and ",b," is ",gcd(a,b));
c := 49865; d := 69811;
print(" the gcd of",c," and ",d," is ",gcd(c,d));
proc gcd (u, v);
return if v = 0 then abs u else gcd (v, u mod v) end;
end; |
http://rosettacode.org/wiki/Greatest_common_divisor | Greatest common divisor | Greatest common divisor
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find the greatest common divisor (GCD) of two integers.
Greatest common divisor is also known as greatest common factor (gcf) and greatest common measure.
Related tas... | #Sidef | Sidef | var arr = [100, 1_000, 10_000, 20];
say Math.gcd(arr...); |
http://rosettacode.org/wiki/Generate_Chess960_starting_position | Generate Chess960 starting position | Chess960 is a variant of chess created by world champion Bobby Fischer. Unlike other variants of the game, Chess960 does not require a different material, but instead relies on a random initial position, with a few constraints:
as in the standard chess game, all eight white pawns must be placed on the second rank.
W... | #Clojure | Clojure | (ns c960.core
(:gen-class)
(:require [clojure.string :as s]))
;; legal starting rank - unicode chars for rook, knight, bishop, queen, king, bishop, knight, rook
(def starting-rank [\♖ \♘ \♗ \♕ \♔ \♗ \♘ \♖])
(defn bishops-legal?
"True if Bishops are odd number of indicies apart"
[rank]
(odd? (apply - (cons... |
http://rosettacode.org/wiki/Gapful_numbers | Gapful numbers | Numbers (positive integers expressed in base ten) that are (evenly) divisible by the number formed by the
first and last digit are known as gapful numbers.
Evenly divisible means divisible with no remainder.
All one─ and two─digit numbers have this property and are trivially excluded. Only
numb... | #ALGOL_68 | ALGOL 68 | BEGIN # find some gapful numbers - numbers divisible by f*10 + b #
# where f is the first digit and b is the final digit #
# unary GAPFUL operator - returns TRUE if n is gapful #
# FALSE otherwise #
OP GAPFUL = ( INT n )BOOL:
BEGIN
... |
http://rosettacode.org/wiki/Generate_random_chess_position | Generate random chess position | Task
Generate a random chess position in FEN format.
The position does not have to be realistic or even balanced, but it must comply to the following rules:
there is one and only one king of each color (one black king and one white king);
the kings must not be placed on adjacent squares;
there can not be any p... | #J | J | getlayout=:3 :0
whilst. NB. first two positions are non-adjacent kings
(0{pos) e. (1{pos)+(,-)1 7 8 9
do.
pos=: y?64
end.
)
randboard=:3 :0
n=: ?30 NB. number of non-king pieces on board
layout=: getlayout 2+n NB. where they go
white=: 0 1,?n#2 NB. which ones are white?
pawns=: 0 0,?n... |
http://rosettacode.org/wiki/Gauss-Jordan_matrix_inversion | Gauss-Jordan matrix inversion | Task
Invert matrix A using Gauss-Jordan method.
A being an n × n matrix.
| #360_Assembly | 360 Assembly | * Gauss-Jordan matrix inversion 17/01/2021
GAUSSJOR CSECT
USING GAUSSJOR,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
SAVE (14,12) save previous context
ST R13,4(R15) link backward
... |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #AWK | AWK | 105
3 Fizz
5 Buzz
7 Baxx |
http://rosettacode.org/wiki/General_FizzBuzz | General FizzBuzz | Task
Write a generalized version of FizzBuzz that works for any list of factors, along with their words.
This is basically a "fizzbuzz" implementation where the user supplies the parameters.
The user will enter the max number, then they will enter the factors to be calculated along with the corresponding word to be ... | #Batch_File | Batch File | @echo off
rem input range
set /p "range=> "
rem input data (no error-checking)
set "data_ctr=0"
:input_loop
set "data="
set /p "data=> "
if "%data%" equ "" goto count
rem parsing data into 1-based pseudo-array
set /a "data_ctr+=1"
for /f "tokens=1-2 delims= " %%D in ("%data%") do (
set "facto%data_ctr%=%%D"
set ... |
http://rosettacode.org/wiki/Hailstone_sequence | Hailstone sequence | The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
If n is 1 then the sequence ends.
If n is even then the next n of the sequence = n/2
If n is odd then the next n of the sequence = (3 * n) + 1
The (unproven) Collatz conje... | #Swift | Swift |
func hailstone(var n:Int) -> [Int] {
var arr = [n]
while n != 1 {
if n % 2 == 0 {
n /= 2
} else {
n = (3 * n) + 1
}
arr.append(n)
}
return arr
}
let n = hailstone(27)
println("hailstone(27): \(n[0...3]) ... \(n[n.count-4...n.cou... |
http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet | Generate lower case ASCII alphabet | Task
Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence.
For this basic task use a reliable style of coding, a sty... | #Applesoft_BASIC | Applesoft BASIC | L$="abcdefghijklmnopqrstuvwxyz" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.