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 ...
#BASIC
BASIC
DECLARE FUNCTION multiply% (a AS INTEGER, b AS INTEGER)   FUNCTION multiply% (a AS INTEGER, b AS INTEGER) multiply = a * b END FUNCTION
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...
#Python
Python
from collections import deque from itertools import islice, count     def fusc(): q = deque([1]) yield 0 yield 1   while True: x = q.popleft() q.append(x) yield x   x += q[0] q.append(x) yield x     def longest_fusc(): sofar = 0 for i, f in zip(cou...
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...
#Limbo
Limbo
implement Lanczos7;   include "sys.m"; sys: Sys; include "draw.m"; include "math.m"; math: Math; lgamma, exp, pow, sqrt: import math;   Lanczos7: module { init: fn(nil: ref Draw->Context, nil: list of string); };   init(nil: ref Draw->Context, nil: list of string) { sys = load Sys Sys->PATH; math = load Math 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...
#SQL
SQL
  /* This code is an implementation of gapful numbers in SQL ORACLE 19c p_start -- start point p_count -- total number to be found */ WITH FUNCTION gapful_numbers(p_start IN INTEGER, p_count IN INTEGER) RETURN varchar2 IS v_start INTEGER := p_start; v_count INTEGER := 0; v_res varchar2(32767); ...
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
#Raku
Raku
sub gauss-jordan-solve (@a, @b) { @b.kv.map: { @a[$^k].append: $^v }; @a.&rref[*]»[*-1]; }   # reduced row echelon form sub rref (@m) { my ($lead, $rows, $cols) = 0, @m, @m[0];   for ^$rows -> $r { $lead < $cols or return @m; my $i = $r; until @m[$i;$lead] { ++$i == $...
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...
#Pascal
Pascal
program lowerCaseAscii(input, output, stdErr); var alphabet: set of char; begin // as per ISO 7185, 'a'..'z' do not necessarily have to be contiguous alphabet := [ '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' ]; end.
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
#PL.2FI
PL/I
goodbye:proc options(main); put list('Hello world!'); end goodbye;
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...
#VBA
VBA
Public lastsquare As Long Public nextsquare As Long Public lastcube As Long Public midcube As Long Public nextcube As Long Private Sub init() lastsquare = 1 nextsquare = -1 lastcube = -1 midcube = 0 nextcube = 1 End Sub   Private Function squares() As Long lastsquare = lastsquare + nextsquare ...
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...
#JavaScript
JavaScript
function compose(f, g) { return function(x) { return 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...
#Joy
Joy
g f
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
#Perl
Perl
use GD::Simple;   my ($width, $height) = (1000,1000); # image dimension my $scale = 6/10; # branch scale relative to trunk my $length = 400; # trunk size   my $img = GD::Simple->new($width,$height); $img->fgcolor('black'); $img->penSize(1,1);   tree($width/2, $height, $length, 270);   print $img->png;     sub tree { ...
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...
#Python
Python
def indexOf(haystack, needle): idx = 0 for straw in haystack: if straw == needle: return idx else: idx += 1 return -1   def getDigits(n, le, digits): while n > 0: r = n % 10 if r == 0 or indexOf(digits, r) >= 0: return False le ...
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 ...
#Java
Java
import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class Fractran{   public static void main(String []args){   new 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); } final int limit = 15;     Vector<Intege...
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 ...
#Batch_File
Batch File
@ECHO OFF SET /A result = 0 CALL :multiply 2 3 ECHO %result% GOTO :eof   :multiply SET /A result = %1 * %2 GOTO :eof   :eof
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...
#Quackery
Quackery
  [ 1 & ] is odd ( n --> b )   [ 0 swap [ dip 1+ 10 / dup 0 = until ] drop ] is digits ( n --> n )   [ dup dup size dup odd iff [ dup 1 - 2 / dip [ 1 + 2 / peek over ] peek + ] else [ 2 / peek ] jo...
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...
#R
R
firstNFuscNumbers <- function(n) { stopifnot(n > 0) if(n == 1) return(0) else fusc <- c(0, 1) if(n > 2) { for(i in seq(from = 3, to = n, by = 1)) { fusc[i] <- if(i %% 2) fusc[(i + 1) / 2] else fusc[i / 2] + fusc[(i + 2) / 2] } } fusc } first61 <- firstNFuscNumbers(61) cat("The first 61 Fus...
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...
#Lua
Lua
gamma, coeff, quad, qui, set = 0.577215664901, -0.65587807152056, -0.042002635033944, 0.16653861138228, -0.042197734555571 function recigamma(z) return z + gamma * z^2 + coeff * z^3 + quad * z^4 + qui * z^5 + set * z^6 end   function gammafunc(z) if z == 1 then return 1 elseif math.abs(z) <= 0.5 then return 1 / 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...
#Swift
Swift
func isGapful(n: Int) -> Bool { guard n > 100 else { return true }   let asString = String(n) let div = Int("\(asString.first!)\(asString.last!)")!   return n % div == 0 }   let first30 = (100...).lazy.filter(isGapful).prefix(30) let mil = (1_000_000...).lazy.filter(isGapful).prefix(15) let bil = (1_000_0...
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...
#Tcl
Tcl
proc ungap n { if {[string length $n] < 3} { return $n } return [string index $n 0][string index $n end] }   proc gapful n { return [expr {0 == ($n % [ungap $n])}] }   ## --> list of gapful numbers >= n proc GFlist {count n} { set r {} while {[llength $r] < $count} { if {[ga...
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
#REXX
REXX
/* REXX --------------------------------------------------------------- * 07.08.2014 Walter Pachl translated from PL/I) * improved to get integer results for, e.g. this input: -6 -18 13 6 -6 -15 -2 -9 -231 2 20 9 2 16 -12 -18 -5 647 23 18 -14 -14 -1 16 25 -17 -907 -8 -1 -19 4 3 ...
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...
#Perl
Perl
print '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...
#Phix
Phix
string az = "" for ch='a' to 'z' do az &= ch end for ?az ?tagset('z','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
#PL.2FM
PL/M
100H: /* CP/M BDOS SYSTEM CALL */ BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END; /* PRINT A $ TERMINATED STRING */ PRINT$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END; /* HELLO, WORLD! IN MIXED CASE */ DECLARE HELLO$WORLD ( 14 ) BYTE INITIAL( 'H',...
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...
#Visual_Basic_.NET
Visual Basic .NET
Module Program Iterator Function IntegerPowers(exp As Integer) As IEnumerable(Of Integer) Dim i As Integer = 0 Do Yield CInt(Math.Pow(i, exp)) i += 1 Loop End Function   Function Squares() As IEnumerable(Of Integer) Return IntegerPowers(2) End Func...
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...
#jq
jq
  # apply g first and then f def compose(f; g): g | f;  
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...
#Julia
Julia
@show (asin ∘ sin)(0.5)
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
#Phix
Phix
-- -- demo\rosetta\FractalTree.exw -- ============================ -- with javascript_semantics include pGUI.e Ihandle dlg, canvas cdCanvas cddbuffer, cdcanvas procedure drawTree(integer level, atom angle, len, integer x, y) integer xn = x + floor(len*cos(angle)), yn = y + floor(len*sin(angle)), ...
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...
#Racket
Racket
#lang racket   (require racket/generator syntax/parse/define)   (define-syntax-parser for** [(_ [x:id {~datum <-} (e ...)] rst ...) #'(e ... (λ (x) (for** rst ...)))] [(_ e ...) #'(begin e ...)])   (define (permutations xs n yield #:lower [lower #f]) (let loop ([xs xs] [n n] [acc '()] [lower lower]) ...
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 ...
#JavaScript
JavaScript
// Parses the input string for the numerators and denominators function compile(prog, numArr, denArr) { let regex = /\s*(\d*)\s*\/\s*(\d*)\s*(.*)/m; let result; while (result = regex.exec(prog)) { numArr.push(result[1]); denArr.push(result[2]); prog = result[3]; } return [num...
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 ...
#BBC_BASIC
BBC BASIC
PRINT FNmultiply(6,7) END   DEF FNmultiply(a,b) = a * b
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...
#Racket
Racket
#lang racket   (require racket/generator)   (define (memoize f) (define table (make-hash)) (λ args (hash-ref! table args (thunk (apply f args)))))   (define fusc (memoize (λ (n) (cond [(<= n 1) n] [(even? n) (fusc (/ n 2))] [else (+ (fusc (/ (sub1 n) 2)) (fusc (/ (add1 n) 2)))]))))   ...
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...
#Raku
Raku
my @Fusc = 0, 1, 1, { |(@Fusc[$_ - 1] + @Fusc[$_], @Fusc[$_]) given ++$+1 } ... *;   sub comma { $^i.flip.comb(3).join(',').flip }   put "First 61 terms of the Fusc sequence:\n{@Fusc[^61]}" ~ "\n\nIndex and value for first term longer than any previous:";   for flat 'Index', 'Value', 0, 0, (1..4).map({ my $l = ...
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...
#M2000_Interpreter
M2000 Interpreter
  Module PrepareLambdaFunctions { Const e = 2.7182818284590452@ Exp= Lambda e (x) -> e^x gammaStirling=lambda e (x As decimal)->Sqrt(2.0 * pi / x) * ((x / e) ^ x) Rad2Deg =Lambda pidivby180=pi/180 (RadAngle)->RadAngle / pidivby180 Dim p(9) p(0)=0.99999999999980993@, 676.5203681218851...
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...
#UNIX_Shell
UNIX Shell
first-digit() { printf '%s\n' "${1:0:1}" }   last-digit() { printf '%s\n' $(( $1 % 10 )) }   bookend-number() { printf '%s%s\n' "$(first-digit "$@")" "$(last-digit "$@")" }   is-gapful() { (( $1 >= 100 && $1 % $(bookend-number "$1") == 0 )) }   gapfuls-in-range() { local gapfuls=() local -i i found for ((...
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
#Ruby
Ruby
  require 'bigdecimal/ludcmp' include LUSolve   BigDecimal::limit(30)   a = [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.87, 31.01, 97.41, ...
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...
#Phixmonti
Phixmonti
0 tolist 'a' 'z' 2 tolist for tochar 0 put endfor print
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...
#PHP
PHP
<?php $lower = range('a', 'z'); var_dump($lower); ?>
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
#PL.2FSQL
PL/SQL
  SET serveroutput ON   BEGIN DBMS_OUTPUT.PUT_LINE('Hello world!'); 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...
#XPL0
XPL0
code ChOut=8, IntOut=11;   func Gen(M); \Generate Mth powers of positive integers int M; int N, R, I; [N:= [0, 0, 0, 0]; \provides own/static variables R:= 1; for I:= 1 to M do R:= R*N(M); N(M):= N(M)+1; return R; ];   func Filter; \Generate squares of positive integers that aren't cubes in...
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...
#K
K
compose:{'[x;y]}
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...
#Klingphix
Klingphix
include ..\Utilitys.tlhy   :*2 2 * ; :++ 1 + ; :composite swap exec swap exec ;   @++ @*2 3 composite ? { result: 7 }   "End " input
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
#PHP
PHP
  <?php header("Content-type: image/png");   $width = 512; $height = 512; $img = imagecreatetruecolor($width,$height); $bg = imagecolorallocate($img,255,255,255); imagefilledrectangle($img, 0, 0, $width, $width, $bg);   $depth = 8; function drawTree($x1, $y1, $angle, $depth){   global $img;   if ($depth != 0){ ...
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...
#Raku
Raku
my %reduced; my $digits = 2..4;   for $digits.map: * - 1 -> $exp { my $start = sum (0..$exp).map( { 10 ** $_ * ($exp - $_ + 1) }); my $end = 10**($exp+1) - sum (^$exp).map( { 10 ** $_ * ($exp - $_) } ) - 1;   ($start ..^ $end).race(:8degree, :3batch).map: -> $den { next if $den.contains: '0'; ...
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 ...
#Julia
Julia
function fractran(n::Integer, ratios::Vector{<:Rational}, steplim::Integer) rst = zeros(BigInt, steplim) for i in 1:steplim rst[i] = n if (pos = findfirst(x -> isinteger(n * x), ratios)) > 0 n *= ratios[pos] else break end end return rst end   usin...
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 ...
#bc
bc
define multiply(a, b) { return a*b }   print multiply(2, 3)
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...
#REXX
REXX
/*REXX program calculates and displays the fusc (or Stern's Diatomic) sequence. */ parse arg st # xw . /*obtain optional arguments from the CL*/ if st=='' | st=="," then st= 0 /*Not specified? Then use the default.*/ if #=='' | #=="," then #= 61 ...
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...
#Maple
Maple
GAMMA(17/2); GAMMA(7*I); M := Matrix(2, 3, 'fill' = -3.6); MTM:-gamma(M);
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...
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   Function FirstNum(n As Integer) As Integer REM Divide by ten until the leading digit remains. While n >= 10 n /= 10 End While Return n End Function   Function LastNum(n As Integer) As Integer REM Modulo gives you the last digit. Re...
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
#Rust
Rust
  // using a Vec<f32> might be a better idea // for now, let us create a fixed size array // of size: const SIZE: usize = 6;   pub fn eliminate(mut system: [[f32; SIZE+1]; SIZE]) -> Option<Vec<f32>> { // produce the row reduced echelon form // // for every row... for i in 0..SIZE-1 { // for ever...
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...
#Picat
Picat
main => Alpha1 = (0'a..0'z).map(chr), println(Alpha1), Alpha2 = [chr(I) : I in 97..122], println(Alpha2).
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...
#PicoLisp
PicoLisp
(mapcar char (range (char "a") (char "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
#Plain_English
Plain English
\This prints Hello World within the CAL-4700 IDE. \...and backslashes are comments! To run: Start up. Write "Hello World!" to the console. Wait for the escape key. Shut down.
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...
#Wren
Wren
var powers = Fn.new { |m| var i = 0 return Fn.new { var p = i.pow(m) i = i + 1 return p } }   var squaresNotCubes = Fn.new { |squares, cubes| var sq = squares.call() var cu = cubes.call() return Fn.new { var p while (true) { if (sq < cu) { ...
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...
#Kotlin
Kotlin
// version 1.0.6   fun f(x: Int): Int = x * x   fun g(x: Int): Int = x + 2   fun compose(f: (Int) -> Int, g: (Int) -> Int): (Int) -> Int = { f(g(it)) }   fun main(args: Array<String>) { val x = 10 println(compose(::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...
#Lambdatalk
Lambdatalk
  {def compose {lambda {:f :g :x} {:f {:g :x}}}} -> compose   {def funcA {lambda {:x} {* :x 10}}} -> funcA   {def funcB {lambda {:x} {+ :x 5}}} -> funcB   {def f {compose funcA funcB}} -> f   {{f} 3} -> 80  
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
#PicoLisp
PicoLisp
(load "@lib/math.l")   (de fractalTree (Img X Y A D) (unless (=0 D) (let (R (*/ A pi 180.0) DX (*/ (cos R) D 0.2) DY (*/ (sin R) D 0.2)) (brez Img X Y DX DY) (fractalTree Img (+ X DX) (+ Y DY) (+ A 30.0) (dec D)) (fractalTree Img (+ X DX) (+ Y DY) (- A 30.0) (dec D)) ) ) )   (let I...
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
#Plain_English
Plain English
To run: Start up. Clear the screen to the lightest blue color. Pick a brownish color. Put the screen's bottom minus 1/2 inch into the context's spot's y coord. Draw a tree given 3 inches. Refresh the screen. Wait for the escape key. Shut down.   To draw a tree given a size: If the size is less than 1/32 inch, exit. Put...
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...
#REXX
REXX
/*REXX pgm reduces fractions by "crossing out" matching digits in nominator&denominator.*/ parse arg high show . /*obtain optional arguments from the CL*/ if high=='' | high=="," then high= 4 /*Not specified? Then use the default.*/ if show=='' | show=="," then show= 12 ...
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 ...
#Kotlin
Kotlin
// version 1.1.3   import java.math.BigInteger   class Fraction(val num: BigInteger, val denom: BigInteger) { operator fun times(n: BigInteger) = Fraction (n * num, denom)   fun isIntegral() = num % denom == BigInteger.ZERO }   fun String.toFraction(): Fraction { val split = this.split('/') return Fract...
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 ...
#BCPL
BCPL
let multiply(a, b) = a * b
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...
#Ring
Ring
  # Project: Fusc sequence   max = 60 fusc = list(36000) fusc[1] = 1 see "working..." + nl see "wait for done..." + nl see "The first 61 fusc numbers are:" + nl fuscseq(max) see "0" for m = 1 to max see " " + fusc[m] next   see nl see "The fusc numbers whose length > any previous fusc number length are:" + nl see "...
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...
#Ruby
Ruby
fusc = Enumerator.new do |y| y << 0 y << 1 arr = [0,1] 2.step do |n| res = n.even? ? arr[n/2] : arr[(n-1)/2] + arr[(n+1)/2] y << res arr << res end end   fusc_max_digits = Enumerator.new do |y| cur_max, cur_exp = 0, 0 0.step do |i| f = fusc.next if f >= cur_max cur_exp ...
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Gamma[x]
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...
#Maxima
Maxima
fpprec: 30$   gamma_coeff(n) := block([a: makelist(1, n)], a[2]: bfloat(%gamma), for k from 3 thru n do a[k]: bfloat((sum((-1)^j * zeta(j) * a[k - j], j, 2, k - 1) - a[2] * a[k - 1]) / (1 - k * a[1])), a)$   poleval(a, x) := block([y: 0], for k from length(a) thru 1 step -1 do y: y * x + a[k], ...
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...
#Vlang
Vlang
fn commatize(n u64) string { mut s := n.str() le := s.len for i := le - 3; i >= 1; i -= 3 { s = '${s[0..i]},$s[i..]' } return s }   fn main() { starts := [u64(1e2), u64(1e6), u64(1e7), u64(1e9), u64(7123)] counts := [30, 15, 15, 10, 25] for i in 0..starts.len { mut count ...
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...
#Wren
Wren
import "/fmt" for Fmt   var starts = [1e2, 1e6, 1e7, 1e9, 7123] var counts = [30, 15, 15, 10, 25] for (i in 0...starts.count) { var count = 0 var j = starts[i] var pow = 100 while (true) { if (j < pow * 10) break pow = pow * 10 } System.print("First %(counts[i]) gapful numbers st...
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
#Sidef
Sidef
func gauss_jordan_solve (a, b) {   var A = gather { ^b -> each {|i| take(a[i] + b[i]) } }   rref(A).map{ .last } }   var a = [ [ 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...
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...
#PL.2FI
PL/I
gen: procedure options (main); /* 7 April 2014. */ declare 1 ascii union, 2 letters (26) character (1), 2 iletters(26) unsigned fixed binary (8), letter character(1); declare i fixed binary;   letters(1), letter = lowercase('A');   do i = 2 to 26; iletters(i) = il...
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...
#PL.2FM
PL/M
100H: /* PRINT THE LOWERCASE LETTERS */   /* CP/M BDOS SYSTEM CALL */ BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5;END; /* CONSOLE OUTPUT ROUTINES */ PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;   /* TASK */ DECLARE C BYTE, LC ( 27 )BYTE; DO C = 0 TO 25;...
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
#Plan
Plan
#STEER LIST,BINARY #PROGRAM HLWD #LOWER MSG1A 11HHELLO WORLD MSG1B 11/MSG1A #PROGRAM #ENTRY 0 DISTY MSG1B SUSWT 2HHH #END #FINISH #STOP
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...
#zkl
zkl
fcn powers(m){ n:=0.0; while(1){vm.yield(n.pow(m).toInt()); n+=1} } var squared=Utils.Generator(powers,2), cubed=Utils.Generator(powers,3);   fcn filtered(sg,cg){s:=sg.next(); c:=cg.next(); while(1){ if(s>c){c=cg.next(); continue;} else if(s<c) vm.yield(s); s=sg.next() } } var f=Utils.Generato...
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...
#LFE
LFE
  (defun compose (f g) (lambda (x) (funcall f (funcall g x))))   (defun compose (funcs) (lists:foldl #'compose/2 (lambda (x) x) funcs))   (defun check () (let* ((sin-asin (compose #'math:sin/1 #'math:asin/1)) (expected (math:sin (math:asin 0.5))) (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...
#Lingo
Lingo
-- in some movie script ---------------------------------------- -- Composes 2 call-functions, returns a new call-function -- @param {symbol|instance} f -- @param {symbol|instance} g -- @return {instance} ---------------------------------------- on compose (f, g) return script("Composer").new(f, g) end
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
#PostScript
PostScript
%!PS %%BoundingBox: 0 0 300 300 %%EndComments /origstate save def /ld {load def} bind def /m /moveto ld /g /setgray ld /t /translate ld /r /rotate ld /l /lineto ld /rl /rlineto ld /s /scale ld %%EndProlog /PerturbateAngle {} def /PerturbateLength {} def % ** To add perturbations, define properly PerturbateAngle and Per...
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
#POV-Ray
POV-Ray
#include "colors.inc" #include "transforms.inc"   #declare CamLoc = <0, 5, 0>; #declare CamLook = <0,0,0>; camera { location CamLoc look_at CamLook rotate y*90 }   light_source { CamLoc color White }   #declare Init_Height = 10; #declare Spread_Ang = 35; #declare Branches = 14; #declare Scaling_F...
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...
#Ruby
Ruby
def indexOf(haystack, needle) idx = 0 for straw in haystack if straw == needle then return idx else idx = idx + 1 end end return -1 end   def getDigits(n, le, digits) while n > 0 r = n % 10 if r == 0 or indexOf(digits, r) >= 0 then ...
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 ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
fractionlist = {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}; n = 2; steplimit = 20; j = 0; break = False; While[break == False && j <= steplimit, newlist = n fractionlist; isintegerlist = IntegerQ[#] & /@ newlist; truepositions = Position[isintegerlist, True]; If[...
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 ...
#BlitzMax
BlitzMax
function multiply:float( a:float, b:float ) return a*b end function   print multiply(3.1416, 1.6180)
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...
#Rust
Rust
fn fusc_sequence() -> impl std::iter::Iterator<Item = u32> { let mut sequence = vec![0, 1]; let mut n = 0; std::iter::from_fn(move || { if n > 1 { sequence.push(match n % 2 { 0 => sequence[n / 2], _ => sequence[(n - 1) / 2] + sequence[(n + 1) / 2], ...
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...
#Sidef
Sidef
func fusc(n) is cached {   return 0 if n.is_zero return 1 if n.is_one   n.is_even ? fusc(n/2) : (fusc((n-1)/2) + fusc(((n-1)/2)+1)) }   say ("First 61 terms of the Stern-Brocot sequence: ", 61.of(fusc).join(' '))   say "\nIndex and value for first term longer than any previous:" printf("%15s : %s\n", "Index...
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...
#.D0.9C.D0.9A-61.2F52
МК-61/52
П9 9 П0 ИП9 ИП9 1 + * Вx L0 05 1 + П9 ^ ln 1 - * ИП9 1 2 * 1/x + e^x <-> / 2 пи * ИП9 / КвКор * ^ ВП 3 + Вx - С/П
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...
#Modula-3
Modula-3
MODULE Gamma EXPORTS Main;   FROM IO IMPORT Put; FROM Fmt IMPORT Extended, Style;   PROCEDURE Taylor(x: EXTENDED): EXTENDED = CONST a = ARRAY [0..29] OF EXTENDED { 1.00000000000000000000X0, 0.57721566490153286061X0, -0.65587807152025388108X0, -0.04200263503409523553X0, 0.16653861138229148950X0, -0.0421977...
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...
#XBS
XBS
func isgapful(n:number):boolean{ set s:string = tostring(n); set d = toint(`{s::at(0)}{s::at(?s-1)}`); send (n%d)==0 }   func findGapfulNumbers(start,amount){ set gapful=[]; set ind = start; while(true){ if(isgapful(ind)){ gapful::insert(ind); } ind++; if((?gapful)>=amount){ stop; } } log(`First...
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...
#XPL0
XPL0
func Gapful(N0); \Return 'true' if gapful number int N0, N, First, Last; [N:= N0; N:= N/10; Last:= rem(0); repeat N:= N/10; First:= rem(0); until N = 0; N:= First*10 + Last; return rem(N0/N) = 0; ];   proc ShowGap(Start, Limit); \Display gapful numbers int Start, Limit, Count, N; [Text(0, "First ");...
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
#Stata
Stata
void gauss(real matrix a, real matrix b, real scalar det) { real scalar i,j,n,s real vector js   det = 1 n = rows(a) for (i=1; i<n; i++) { maxindex(abs(a[i::n,i]), 1, js=., .) j = js[1]+i-1 if (j!=i) { a[(i\j),i..n] = a[(j\i),i..n] b[(i\j),.] = b[(j\i),.] det = -det } for (j=i+1; j<=n; j++) { ...
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...
#PL.2FSQL
PL/SQL
Declare sbAlphabet varchar2(100); Begin For nuI in 97..122 loop if sbAlphabet is null then sbAlphabet:=chr(nuI); Else sbAlphabet:=sbAlphabet||','||chr(nuI); End if; End loop; Dbms_Output.Put_Line(sbAlphabet); 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...
#Plain_English
Plain English
To run: Start up. Generate the lowercase ASCII alphabet giving a string. Write the string on the console. Wait for the escape key. Shut down.   To generate the lowercase ASCII alphabet giving a string: Put the little-a byte into a letter. Loop. Append the letter to the string. If the letter is the little-z byte, exit. ...
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
#Pony
Pony
actor Main new create(env: Env) => env.out.print("Hello world!")
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...
#LOLCODE
LOLCODE
HAI 1.3   I HAS A fx, I HAS A gx   HOW IZ I composin YR f AN YR g fx R f, gx R g HOW IZ I composed YR x FOUND YR I IZ fx YR I IZ gx YR x MKAY MKAY IF U SAY SO FOUND YR composed IF U SAY SO   HOW IZ I incin YR num FOUND YR SUM OF num AN 1 IF U SAY SO   HOW IZ I sqrin YR num FOUND YR PRODU...
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...
#Lua
Lua
function compose(f, g) return function(...) return f(g(...)) end end
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
#Prolog
Prolog
fractal :- new(D, window('Fractal')), send(D, size, size(800, 600)), drawTree(D, 400, 500, -90, 9), send(D, open).     drawTree(_D, _X, _Y, _Angle, 0).   drawTree(D, X1, Y1, Angle, Depth) :- X2 is X1 + cos(Angle * pi / 180.0) * Depth * 10.0, Y2 is Y1 + sin(Angle * pi / 180.0) * Depth * 10.0, new(Li...
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...
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   Function IndexOf(n As Integer, s As Integer()) As Integer For ii = 1 To s.Length Dim i = ii - 1 If s(i) = n Then Return i End If Next Return -1 End Function   Function GetDigits(n As Integer, le As Integer, digits A...
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 ...
#Nim
Nim
  import strutils import bignum   const PrimeProg = "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"   iterator values(prog: openArray[Rat]; init: Natural): Int = ## Run the program "prog" with initial value "init" and yield the values. var n = newInt(init) var next: Rat while ...
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 ...
#Boo
Boo
def multiply(x as int, y as int): return x * y   print multiply(3, 2)
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...
#Swift
Swift
struct FuscSeq: Sequence, IteratorProtocol { private var arr = [0, 1] private var i = 0   mutating func next() -> Int? { defer { i += 1 }   guard i > 1 else { return arr[i] }   switch i & 1 { case 0: arr.append(arr[i / 2]) case 1: arr.append(arr[(i - 1) / 2] + a...
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...
#Tcl
Tcl
proc fusc n { if {$n < 2} { return $n }   if {[info exists ::g_fusc($n)]} { return $::g_fusc($n) }   if {$n % 2} { ;# n is odd set r [expr {[fusc [expr {($n-1)/2}]] + [fusc [expr {($n+1)/2}]]}] } else { ;# n is even set r [fusc [expr {$n/2}]] ...
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...
#Nim
Nim
import math, strformat   const A = [ 1.00000000000000000000, 0.57721566490153286061, -0.65587807152025388108, -0.04200263503409523553, 0.16653861138229148950, -0.04219773455554433675, -0.00962197152787697356, 0.00721894324666309954, -0.00116516759185906511, -0.00021524167411495097, 0.00012805028238811619, -0.00002...
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...
#Yabasic
Yabasic
sub is_gapful(n) m = n l = mod(n, 10) while (m >= 10) m = int(m / 10) wend return (m * 10) + l end sub   sub muestra_gapful(n, gaps) inc = 0 print "Primeros ", gaps, " numeros gapful >= ", n while inc < gaps if mod(n, is_gapful(n)) = 0 then print " " , 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...
#zkl
zkl
fcn gapfulW(start){ //--> iterator [start..].tweak( fcn(n){ if(n % (10*n.toString()[0] + n%10)) Void.Skip else 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
#Swift
Swift
func gaussEliminate(_ sys: [[Double]]) -> [Double]? { var system = sys   let size = system.count   for i in 0..<size-1 where system[i][i] != 0 { for j in i..<size-1 { let factor = system[j + 1][i] / system[i][i]   for k in i..<size+1 { system[j + 1][k] -= factor * system[i][k] } ...