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/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...
#ARM_Assembly
ARM Assembly
ProgramStart: mov sp,#0x03000000 ;Init Stack Pointer   mov r4,#0x04000000 ;DISPCNT -LCD Control mov r2,#0x403 ;4= Layer 2 on / 3= ScreenMode 3 str r2,[r4] ;hardware specific routine, activates Game Boy's bitmap mode   mov r0,#0x61 ;ASCII "a" mov r2,#ramarea mov r1,#...
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
#newLISP
newLISP
(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...
#Stata
Stata
mata a=1,2,3 b="ars longa vita brevis" swap(a, b) 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...
#Swift
Swift
func swap<T>(inout a: T, inout b: T) { (a, b) = (b, a) }
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...
#Emacs_Lisp
Emacs Lisp
;; lexical-binding: t (require 'generator)   (iter-defun exp-gen (pow) (let ((i -1)) (while (setq i (1+ i)) (iter-yield (expt i pow)))))   (iter-defun flt-gen () (let* ((g (exp-gen 2)) (f (exp-gen 3)) (i (iter-next g)) (j (iter-next f))) (while (setq i (iter-next g)) (while (> ...
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...
#Simula
Simula
BEGIN INTEGER PROCEDURE GCD(a, b); INTEGER a, b; BEGIN IF a = 0 THEN a := b ELSE WHILE 0 < b DO BEGIN INTEGER i; i := MOD(a, b); a := b; b := i; END; GCD := a END;   INTEGER a, b;  !outint(SYSOUT.IMAGE.MAIN.LENGTH, 0);!OUTIMAGE;!OUTIMAGE...
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...
#Slate
Slate
40902 gcd: 24140
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...
#Common_Lisp
Common Lisp
(defun chess960-from-sp-id (&optional (sp-id (random 360 (make-random-state t)))) (labels ((combinations (lst r) (cond ((numberp lst) (combinations (loop for i from 0 while (< i lst) collect i) r)) ((= r 1) (mapcar #'list lst)) (t ...
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...
#AppleScript
AppleScript
on isGapful(n) set units to n mod 10 set temp to n div 10 repeat until (temp < 10) set temp to temp div 10 end repeat   return (n mod (temp * 10 + units) = 0) end isGapful   -- Task code: on getGapfuls(n, q) set collector to {} repeat until ((count collector) = q) if (isGapfu...
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...
#Java
Java
import static java.lang.Math.abs; import java.util.Random;   public class Fen { static Random rand = new Random();   public static void main(String[] args) { System.out.println(createFen()); }   static String createFen() { char[][] grid = new char[8][8];   placeKings(grid); ...
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.
#ALGOL_60
ALGOL 60
begin comment Gauss-Jordan matrix inversion - 22/01/2021; integer n; n:=4; begin procedure rref(m); real array m; begin integer r, c, i; real d, w; for r := 1 step 1 until n do begin d := m[r,r]; if d notequal 0 then ...
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 ...
#BBC_BASIC
BBC BASIC
REM >genfizzb INPUT "Maximum number: " max% INPUT "Number of factors: " n% DIM factors%(n% - 1) DIM words$(n% - 1) FOR i% = 0 TO n% - 1 INPUT "> " factor$ factors%(i%) = VAL(LEFT$(factor$, INSTR(factor$, " ") - 1)) words$(i%) = MID$(factor$, INSTR(factor$, " ") + 1) NEXT FOR i% = 1 TO max% matched% = FA...
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 ...
#BQN
BQN
GenFizzBuzz ← {factors‿words ← <˘⍉>𝕨 ⋄ (∾´∾⟜words/˜·(¬∨´)⊸∾0=factors|⊢)¨1+↕𝕩}
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...
#Tcl
Tcl
proc hailstone n { while 1 { lappend seq $n if {$n == 1} {return $seq} set n [expr {$n & 1 ? $n*3+1 : $n/2}] } }   set h27 [hailstone 27] puts "h27 len=[llength $h27]" puts "head4 = [lrange $h27 0 3]" puts "tail4 = [lrange $h27 end-3 end]"   set maxlen [set max 0] for {set i 1} {$i<100000} {incr i} { set...
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...
#Arturo
Arturo
print to [:char] 97..122
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...
#ATS
ATS
  (* ****** ****** *) // // How to compile: // // patscc -DATS_MEMALLOC_LIBC -o lowercase lowercase.dats // (* ****** ****** *) // #include "share/atspre_staload.hats" // (* ****** ****** *)   implement main0 () = { // val N = 26 // val A = arrayref_tabulate_cloref<char> ( i2sz(N), lam(i) => int2char0(char2int0('a') ...
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
#Nickle
Nickle
printf("Hello world!\n")
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...
#Tcl
Tcl
proc swap {aName bName} { upvar 1 $aName a $bName b lassign [list $a $b] b a }
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...
#Erlang
Erlang
  -module( generator ).   -export( [filter/2, next/1, power/1, task/0] ).   filter( Source_pid, Remove_pid ) -> First_remove = next( Remove_pid ), erlang:spawn( fun() -> filter_loop(Source_pid, Remove_pid, First_remove) end ).   next( Pid ) -> Pid ! {next, erlang:self()}, receive X -> X end.   power( M...
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...
#Smalltalk
Smalltalk
(40902 gcd: 24140) displayNl
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...
#SNOBOL4
SNOBOL4
define('gcd(i,j)') :(gcd_end) gcd ?eq(i,0) :s(freturn) ?eq(j,0) :s(freturn)   loop gcd = remdr(i,j) gcd = ?eq(gcd,0) j :s(return) i = j j = gcd :(loop) gcd_end   output = gcd(1071,1029) 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...
#D
D
void main() { import std.stdio, std.range, std.algorithm, std.string, permutations2;   const pieces = "KQRrBbNN"; alias I = indexOf; auto starts = pieces.dup.permutations.filter!(p => I(p, 'B') % 2 != I(p, 'b') % 2 && // Bishop constraint. // King constraint. ((I(p, '...
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...
#Arturo
Arturo
gapful?: function [n][ s: to :string n divisor: to :integer (first s) ++ last s 0 = n % divisor ]   specs: [100 30, 1000000 15, 1000000000 10, 7123 25]   loop specs [start,count][ print "----------------------------------------------------------------" print ["first" count "gapful numbers starting...
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...
#JavaScript
JavaScript
  Array.prototype.shuffle = function() { for (let i = this.length - 1; i > 0; i--) { let j = Math.floor(Math.random() * (i + 1)); [this[i], this[j]] = [this[j], this[i]]; } }   function randomFEN() {   let board = []; for (let x = 0; x < 8; x++) board.push('. . . . . . . .'.split(' '));   function get...
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.
#ALGOL_68
ALGOL 68
BEGIN # Gauss-Jordan matrix inversion # PROC rref = ( REF[,]REAL m )VOID: BEGIN INT n = 1 UPB m; FOR r TO n DO REAL d = m[ r, r ]; IF d /= 0 THEN FOR c TO n * 2 DO m[ r, c ] := m[ r, c ] / d OD ELSE ...
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 ...
#C
C
  #include <stdio.h> #include <stdlib.h>   struct replace_info { int n; char *text; };   int compare(const void *a, const void *b) { struct replace_info *x = (struct replace_info *) a; struct replace_info *y = (struct replace_info *) b; return x->n - y->n; }   void generic_fizz_buzz(int max, struct ...
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...
#TI-83_BASIC
TI-83 BASIC
prompt N N→M: 0→X: 1→L While L=1 X+1→X Disp M If M=1 Then: 0→L Else If remainder(M,2)=1 Then: 3*M+1→M Else: M/2→M End End End {N,X}
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...
#AutoHotkey
AutoHotkey
a :={} Loop, 26 a.Insert(Chr(A_Index + 96))
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
#Nim
Nim
echo("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...
#ThinBASIC
ThinBASIC
Swap Var1, Var2
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...
#F.23
F#
let m n = Seq.unfold(fun i -> Some(bigint.Pow(i, n), i + 1I)) 0I   let squares = m 2 let cubes = m 3   let (--) orig veto = Seq.where(fun n -> n <> (Seq.find(fun m -> m >= n) veto)) orig   let ``squares without cubes`` = squares -- cubes   Seq.take 10 (Seq.skip 20 (``squares without cubes``)) |> Seq.toList |> printfn "...
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...
#Sparkling
Sparkling
function factors(n) { var f = {};   for var i = 2; n > 1; i++ { while n % i == 0 { n /= i; f[i] = f[i] != nil ? f[i] + 1 : 1; } }   return f; }   function GCD(n, k) { let f1 = factors(n); let f2 = factors(k);   let fs = map(f1, function(factor, multiplicity) { let m = f2[factor]; return m == nil ? ...
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...
#SQL
SQL
DROP TABLE tbl; CREATE TABLE tbl ( u NUMBER, v NUMBER );   INSERT INTO tbl ( u, v ) VALUES ( 20, 50 ); INSERT INTO tbl ( u, v ) VALUES ( 21, 50 ); INSERT INTO tbl ( u, v ) VALUES ( 21, 51 ); INSERT INTO tbl ( u, v ) VALUES ( 22, 50 ); INSERT INTO tbl ( u, v ) VALUES ( 22, 55 );   commit;   W...
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...
#EchoLisp
EchoLisp
(define-values (K Q R B N) (iota 5)) (define *pos* (list R N B Q K B N R)) ;; standard starter   ;; check opposite color bishops, and King between rooks (define (legal-pos p) (and (> (list-index K p) (list-index R p)) (> (list-index K (reverse p)) (list-index R (reverse p))) (eve...
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...
#AutoHotkey
AutoHotkey
Gapful_numbers(Min, Qty){ counter:= 0, output := "" while (counter < Qty){ n := A_Index+Min-1 d := SubStr(n, 1, 1) * 10 + SubStr(n, 0) if (n/d = Floor(n/d)) output .= ++counter ": " n "`t" n " / " d " = " Format("{:d}", n/d) "`n" } return output }
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...
#Julia
Julia
module Chess   using Printf   struct King end struct Pawn end   function placepieces!(grid, ::King) axis = axes(grid, 1) while true r1, c1, r2, c2 = rand(axis, 4) if r1 != r2 && abs(r1 - r2) > 1 && abs(c1 - c2) > 1 grid[r1, c1] = '♚' grid[r2, c2] = '♔' return ...
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...
#Kotlin
Kotlin
// version 1.2.0   import java.util.Random import kotlin.math.abs   val rand = Random()   val grid = List(8) { CharArray(8) }   const val NUL = '\u0000'   fun createFen(): String { placeKings() placePieces("PPPPPPPP", true) placePieces("pppppppp", true) placePieces("RNBQBNR", false) placePieces("rnb...
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.
#C
C
/*---------------------------------------------------------------------- gjinv - Invert a matrix, Gauss-Jordan algorithm A is destroyed. Returns 1 for a singular matrix.   ___Name_____Type______In/Out____Description_____________________________ a[n*n] double* In An N by N matrix n int In ...
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 ...
#C.23
C#
  using System;   public class GeneralFizzBuzz { public static void Main() { int i; int j; int k;   int limit;   string iString; string jString; string kString;   Console.WriteLine("First integer:"); i = Convert.ToInt32(Console.ReadLine())...
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...
#Transd
Transd
#lang transd   MainModule: { hailstone: (λ n Int() (with seq Vector<Int>([n]) (while (> n 1) (= n (if (mod n 2) (+ (* 3 n) 1) else (/ n 2))) (append seq n) ) (ret seq) ) ),   _start: (λ (with h...
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...
#AutoIt
AutoIt
  Func _a2z() Local $a2z = "" For $i = 97 To 122 $a2z &= Chr($i) Next Return $a2z EndFunc  
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
#Nit
Nit
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...
#TI-89_BASIC
TI-89 BASIC
Define swap(swapvar1, swapvar2) = Prgm Local swaptmp #swapvar1 → swaptmp #swapvar2 → #swapvar1 swaptmp → #swapvar2 EndPrgm   1 → x 2 → y swap("x", "y") x 2 y 1
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...
#Tiny_BASIC
Tiny BASIC
LET a = 11 LET b = 22 PRINT a, " ", b GOSUB 100 PRINT a, " ", b END   100 REM swap(a, b) LET t = a LET a = b LET b = t RETURN
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...
#Factor
Factor
USING: fry kernel lists lists.lazy math math.functions prettyprint ; IN: rosetta-code.generator-exponential   : mth-powers-generator ( m -- lazy-list ) [ 0 lfrom ] dip [ ^ ] curry lmap-lazy ;   : lmember? ( elt list -- ? ) over '[ unswons dup _ >= ] [ drop ] until nip = ;   : 2-not-3-generator ( -- lazy-list ) ...
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...
#Standard_ML
Standard ML
(* Euclid’s algorithm. *)   fun gcd (u, v) = let fun loop (u, v) = if v = 0 then u else loop (v, u mod v) in loop (abs u, abs v) end   (* Using the Rosetta Code example for assertions in Standard ML. *) fun assert cond = if cond the...
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...
#Stata
Stata
function gcd(a_,b_) { a = abs(a_) b = abs(b_) while (b>0) { a = mod(a,b) swap(a,b) } return(a) }
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...
#Elixir
Elixir
defmodule Chess960 do @pieces ~w(♔ ♕ ♘ ♘ ♗ ♗ ♖ ♖) # ~w(K Q N N B B R R) @regexes [~r/♗(..)*♗/, ~r/♖.*♔.*♖/] # [~r/B(..)*B/, ~r/R.*K.*R/]   def shuffle do row = Enum.shuffle(@pieces) |> Enum.join if Enum.all?(@regexes, &Regex.match?(&1, row)), do: row, else: shuffle end end   Enum.e...
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...
#Factor
Factor
USING: io kernel math random sequences ; IN: rosetta-code.chess960   : empty ( seq -- n ) 32 swap indices random ;  ! return a random empty index (i.e. equal to 32) of seq : next ( seq -- n ) 32 swap index ;  ! return the leftmost empty index of seq : place ( seq elt n -- seq' ) rot [ set-nt...
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...
#AWK
AWK
  # syntax: GAWK -f GAPFUL_NUMBERS.AWK # converted from C++ BEGIN { show_gapful(100,30) show_gapful(1000000,15) show_gapful(1000000000,10) show_gapful(7123,25) exit(0) } function is_gapful(n, m) { m = n while (m >= 10) { m = int(m / 10) } return(n % ((n % 10) + 10 * (m % 10)) ...
http://rosettacode.org/wiki/Gaussian_elimination
Gaussian elimination
Task Solve   Ax=b   using Gaussian elimination then backwards substitution. A   being an   n by n   matrix. Also,   x and b   are   n by 1   vectors. To improve accuracy, please use partial pivoting and scaling. See also   the Wikipedia entry:   Gaussian elimination
#11l
11l
F swap_row(&a, &b, r1, r2) I r1 != r2 swap(&a[r1], &a[r2]) swap(&b[r1], &b[r2])   F gauss_eliminate(&a, &b) L(dia) 0 .< a.len V (max_row, max) = (dia, a[dia][dia]) L(row) dia+1 .< a.len V tmp = abs(a[row][dia]) I tmp > max (max_row, max) = (row, tmp)   s...
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
g = ConstantArray["", {8, 8}]; While[Norm@First@Differences[r = RandomChoice[Tuples[Range[8], 2], 2]] <= Sqrt[2], Null]; g = ReplacePart[g, {r[[1]] -> "K", r[[2]] -> "k"}]; avail = Position[g, "", {2}]; n = RandomInteger[{2, 14}]; rls = Thread[RandomSample[avail, n] -> RandomChoice[Characters@"NBRQnbrq", n]]; g = Repla...
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...
#Nim
Nim
import random   type   Piece {.pure.} = enum None WhiteBishop = ('B', "♗") WhiteKing = ('K', "♔") WhiteKnight = ('N', "♘") WhitePawn = ('P', "♙") WhiteQueen = ('Q', "♕") WhiteRook = ('R', "♖") BlackBishop = ('b', "♝") BlackKing = ('k', "♚") BlackKnight = ('n', "♞") BlackPaw...
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.
#C.23
C#
  using System;   namespace Rosetta { internal class Vector { private double[] b; internal readonly int rows;   internal Vector(int rows) { this.rows = rows; b = new double[rows]; }   internal Vector(double[] initArray) { ...
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 ...
#C.2B.2B
C++
  #include <algorithm> #include <iostream> #include <vector> #include <string>   class pair { public: pair( int s, std::string z ) { p = std::make_pair( s, z ); } bool operator < ( const pair& o ) const { return i() < o.i(); } int i() const { return p.first; } std::...
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...
#TXR
TXR
@(do (defun hailstone (n) (cons n (gen (not (eq n 1)) (set n (if (evenp n) (trunc n 2) (+ (* 3 n) 1))))))) @(next :list @(mapcar* (fun tostring) (hailstone 27))) 27 82 41 124 @(skip) 8 4 2 1 @(eof) @(do (let ((max 0) maxi) ...
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...
#AWK
AWK
  # syntax: GAWK -f GENERATE_LOWER_CASE_ASCII_ALPHABET.AWK BEGIN { for (i=0; i<=255; i++) { c = sprintf("%c",i) if (c ~ /[[:lower:]]/) { lower_chars = lower_chars c } } printf("%s %d: %s\n",ARGV[0],length(lower_chars),lower_chars) exit(0) }  
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#Nix
Nix
"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...
#Trith
Trith
swap
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...
#True_BASIC
True BASIC
SUB SWAP(a, b) LET temp = a LET a = b LET b = temp END SUB   LET a = 1 LET b = 2   PRINT a, b CALL SWAP(a, b) PRINT a, b END
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...
#Fantom
Fantom
  class Main { // Create and return a function which generates mth powers when called |->Int| make_generator (Int m) { current := 0 return |->Int| { current += 1 return (current-1).pow (m) } }   |->Int| squares_without_cubes () { squares := make_generator (2) cubes := mak...
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...
#Swift
Swift
// Iterative   func gcd(var a: Int, var b: Int) -> Int {   a = abs(a); b = abs(b)   if (b > a) { swap(&a, &b) }   while (b > 0) { (a, b) = (b, a % b) }   return a }   // Recursive   func gcdr (var a: Int, var b: Int) -> Int {   a = abs(a); b = abs(b)   if (b > a) { swap(&a, &b) }   return gc...
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...
#Tcl
Tcl
package require Tcl 8.5 namespace path {::tcl::mathop ::tcl::mathfunc} proc gcd_iter {p q} { while {$q != 0} { lassign [list $q [% $p $q]] p q } abs $p }
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...
#Forth
Forth
\ make starting position for Chess960, constructive   \ 0 1 2 3 4 5 6 7 8 9 create krn S" NNRKRNRNKRNRKNRNRKRNRNNKRRNKNRRNKRNRKNNRRKNRNRKRNN" mem,   create pieces 8 allot   : chess960 ( n -- ) pieces 8 erase 4 /mod swap 2* 1+ pieces + 'B swap c! 4 /mod swap 2* pieces + ...
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...
#Fortran
Fortran
program chess960 implicit none   integer, pointer :: a,b,c,d,e,f,g,h integer, target :: p(8) a => p(1) b => p(2) c => p(3) d => p(4) e => p(5) f => p(6) g => p(7) h => p(8)   king: do a=2,7 ! King on an internal square r1:...
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...
#BASIC256
BASIC256
function is_gapful(n) m = n l = n mod 10 while (m >= 10) m = int(m / 10) end while return (m * 10) + l end function   subroutine muestra_gapful(n, gaps) inc = 0 print "Primeros "; gaps; " números gapful >= "; n while inc < gaps if n mod is_gapful(n) = 0 then print " " ; n ; inc = inc + 1 end if n ...
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...
#C
C
  #include<stdio.h>   void generateGaps(unsigned long long int start,int count){   int counter = 0; unsigned long long int i = start; char str[100];   printf("\nFirst %d Gapful numbers >= %llu :\n",count,start);   while(counter<count){ sprintf(str,"%llu",i); if((i%(10*(str[0]-'0') + ...
http://rosettacode.org/wiki/Gaussian_elimination
Gaussian elimination
Task Solve   Ax=b   using Gaussian elimination then backwards substitution. A   being an   n by n   matrix. Also,   x and b   are   n by 1   vectors. To improve accuracy, please use partial pivoting and scaling. See also   the Wikipedia entry:   Gaussian elimination
#360_Assembly
360 Assembly
* Gaussian elimination 09/02/2019 GAUSSEL CSECT USING GAUSSEL,R13 base register B 72(R15) skip savearea DC 17F'0' savearea SAVE (14,12) save previous context ST R13,4(R15) link backward ST...
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...
#Perl
Perl
use strict; use warnings; use feature 'say'; use utf8; use List::AllUtils <shuffle any natatime>;   sub pick1 { return @_[rand @_] }   sub gen_FEN { my $n = 1 + int rand 31; my @n = (shuffle(0 .. 63))[1 .. $n];   my @kings;   KINGS: { for my $a (@n) { for my $b (@n) { next unless $...
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.
#C.2B.2B
C++
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector>   template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {}   matrix(size_t rows, size_t columns, scalar_type 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 ...
#Cach.C3.A9_ObjectScript
Caché ObjectScript
GENFIZBUZZ(MAX,WORDS,NUMBERS)  ; loop until max, casting numeric to avoid errors for i=1:1:+MAX { set j = 1 set descr = ""    ; assumes NUMBERS parameter is comma-delimited while (j <= $length(NUMBERS,",")) { if ((i # $piece(NUMBERS,",",j,j)) = 0) {    ; ...
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 ...
#Ceylon
Ceylon
shared void run() {   print("enter the max value"); assert(exists maxLine = process.readLine(), exists max = parseInteger(maxLine));   print("enter your number/word pairs enter a blank line to stop");   variable value divisorsToWords = map<Integer, String> {};   while(true) { value line = process.read...
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...
#uBasic.2F4tH
uBasic/4tH
' ------=< MAIN >=------   m = 0 Proc _hailstone_print(27) Print   For x = 1 To 10000 n = Func(_hailstone(x)) If n > m Then t = x m = n EndIf Next   Print "The longest sequence is for "; t; ", it has a sequence length of "; m   End   _hailstone_print Param (1) ' print the number and seq...
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...
#BASIC
BASIC
DIM lower&(25) FOR i%=0TO25 lower&(i%)=ASC"a"+i% NEXT END
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...
#Batch_File
Batch File
  @echo off setlocal enabledelayedexpansion :: This code appends the ASCII characters from 97-122 to %alphabet%, removing any room for error.   for /l %%i in (97,1,122) do ( cmd /c exit %%i set "alphabet=!alphabet! !=exitcodeAscii!" ) echo %alphabet% pause>nul  
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
#NLP.2B.2B
NLP++
  @CODE "output.txt" << "Hello world!"; @@CODE  
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...
#TXR
TXR
(defmacro swp (left right) (with-gensyms (tmp) ^(let ((,tmp ,left)) (set ,left ,right ,right ,tmp))))
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...
#uBasic.2F4tH
uBasic/4tH
a = 5 : b = 7 Print a,b Push a,b : a = Pop() : b = Pop() Print a,b
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...
#Forth
Forth
  \ genexp-rcode.fs Generator/Exponential for RosettaCode.org   \ Generator/filter implementation using return stack as continuations stack : ENTER ( cont.addr --  ;borrowed from M.L.Gasanenko papers) >R ; : | ( f --  ;true->go ahead, false->return into generator ) IF EXIT THEN R> ...
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...
#TI-83_BASIC.2C_TI-89_BASIC
TI-83 BASIC, TI-89 BASIC
gcd(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...
#Tiny_BASIC
Tiny BASIC
10 PRINT "First number" 20 INPUT A 30 PRINT "Second number" 40 INPUT B 50 IF A<0 THEN LET A=-A 60 IF B<0 THEN LET B=-B 70 IF A>B THEN GOTO 130 80 LET B = B - A 90 IF A=0 THEN GOTO 110 100 GOTO 50 110 PRINT B 120 END 130 LET C=A 140 LET A=B 150 LET B=C 160 GOTO 70
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...
#Go
Go
package main   import ( "fmt" "math/rand" )   type symbols struct{ k, q, r, b, n rune }   var A = symbols{'K', 'Q', 'R', 'B', 'N'} var W = symbols{'♔', '♕', '♖', '♗', '♘'} var B = symbols{'♚', '♛', '♜', '♝', '♞'}   var krn = []string{ "nnrkr", "nrnkr", "nrknr", "nrkrn", "rnnkr", "rnknr", "rnkrn", "r...
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...
#C.2B.2B
C++
#include <iostream>   bool gapful(int n) { int m = n; while (m >= 10) m /= 10; return n % ((n % 10) + 10 * (m % 10)) == 0; }   void show_gapful_numbers(int n, int count) { std::cout << "First " << count << " gapful numbers >= " << n << ":\n"; for (int i = 0; i < count; ++n) { if (gap...
http://rosettacode.org/wiki/Gaussian_elimination
Gaussian elimination
Task Solve   Ax=b   using Gaussian elimination then backwards substitution. A   being an   n by n   matrix. Also,   x and b   are   n by 1   vectors. To improve accuracy, please use partial pivoting and scaling. See also   the Wikipedia entry:   Gaussian elimination
#Ada
Ada
with Ada.Text_IO; with Ada.Numerics.Generic_Real_Arrays;   procedure Gaussian_Eliminations is   type Real is new Float;   package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real); use Real_Arrays;   function Gaussian_Elimination (A : in Real_Matrix; B : in 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...
#Phix
Phix
with javascript_semantics constant show_bad_boards = false string board function fen() string res = "" for i=1 to 64 by 8 do integer empty = 0 for j=i to i+7 do if board[j]='.' then empty += 1 else if empty then res ...
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.
#Factor
Factor
USING: kernel math.matrices math.matrices.elimination prettyprint sequences ;   ! Augment a matrix with its identity. E.g. ! ! 1 2 3 1 2 3 1 0 0 ! 4 5 6 augment-identity -> 4 5 6 0 1 0 ! 7 8 9 7 8 9 0 0 1   : augment-identity ( matrix -- new-matrix ) dup first length...
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 ...
#Clojure
Clojure
(defn fix [pairs] (map second pairs))   (defn getvalid [pairs n] (filter (fn [p] (zero? (mod n (first p)))) (sort-by first pairs)))   (defn gfizzbuzz [pairs numbers] (interpose "\n" (map (fn [n] (let [f (getvalid pairs n)] (if (empty? f) ...
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...
#UNIX_Shell
UNIX Shell
#!/bin/bash # seq is the array genereated by hailstone # index is used for seq declare -a seq declare -i index   # Create a routine to generate the hailstone sequence for a number hailstone () { unset seq index seq[$((index++))]=$((n=$1)) while [ $n -ne 1 ]; do [ $((n % 2)) -eq 1 ] && ((n=n*3+1)) || ((n=n/2))...
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...
#Befunge
Befunge
0"z":>"a"`#v_ >:#,_$@ ^:- 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...
#BQN
BQN
'a'+↕26
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
#NS-HUBASIC
NS-HUBASIC
10 ? "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...
#UNIX_Shell
UNIX Shell
$ swap() { typeset -n var1=$1 var2=$2; set -- "$var1" "$var2"; var1=$2; var2=$1; } $ a=1 b=2 $ echo $a $b 1 2 $ swap a b $ echo $a $b ...
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...
#FreeBASIC
FreeBASIC
Dim Shared As Long lastsquare, nextsquare, lastcube, midcube, nextcube   Function squares() As Long lastsquare += nextsquare nextsquare += 2 squares = lastsquare End Function   Function cubes() As Long lastcube += nextcube nextcube += midcube midcube += 6 cubes = lastcube End Function   last...
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...
#Transact-SQL
Transact-SQL
  CREATE OR ALTER FUNCTION [dbo].[PGCD] ( @a BigInt , @b BigInt ) RETURNS BigInt WITH RETURNS NULL ON NULL INPUT -- Calculates the Greatest Common Denominator of two numbers (1 if they are coprime). BEGIN DECLARE @PGCD BigInt;   WITH Vars(A, B) As ( SELECT Max(V.N) As A , Min(V.N)...
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...
#True_BASIC
True BASIC
  REM Solución iterativa FUNCTION gcdI(x, y) DO WHILE y > 0 LET t = y LET y = remainder(x, y) LET x = t LOOP LET gcdI = x END FUNCTION     LET a = 111111111111111 LET b = 11111   PRINT PRINT "GCD(";a;", ";b;") = "; gcdI(a, b) PRINT PRINT "GCD(";a;", 111) = "; gcdI(a, 111) 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...
#Haskell
Haskell
import Data.List import qualified Data.Set as Set   data Piece = K | Q | R | B | N deriving (Eq, Ord, Show)   isChess960 :: [Piece] -> Bool isChess960 rank = (odd . sum $ findIndices (== B) rank) && king > rookA && king < rookB where Just king = findIndex (== K) rank [rookA, rookB] = findIndices (== R)...
http://rosettacode.org/wiki/Function_prototype
Function prototype
Some languages provide the facility to declare functions and subroutines through the use of function prototyping. Task Demonstrate the methods available for declaring prototypes within the language. The provided solutions should include: An explanation of any placement restrictions for prototype declarations A p...
#Ada
Ada
function noargs return Integer; function twoargs (a, b : Integer) return Integer; -- varargs do not exist function optionalargs (a, b : Integer := 0) return Integer; -- all parameters are always named, only calling by name differs procedure dostuff (a : Integer);
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...
#C.23
C#
  using System;   namespace GapfulNumbers { class Program { static void Main(string[] args) { Console.WriteLine("The first 30 gapful numbers are: "); /* Starting at 100, find 30 gapful numbers */ FindGap(100, 30);   Console.WriteLine("The first 15 ...
http://rosettacode.org/wiki/Gaussian_elimination
Gaussian elimination
Task Solve   Ax=b   using Gaussian elimination then backwards substitution. A   being an   n by n   matrix. Also,   x and b   are   n by 1   vectors. To improve accuracy, please use partial pivoting and scaling. See also   the Wikipedia entry:   Gaussian elimination
#ALGOL_68
ALGOL 68
# -*- coding: utf-8 -*- # COMMENT PROVIDES MODE FIXED; INT fixed exception, unfixed exception; PROC (STRING message) FIXED raise, raise value error END COMMENT   # Note: ℵ indicates attribute is "private", and should not be used outside of this prelude #   MODE FIXED = BOOL; # if an exception is detected, ...
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...
#PicoLisp
PicoLisp
(load "@lib/simul.l") (seed (in "/dev/urandom" (rd 8))) (de pieceN (P) (case P ("p" 8) ("q" 1) (T 2) ) ) (de pieceset () (let C 0 (make (for P (conc (cons "p") (shuffle '("r" "n" "b" "q"))) (let (X (pieceN P) N (rand 0 (+ X C))) (do N ...