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/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...
#TypeScript
TypeScript
  // Catalan numbers var c: number[] = [1]; console.log(`${0}\t${c[0]}`); for (n = 0; n < 15; n++) { c[n + 1] = 0; for (i = 0; i <= n; i++) c[n + 1] = c[n + 1] + c[i] * c[n - i]; console.log(`${n + 1}\t${c[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...
#uBasic.2F4tH
uBasic/4tH
Print " XXXX" Print " X XX" Print " X *** X XXXXX" Print " X ***** X XXX XX" Print " XXXX ******* XXX XXXX XX" Print " XX X ****** XXXXXXXXX XX X...
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...
#Phix
Phix
-- -- demo\rosetta\BullsAndCows.exw -- ============================= -- with javascript_semantics -- (DEV lots of resizing issues) constant N = 4 function mask(integer ch) return power(2,ch-'1') end function function score(string guess, goal) integer bits = 0, bulls = 0, cows = 0, b for i=1 to N do ...
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...
#Liberty_BASIC
Liberty BASIC
key = 7   Print "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"   'Encrypt the text Print CaesarCypher$("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", key)   'Decrypt the text by changing the key to (26 - key) Print CaesarCypher$(CaesarCypher$("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 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...
#Swift
Swift
// call a function with no args noArgs()   // call a function with one arg with no external name oneArgUnnamed(1)   // call a function with one arg with external name oneArgNamed(arg: 1)   // call a function with two args with no external names twoArgsUnnamed(1, 2)   // call a function with two args and external names ...
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...
#Tcl
Tcl
aCallToACommandWithNoArguments aCallToACommandWithOne argument aCallToACommandWith arbitrarily many arguments aCallToACommandWith {*}$manyArgumentsComingFromAListInAVariable aCallToACommandWith -oneNamed argument -andAnother namedArgument aCallToACommandWith theNameOfAnotherCommand aCallToOneCommand [withTheResultOfAno...
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...
#Ursala
Ursala
#import std #import nat   catalan = quotient^\successor choose^/double ~&   #cast %nL   t = catalan* iota 16
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...
#UNIX_Shell
UNIX Shell
  #!/bin/sh echo "Snoopy goes here" cal 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...
#PHP
PHP
<?php $size = 4;   $chosen = implode(array_rand(array_flip(range(1,9)), $size));   echo "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 ($guesses = 1; ; $guesses++) { while (true) { echo "\nNext guess [$guesses]: "; $gues...
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...
#LiveCode
LiveCode
function caesarCipher rot phrase local rotPhrase, lowerLetters, upperLetters put "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" into lowerLetters put "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" into upperLetters repeat for each char letter in phrase get charTonum(letter) ...
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...
#True_BASIC
True BASIC
FUNCTION Copialo$ (txt$, siNo, final$) FOR cont = 1 TO ROUND(siNo) LET nuevaCadena$ = nuevaCadena$ & txt$ NEXT cont   LET Copialo$ = LTRIM$(RTRIM$(nuevaCadena$)) & final$ END FUNCTION   SUB Saludo PRINT "Hola mundo!" END SUB   SUB testCadenas (txt$) FOR cont = 1 TO ROUND(LEN(txt$)) P...
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...
#Vala
Vala
namespace CatalanNumbers { public class CatalanNumberGenerator { private static double factorial(double n) { if (n == 0) return 1; return n * factorial(n - 1); }   public double first_method(double n) { const double top_multiplier = 2; return factorial(top_multiplier * n) /...
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...
#Vedit_macro_language
Vedit macro language
Buf_Switch(Buf_Free) Config_Tab(5,30,55) #9 = 1 // first day of week: 0=Su, 1=Mo #3 = 3 // number of months per line #2 = 1969 // year #1 = 1 // starting month Repeat(12/#3) { Repeat (#3) { Buf_Switch(Buf_Free) Call_File(122, "calendar...
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...
#Picat
Picat
main => Digits = to_array("123456789"), Size = 4, random_sample(Size,Size,[],ChosenIndecies), Chosen = {Digits[I] : I in ChosenIndecies}, printf("I have chosen a number from %d unique digits from 1 to 9 arranged in a random order.\n", Size), printf("You need to input a %d digit, unique digit num...
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...
#Logo
Logo
; some useful constants make "lower_a ascii "a make "lower_z ascii "z make "upper_a ascii "A make "upper_z ascii "Z   ; encipher a single character to encipher_char :char :key local "code make "code ascii :char local "base make "base 0 ifelse [and (:code >= :lower_a) (:code <= :lower_z)] [make "base :lower_a] [ ...
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...
#UNIX_Shell
UNIX Shell
sayhello # Call a function in statement context with no arguments multiply 3 4 # Call a function in statement context with two 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...
#VBA
VBA
'definitions/declarations 'Calling a function that requires no arguments Function no_arguments() As String no_arguments = "ok" End Function   'Calling a function with a fixed number of arguments Function fixed_number(argument1 As Integer, argument2 As Integer) fixed_number = argument1 + argument2 End Function ...
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...
#VBA
VBA
Public Sub Catalan1(n As Integer) 'Computes the first n Catalan numbers according to the first recursion given Dim Cat() As Long Dim sum As Long   ReDim Cat(n) Cat(0) = 1 For i = 0 To n - 1 sum = 0 For j = 0 To i sum = sum + Cat(j) * Cat(i - j) Next j Cat(i + 1) = sum Next i Debug.Print For i = 0 To n Deb...
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...
#Visual_Basic_.NET
Visual Basic .NET
Option Compare Binary Option Explicit On Option Infer On Option Strict On   Imports System.Globalization Imports System.Text Imports System.Runtime.InteropServices Imports System.Runtime.CompilerServices
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...
#PicoLisp
PicoLisp
(de ok? (N) (let D (mapcar 'format (chop N)) (and (num? N) (not (member 0 D)) (= 4 (length D)) (= D (uniq D)) D )) )   (de init-cows () (until (setq *Hidden (ok? (rand 1234 9876)))) )   (de guess (N) (let D (ok? N) (if D (let Bulls (cnt '= D *Hid...
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...
#Lua
Lua
local function encrypt(text, key) return text:gsub("%a", function(t) local base = (t:lower() == t and string.byte('a') or string.byte('A'))   local r = t:byte() - base r = r + key r = r%26 -- works correctly even if r is negative r = r + base return string.char(r) end) end   local function decrypt(...
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...
#WDTE
WDTE
let noargs => + 2 5; noargs -- print;   let fixedargs a b => + a b; fixedargs 3 5 -- print;   let m => import 'math'; m.cos 3 -- print;   # WDTE only has expressions, not statements, so statement vs. # first-class context doesn't make sense.   # Arguments in WDTE are technically passed by reference, in a way, but # bec...
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...
#WebAssembly
WebAssembly
(func $main (export "_start")   (local $result i32)    ;;Call a function with no arguments call $noargfunc    ;;Multiply two numbers and store the result, flat syntax i32.const 12 i32.const 3 call $multipy set_local $result    ;;Multiply two numbers and store the result, indented syntax...
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...
#VBScript
VBScript
  Function catalan(n) catalan = factorial(2*n)/(factorial(n+1)*factorial(n)) End Function   Function factorial(n) If n = 0 Then Factorial = 1 Else For i = n To 1 Step -1 If i = n Then factorial = n Else factorial = factorial * i End If Next End If End Function   'Find the first 15 Catalan num...
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...
#VBScript
VBScript
  'call it with year, number of months per row (1,2,3,4,6) and locale ("" for default) docal 1969,6,""   function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function   sub print(x) wscript.stdout.writeline x : end sub   function iif(a,b,c) :if a then iif=b else iif =c end if : end functio...
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...
#PowerShell
PowerShell
  [int]$guesses = $bulls = $cows = 0 [string]$guess = "none" [string]$digits = ""   while ($digits.Length -lt 4) { $character = [char](49..57 | Get-Random)   if ($digits.IndexOf($character) -eq -1) {$digits += $character} }   Write-Host "`nGuess four digits (1-9) using no digit twice.`n" -ForegroundColor Cyan  ...
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...
#M2000_Interpreter
M2000 Interpreter
  a$="THIS IS MY TEXT TO ENCODE WITH CAESAR CIPHER" Function Cipher$(a$, N) { If Len(a$)=0 Then Exit a$=Ucase$(a$) N=N mod 25 +1 \\ Integer in Mem is unsigned number Buffer Mem as Integer*Len(a$) Return Mem, 0:=a$ For i=0 to Len(a$)-1 { If Eval(mem, i)>=65 and Eval(...
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...
#Wren
Wren
var f1 = Fn.new { System.print("Function 'f1' with no arguments called.") } var f2 = Fn.new { |a, b| System.print("Function 'f2' with 2 arguments called and passed %(a) & %(b).") } var f3 = Fn.new { 42 } // function which returns a concrete value   f1.call() // statement context f2.call(2, 3) ...
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...
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   Function Factorial(n As Double) As Double If n < 1 Then Return 1 End If   Dim result = 1.0 For i = 1 To n result = result * i Next   Return result End Function   Function FirstOption(n As Double) As Double Retur...
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...
#WYLBUR
WYLBUR
Any Year Calendar -------------------- S M T W T F S
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...
#Processing
Processing
IntDict score; StringList choices; StringList guess; StringList secret; int gamesWon = -1;   void setup() { choices = new StringList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); newGame(); }   void newGame() { gamesWon++; choices.shuffle(); secret = new StringList(); for (int i=0; i<4; i++) { // selec...
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...
#Maple
Maple
  > StringTools:-Encode( "The five boxing wizards jump quickly", encoding = alpharot[3] ); "Wkh ilyh eralqj zlcdugv mxps txlfnob"   > StringTools:-Encode( %, encoding = alpharot[ 23 ] ); "The five boxing wizards jump quickly"  
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...
#XLISP
XLISP
; call a function (procedure) with no arguments: (foo)   ; call a function (procedure) with arguments: (foo bar baz) ; the first symbol after "(" is the name of the function ; the other symbols are the arguments   ; call a function on a list of arguments formed at run time: (apply foo bar)   ; In a REPL, the return val...
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...
#Vlang
Vlang
import math.big   fn main() { mut b:= big.zero_int for n := i64(0); n < 15; n++ { b = big.integer_from_i64(n) b = (b*big.two_int).factorial()/(b.factorial()*(b*big.two_int-b).factorial()) println(b/big.integer_from_i64(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...
#Wren
Wren
import "/date" for Date import "/fmt" for Fmt import "/seq" for Lst   var calendar = Fn.new { |year| var snoopy = "🐶" var days = "Su Mo Tu We Th Fr Sa" var months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ...
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...
#Prolog
Prolog
:- use_module(library(lambda)). :- use_module(library(clpfd)).   % Parameters of the server   % length of the guess proposition(4).   % Numbers of digits % 0 -> 8 digits(8).     bulls_and_cows_server :- proposition(LenGuess), length(Solution, LenGuess), choose(Solution), repeat, write('Your guess : '), read(Guess...
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...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,n]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
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...
#XSLT
XSLT
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <demo> <!-- XSLT 1.0 actually defines two function-like constructs that are ...
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...
#Wortel
Wortel
; the following number expression calculcates the nth Catalan number #~ddiFSFmSoFSn ; which stands for: dup dup inc fac swap fac mult swap double fac swap divide ; to get the first 15 Catalan numbers we map this function over a list from 0 to 15 !*#~ddiFSFmSoFSn @til 15 ; returns [1 1 2 5 14 42 132 429 1430 4862 16796 ...
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...
#XLISP
XLISP
(defun calendar (year) (define months-list '(("JANUARY" 31) ("FEBRUARY" 28) ("MARCH" 31) ("APRIL" 30) ("MAY" 31) ("JUNE" 30) ("JULY" 31) ("AUGUST" 31) ("SEPTEMBER" 30) ("OCTOBER" 31) ("NOVEMBER" 30) ("DECEMBER" 31))) (define days #(" Sunday " "Monday " "Tuesday " "Wednesday ...
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...
#PureBasic
PureBasic
Define.s secret, guess, c Define.i bulls, cows, guesses, i   If OpenConsole()   While Len(secret) < 4 c = Chr(Random(8) + 49) If FindString(secret, c, 1) = 0 secret + c EndIf Wend   Repeat Print("Guess a 4-digit number with no duplicate digits: ") guess = Input() If Len(guess) = 0 ...
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...
#MATLAB_.2F_Octave
MATLAB / Octave
function s = cipherCaesar(s, key) s = char( mod(s - 'A' + key, 25 ) + 'A'); end; function s = decipherCaesar(s, key) s = char( mod(s - 'A' - key, 25 ) + 'A'); end;
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...
#Yabasic
Yabasic
  sub test(a, b, c) : print a, b, c : end sub   test(1, 2, 3) // show 1 2 3 test(1, 2) // show 1 2 0   execute("test", 1, 2, 3) // show 1 2 3   sub test$(a$) // show all members of a "list" local n, i, t$(1)   n = token(a$, t$(), ", ") for i = 1 to n print t$(i), " "; next end sub   test$("1, 2, 3, 4, text, 6, 7,...
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...
#Wren
Wren
import "/fmt" for Fmt import "/math" for Int   var catalan = Fn.new { |n| if (n < 0) Fiber.abort("Argument must be a non-negative integer") var prod = 1 var i = n + 2 while (i <= n * 2) { prod = prod * i i = i + 1 } return prod / Int.factorial(n) }   var catalanRec catalanRec = F...
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...
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations   func WeekDay(Year, Month, Day); \Return day of week (0=Sun 1=Mon..6=Sat) int Year, Month, Day; \Works for years from 1583 onward [if Month<=2 then [Month:= Month+12; Year:= Year-1]; return rem((Day-1 + (Month+1)*26/10 + Year + Year/4 + Year/100...
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...
#Python
Python
''' Bulls and cows. A game pre-dating, and similar to, Mastermind. '''   import random   digits = '123456789' size = 4 chosen = ''.join(random.sample(digits,size)) #print chosen # Debug print '''I have chosen a number from %s unique digits from 1 to 9 arranged in a random order. You need to input a %i digit, unique di...
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...
#Microsoft_Small_Basic
Microsoft Small Basic
  TextWindow.Write("Enter a 1-25 number key (-ve number to decode): ") key = TextWindow.ReadNumber() TextWindow.Write("Enter message: ") message = text.ConvertToUpperCase(TextWindow.Read()) caeser = "" For n = 1 To Text.GetLength(message) letter = Text.GetSubText(message,n,1) code = Text.GetCharacterCode(letter) ...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#C
C
/* interface */ void print_jpg(image img, int qual);
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...
#zkl
zkl
f(); f(1,2,3,4); fcn f(a=1){}() // define and call f, which gets a set to 1 fcn{vm.arglist}(1,2,3,4) // arglist is L(1,2,3,4) fcn{a1:=vm.nthArg(1)}(1,2,3) // a1 == 2 (f() == True); (f() and 1 or 2) if (f()) println() f(f) // pass f to itself s:=f() fcn{}.isType(self.fcn) //True fcn{}.len.isType(self.fcn) //False, ...
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...
#Yabasic
Yabasic
print " n First Second Third" print " - ----- ------ -----" print for i = 0 to 15 print i using "###", catalan1(i) using "########", catalan2(i) using "########", catalan3(i) using "########" next i end   sub factorial(n) if n = 0 return 1 return n * factorial(n - 1) end sub   sub catalan1(n...
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...
#Yabasic
Yabasic
  clear screen   sub snoopy() local n, a$   n = open("snoopy.txt", "r")   while(not eof(#n)) line input #n a$ print " "; : print color("black", "white") a$ wend   close #n end sub   sub floor(n) return int(n + 0.5) end sub   sub string.rep$(s$, n) local i, r$   for i = 1 to n r$ = r$ + s$ next i   ret...
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...
#R
R
target <- sample(1:9,4) bulls <- 0 cows <- 0 attempts <- 0 while (bulls != 4) { input <- readline("Guess a 4-digit number with no duplicate digits or 0s: ") if (nchar(input) == 4) { input <- as.integer(strsplit(input,"")[[1]]) if ((sum(is.na(input)+sum(input==0))>=1) | (length(table(input)) != 4)) {pr...
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...
#MiniScript
MiniScript
caesar = function(s, key) chars = s.values for i in chars.indexes c = chars[i] if c >= "a" and c <= "z" then chars[i] = char(97 + (code(c)-97+key)%26) if c >= "A" and c <= "Z" then chars[i] = char(65 + (code(c)-65+key)%26) end for return chars.join("") end function   print caesar...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Go
Go
package main   // Files required to build supporting package raster are found in: // * Bitmap // * Write a PPM file   import ( "fmt" "math/rand" "os/exec" "raster" )   func main() { b := raster.NewBitmap(400, 300) // a little extravagant, this draws a design of dots and lines b.FillRgb(0xc08...
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...
#zonnon
zonnon
  module CallingProcs; type {public} Vector = array {math} * of integer;   var nums: array {math} 4 of integer; ints: Vector; total: integer;   procedure Init(): boolean; (* private by default *) begin nums := [1,2,3,4]; ints := new Vector(5); ints := [2,4,6,8,10]; return true; end Init;   ...
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...
#Z80_Assembly
Z80 Assembly
PackNibbles: ;input: B = top nibble, C = bottom nibble. Outputs to accumulator. ;usage: B = &0X, C = &0Y, => A = &XY LD A,B AND %00001111 RLCA RLCA RLCA RLCA OR C RET
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...
#XLISP
XLISP
(defun catalan (n) (if (= n 0) 1 (* (/ (* 2 (- (* 2 n) 1)) (+ n 1)) (catalan (- n 1))) ) )   (defun range (x y) (cons x (if (< x y) (range (+ x 1) y) ) ) )   (print (mapcar catalan (range 0 14)))
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...
#zkl
zkl
var [const] D=Time.Date, days="Su Mo Tu We Th Fr Sa";   fcn center(text,m) { String(" "*((m-text.len())/2),text) }   fcn oneMonth(year,month){ day1:=D.zeller(year,month,1); //1969-1-1 -->3 (Wed, ISO 8601) dayz:=D.daysInMonth(year,month); //1969-1 -->31 List(center(D.monthNames[month],days.len()),days).ext...
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...
#Racket
Racket
  #lang racket   ; secret : (listof exact-nonnegative-integer?) (define secret (foldr (λ (n result) (cons n (map (λ (y) (if (>= y n) (add1 y) y)) result))) '() (map random '(10 9 8 7))))   ; (count-bulls/cows guess) -> (values exact-nonnegative-integer? ; ...
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...
#ML
ML
fun readfile () = readfile [] | x = let val ln = readln () in if eof ln then rev x else readfile ` ln :: x end   local val lower_a = ord #"a"; val lower_z = ord #"z"; val upper_a = ord #"A"; val upper_z = o...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Julia
Julia
using Images, FileIO   ppmimg = load("data/bitmapInputTest.ppm") save("data/bitmapOutputTest.jpg", ppmimg)
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Kotlin
Kotlin
// Version 1.2.40   import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage   class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR)   fun fill(c: Color) { val g = image.graphics g.color = c 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...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 REM functions cannot be called in statement context 20 PRINT FN a(5): REM The function is used in first class context. Arguments are not named 30 PRINT FN b(): REM Here we call a function that has no arguments 40 REM subroutines cannot be passed parameters, however variables are global 50 LET n=1: REM This variable ...
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...
#XPL0
XPL0
code CrLf=9, IntOut=11; int C, N; [C:= 1; IntOut(0, C); CrLf(0); for N:= 1 to 14 do [C:= C*2*(2*N-1)/(N+1); IntOut(0, C); CrLf(0); ]; ]
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...
#Raku
Raku
my $size = 4; my @secret = pick $size, '1' .. '9';   for 1..* -> $guesses { my @guess; loop { @guess = (prompt("Guess $guesses: ") // exit).comb; last if @guess == $size and all(@guess) eq one(@guess) & any('1' .. '9'); say 'Malformed guess; try again.'; } my ($bulls,...
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...
#Modula-2
Modula-2
MODULE CaesarCipher; FROM Conversions IMPORT IntToStr; FROM Terminal IMPORT WriteString, WriteLn, ReadChar;   TYPE String = ARRAY[0..64] OF CHAR;   PROCEDURE Encrypt(p : String; key : CARDINAL) : String; VAR e : String; VAR i,t : CARDINAL; VAR c : CHAR; BEGIN FOR i:=0 TO HIGH(p) DO IF p[i]=0C THEN BREAK; EN...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
convert[image_,out_]:=Module[{process=StartProcess[{ "wolfram","-noinit","-noprompt","-run", "Export[FromCharacterCode["~~ToString[ToCharacterCode[out]]~~"],ImportString[StringRiffle[Table[InputString[],{4}],FromCharacterCode[10]],FromCharacterCode[{80,80,77}]]]" }]}, WriteLine[process,image]; WriteLine[process,"Quit[]...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Nim
Nim
import bitmap import ppm_write import osproc   # Build an image. var image = newImage(100, 50) image.fill(color(255, 0, 0)) for row in 10..20: for col in 0..<image.w: image[col, row] = color(0, 255, 0) for row in 30..40: for col in 0..<image.w: image[col, row] = color(0, 0, 255)   # Launch ImageMagick "conv...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#OCaml
OCaml
let print_jpeg ~img ?(quality=96) () = let cmd = Printf.sprintf "cjpeg -quality %d" quality in (* let cmd = Printf.sprintf "ppmtojpeg -quality %d" quality in let cmd = Printf.sprintf "convert ppm:- -quality %d jpg:-" quality in *) let ic, oc = Unix.open_process cmd in output_ppm ~img ~oc; try while ...
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...
#zkl
zkl
var BN=Import("zklBigNum"); fcn catalan(n){ BN(2*n).factorial() / BN(n+1).factorial() / BN(n).factorial(); }   foreach n in (16){ println("%2d --> %,d".fmt(n, catalan(n))); } println("%2d --> %,d".fmt(100, catalan(100)));
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...
#Red
Red
  Red[] a: "0123456789" bulls: 0 random/seed now/time number: copy/part random a 4 while [bulls <> 4] [ bulls: 0 cows: 0 guess: ask "make a guess: " repeat i 4 [ if (pick guess i) = (pick number i) [bulls: bulls + 1] ] cows: (length? intersect guess number) - bulls print ["bulls: " bulls " cows: " cows] ] prin...
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...
#Modula-3
Modula-3
MODULE Caesar EXPORTS Main;   IMPORT IO, IntSeq, Text;   EXCEPTION BadCharacter; (* Used whenever message contains a non-alphabetic character. *)   PROCEDURE Encode(READONLY message: TEXT; numbers: IntSeq.T) RAISES { BadCharacter } = (* Converts upper or lower case letter to 0..25. Raises a "BadCharacter" exception for...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Perl
Perl
# 20211224 Perl programming solution   use strict; use warnings;   use Imager; use Imager::Test 'test_image_raw';   my $img = test_image_raw(); my $IO = Imager::io_new_bufchain(); Imager::i_writeppm_wiol($img, $IO) or die; my $raw = Imager::io_slurp($IO) or die;   open my $fh, '|-', '/usr/local/bin/convert - -compres...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Phix
Phix
-- demo\rosetta\Bitmap_PPM_conversion_through_a_pipe.exw without js -- file i/o, system_exec(), pipes[!!] include builtins\pipeio.e include builtins\serialize.e include ppm.e -- read_ppm() sequence pipes = repeat(0,3) pipes[PIPEIN] = create_pipe(INHERIT_WRITE) -- Create the child process, with replacement stdin. str...
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...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 FOR i=0 TO 15 20 LET n=i: LET m=2*n 30 LET r=1: LET d=m-n 40 IF d>n THEN LET n=d: LET d=m-n 50 IF m<=n THEN GO TO 90 60 LET r=r*m: LET m=m-1 70 IF (d>1) AND NOT FN m(r,d) THEN LET r=r/d: LET d=d-1: GO TO 70 80 GO TO 50 90 PRINT i;TAB 4;r/(1+n) 100 NEXT i 110 STOP 120 DEF FN m(a,b)=a-INT (a/b)*b: REM Modulus functio...
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...
#REXX
REXX
/*REXX program scores the Bulls & Cows game with CBLFs (Carbon Based Life Forms). */ ?=; do until length(?)==4; r= random(1, 9) /*generate a unique four-digit number. */ if pos(r,?)\==0 then iterate;  ?= ? || r /*don't allow a repeated digit/numeral. */ end /*until length*/ ...
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...
#Nanoquery
Nanoquery
def caesar_encode(plaintext, shift) uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" lowercase = "abcdefghijklmnopqrstuvwxyz"   cipher = "" for char in plaintext if char in uppercase cipher += uppercase[uppercase[char] - (26 - shift)] else if char in lowercase cipher += lowercase[lowercase[char] - (26 - shift)] ...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#PicoLisp
PicoLisp
# Create an empty image of 120 x 90 pixels (setq *Ppm (make (do 90 (link (need 120)))))   # Fill background with green color (ppmFill *Ppm 0 255 0)   # Draw a diagonal line (for I 80 (ppmSetPixel *Ppm I I 0 0 0))   # Write to "img.jpg" through a pipe (ppmWrite *Ppm '("convert" "-" "img.jpg"))
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Python
Python
  """ Adapted from https://stackoverflow.com/questions/26937143/ppm-to-jpeg-jpg-conversion-for-python-3-4-1 Requires pillow-5.3.0 with Python 3.7.1 32-bit on Windows. Sample ppm graphics files from http://www.cs.cornell.edu/courses/cs664/2003fa/images/ """   from PIL import Image   im = Image.open("boxes_1.ppm") im.sav...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Racket
Racket
  (define (ppm->jpeg bitmap [jpg-file "output"] [quality 75]) (define command (format "convert ppm:- -quality ~a jpg:~a.jpg" quality jpg-file)) (match-define (list in out pid err ctrl) (process command)) (bitmap->ppm bitmap out) (close-input-port in) (close-output-port out))   (ppm->jpeg bm)
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...
#Ring
Ring
  # Project : Bulls and cows   secret = "" while len(secret) != 4 c = char(48 + random(9)) if substr(secret, c) = 0 secret = secret + c ok end   see "guess a four-digit number with no digit used twice." guesses = 0 guess = "" while true guess = "" while len(guess) != 4...
http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe
Bitmap/Read an image through a pipe
This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PP...
#AutoHotkey
AutoHotkey
ppm := Run("cmd.exe /c convert lena50.jpg ppm:-") ; pipe in from imagemagick img := ppm_read("", ppm) ; x := img[4,4] ; get pixel(4,4) y := img[24,24] ; get pixel(24,24) msgbox % x.rgb() " " y.rgb() img.write("lena50copy.ppm") return   ppm_read(filename, ppmo=0) ; only ppm6 files supported {...
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...
#NetRexx
NetRexx
/* NetRexx */   options replace format comments java crossref savelog symbols nobinary   messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13]   loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, k...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Raku
Raku
# Reference: # https://rosettacode.org/wiki/Bitmap/Write_a_PPM_file#Raku   use v6;   class Pixel { has uint8 ($.R, $.G, $.B) } class Bitmap { has UInt ($.width, $.height); has Pixel @!data;   method fill(Pixel $p) { @!data = $p.clone xx ($!width*$!height) } method pixel( $i where ^...
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...
#Ruby
Ruby
def generate_word(len) [*"1".."9"].shuffle.first(len) # [*"1".."9"].sample(len) ver 1.9+ end   def get_guess(len) loop do print "Enter a guess: " guess = gets.strip err = case when guess.match(/[^1-9]/)  ; "digits only" when guess.length != len  ; "exa...
http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe
Bitmap/Read an image through a pipe
This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PP...
#C
C
image read_image(const char *name);
http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe
Bitmap/Read an image through a pipe
This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PP...
#Go
Go
package main   // Files required to build supporting package raster are found in: // * Bitmap // * Read a PPM file // * Write a PPM file   import ( "log" "os/exec" "raster" )   func main() { c := exec.Command("convert", "Unfilledcirc.png", "-depth", "1", "ppm:-") pipe, err := c.StdoutPipe() if e...
http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe
Bitmap/Read an image through a pipe
This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PP...
#Julia
Julia
using Images, FileIO   img = load("data/bitmapOutputTest.jpg") save("data/bitmapOutputTest.ppm", img)
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...
#Nim
Nim
import strutils   proc caesar(s: string, k: int, decode = false): string = var k = if decode: 26 - k else: k result = "" for i in toUpper(s): if ord(i) >= 65 and ord(i) <= 90: result.add(chr((ord(i) - 65 + k) mod 26 + 65))   let msg = "The quick brown fox jumped over the lazy dogs" echo msg let enc = ca...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Ruby
Ruby
class Pixmap PIXMAP_FORMATS = ["P3", "P6"] # implemented output formats PIXMAP_BINARY_FORMATS = ["P6"] # implemented output formats which are binary   def write_ppm(ios, format="P6") if not PIXMAP_FORMATS.include?(format) raise NotImplementedError, "pixmap format #{format} has not been implemented" ...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Standard_ML
Standard ML
  val useOSConvert = fn ppm => let val img = String.translate (fn #"\"" => "\\\""|n=>str n ) ppm ; val app = " convert - jpeg:- " val fname = "/tmp/fConv" ^ (String.extract (Time.toString (Posix.ProcEnv.time()),7,NONE) ); val shellCommand = " echo \"" ^ img ^ "\" | " ^ app  ;...
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...
#Rust
Rust
use std::io; use rand::{Rng,thread_rng};   extern crate rand;   const NUMBER_OF_DIGITS: usize = 4;   static DIGITS: [char; 9] = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];   fn generate_digits() -> Vec<char> { let mut temp_digits: Vec<_> = (&DIGITS[..]).into(); thread_rng().shuffle(&mut temp_digits); ret...
http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe
Bitmap/Read an image through a pipe
This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PP...
#Kotlin
Kotlin
// Version 1.2.40   import java.awt.Color import java.awt.Graphics import java.awt.image.BufferedImage import java.io.PushbackInputStream import java.io.File import javax.imageio.ImageIO   class BasicBitmapStorage(width: Int, height: Int) { val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR)   ...
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...
#Oberon-2
Oberon-2
  MODULE Caesar; IMPORT Out; CONST encode* = 1; decode* = -1;   VAR text,cipher: POINTER TO ARRAY OF CHAR;   PROCEDURE Cipher*(txt: ARRAY OF CHAR; key: INTEGER; op: INTEGER; VAR cipher: ARRAY OF CHAR); VAR i: LONGINT; BEGIN i := 0; WHILE i < LEN(txt) - 1 DO IF (txt[i] >= 'A') & (txt[i] ...
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Tcl
Tcl
package require Tk   proc output_jpeg {image filename {quality 75}} { set f [open |[list convert ppm:- -quality $quality jpg:- > $filename] w] fconfigure $f -translation binary puts -nonewline $f [$image data -format ppm] close $f }
http://rosettacode.org/wiki/Bitmap/PPM_conversion_through_a_pipe
Bitmap/PPM conversion through a pipe
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page. There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux)...
#Wren
Wren
/* gcc -O3 -std=c11 -shared -o pipeconv.so -fPIC -I./include pipeconv.c */   #include <stdlib.h> #include <string.h> #include "dome.h"   static DOME_API_v0* core; static WREN_API_v0* wren;   static const char* source = "" "class PipeConv {\n" "foreign static convert(from, to) \n" "} \n";   void C_convert(WrenVM* v...
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...
#Scala
Scala
import scala.util.Random   object BullCow { def main(args: Array[String]): Unit = { val number=chooseNumber var guessed=false var guesses=0   while(!guessed){ Console.print("Guess a 4-digit number with no duplicate digits: ") val input=Console.readInt val digits=inp...
http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe
Bitmap/Read an image through a pipe
This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PP...
#Lua
Lua
function Bitmap:loadPPM(filename, fp) if not fp then fp = io.open(filename, "rb") end if not fp then return end local head, width, height, depth, tail = fp:read("*line", "*number", "*number", "*number", "*line") self.width, self.height = width, height self:alloc() for y = 1, self.height do for x = 1, se...
http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe
Bitmap/Read an image through a pipe
This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PP...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Export["data/bitmapOutputTest.ppm",Import["data/bitmapOutputTest.jpg"]];
http://rosettacode.org/wiki/Bitmap/Read_an_image_through_a_pipe
Bitmap/Read an image through a pipe
This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PP...
#Nim
Nim
import bitmap import osproc import ppm_read import streams   # Launch Netpbm "jpegtopnm". # Input is taken from "input.jpeg" and result sent to stdout. let p = startProcess("jpegtopnm", args = ["input.jpeg"], options = {poUsePath}) let stream = FileStream(p.outputStream()) let image = stream.readPPM() echo image.w, " "...