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/Function_definition
Function definition
A function is a body of code that returns a value. The value returned may depend on arguments provided to the function. Task Write a definition of a function called "multiply" that takes two arguments and returns their product. (Argument types should be chosen so as not to distract from showing how functions are ...
#ArnoldC
ArnoldC
LISTEN TO ME VERY CAREFULLY multiply I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE a I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE b GIVE THESE PEOPLE AIR HEY CHRISTMAS TREE product YOU SET US UP @I LIED GET TO THE CHOPPER product HERE IS MY INVITATION a YOU'RE FIRED b ENOUGH TALK I'LL BE BACK product HASTA L...
http://rosettacode.org/wiki/Fusc_sequence
Fusc sequence
Definitions The   fusc   integer sequence is defined as:   fusc(0) = 0   fusc(1) = 1   for n>1,   the   nth   term is defined as:   if   n   is even;     fusc(n) = fusc(n/2)   if   n   is   odd;     fusc(n) = fusc((n-1)/2)   +   fusc((n+1)/2) Note that MathWorld's definition starts with unity, not zero.   Th...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
ClearAll[Fusc] Fusc[0] := 0 Fusc[1] := 1 Fusc[n_] := Fusc[n] = If[EvenQ[n], Fusc[n/2], Fusc[(n - 1)/2] + Fusc[(n + 1)/2]] Fusc /@ Range[0, 60] res = {{0, 1}}; i = 0; PrintTemporary[Dynamic[{res, i}]]; While[Length[res] < 6, f = Fusc[i]; If[IntegerLength[res[[-1, -1]]] < IntegerLength[f], AppendTo[res, {i, f}] ...
http://rosettacode.org/wiki/Fusc_sequence
Fusc sequence
Definitions The   fusc   integer sequence is defined as:   fusc(0) = 0   fusc(1) = 1   for n>1,   the   nth   term is defined as:   if   n   is even;     fusc(n) = fusc(n/2)   if   n   is   odd;     fusc(n) = fusc((n-1)/2)   +   fusc((n+1)/2) Note that MathWorld's definition starts with unity, not zero.   Th...
#Nim
Nim
import strformat   func fusc(n: int): int = if n == 0 or n == 1: n elif n mod 2 == 0: fusc(n div 2) else: fusc((n - 1) div 2) + fusc((n + 1) div 2)   echo "The first 61 Fusc numbers:" for i in 0..61: write(stdout, fmt"{fusc(i)} ") echo "\n\nThe Fusc numbers whose lengths are greater than those of pr...
http://rosettacode.org/wiki/Gamma_function
Gamma function
Task Implement one algorithm (or more) to compute the Gamma ( Γ {\displaystyle \Gamma } ) function (in the real field only). If your language has the function as built-in or you know a library which has it, compare your implementation's results with the results of the built-in/library function. The Gamma funct...
#Java
Java
public class GammaFunction {   public double st_gamma(double x){ return Math.sqrt(2*Math.PI/x)*Math.pow((x/Math.E), x); }   public double la_gamma(double x){ double[] p = {0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, ...
http://rosettacode.org/wiki/Galton_box_animation
Galton box animation
Example of a Galton Box at the end of animation. A   Galton device   Sir Francis Galton's device   is also known as a   bean machine,   a   Galton Board,   or a   quincunx. Description of operation In a Galton box, there are a set of pins arranged in a triangular pattern.   A number of balls are dropped so that ...
#zig
zig
const std = @import("std"); const rand = std.rand; const time = std.os.time;   const PEG_LINES = 20;   fn boardSize(comptime peg_lines: u16) u16 { var i: u16 = 0; var size: u16 = 0; inline while (i <= PEG_LINES) : (i += 1) { size += i+1; } return size; }   const BOARD_SIZE = boardSize(PEG_LI...
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...
#Python
Python
from itertools import islice, count for start, n in [(100, 30), (1_000_000, 15), (1_000_000_000, 10)]: print(f"\nFirst {n} gapful numbers from {start:_}") print(list(islice(( x for x in count(start) if (x % (int(str(x)[0]) * 10 + (x % 10)) == 0) ) , n)))
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
#PHP
PHP
function swap_rows(&$a, &$b, $r1, $r2) { if ($r1 == $r2) return;   $tmp = $a[$r1]; $a[$r1] = $a[$r2]; $a[$r2] = $tmp;   $tmp = $b[$r1]; $b[$r1] = $b[$r2]; $b[$r2] = $tmp; }   function gauss_eliminate($A, $b, $N) { for ($col = 0; $col < $N; $col++) { $j = $col; $max = ...
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 ...
#Tcl
Tcl
proc fizzbuzz {n args} { if {$args eq ""} { set args {{3 Fizz} {5 Buzz}} } while {[incr i] <= $n} { set out "" foreach rule $args { lassign $rule m echo if {$i % $m == 0} {append out $echo} } if {$out eq ""} {set out $i} puts $out }...
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...
#MATLAB_.2F_Octave
MATLAB / Octave
'a':'z'
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...
#Maxima
Maxima
  delete([], makelist(if(alphacharp(ascii(i))) then parse_string(ascii(i)) else [], i, 96, 122));
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
#Pict
Pict
(prNL "Hello World!");
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...
#Scheme
Scheme
(define (power-seq n) (let ((i 0)) (lambda () (set! i (+ 1 i)) (expt i n))))   (define (filter-seq m n) (let* ((s1 (power-seq m)) (s2 (power-seq n)) (a 0) (b 0)) (lambda () (set! a (s1)) (let loop () (if (>= a b) (begin (cond ((> a b) (set! b (s2))) ((= a b) ...
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#Fortress
Fortress
  compose[\A, B, C\](f:A->B, g:B->C, i:Any): A->C = do f(g(i)) end   composed(i:RR64): RR64 = compose(sin, cos, i)  
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#FreeBASIC
FreeBASIC
function compose( f as function(as integer) as integer,_ g as function(as integer) as integer,_ n as integer ) as integer return f(g(n)) end function
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#Liberty_BASIC
Liberty BASIC
  NoMainWin sw = 640 : sh = 480 WindowWidth = sw+8 : WindowHeight = sh+31 UpperLeftX = (DisplayWidth -sw)/2 UpperLeftY = (DisplayHeight-sh)/2 Open"Fractal Tree" For Graphics_nf_nsb As #g #g "Down; Color darkgreen; TrapClose halt" h$ = "#g"   'initial assignments initAngle = Acs(-1)*1.5 'radian equivalent of 270 deg...
http://rosettacode.org/wiki/Fraction_reduction
Fraction reduction
There is a fine line between numerator and denominator.       ─── anonymous A method to   "reduce"   some reducible fractions is to   cross out   a digit from the numerator and the denominator.   An example is: 16 16 ──── and then (simp...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[AnomalousCancellationQ2] AnomalousCancellationQ2[frac : {i_?Positive, j_?Positive}] := Module[{samedigits, idig, jdig, ff, p, q, r, tmp}, idig = IntegerDigits[i]; jdig = IntegerDigits[j]; samedigits = Intersection[idig, jdig]; ff = i/j; If[samedigits != {}, r = {}; Do[ p = Flatten[Positio...
http://rosettacode.org/wiki/Fractran
Fractran
FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Horton Conway. A FRACTRAN program is an ordered list of positive fractions P = ( f 1 , f 2 , … , f m ) {\displaystyle P=(f_{1},f_{2},\ldots ,f_{m})} , together with an initial positive integer input n ...
#FreeBASIC
FreeBASIC
' version 06-07-2015 ' compile with: fbc -s console ' uses gmp   #Include Once "gmp.bi"   ' in case the two #define's are missing from 'gmp.bi' define them now #Ifndef mpq_numref #Define mpq_numref(Q) (@(Q)->_mp_num) #Define mpq_denref(Q) (@(Q)->_mp_den) #EndIf   Dim As String prog(0 To ...) = {"17/91", "78/85"...
http://rosettacode.org/wiki/Function_definition
Function definition
A function is a body of code that returns a value. The value returned may depend on arguments provided to the function. Task Write a definition of a function called "multiply" that takes two arguments and returns their product. (Argument types should be chosen so as not to distract from showing how functions are ...
#Arturo
Arturo
multiply: $[x,y][x*y]   print multiply 3 7   multiply2: function [x,y][ return x*y ]   print multiply2 3 7  
http://rosettacode.org/wiki/Fusc_sequence
Fusc sequence
Definitions The   fusc   integer sequence is defined as:   fusc(0) = 0   fusc(1) = 1   for n>1,   the   nth   term is defined as:   if   n   is even;     fusc(n) = fusc(n/2)   if   n   is   odd;     fusc(n) = fusc((n-1)/2)   +   fusc((n+1)/2) Note that MathWorld's definition starts with unity, not zero.   Th...
#Pascal
Pascal
program fusc; uses sysutils; const {$IFDEF FPC} MaxIdx = 1253 * 1000 * 1000; //19573420; // must be even {$ELSE} // Dynamics arrays in Delphi cann't be to large MaxIdx = 19573420; {$ENDIF}   type tFuscElem = LongWord; tFusc = array of tFuscElem; var FuscField : tFusc;   function commatize(n:NativeUint):s...
http://rosettacode.org/wiki/Gamma_function
Gamma function
Task Implement one algorithm (or more) to compute the Gamma ( Γ {\displaystyle \Gamma } ) function (in the real field only). If your language has the function as built-in or you know a library which has it, compare your implementation's results with the results of the built-in/library function. The Gamma funct...
#JavaScript
JavaScript
function gamma(x) { var p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7 ];   var g = 7; if (x < 0.5) { return Math.PI / (Math.sin(Math...
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...
#Raku
Raku
use Lingua::EN::Numbers;   for (1e2, 30, 1e6, 15, 1e9, 10, 7123, 25)».Int -> $start, $count { put "\nFirst $count gapful numbers starting at {comma $start}:\n" ~ <Sir Lord Duke King>.pick ~ ": ", ~ ($start..*).grep( { $_ %% .comb[0, *-1].join } )[^$count]; }
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
#PL.2FI
PL/I
Solve: procedure options (main); /* 11 January 2014 */   declare n fixed binary; put ('Program to solve n simultaneous equations of the form Ax = b. Please type n:' ); get (n);   begin; declare (A(n, n), b(n), x(n)) float(18); declare (SA(n,n), Sb(n)) float (18); declare i fixed binary;   put sk...
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 ...
#Ursa
Ursa
# # general fizzbuzz # decl int<> factors decl string<> words decl int max   # get the max number out ">" console set max (in int console)   # get the factors decl string input set input " " while (not (= input "")) out ">" console set input (in string console) if (not (= input "")) ...
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 ...
#VBA
VBA
  Option Explicit   Private Type Choice Number As Integer Name As String End Type   Private MaxNumber As Integer   Sub Main() Dim U(1 To 3) As Choice, i As Integer, j As Integer, t$   MaxNumber = Application.InputBox("Enter the max number : ", "Integer please", Type:=1) For i = 1 To 3 U(i) = Use...
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...
#Mercury
Mercury
:- module gen_lowercase_ascii. :- interface.   :- import_module io.   :- pred main(io::di, io::uo) is det.   :- implementation.   :- import_module char, int, list.   main(!IO) :- list.map(char.det_from_int, 0'a .. 0'z, Alphabet), io.print_line(Alphabet, !IO).   :- end_module gen_lowercase_ascii.
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...
#MiniScript
MiniScript
letters = [] for i in range(code("a"), code("z")) letters.push char(i) end for   print letters
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
#Pikachu
Pikachu
pikachu pika pikachu pika pika pi pi pika pikachu pika pikachu pi pikachu pi pikachu pi pika pi pikachu pikachu pi pi pika pika pikachu pika pikachu pikachu pi pika pi pika pika pi pikachu pikachu pi pikachu pi pika pikachu pi pikachu pika pikachu pi pikachu pikachu pi pikachu pika pika pikachu pi pikachu pi pi pikachu...
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...
#SenseTalk
SenseTalk
// ExponentialGenerator.script   to initialize set my base to 0 if my exponent is empty then set my exponent to 1 -- default if not given end initialize   to handle nextValue add 1 to my base return my base to the power of my exponent end nextValue
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#FunL
FunL
import math.{sin, asin}   def compose( f, g ) = x -> f( g(x) )   sin_asin = compose( sin, asin )   println( sin_asin(0.5) )
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#F.C5.8Drmul.C3.A6
Fōrmulæ
Composition := function(f, g) return x -> f(g(x)); end;   h := Composition(x -> x+1, x -> x*x); h(5); # 26
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#Lingo
Lingo
---------------------------------------- -- Creates an image of a fractal tree -- @param {integer} width -- @param {integer} height -- @param {integer} fractalDepth -- @param {integer|float} initSize -- @param {float} spreadAngle -- @param {float} [scaleFactor=1.0] -- @return {image} -----------------------------------...
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#Logo
Logo
to tree :depth :length :scale :angle if :depth=0 [stop] setpensize round :depth/2 forward :length right :angle tree :depth-1 :length*:scale :scale :angle left 2*:angle tree :depth-1 :length*:scale :scale :angle right :angle back :length end   clearscreen tree 10 80 0.7 30
http://rosettacode.org/wiki/Fraction_reduction
Fraction reduction
There is a fine line between numerator and denominator.       ─── anonymous A method to   "reduce"   some reducible fractions is to   cross out   a digit from the numerator and the denominator.   An example is: 16 16 ──── and then (simp...
#MiniZinc
MiniZinc
  %Fraction Reduction. Nigel Galloway, September 5th., 2019 include "alldifferent.mzn"; include "member.mzn"; int: S; array [1..9] of int: Pn=[1,10,100,1000,10000,100000,1000000,10000000,100000000]; array [1..S] of var 1..9: Nz; constraint alldifferent(Nz); array [1..S] of var 1..9: Gz; constraint alldifferent(Gz); var...
http://rosettacode.org/wiki/Fractran
Fractran
FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Horton Conway. A FRACTRAN program is an ordered list of positive fractions P = ( f 1 , f 2 , … , f m ) {\displaystyle P=(f_{1},f_{2},\ldots ,f_{m})} , together with an initial positive integer input n ...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import ( "fmt" "log" "math/big" "os" "strconv" "strings" )   func compile(src string) ([]big.Rat, bool) { s := strings.Fields(src) r := make([]big.Rat, len(s)) for i, s1 := range s { if _, ok := r[i].SetString(s1); !ok { return nil, false } ...
http://rosettacode.org/wiki/Function_definition
Function definition
A function is a body of code that returns a value. The value returned may depend on arguments provided to the function. Task Write a definition of a function called "multiply" that takes two arguments and returns their product. (Argument types should be chosen so as not to distract from showing how functions are ...
#AutoHotkey
AutoHotkey
MsgBox % multiply(10,2)   multiply(multiplicand, multiplier) { Return (multiplicand * multiplier) }
http://rosettacode.org/wiki/Fusc_sequence
Fusc sequence
Definitions The   fusc   integer sequence is defined as:   fusc(0) = 0   fusc(1) = 1   for n>1,   the   nth   term is defined as:   if   n   is even;     fusc(n) = fusc(n/2)   if   n   is   odd;     fusc(n) = fusc((n-1)/2)   +   fusc((n+1)/2) Note that MathWorld's definition starts with unity, not zero.   Th...
#Perl
Perl
use strict; use warnings; use feature 'say';   sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }   sub stern_diatomic { my ($p,$q,$i) = (0,1,shift); while ($i) { if ($i & 1) { $p += $q; } else { $q += $p; } $i >>= 1; } $p; }   say "First 61 terms of the Fusc sequence:\n" . join ' ', ...
http://rosettacode.org/wiki/Gamma_function
Gamma function
Task Implement one algorithm (or more) to compute the Gamma ( Γ {\displaystyle \Gamma } ) function (in the real field only). If your language has the function as built-in or you know a library which has it, compare your implementation's results with the results of the built-in/library function. The Gamma funct...
#jq
jq
def gamma: [ 1.00000000000000000000, 0.57721566490153286061, -0.65587807152025388108, -0.04200263503409523553, 0.16653861138229148950, -0.04219773455554433675, -0.00962197152787697356, 0.00721894324666309954, -0.00116516759185906511, -0.00021524167411495097, 0.00012805028238811619, -0.000020134854780...
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...
#REXX
REXX
/*REXX program computes and displays a series of gapful numbers starting at some number.*/ numeric digits 20 /*ensure enough decimal digits gapfuls.*/ parse arg gapfuls /*obtain optional arguments from the CL*/ if gapfuls='' then gapfuls= 30 25@7123 15@1000...
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
#PowerShell
PowerShell
  function gauss($a,$b) { $n = $a.count for ($k = 0; $k -lt $n; $k++) { $lmax, $max = $k, [Math]::Abs($a[$k][$k]) for ($l = $k+1; $l -lt $n; $l++) { $tmp = [Math]::Abs($a[$l][$k]) if($max -lt $tmp) { $max, $lmax = $tmp, $l } } ...
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 ...
#VBScript
VBScript
'The Function Function FizzBuzz(range, mapping) data = Array()   'Parse the mapping and put to "data" array temp = Split(mapping, ",") ReDim data(UBound(temp),1) For i = 0 To UBound(temp) map = Split(temp(i), " ") data(i, 0) = map(0) data(i, 1) = map(1) Next   'Do...
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 ...
#Visual_Basic_.NET
Visual Basic .NET
Imports System.Globalization   Module Program Sub Main() Console.Write("Max: ") Dim max = Integer.Parse(Console.ReadLine(), CultureInfo.InvariantCulture)   Dim factors As New SortedDictionary(Of Integer, String)   Const NUM_FACTORS = 3 For i = 1 To NUM_FACTORS Con...
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...
#MUMPS
MUMPS
  LOWASCMIN set lowstr = "" for i = 97:1:122 set delim = $select(i=97:"",1:",") set lowstr = lowstr_delim_$char(i) write lowstr quit  
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...
#Nanoquery
Nanoquery
lowercase = list() for i in range(ord("a"), ord("z")) lowercase.append(chr(i)) end println lowercase
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
#Pike
Pike
int main(){ write("Hello world!\n"); }
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...
#Sidef
Sidef
func gen_pow(m) { var e = 0; func { e++ ** m }; }   func gen_filter(g1, g2) { var v2 = g2.run; func { loop { var v1 = g1.run; while (v1 > v2) { v2 = g2.run }; v1 == v2 || return v1; } } }   # Create generators. var squares = gen_pow(2); var cubes =...
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#GAP
GAP
Composition := function(f, g) return x -> f(g(x)); end;   h := Composition(x -> x+1, x -> x*x); h(5); # 26
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#Go
Go
// Go doesn't have generics, but sometimes a type definition helps // readability and maintainability. This example is written to // the following function type, which uses float64. type ffType func(float64) float64   // compose function requested by task func compose(f, g ffType) ffType { return func(x float64) ...
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#Lua
Lua
  g, angle = love.graphics, 26 * math.pi / 180 wid, hei = g.getWidth(), g.getHeight() function rotate( x, y, a ) local s, c = math.sin( a ), math.cos( a ) local a, b = x * c - y * s, x * s + y * c return a, b end function branches( a, b, len, ang, dir ) len = len * .76 if len < 5 then return end g.setColor(...
http://rosettacode.org/wiki/Fraction_reduction
Fraction reduction
There is a fine line between numerator and denominator.       ─── anonymous A method to   "reduce"   some reducible fractions is to   cross out   a digit from the numerator and the denominator.   An example is: 16 16 ──── and then (simp...
#Nim
Nim
  # Fraction reduction.   import strformat import times   type Result = tuple[n: int, nine: array[1..9, int]]   template find[T; N: static int](a: array[1..N, T]; value: T): int = ## Return the one-based index of a value in an array. ## This is needed as "system.find" returns a 0-based index even if the ## array ...
http://rosettacode.org/wiki/Fractran
Fractran
FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Horton Conway. A FRACTRAN program is an ordered list of positive fractions P = ( f 1 , f 2 , … , f m ) {\displaystyle P=(f_{1},f_{2},\ldots ,f_{m})} , together with an initial positive integer input n ...
#Go
Go
package main   import ( "fmt" "log" "math/big" "os" "strconv" "strings" )   func compile(src string) ([]big.Rat, bool) { s := strings.Fields(src) r := make([]big.Rat, len(s)) for i, s1 := range s { if _, ok := r[i].SetString(s1); !ok { return nil, false } ...
http://rosettacode.org/wiki/Function_definition
Function definition
A function is a body of code that returns a value. The value returned may depend on arguments provided to the function. Task Write a definition of a function called "multiply" that takes two arguments and returns their product. (Argument types should be chosen so as not to distract from showing how functions are ...
#AutoIt
AutoIt
#AutoIt Version: 3.2.10.0 $I=11 $J=12 MsgBox(0,"Multiply", $I &" * "& $J &" = " & product($I,$J)) Func product($a,$b) Return $a * $b EndFunc
http://rosettacode.org/wiki/Fusc_sequence
Fusc sequence
Definitions The   fusc   integer sequence is defined as:   fusc(0) = 0   fusc(1) = 1   for n>1,   the   nth   term is defined as:   if   n   is even;     fusc(n) = fusc(n/2)   if   n   is   odd;     fusc(n) = fusc((n-1)/2)   +   fusc((n+1)/2) Note that MathWorld's definition starts with unity, not zero.   Th...
#Phix
Phix
constant limit = 20_000_000 sequence fuscs = repeat(0,limit); -- NB 1-based indexing; fusc(0)===fuscs[1] fuscs[2] = 1 -- ie fusc(1):=1 for n=3 to limit do fuscs[n] = iff(remainder(n-1,2)?fuscs[n/2]+fuscs[n/2+1]:fuscs[(n+1)/2]) end for --printf(1,"First 61 terms of the Fusc seque...
http://rosettacode.org/wiki/Gamma_function
Gamma function
Task Implement one algorithm (or more) to compute the Gamma ( Γ {\displaystyle \Gamma } ) function (in the real field only). If your language has the function as built-in or you know a library which has it, compare your implementation's results with the results of the built-in/library function. The Gamma funct...
#Jsish
Jsish
#!/usr/bin/env jsish /* Gamma function, in Jsish, using the Lanczos approximation */ function gamma(x) { var p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e...
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...
#Ring
Ring
  nr = 0 gapful1 = 99 gapful2 = 999999 gapful3 = 999999999 limit1 = 30 limit2 = 15 limit3 = 10   see "First 30 gapful numbers >= 100:" + nl while nr < limit1 gapful1 = gapful1 + 1 gap1 = left((string(gapful1)),1) gap2 = right((string(gapful1)),1) gap = number(gap1 +gap2) if gapful1 % gap =...
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...
#Ruby
Ruby
class Integer def gapful? a = digits self % (a.last*10 + a.first) == 0 end end   specs = {100 => 30, 1_000_000 => 15, 1_000_000_000 => 10, 7123 => 25}   specs.each do |start, num| puts "first #{num} gapful numbers >= #{start}:" p (start..).lazy.select(&:gapful?).take(num).to_a end  
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
#Python
Python
# The 'gauss' function takes two matrices, 'a' and 'b', with 'a' square, and it return the determinant of 'a' and a matrix 'x' such that a*x = b. # If 'b' is the identity, then 'x' is the inverse of 'a'.   import copy from fractions import Fraction   def gauss(a, b): a = copy.deepcopy(a) b = copy.deepcopy(b) ...
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 ...
#Vlang
Vlang
import os   fn main() { max := os.input('Max: ').int() f1 := os.input('Starting factor (#) and word: ').fields() f2 := os.input('Next factor (#) and word: ').fields() f3 := os.input('Next factor (#) and word: ').fields()   //using the provided data words := { f1[0].int(): f1[1], ...
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 ...
#Wren
Wren
import "io" for Stdin, Stdout import "/sort" for Sort   var n   while (true) { System.write("Maximum number : ") Stdout.flush() n = Num.fromString(Stdin.readLine()) if (!n || !n.isInteger || n < 3) { System.print("Must be an integer > 2, try again.") } else { break } }   var fact...
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...
#Neko
Neko
/** <doc>Generate lower case ASCII, in Neko</doc> **/   var slot = 25 var generated = $smake(slot + 1) var lower_a = $sget("a", 0)   /* 'a'+25 down to 'a'+0 */ while slot >= 0 { $sset(generated, slot, slot + lower_a) slot -= 1 }   $print(generated, "\n")
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...
#NESL
NESL
lower_case_ascii = {code_char(c) : c in [97:123]};
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
#PILOT
PILOT
T:Hello world!
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...
#SuperCollider
SuperCollider
  f = { |m| {:x, x<-(0..) } ** m }; g = f.(2); g.nextN(10); // answers [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ]  
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#Groovy
Groovy
final times2 = { it * 2 } final plus1 = { it + 1 }   final plus1_then_times2 = times2 << plus1 final times2_then_plus1 = times2 >> plus1   assert plus1_then_times2(3) == 8 assert times2_then_plus1(3) == 7
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#Haskell
Haskell
Prelude> let sin_asin = sin . asin Prelude> sin_asin 0.5 0.49999999999999994
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
fractalTree[ pt : {_, _}, \[Theta]orient_: \[Pi]/2, \[Theta]sep_: \[Pi]/9, depth_Integer: 9] := Module[{pt2}, If[depth == 0, Return[]]; pt2 = pt + {Cos[\[Theta]orient], Sin[\[Theta]orient]}*depth; DeleteCases[ Flatten@{ Line[{pt, pt2}], fractalTree[pt2, \[Theta]orient - \[Theta]sep, \[Theta]sep,...
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   import java.awt.Color import java.awt.Graphics import javax.swing.JFrame   class RFractalTree public extends JFrame properties constant isTrue = (1 == 1) isFalse = \isTrue -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~...
http://rosettacode.org/wiki/Fraction_reduction
Fraction reduction
There is a fine line between numerator and denominator.       ─── anonymous A method to   "reduce"   some reducible fractions is to   cross out   a digit from the numerator and the denominator.   An example is: 16 16 ──── and then (simp...
#Pascal
Pascal
  program FracRedu; {$IFDEF FPC} {$MODE DELPHI} {$OPTIMIZATION ON,ALL} {$ELSE} {$APPTYPE CONSOLE} {$ENDIF} uses SysUtils;   type tdigit = 0..9; const cMaskDgt: array [tdigit] of Uint32 = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512 {,1024,2048,4096,8193,16384,32768}); cMaxDigits = High(tdigit); type tPerm...
http://rosettacode.org/wiki/Fractran
Fractran
FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Horton Conway. A FRACTRAN program is an ordered list of positive fractions P = ( f 1 , f 2 , … , f m ) {\displaystyle P=(f_{1},f_{2},\ldots ,f_{m})} , together with an initial positive integer input n ...
#Haskell
Haskell
import Data.List (find) import Data.Ratio (Ratio, (%), denominator)   fractran :: (Integral a) => [Ratio a] -> a -> [a] fractran fracts n = n : case find (\f -> n `mod` denominator f == 0) fracts of Nothing -> [] Just f -> fractran fracts $ truncate (fromIntegral n * f)
http://rosettacode.org/wiki/Function_definition
Function definition
A function is a body of code that returns a value. The value returned may depend on arguments provided to the function. Task Write a definition of a function called "multiply" that takes two arguments and returns their product. (Argument types should be chosen so as not to distract from showing how functions are ...
#AWK
AWK
function multiply(a, b) { return a*b } BEGIN { print multiply(5, 6) }
http://rosettacode.org/wiki/Fusc_sequence
Fusc sequence
Definitions The   fusc   integer sequence is defined as:   fusc(0) = 0   fusc(1) = 1   for n>1,   the   nth   term is defined as:   if   n   is even;     fusc(n) = fusc(n/2)   if   n   is   odd;     fusc(n) = fusc((n-1)/2)   +   fusc((n+1)/2) Note that MathWorld's definition starts with unity, not zero.   Th...
#Picat
Picat
main => println("First 61 fusc numbers:"), println([fusc(I) : I in 0..60]), nl, println("Points in the sequence whose length is greater than any previous fusc number length:\n"), println(" Index fusc Len"), largest_fusc_string(20_000_000).   table fusc(0) = 0. fusc(1) = 1. fusc(N) = fusc(N//2), eve...
http://rosettacode.org/wiki/Fusc_sequence
Fusc sequence
Definitions The   fusc   integer sequence is defined as:   fusc(0) = 0   fusc(1) = 1   for n>1,   the   nth   term is defined as:   if   n   is even;     fusc(n) = fusc(n/2)   if   n   is   odd;     fusc(n) = fusc((n-1)/2)   +   fusc((n+1)/2) Note that MathWorld's definition starts with unity, not zero.   Th...
#Processing
Processing
void setup() { println("First 61 terms:"); for (int i = 0; i < 60; i++) { print(fusc(i) + " "); } println(fusc(60)); println(); println("Sequence elements where number of digits of the value increase:"); int max_len = 0; for (int i = 0; i < 700000; i++) { int temp = fusc(i); if (str(temp).le...
http://rosettacode.org/wiki/Gamma_function
Gamma function
Task Implement one algorithm (or more) to compute the Gamma ( Γ {\displaystyle \Gamma } ) function (in the real field only). If your language has the function as built-in or you know a library which has it, compare your implementation's results with the results of the built-in/library function. The Gamma funct...
#Julia
Julia
@show gamma(1)
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...
#Scheme
Scheme
(define (first-digit n) (string->number (string (string-ref (number->string n) 0)))) (define (last-digit n) (modulo n 10)) (define (bookend-number n) (+ (* 10 (first-digit n)) (last-digit n))) (define (gapful? n) (and (>= n 100) (zero? (modulo n (bookend-number n)))))   (define (gapfuls-in-range start size) (let ((fo...
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
#R
R
gauss <- function(a, b) { n <- nrow(a) det <- 1   for (i in seq_len(n - 1)) { j <- which.max(a[i:n, i]) + i - 1 if (j != i) { a[c(i, j), i:n] <- a[c(j, i), i:n] b[c(i, j), ] <- b[c(j, i), ] det <- -det }   k <- seq(i + 1, n) for (j in k) { s <- a[[j, i]] / a[[i, i]] ...
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 ...
#zkl
zkl
stop:=ask("Count: ").toInt(); fizzBuzzers:=List(); do(3){ n,txt:=ask(">").split(); fizzBuzzers.append(T(n.toInt(),txt)) } foreach n in ([1..stop]){ s:=fizzBuzzers.filter('wrap([(fb,txt)]){ n%fb==0 }).apply("get",1).concat(); println(s or n); }
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 ...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 INPUT "Maximum number: ";max 20 INPUT "Number of factors: ";n 30 DIM f(n): DIM w$(n,4) 40 FOR i=1 TO n 50 INPUT "Input value-ENTER-word: ";f(i);w$(i) 60 NEXT i 70 FOR i=1 TO max 80 LET matched=0 90 FOR j=1 TO n 100 IF FN m(i,f(j))=0 THEN LET matched=1: PRINT w$(j); 110 NEXT j 120 IF NOT matched THEN PRINT ;i: GO TO ...
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...
#Nim
Nim
# A slice just contains the first and last value let alpha: Slice[char] = 'a'..'z' echo alpha # (a: a, b: z)   # but can be used to check if a character is in it: echo 'f' in alpha # true echo 'G' in alpha # false   # A set contains all elements as a bitvector: let alphaSet: set[char] = {'a'..'z'} echo alphaSet # {a, b...
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...
#OCaml
OCaml
# Array.make 26 'a' |> Array.mapi (fun i c -> int_of_char c + i |> char_of_int);; - : char array = [|'a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't'; 'u'; 'v'; 'w'; 'x'; 'y'; '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
#PIR
PIR
.sub hello_world_text :main print "Hello world!\n" .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...
#Swift
Swift
func powGen(m: Int) -> GeneratorOf<Int> { let power = Double(m) var cur: Double = 0 return GeneratorOf { Int(pow(cur++, power)) } }   var squares = powGen(2) var cubes = powGen(3)   var nCube = cubes.next()   var filteredSqs = GeneratorOf<Int> { for var nSq = squares.next() ;; nCube = cubes.next() { if nCub...
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#Hy
Hy
(defn compose [f g] (fn [x] (f (g x))))
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#Icon_and_Unicon
Icon and Unicon
x @ f # use this syntax in Icon instead of the Unicon f(x) to call co-expressions every push(fL := [],!rfL) # use this instead of reverse(fL) as the Icon reverse applies only to strings
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#Nim
Nim
  import math import strformat   const Width = 1000 Height = 1000 TrunkLength = 400 ScaleFactor = 0.6 StartingAngle = 1.5 * PI DeltaAngle = 0.2 * PI   proc drawTree(outfile: File; x, y, len, theta: float) = if len >= 1: let x2 = x + len * cos(theta) let y2 = y + len * sin(theta) outfile.write(...
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#OCaml
OCaml
#directory "+cairo" #load "bigarray.cma" #load "cairo.cma"   let img_name = "/tmp/fractree.png" let width = 480 let height = 640   let level = 9 let line_width = 4.0   let color = (1.0, 0.5, 0.0)   let pi = 4.0 *. atan 1.0   let angle_split = pi *. 0.12 let angle_rand = pi *. 0.12   let () = Random.self_init(); l...
http://rosettacode.org/wiki/Fraction_reduction
Fraction reduction
There is a fine line between numerator and denominator.       ─── anonymous A method to   "reduce"   some reducible fractions is to   cross out   a digit from the numerator and the denominator.   An example is: 16 16 ──── and then (simp...
#Perl
Perl
use strict; use warnings; use feature 'say'; use List::Util qw<sum uniq uniqnum head tail>;   for my $exp (map { $_ - 1 } <2 3 4>) { my %reduced; my $start = sum map { 10 ** $_ * ($exp - $_ + 1) } 0..$exp; my $end = 10**($exp+1) - -1 + sum map { 10 ** $_ * ($exp - $_) } 0..$exp-1;   for my $den ($star...
http://rosettacode.org/wiki/Fractran
Fractran
FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Horton Conway. A FRACTRAN program is an ordered list of positive fractions P = ( f 1 , f 2 , … , f m ) {\displaystyle P=(f_{1},f_{2},\ldots ,f_{m})} , together with an initial positive integer input n ...
#Icon_and_Unicon
Icon and Unicon
record fract(n,d)   procedure main(A) fractran("17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11 15/14 15/2 55/1", 2) end   procedure fractran(s, n, limit) execute(parse(s),n, limit) end   procedure parse(s) f := [] s ? while not pos(0) do { tab(upto(' ')|0) ? put(f,fract(tab...
http://rosettacode.org/wiki/Function_definition
Function definition
A function is a body of code that returns a value. The value returned may depend on arguments provided to the function. Task Write a definition of a function called "multiply" that takes two arguments and returns their product. (Argument types should be chosen so as not to distract from showing how functions are ...
#Axe
Axe
Lbl MULT r₁*r₂ Return
http://rosettacode.org/wiki/Fusc_sequence
Fusc sequence
Definitions The   fusc   integer sequence is defined as:   fusc(0) = 0   fusc(1) = 1   for n>1,   the   nth   term is defined as:   if   n   is even;     fusc(n) = fusc(n/2)   if   n   is   odd;     fusc(n) = fusc((n-1)/2)   +   fusc((n+1)/2) Note that MathWorld's definition starts with unity, not zero.   Th...
#Prolog
Prolog
:- dynamic fusc_cache/2.   fusc(0, 0):-!. fusc(1, 1):-!. fusc(N, F):- fusc_cache(N, F), !. fusc(N, F):- 0 is N mod 2, !, M is N//2, fusc(M, F), assertz(fusc_cache(N, F)). fusc(N, F):- N1 is (N - 1)//2, N2 is (N + 1)//2, fusc(N1, F1), fusc(N2, F2), F is F1 + F2, assert...
http://rosettacode.org/wiki/Gamma_function
Gamma function
Task Implement one algorithm (or more) to compute the Gamma ( Γ {\displaystyle \Gamma } ) function (in the real field only). If your language has the function as built-in or you know a library which has it, compare your implementation's results with the results of the built-in/library function. The Gamma funct...
#Kotlin
Kotlin
// version 1.0.6   fun gammaStirling(x: Double): Double = Math.sqrt(2.0 * Math.PI / x) * Math.pow(x / Math.E, x)   fun gammaLanczos(x: Double): Double { var xx = x val p = doubleArrayOf( 0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -17...
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...
#Sidef
Sidef
func is_gapful(n, base=10) { n.is_div(base*floor(n / base**n.ilog(base)) + n%base) }   var task = [ "(Required) The first %s gapful numbers (>= %s)", 30, 1e2, 10, "(Required) The first %s gapful numbers (>= %s)", 15, 1e6, 10, "(Required) The first %s gapful numbers (>= %s)", 10, 1e9, 10, "(Extra) Th...
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
#Racket
Racket
  #lang racket (require math/matrix) (define A (matrix [[1.00 0.00 0.00 0.00 0.00 0.00] [1.00 0.63 0.39 0.25 0.16 0.10] [1.00 1.26 1.58 1.98 2.49 3.13] [1.00 1.88 3.55 6.70 12.62 23.80] [1.00 2.51 6.32 15.88 39.90 100.28] [1.00 3.14 9.8...
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...
#Oforth
Oforth
'a' 'z' seqFrom
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...
#PARI.2FGP
PARI/GP
Strchr(Vecsmall([97..122]))
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
#Pixilang
Pixilang
fputs("Hello world!\n")
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...
#Tcl
Tcl
package require Tcl 8.6   proc powers m { yield for {set n 0} true {incr n} { yield [expr {$n ** $m}] } } coroutine squares powers 2 coroutine cubes powers 3 coroutine filtered apply {{s1 s2} { yield set f [$s2] set v [$s1] while true { if {$v > $f} { set f [$s2] continue } else...
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#J
J
compose =: @
http://rosettacode.org/wiki/Function_composition
Function composition
Task Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument. The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function   f   to the result of applying function   g   to   x. Example compose...
#Java
Java
public class Compose {   // Java doesn't have function type so we define an interface // of function objects instead public interface Fun<A,B> { B call(A x); }   public static <A,B,C> Fun<A,C> compose(final Fun<B,C> f, final Fun<A,B> g) { return new Fun<A,C>() { public C ...
http://rosettacode.org/wiki/Fractal_tree
Fractal tree
Generate and draw a fractal tree. Draw the trunk At the end of the trunk, split by some angle and draw two branches Repeat at the end of each branch until a sufficient level of branching is reached Related tasks Pythagoras Tree
#PARI.2FGP
PARI/GP
  \\ Fractal tree (w/recursion) \\ 4/10/16 aev plotline(x1,y1,x2,y2)={plotmove(0, x1,y1);plotrline(0,x2-x1,y2-y1);}   plottree(x,y,a,d)={ my(x2,y2,d2r=Pi/180.0,a1=a*d2r,d1); if(d<=0, return();); if(d>0, d1=d*10.0; x2=x+cos(a1)*d1; y2=y+sin(a1)*d1; plotline(x,y,x2,y2); plottree(x2,y2,a-20,d-1); plott...
http://rosettacode.org/wiki/Fraction_reduction
Fraction reduction
There is a fine line between numerator and denominator.       ─── anonymous A method to   "reduce"   some reducible fractions is to   cross out   a digit from the numerator and the denominator.   An example is: 16 16 ──── and then (simp...
#Phix
Phix
with javascript_semantics function to_n(sequence digits, integer remove_digit=0) if remove_digit!=0 then digits = deep_copy(digits) integer d = find(remove_digit,digits) digits[d..d] = {} end if integer res = digits[1] for i=2 to length(digits) do res = res*10+digits[i] ...
http://rosettacode.org/wiki/Fractran
Fractran
FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Horton Conway. A FRACTRAN program is an ordered list of positive fractions P = ( f 1 , f 2 , … , f m ) {\displaystyle P=(f_{1},f_{2},\ldots ,f_{m})} , together with an initial positive integer input n ...
#J
J
toFrac=: '/r' 0&".@charsub ] NB. read fractions from string fractran15=: ({~ (= <.) i. 1:)@(toFrac@[ * ]) ^:(<15) NB. return first 15 Fractran results