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/Brownian_tree
Brownian tree
Brownian tree You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw a   Brownian Tree. A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. The initial "seed" is placed somewhere wi...
#Sinclair_ZX81_BASIC
Sinclair ZX81 BASIC
10 DIM A$(20,20) 20 LET A$(10,10)="1" 30 FOR Y=42 TO 23 STEP -1 40 FOR X=0 TO 19 50 PLOT X,Y 60 NEXT X 70 NEXT Y 80 UNPLOT 9,33 90 FOR I=1 TO 80 100 LET X=INT (RND*18)+2 110 LET Y=INT (RND*18)+2 120 IF A$(X,Y)="1" THEN GOTO 100 130 UNPLOT X-1,43-Y 140 IF A$(X+1,Y+1)="1" OR A$(X+1,Y)="1" OR A$(X+1,Y-1)="1" OR A...
http://rosettacode.org/wiki/Brownian_tree
Brownian tree
Brownian tree You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw a   Brownian Tree. A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. The initial "seed" is placed somewhere wi...
#Tcl
Tcl
package require Tcl 8.5 package require Tk   set SIZE 300   image create photo brownianTree -width $SIZE -height $SIZE interp alias {} plot {} brownianTree put white -to brownianTree put black -to 0 0 [expr {$SIZE-1}] [expr {$SIZE-1}] proc rnd {range} {expr {int(rand() * $range)}}   proc makeBrownianTree count { gl...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Lua
Lua
function ShuffleArray(array) for i=1,#array-1 do local t = math.random(i, #array) array[i], array[t] = array[t], array[i] end end   function GenerateNumber() local digits = {1,2,3,4,5,6,7,8,9}   ShuffleArray(digits)   return digits[1] * 1000 + digits[2] * 100 + digits[3] ...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Groovy
Groovy
def caesarEncode(​cipherKey, text) { def builder = new StringBuilder() text.each { character -> int ch = character[0] as char switch(ch) { case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break } ...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Oforth
Oforth
a b c f
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Ol
Ol
  ; note: sign "==>" indicates expected output   ;;; Calling a function that requires no arguments (define (no-args-function) (print "ok."))   (no-args-function) ; ==> ok.     ;;; Calling a function with a fixed number of arguments (define (two-args-function a b) (print "a: " a) (print "b: " b))   (two-args-fu...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Raku
Raku
constant Catalan = 1, { [+] @_ Z* @_.reverse } ... *;
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Python
Python
>>> import calendar >>> help(calendar.prcal) Help on method pryear in module calendar:   pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance Print a years calendar.   >>> calendar.prcal(1969) 1969   January February ...
http://rosettacode.org/wiki/Brownian_tree
Brownian tree
Brownian tree You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw a   Brownian Tree. A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. The initial "seed" is placed somewhere wi...
#TI-83_BASIC
TI-83 BASIC
:StoreGDB 0 :ClrDraw :FnOff :AxesOff :Pxl-On(31,47) :For(I,1,50) :randInt(1,93)→X :randInt(1,61)→Y :1→A :While A :randInt(1,4)→D :Pxl-Off(Y,X) :If D=1 and Y≥2 :Y-1→Y :If D=2 and X≤92 :X+1→X :If D=3 and Y≤60 :Y+1→Y :If D=4 and X≥2 :X-1→X :Pxl-On(Y,X) :If pxl-Test(Y+1,X) or pxl-Test(Y+1,X+1) or pxl-Test(Y+1,X-1) or pxl-...
http://rosettacode.org/wiki/Brownian_tree
Brownian tree
Brownian tree You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw a   Brownian Tree. A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. The initial "seed" is placed somewhere wi...
#Visual_Basic_.NET
Visual Basic .NET
  Imports System.Drawing.Imaging   Public Class Form1   ReadOnly iCanvasColor As Integer = Color.Black.ToArgb ReadOnly iSeedColor As Integer = Color.White.ToArgb   Dim iCanvasWidth As Integer = 0 Dim iCanvasHeight As Integer = 0   Dim iPixels() As Integer = Nothing   Private Sub BrownianTree()   Dim oCa...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#M2000_Interpreter
M2000 Interpreter
  Module Game { Malformed=lambda (a$)->{ =true if len(a$)<>4 then exit n=0 : dummy=val(a$,"int",n) if n<>5 or dummy=0 then exit for i=1 to 9 if len(filter$(a$,str$(i,0)))<3 then break next i =false } ...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Haskell
Haskell
module Caesar (caesar, uncaesar) where   import Data.Char   caesar, uncaesar :: (Integral a) => a -> String -> String caesar k = map f where f c = case generalCategory c of LowercaseLetter -> addChar 'a' k c UppercaseLetter -> addChar 'A' k c _ -> c uncaesar ...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#ooRexx
ooRexx
say 'DATE'() Say date() Exit daTe: Return 'my date'
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#REXX
REXX
/*REXX program calculates and displays Catalan numbers using four different methods. */ parse arg LO HI . /*obtain optional arguments from the CL*/ if LO=='' | LO=="," then do; HI=15; LO=0; end /*No args? Then use a range of 0 ──► 15*/ if HI=='' | HI=="," then HI=LO ...
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Racket
Racket
#lang racket (require racket/date net/base64 file/gunzip) (define (calendar yr) (define (nsplit n l) (if (null? l) l (cons (take l n) (nsplit n (drop l n))))) (define months (for/list ([mn (in-naturals 1)] [mname '(January February March April May June July August Septembe...
http://rosettacode.org/wiki/Brownian_tree
Brownian tree
Brownian tree You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw a   Brownian Tree. A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. The initial "seed" is placed somewhere wi...
#Wren
Wren
import "graphics" for Canvas, Color import "dome" for Window import "random" for Random   var Rand = Random.new()   var N8 = [ [-1, -1], [-1, 0], [-1, 1], [ 0, -1], [ 0, 1], [ 1, -1], [ 1, 0], [ 1, 1] ]   class BrownianTree { construct new(width, height, particles) { Window.title = "Bro...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Maple
Maple
BC := proc(n) #where n is the number of turns the user wishes to play before they quit local target, win, numGuesses, guess, bulls, cows, i, err; target := [0, 0, 0, 0]: randomize(); #This is a command that makes sure that the numbers are truly randomized each time, otherwise your first time will always give...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Hoon
Hoon
|% ++ enc |= [msg=tape key=@ud] ^- tape ...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#PARI.2FGP
PARI/GP
f(); \\ zero arguments sin(Pi/2); \\ fixed number of arguments vecsort([5,6]) != vecsort([5,6],,4) \\ optional arguments Str("gg", 1, "hh") \\ variable number of arguments call(Str, ["gg", 1, "hh"]) \\ variable number of arguments in a vector (x->x^2)(3); \\ first-class x = sin(0); \\ get function value
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Ring
Ring
  for n = 1 to 15 see catalan(n) + nl next   func catalan n if n = 0 return 1 ok cat = 2 * (2 * n - 1) * catalan(n - 1) / (n + 1) return cat  
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Raku
Raku
my $months-per-row = 3; my @weekday-names = <Mo Tu We Th Fr Sa Su>; my @month-names = <Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec>;   my Int() $year = @*ARGS.shift || 1969; say fmt-year($year);   sub fmt-year ($year) { my @month-strs; @month-strs[$_] = [fmt-month($year, $_).lines] for 1 .. 12; my @...
http://rosettacode.org/wiki/Brownian_tree
Brownian tree
Brownian tree You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw a   Brownian Tree. A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. The initial "seed" is placed somewhere wi...
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations def W=128, H=W; \width and height of field int X, Y; [SetVid($13); \set 320x200 graphic video mode Point(W/2, H/2, 6\brown\); \place seed in center of field loop [repeat X:= Ran(W); Y:= Ran(H); \inject particle until Re...
http://rosettacode.org/wiki/Brownian_tree
Brownian tree
Brownian tree You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw a   Brownian Tree. A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. The initial "seed" is placed somewhere wi...
#zkl
zkl
w:=h:=400; numParticles:=20_000; bitmap:=PPM(w+2,h+2,0); // add borders as clip regions   bitmap[w/2,h/2]=0xff|ff|ff; // plant seed bitmap.circle(w/2,h/2,h/2,0x0f|0f|0f); // plant seeds   fcn touching(x,y,bitmap){ // is (x,y) touching another pixel? // (x,y) isn't on the border/edge of bitmap so no edge c...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
digits=Last@FixedPointList[If[Length@Union@#==4,#,Table[Random[Integer,{1,9}],{4}]]&,{}] codes=ToCharacterCode[StringJoin[ToString/@digits]]; Module[{r,bulls,cows}, While[True, r=InputString[]; If[r===$Canceled,Break[], With[{userCodes=ToCharacterCode@r}, If[userCodes===codes,Print[r<>": You got it!"];Break[], ...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Icon_and_Unicon
Icon and Unicon
procedure main() ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog")) dtext := caesar(ctext,,"decrypt") write("Plain text = ",image(ptext)) write("Encphered text = ",image(ctext)) write("Decphered text = ",image(dtext)) end   procedure caesar(text,k,mode) #: mono-alphabetic shift cipher /k :...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Pascal
Pascal
foo
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Perl
Perl
foo(); # Call foo on the null list &foo(); # Ditto foo($arg1, $arg2); # Call foo on $arg1 and $arg2 &foo($arg1, $arg2); # Ditto; ignores prototypes
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Ruby
Ruby
def factorial(n) (1..n).reduce(1, :*) end   # direct   def catalan_direct(n) factorial(2*n) / (factorial(n+1) * factorial(n)) end   # recursive   def catalan_rec1(n) return 1 if n == 0 (0...n).inject(0) {|sum, i| sum + catalan_rec1(i) * catalan_rec1(n-1-i)} end   def catalan_rec2(n) return 1 if n == 0 2*(2*...
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Rebol
Rebol
  do [if "" = y: ask "Year (ENTER for current):^/^/" [prin y: now/year] foreach m system/locale/months [ prin rejoin ["^/^/ " m "^/^/ "] foreach day system/locale/days [prin join copy/part day 2 " "] print "" f: to-date rejoin ["1-"m"-"y] loop f/weekday - 1 [prin " "] repeat i 31 [ if attempt [c: to...
http://rosettacode.org/wiki/Brownian_tree
Brownian tree
Brownian tree You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw a   Brownian Tree. A Brownian Tree is generated as a result of an initial seed, followed by the interaction of two processes. The initial "seed" is placed somewhere wi...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 LET np=1000 20 PAPER 0: INK 4: CLS 30 PLOT 128,88 40 FOR i=1 TO np 50 GO SUB 1000 60 IF NOT ((POINT (x+1,y+1)+POINT (x,y+1)+POINT (x+1,y)+POINT (x-1,y-1)+POINT (x-1,y)+POINT (x,y-1))=0) THEN GO TO 100 70 LET x=x+RND*2-1: LET y=y+RND*2-1 80 IF x<1 OR x>254 OR y<1 OR y>174 THEN GO SUB 1000 90 GO TO 60 100 PLOT x,y 11...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#MATLAB
MATLAB
function BullsAndCows % Plays the game Bulls and Cows as the "game master"   % Create a secret number nDigits = 4; lowVal = 1; highVal = 9; digitList = lowVal:highVal; secret = zeros(1, 4); for k = 1:nDigits idx = randi(length(digitList)); secret(k) = digitList(idx); ...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#IS-BASIC
IS-BASIC
100 PROGRAM "CaesarCi.bas" 110 STRING M$*254 120 INPUT PROMPT "String: ":M$ 130 DO 140 INPUT PROMPT "Key (1-25): ":KEY 150 LOOP UNTIL KEY>0 AND KEY<26 160 PRINT "Original message: ";M$ 170 CALL ENCRYPT(M$,KEY) 180 PRINT "Encrypted message: ";M$ 190 CALL DECRYPT(M$,KEY) 200 PRINT "Decrypted message: ";M$ 210 DEF ENCR...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Phix
Phix
{} = myfunction()
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Phixmonti
Phixmonti
def saludo "Hola mundo" print nl enddef   saludo   getid saludo exec
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Run_BASIC
Run BASIC
FOR i = 1 TO 15 PRINT i;" ";catalan(i) NEXT   FUNCTION catalan(n) catalan = 1 if n <> 0 then catalan = ((2 * ((2 * n) - 1)) / (n + 1)) * catalan(n - 1) END FUNCTION
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#REXX
REXX
11 9999999 6666666 9999999 111 999999999 666666666 999999999 1111 99 99 66 66 99 99 11 99 99 66 99 99 11 99 999 66 ...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#MAXScript
MAXScript
  numCount = 4 -- number of digits to use   digits = #(1, 2, 3, 4, 5, 6, 7, 8, 9) num = "" while num.count < numCount and digits.count > 0 do ( local r = random 1 digits.count append num (digits[r] as string) deleteitem digits r ) digits = undefined numGuesses = 0 inf = "Rules: \n1. Choose only % unique digits in an...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#J
J
cndx=: [: , 65 97 +/ 26 | (i.26)&+ caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#PicoLisp
PicoLisp
(foo) (bar 1 'arg 2 'mumble)
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#PureBasic
PureBasic
Procedure Saludo() PrintN("Hola mundo!") EndProcedure   Procedure.s Copialo(txt.s, siNo.b, final.s = "") Define nuevaCadena.s, resul.s   For cont.b = 1 To siNo nuevaCadena + txt Next   Resul = Trim(nuevaCadena) + final   ProcedureReturn resul EndProcedure   Procedure testNumeros(a.i, b.i, c.i = 0) Pri...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Rust
Rust
fn c_n(n: u64) -> u64 { match n { 0 => 1, _ => c_n(n - 1) * 2 * (2 * n - 1) / (n + 1) } }   fn main() { for i in 1..16 { println!("c_n({}) = {}", i, c_n(i)); } }
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Ring
Ring
  # Project : Calendar   load "guilib.ring" load "stdlib.ring"   new qapp { win1 = new qwidget() {   day = list(12) pos = newlist(12,37) month = list(12) week = list(7) weekday = list(7) but...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#MiniScript
MiniScript
secret = range(1,9) secret.shuffle secret = secret[:4].join("")   while true guess = input("Your guess? ").split("") if guess.len != 4 then print "Please enter 4 numbers, with no spaces." continue end if bulls = 0 cows = 0 for i in guess.indexes if secret[i] == guess[i] t...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Janet
Janet
  (def alphabet "abcdefghijklmnopqrstuvwxyz")   (defn rotate "shift bytes given x" [str x] (let [r (% x (length alphabet)) b (string/bytes str) abyte (get (string/bytes "a") 0) zbyte (get (string/bytes "z") 0)] (var result @[]) (for i 0 (length b) (let [ch (bor (get b i) 0x20...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Python
Python
def no_args(): pass # call no_args()   def fixed_args(x, y): print('x=%r, y=%r' % (x, y)) # call fixed_args(1, 2) # x=1, y=2   ## Can also called them using the parameter names, in either order: fixed_args(y=2, x=1)   ## Can also "apply" fixed_args() to a sequence: myargs=(1,2) # tuple fixed_args(*myargs...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Scala
Scala
  object CatalanNumbers { def main(args: Array[String]): Unit = { for (n <- 0 to 15) { println("catalan(" + n + ") = " + catalan(n)) } }   def catalan(n: BigInt): BigInt = factorial(2 * n) / (factorial(n + 1) * factorial(n))   def factorial(n: BigInt): BigInt = BigInt(1).to(n).foldLeft(BigInt(1))(...
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Ruby
Ruby
require 'date'   # Creates a calendar of _year_. Returns this calendar as a multi-line # string fit to _columns_. def cal(year, columns)   # Start at January 1. # # Date::ENGLAND marks the switch from Julian calendar to Gregorian # calendar at 1752 September 14. This removes September 3 to 13 from # year 1752...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#MUMPS
MUMPS
BullCow New bull,cow,guess,guessed,ii,number,pos,x Set number="",x=1234567890 For ii=1:1:4 Do . Set pos=$Random($Length(x))+1 . Set number=number_$Extract(x,pos) . Set $Extract(x,pos)="" . Quit Write !,"The computer has selected a number that consists" Write !,"of four different digits." Write !!,"As you are g...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Java
Java
public class Cipher { public static void main(String[] args) {   String str = "The quick brown fox Jumped over the lazy Dog";   System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); }   public static String decode(String enc...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#QBasic
QBasic
FUNCTION Copialo$ (txt$, siNo, final$) DIM nuevaCadena$   FOR cont = 1 TO siNo nuevaCadena$ = nuevaCadena$ + txt$ NEXT cont   Copialo$ = LTRIM$(RTRIM$(nuevaCadena$)) + final$ END FUNCTION   SUB Saludo PRINT "Hola mundo!" END SUB   SUB testCadenas (txt$) FOR cont = 1 TO LEN(txt$) PRINT MID$(txt...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Scheme
Scheme
(define (catalan m) (let loop ((c 1)(n 0)) (if (not (eqv? n m)) (begin (display n)(display ": ")(display c)(newline) (loop (* (/ (* 2 (- (* 2 (+ n 1)) 1)) (+ (+ n 1) 1)) c) (+ n 1) )))))   (catalan 15)
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Rust
Rust
// Assume your binary name is 'calendar'. // Command line: // >>$ calendar 2019 150 // First argument: year number. // Second argument (optional): text area width (in characters).   extern crate chrono;   use std::{env, cmp}; use chrono::{NaiveDate, Datelike};   const MONTH_WIDTH: usize = 22;   fn print_header(months: ...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Nanoquery
Nanoquery
import Nanoquery.Util; random = new(Random)   // a function to verify the user's input def verify_digits(input) global size seen = ""   if len(input) != size return false else for char in input if not char in "0123456789" return false else if char in seen return false end   seen += char en...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#JavaScript
JavaScript
function caesar (text, shift) { return text.toUpperCase().replace(/[^A-Z]/g,'').replace(/./g, function(a) { return String.fromCharCode(65+(a.charCodeAt(0)-65+shift)%26); }); }   // Tests var text = 'veni, vidi, vici'; for (var i = 0; i<26; i++) { console.log(i+': '+caesar(text,i)); }
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Quackery
Quackery
/O> 123 7 /mod ... Stack: 17 4 /O> 2 pack ... Stack: [ 17 4 ] /O> echo cr ... [ 17 4 ] Stack empty.
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "bigint.s7i";   const proc: main is func local var bigInteger: n is 0_; begin for n range 0_ to 15_ do writeln((2_ * n) ! n div succ(n)); end for; end func;
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Scala
Scala
import java.util.{ Calendar, GregorianCalendar } import language.postfixOps import collection.mutable.ListBuffer   object CalendarPrint extends App { val locd = java.util.Locale.getDefault() val cal = new GregorianCalendar val monthsMax = cal.getMaximum(Calendar.MONTH)   def JDKweekDaysToISO(dn: Int) = { va...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Nim
Nim
import random, strutils, strformat, sequtils randomize()   const Digits = "123456789" DigitSet = {Digits[0]..Digits[^1]} Size = 4   proc sample(s: string; n: Positive): string = ## Return a random sample of "n" characters extracted from string "s". var s = s s.shuffle() result = s[0..<n]   proc plural(n: ...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#jq
jq
def encrypt(key): . as $s | explode as $xs | (key % 26) as $offset | if $offset == 0 then . else reduce range(0; length) as $i ( {chars: []}; $xs[$i] as $c | .d = $c | if ($c >= 65 and $c <= 90) # 'A' to 'Z' then .d = $c + $offset | if (.d > 90) the...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#R
R
### Calling a function that requires no arguments no_args <- function() NULL no_args()     ### Calling a function with a fixed number of arguments fixed_args <- function(x, y) print(paste("x=", x, ", y=", y, sep="")) fixed_args(1, 2) # x=1, y=2 fixed_args(y=2, x=1) # y=1, x=2     ### Calling a function with o...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Sidef
Sidef
func f(i) { i==0 ? 1 : (i * f(i-1)) } func c(n) { f(2*n) / f(n) / f(n+1) }
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "time.s7i";   const func string: center (in string: stri, in integer: length) is return ("" lpad (length - length(stri)) div 2 <& stri) rpad length;   const proc: printCalendar (in integer: year, in integer: cols) is func local var time: date is time.value; var integer: d...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#OCaml
OCaml
let rec input () = let s = read_line () in try if String.length s <> 4 then raise Exit; String.iter (function | '1'..'9' -> () | _ -> raise Exit ) s; let t = [ s.[0]; s.[1]; s.[2]; s.[3] ] in let _ = List.fold_left (* reject entry with duplication *) (fun ac b -> if Li...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Jsish
Jsish
/* Caesar cipher, in Jsish */ "use strict";   function caesarCipher(input:string, key:number):string { return input.replace(/([a-z])/g, function(mat, p1, ofs, str) { return Util.fromCharCode((p1.charCodeAt(0) + key + 26 - 97) % 26 + 97); }).replace(/([A-Z])/g, ...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Racket
Racket
  #lang racket   ;; Calling a function that requires no arguments (foo)   ;; Calling a function with a fixed number of arguments (foo 1 2 3)   ;; Calling a function with optional arguments ;; Calling a function with a variable number of arguments (foo 1 2 3) ; same in both cases   ;; Calling a function with named argum...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Raku
Raku
foo # as list operator foo() # as function foo.() # as function, explicit postfix form $ref() # as object invocation $ref.() # as object invocation, explicit postfix &foo() # as object invocation &foo.() # as object invocation, explicit post...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#smart_BASIC
smart BASIC
PRINT "Recursive:"!PRINT FOR n = 0 TO 15 PRINT n,"#######":catrec(n) NEXT n PRINT!PRINT   PRINT "Non-recursive:"!PRINT FOR n = 0 TO 15 PRINT n,"#######":catnonrec(n) NEXT n   END   DEF catrec(x) IF x = 0 THEN temp = 1 ELSE n = x temp = ((2*((2*n)-1))/(n+1))*catrec(n-1) END I...
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Sidef
Sidef
require('DateTime')   define months_per_col = 3 define week_day_names = <Mo Tu We Th Fr Sa Su> define month_names = <Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec>   func fmt_month (year, month) { var str = sprintf("%-20s\n", month_names[month-1]) str += week_day_names.join(' ')+"\n"   var dt = %s<DateTim...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Oforth
Oforth
: bullsAndCows | numbers guess digits bulls cows |   ListBuffer new ->numbers while(numbers size 4 <>) [ 9 rand dup numbers include ifFalse: [ numbers add ] else: [ drop ] ]   while(true) [ "Enter a number of 4 different digits between 1 and 9 : " print System.Console askln ->digits digits as...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Julia
Julia
  # Caeser cipher # Julia 1.5.4 # author: manuelcaeiro | https://github.com/manuelcaeiro   function csrcipher(text, key) ciphtext = "" for l in text numl = Int(l) ciphnuml = numl + key if numl in 65:90 if ciphnuml > 90 rotciphnuml = ciphnuml - 26 ...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#REXX
REXX
/*REXX pgms demonstrates various methods/approaches of invoking/calling a REXX function.*/   /*╔════════════════════════════════════════════════════════════════════╗ ║ Calling a function that REQUIRES no arguments. ║ ║ ...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Standard_ML
Standard ML
(* * val catalan : int -> int * Returns the nth Catalan number. *) fun catalan 0 = 1 | catalan n = ((4 * n - 2) * catalan(n - 1)) div (n + 1);   (* * val print_catalans : int -> unit * Prints out Catalan numbers 0 through 15. *) fun print_catalans(n) = if n > 15 then () else (print (Int.toString(catalan...
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Simula
Simula
BEGIN INTEGER WIDTH, YEAR; INTEGER COLS, LEAD, GAP; TEXT ARRAY WDAYS(0:6); CLASS MONTH(MNAME); TEXT MNAME; BEGIN INTEGER DAYS, START_WDAY, AT_POS; END MONTH; REF(MONTH) ARRAY MONTHS(0:11); WIDTH := 80; YEAR := 1969;   BEGIN TEXT T; INTEGER I, M; FOR T :- "Su",...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#ooRexx
ooRexx
declare proc {Main} Solution = {PickNUnique 4 {List.number 1 9 1}}   proc {Loop} Guess = {EnterGuess} in {System.showInfo {Bulls Guess Solution}#" bulls and "# {Cows Guess Solution}#" cows"} if Guess \= Solution then {Loop} end end in {Loop} {S...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#K
K
  s:"there is a tide in the affairs of men" caesar:{ :[" "=x; x; {x!_ci 97+!26}[y]@_ic[x]-97]}' caesar[s;1] "uifsf jt b ujef jo uif bggbjst pg nfo"  
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Ring
Ring
  hello() func hello see "Hello from function" + nl  
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Ruby
Ruby
fn main() { // Rust has a lot of neat things you can do with functions: let's go over the basics first fn no_args() {} // Run function with no arguments no_args();   // Calling a function with fixed number of arguments. // adds_one takes a 32-bit signed integer and returns a 32-bit signed intege...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Stata
Stata
clear set obs 15 gen catalan=1 in 1 replace catalan=catalan[_n-1]*2*(2*_n-3)/_n in 2/l list, noobs noh
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Smalltalk
Smalltalk
CalendarPrinter printOnTranscriptForYearNumber: 1969
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Oz
Oz
declare proc {Main} Solution = {PickNUnique 4 {List.number 1 9 1}}   proc {Loop} Guess = {EnterGuess} in {System.showInfo {Bulls Guess Solution}#" bulls and "# {Cows Guess Solution}#" cows"} if Guess \= Solution then {Loop} end end in {Loop} {S...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Kotlin
Kotlin
// version 1.0.5-2   object Caesar { fun encrypt(s: String, key: Int): String { val offset = key % 26 if (offset == 0) return s var d: Char val chars = CharArray(s.length) for ((index, c) in s.withIndex()) { if (c in 'A'..'Z') { d = c + offset ...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Rust
Rust
fn main() { // Rust has a lot of neat things you can do with functions: let's go over the basics first fn no_args() {} // Run function with no arguments no_args();   // Calling a function with fixed number of arguments. // adds_one takes a 32-bit signed integer and returns a 32-bit signed intege...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Scala
Scala
def ??? = throw new NotImplementedError // placeholder for implementation of hypothetical methods def myFunction0() = ??? myFunction0() // function invoked with empty parameter list myFunction0 // function invoked with empty parameter list omitted   def myFunction = ??? myFunction // function invoked with no...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Swift
Swift
func catalan(_ n: Int) -> Int { switch n { case 0: return 1 case _: return catalan(n - 1) * 2 * (2 * n - 1) / (n + 1) } }   for i in 1..<16 { print("catalan(\(i)) => \(catalan(i))") }  
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#SPL
SPL
year = 1969 #.output(#.str(year,">68<")) > row, 0..3 > col, 1..3 cal[col] = mcal(row*3+col,year) size = #.size(cal[col],1) < > i, 1..8 str = "" > col, 1..3  ? col>1, str += " " line = ""  ? #.size(cal[col],1)!<i, line = cal[col][i] str += #.str(line,"<20<") < #.out...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#PARI.2FGP
PARI/GP
bc()={ my(u,v,bulls,cows); while(#vecsort(v=vector(4,i,random(9)+1),,8)<4,); while(bulls<4, u=input(); if(type(u)!="t_VEC"|#u!=4,next); bulls=sum(i=1,4,u[i]==v[i]); cows=sum(i=1,4,sum(j=1,4,i!=j&v[i]==u[j])); print("You have "bulls" bulls and "cows" cows") ) };
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#LabVIEW
LabVIEW
  {def caesar   {def caesar.alphabet {A.split ABCDEFGHIJKLMNOPQRSTUVWXYZ}}   {def caesar.delta {lambda {:s :i :a} {A.get {% {+ {A.in? {A.get :i :a} {caesar.alphabet}} 26 :s} 26} {caesar.alphabet}}}}   {def caesar.loop {lambda {:s :a :b :n :i} {if {> :i :n} then :b else {caesar.r :s ...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Seed7
Seed7
put zeroArgsFn()   // Function calls can also be made using the following syntax: put the zeroArgsFn   function zeroArgsFn put "This function was run with zero arguments." return "Return value from zero argument function" end zeroArgsFn
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#SenseTalk
SenseTalk
put zeroArgsFn()   // Function calls can also be made using the following syntax: put the zeroArgsFn   function zeroArgsFn put "This function was run with zero arguments." return "Return value from zero argument function" end zeroArgsFn
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#Tcl
Tcl
package require Tcl 8.5   # Memoization wrapper proc memoize {function value generator} { variable memoize set key $function,$value if {![info exists memoize($key)]} { set memoize($key) [uplevel 1 $generator] } return $memoize($key) }   # The simplest recursive definition proc tcl::mathfunc::catala...
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Swift
Swift
import Foundation   let monthWidth = 20 let monthGap = 2 let dayNames = "Su Mo Tu We Th Fr Sa" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "MMMM"   func rpad(string: String, width: Int) -> String { return string.count >= width ? string  : String(repeating: " ", count: width - string.count)...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Pascal
Pascal
Program BullCow;   {$mode objFPC}   uses Math, SysUtils;   type TFourDigit = array[1..4] of integer;   Procedure WriteFourDigit(fd: TFourDigit); { Write out a TFourDigit with no line break following. } var i: integer; begin for i := 1 to 4 do begin Write(fd[i]); end; end;   Function WellFormed(Tent...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#Lambdatalk
Lambdatalk
  {def caesar   {def caesar.alphabet {A.split ABCDEFGHIJKLMNOPQRSTUVWXYZ}}   {def caesar.delta {lambda {:s :i :a} {A.get {% {+ {A.in? {A.get :i :a} {caesar.alphabet}} 26 :s} 26} {caesar.alphabet}}}}   {def caesar.loop {lambda {:s :a :b :n :i} {if {> :i :n} then :b else {caesar.r :s ...
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Sidef
Sidef
foo(); # without arguments foo(1, 2); # with two arguments foo(args...); # with a variable number of arguments foo(name: 'Bar', age: 42); # with named arguments   var f = foo; # store the function foo inside 'f' var result = f(); # obta...
http://rosettacode.org/wiki/Catalan_numbers
Catalan numbers
Catalan numbers You are encouraged to solve this task according to the task description, using any language you may know. Catalan numbers are a sequence of numbers which can be defined directly: C n = 1 n + 1 ( 2 n n ) = ( 2 n ) ! ( n + 1 ) ! n !  for  n ≥ 0. {\displaystyle C...
#TI-83_BASIC
TI-83 BASIC
:For(I,1,15 :Disp (2I)!/((I+1)!I! :End
http://rosettacode.org/wiki/Calendar
Calendar
Create a routine that will generate a text calendar for any year. Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices: A line printer with a width of 132 characters. An IBM 3278 model 4 terminal (80×43 display with accented characters). Target fo...
#Tcl
Tcl
package require Tcl 8.5   # Produce information about the days in a month, without any assumptions about # what those days actually are. proc calMonthDays {timezone locale year month} { set days {} set moment [clock scan [format "%04d-%02d-00 12:00" $year $month] \ -timezone $timezone -locale $locale -form...
http://rosettacode.org/wiki/Bulls_and_cows
Bulls and cows
Bulls and Cows Task Create a four digit random number from the digits   1   to   9,   without duplication. The program should:   ask for guesses to this number   reject guesses that are malformed   print the score for the guess The score is computed as: The player wins if the guess is the same as the random...
#Perl
Perl
use Data::Random qw(rand_set); use List::MoreUtils qw(uniq);   my $size = 4; my $chosen = join "", rand_set set => ["1".."9"], size => $size;   print "I've chosen a number from $size unique digits from 1 to 9; you need to input $size unique digits to guess my number\n";   for ( my $guesses = 1; ; $guesses++ ) { my ...
http://rosettacode.org/wiki/Caesar_cipher
Caesar cipher
Task Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates (either towards left or right) the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to...
#langur
langur
val .rot = f(.s, .key) { cp2s map(f(.c) rotate(rotate(.c, .key, 'a'..'z'), .key, 'A'..'Z'), s2cp .s) }   val .s = "A quick brown fox jumped over something." val .key = 3   writeln " original: ", .s writeln "encrypted: ", .rot(.s, .key) writeln "decrypted: ", .rot(.rot(.s, .key), -.key)
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#Smalltalk
Smalltalk
f valueWithArguments: arguments.
http://rosettacode.org/wiki/Call_a_function
Call a function
Task Demonstrate the different syntax and semantics provided for calling a function. This may include:   Calling a function that requires no arguments   Calling a function with a fixed number of arguments   Calling a function with optional arguments   Calling a function with a variable number of arguments   C...
#SSEM
SSEM
00110000000000100000000000000000 10. -12 to c 10110000000000000000000000000000 11. 13 to CI 11001111111111111111111111111111 12. -13 11001000000000000000000000000000 13. 19