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/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#COBOL
COBOL
  IDENTIFICATION DIVISION. PROGRAM-ID. TOROMAN. DATA DIVISION. working-storage section. 01 ws-number pic 9(4) value 0. 01 ws-save-number pic 9(4). 01 ws-tbl-def. 03 filler pic x(7) value '1000M '. 03 filler pic x(7) value '0900CM '. 03 filler pic x(7) value '0500D '. 03 filler pic x(7) value '04...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#D
D
import std.regex, std.algorithm;   int toArabic(in string s) /*pure nothrow*/ { static immutable weights = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; static immutable symbols = ["M","CM","D","CD","C","XC", "L","XL","X","IX","V","IV","I...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Lua
Lua
-- Function to have roots found function f (x) return x^3 - 3*x^2 + 2*x end   -- Find roots of f within x=[start, stop] or approximations thereof function root (f, start, stop, step) local roots, x, sign, foundExact, value = {}, start, f(start) > 0 while x <= stop do value = f(x) if value == 0 t...
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Java
Java
import java.util.Arrays; import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.Random;   public class RPS { public enum Item{ ROCK, PAPER, SCISSORS, /*LIZARD, SPOCK*/; public List<Item> losesToList; public boolean losesTo(Item other) { return losesTo...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#jq
jq
def runs: reduce .[] as $item ( []; if . == [] then [ [ $item, 1] ] else .[length-1] as $last | if $last[0] == $item then .[length-1] = [$item, $last[1] + 1] else . + [[$item, 1]] end end ) ;
http://rosettacode.org/wiki/Roots_of_unity
Roots of unity
The purpose of this task is to explore working with   complex numbers. Task Given   n,   find the   nth   roots of unity.
#Tcl
Tcl
package require Tcl 8.5 namespace import tcl::mathfunc::*   set pi 3.14159265 for {set n 2} {$n <= 10} {incr n} { set angle 0.0 set row $n: for {set i 1} {$i <= $n} {incr i} { lappend row [format %5.4f%+5.4fi [cos $angle] [sin $angle]] set angle [expr {$angle + 2*$pi/$n}] } puts $row...
http://rosettacode.org/wiki/Roots_of_unity
Roots of unity
The purpose of this task is to explore working with   complex numbers. Task Given   n,   find the   nth   roots of unity.
#TI-89_BASIC
TI-89 BASIC
cZeros(x^n - 1, x)
http://rosettacode.org/wiki/Roots_of_a_quadratic_function
Roots of a quadratic function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Write a program to find the roots of a quadratic equation, i.e., solve the equation a x 2 + b x + c = 0 {\displaystyle ax^{2}+bx+c=0} . Your program must correctly handle n...
#Stata
Stata
mata : polyroots((-2,0,1)) 1 2 +-----------------------------+ 1 | 1.41421356 -1.41421356 | +-----------------------------+   : polyroots((2,0,1)) 1 2 +-------------------------------+ 1 | -1.41421356i 1.41421356i | +-------------...
http://rosettacode.org/wiki/Roots_of_a_quadratic_function
Roots of a quadratic function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Write a program to find the roots of a quadratic equation, i.e., solve the equation a x 2 + b x + c = 0 {\displaystyle ax^{2}+bx+c=0} . Your program must correctly handle n...
#Tcl
Tcl
package require math::complexnumbers namespace import math::complexnumbers::complex math::complexnumbers::tostring   proc quadratic {a b c} { set discrim [expr {$b**2 - 4*$a*$c}] set roots [list] if {$discrim < 0} { set term1 [expr {(-1.0*$b)/(2*$a)}] set term2 [expr {sqrt(abs($discrim))/(2*...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Forth
Forth
: r13 ( c -- o ) dup 32 or \ tolower dup [char] a [char] z 1+ within if [char] m > if -13 else 13 then + else drop then ;
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Woma
Woma
(sieve(n = /0 -> int; limit = /0 -> int; is_prime = [/0] -> *)) * i<@>range(n*n, limit+1, n) is_prime = is_prime[$]i,False <*>is_prime   (primes_upto(limit = 4 -> int)) list(int) primes = [] -> list f = [False, False] -> list(bool) t = [True] -> list(bool) u = limit - 1 -> int tt = t...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#PicoLisp
PicoLisp
(de lastIndex (Item Lst) (- (length Lst) (index Item (reverse Lst)) -1) )   (de findNeedle (Fun Sym Lst) (prinl Sym " " (or (Fun Sym Lst) "not found")) )   (let Lst '(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo) (findNeedle index 'Washington Lst) (findNeedle index 'Bush Lst) (findNeedle lastIndex ...
http://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity
Rosetta Code/Rank languages by popularity
Rosetta Code/Rank languages by popularity You are encouraged to solve this task according to the task description, using any language you may know. Task Sort the most popular computer programming languages based in number of members in Rosetta Code categories. Sample output on 01 juin 2022 at 14:13 +02 Rank: 1 (1,...
#Stata
Stata
copy "http://rosettacode.org/wiki/Category:Programming_Languages" lang.html, replace import delimited lang.html, delim("@") enc("utf-8") clear keep if ustrpos(v1,"/wiki/Category:") gen i = ustrpos(v1,"title=") gen j = ustrpos(v1,char(34),i+1) gen k = ustrpos(v1,char(34),j+1) gen s = usubstr(v1,j,k-j+1) keep if usubstr(...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#CoffeeScript
CoffeeScript
  decimal_to_roman = (n) -> # This should work for any positive integer, although it # gets a bit preposterous for large numbers. if n >= 4000 thousands = decimal_to_roman n / 1000 ones = decimal_to_roman n % 1000 return "M(#{thousands})#{ones}"   s = '' translate_each = (min, roman) -> while ...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Delphi.2FPascal
Delphi/Pascal
program RomanNumeralsDecode;   {$APPTYPE CONSOLE}   function RomanToInteger(const aRoman: string): Integer; function DecodeRomanDigit(aChar: Char): Integer; begin case aChar of 'M', 'm': Result := 1000; 'D', 'd': Result := 500; 'C', 'c': Result := 100; 'L', 'l': Result := 50; 'X', ...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Maple
Maple
f := x^3-3*x^2+2*x; roots(f,x);
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Solve[x^3-3*x^2+2*x==0,x]
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#JavaScript
JavaScript
  const logic = { rock: { w: 'scissor', l: 'paper'}, paper: {w:'rock', l:'scissor'}, scissor: {w:'paper', l:'rock'}, }   class Player { constructor(name){ this.name = name; } setChoice(choice){ this.choice = choice; } challengeOther(PlayerTwo){ return logic[this.c...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Julia
Julia
using IterTools   encode(str::String) = collect((length(g), first(g)) for g in groupby(first, str)) decode(cod::Vector) = join(repeat("$l", n) for (n, l) in cod)   for original in ["aaaaahhhhhhmmmmmmmuiiiiiiiaaaaaa", "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"] encoded = encode(original) ...
http://rosettacode.org/wiki/Roots_of_unity
Roots of unity
The purpose of this task is to explore working with   complex numbers. Task Given   n,   find the   nth   roots of unity.
#Ursala
Ursala
#import std #import nat #import flo   roots = ~&htxPC+ c..mul:-0^*DlSiiDlStK9\iota c..mul@iiX+ c..cpow/-1.+ div/1.+ float   #cast %jLL   tests = roots* <1,2,3,4,5,6>
http://rosettacode.org/wiki/Roots_of_unity
Roots of unity
The purpose of this task is to explore working with   complex numbers. Task Given   n,   find the   nth   roots of unity.
#VBA
VBA
Public Sub roots_of_unity() For n = 2 To 9 Debug.Print n; "th roots of 1:" For r00t = 0 To n - 1 Debug.Print " Root "; r00t & ": "; WorksheetFunction.Complex(Cos(2 * WorksheetFunction.Pi() * r00t / n), _ Sin(2 * WorksheetFunction.Pi() * r00t / n)) Next r00t ...
http://rosettacode.org/wiki/Roots_of_unity
Roots of unity
The purpose of this task is to explore working with   complex numbers. Task Given   n,   find the   nth   roots of unity.
#Wren
Wren
import "/complex" for Complex import "/fmt" for Fmt   var roots = Fn.new { |n| var r = List.filled(n, null) for (i in 0...n) r[i] = Complex.fromPolar(1, 2 * Num.pi * i / n) return r }   for (n in 2..5) { Fmt.print("$d roots of 1:", n) for (r in roots.call(n)) Fmt.print(" $17.14z", r) }
http://rosettacode.org/wiki/Roots_of_a_quadratic_function
Roots of a quadratic function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Write a program to find the roots of a quadratic equation, i.e., solve the equation a x 2 + b x + c = 0 {\displaystyle ax^{2}+bx+c=0} . Your program must correctly handle n...
#TI-89_BASIC
TI-89 BASIC
solve(x^2-1E9x+1.0)
http://rosettacode.org/wiki/Roots_of_a_quadratic_function
Roots of a quadratic function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Write a program to find the roots of a quadratic equation, i.e., solve the equation a x 2 + b x + c = 0 {\displaystyle ax^{2}+bx+c=0} . Your program must correctly handle n...
#Wren
Wren
import "/complex" for Complex   var quadratic = Fn.new { |a, b, c| var d = b*b - 4*a*c if (d == 0) { // single root return [[-b/(2*a)], null] } if (d > 0) { // two real roots var sr = d.sqrt d = (b < 0) ? sr - b : -sr - b return [[d/(2*a), 2*c/d], null] ...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Fortran
Fortran
program test_rot_13   implicit none integer, parameter :: len_max = 256 integer, parameter :: unit = 10 character (len_max) :: file character (len_max) :: fmt character (len_max) :: line integer :: arg integer :: arg_max integer :: iostat   write (fmt, '(a, i0, a)') '(a', len_max, ')' arg_max = ia...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Wren
Wren
var sieveOfE = Fn.new { |n| if (n < 2) return [] var comp = List.filled(n-1, false) var p = 2 while (true) { var p2 = p * p if (p2 > n) break var i = p2 while (i <= n) { comp[i-2] = true i = i + p } while (true) { p = p ...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#PL.2FI
PL/I
search: procedure () returns (fixed binary); declare haystack (0:9) character (200) varying static initial ('apple', 'banana', 'celery', 'dumpling', 'egg', 'flour', 'grape', 'pomegranate', 'raisin', 'sugar' ); declare needle character (200) varying; declare i fixed binary; declare missing_needl...
http://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity
Rosetta Code/Rank languages by popularity
Rosetta Code/Rank languages by popularity You are encouraged to solve this task according to the task description, using any language you may know. Task Sort the most popular computer programming languages based in number of members in Rosetta Code categories. Sample output on 01 juin 2022 at 14:13 +02 Rank: 1 (1,...
#Tcl
Tcl
package require Tcl 8.5 package require http   set response [http::geturl http://rosettacode.org/mw/index.php?title=Special:Categories&limit=8000]   array set ignore { "Basic language learning" 1 "Encyclopedia" 1 "Implementations" 1 "Language Implementati...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Common_Lisp
Common Lisp
(defun roman-numeral (n) (format nil "~@R" n))
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#EasyLang
EasyLang
rom_digs$[] = [ "M" "D" "C" "L" "X" "V" "I" ] rom_vals[] = [ 1000 500 100 50 10 5 1 ] # func rom2int rom_numb$ . val . val = 0 for dig$ in strchars rom_numb$ for i range len rom_digs$[] if rom_digs$[i] = dig$ v = rom_vals[i] . . val += v if old_v < v val -= 2 * old_v ....
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Maxima
Maxima
e: x^3 - 3*x^2 + 2*x$   /* Number of roots in a real interval, using Sturm sequences */ nroots(e, -10, 10); 3   solve(e, x); [x=1, x=2, x=0]   /* 'solve sets the system variable 'multiplicities */   solve(x^4 - 2*x^3 + 2*x - 1, x); [x=-1, x=1]   multiplicities; [1, 3]   /* Rational approximation of roots using Sturm se...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Nim
Nim
import math import strformat   func f(x: float): float = x ^ 3 - 3 * x ^ 2 + 2 * x   var step = 0.01 start = -1.0 stop = 3.0 sign = f(start) > 0 x = start   while x <= stop: var value = f(x)   if value == 0: echo fmt"Root found at {x:.5f}" elif (value > 0) != sign: echo fmt"Root found near {x:....
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Julia
Julia
function rps() print("Welcome to Rock, paper, scissors! Go ahead and type your pick.\n r(ock), p(aper), or s(cissors)\n Enter 'q' to quit.\n>") comp_score = 0 user_score = 0 options = ["r","p","s"] new_pick() = options[rand(1:3)] i_win(m,y) = ((m == "r" && y == "s")|(m == "s" && y == "p")|(m == "p" && y == "r...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#K
K
rle: {,/($-':i,#x),'x@i:&1,~=':x}
http://rosettacode.org/wiki/Roots_of_unity
Roots of unity
The purpose of this task is to explore working with   complex numbers. Task Given   n,   find the   nth   roots of unity.
#zkl
zkl
PI2:=(0.0).pi*2; foreach n,i in ([1..9],n){ c:=s:=0; if(not i) c = 1; else if(n==4*i) s = 1; else if(n==2*i) c = -1; else if(3*n==4*i) s = -1; else a,c,s:=PI2*i/n,a.cos(),a.sin();   if(c) print("%.2g".fmt(c)); print( (s==1 and "i") or (s==-1 and "-i" or (s and "%+.2gi" or"")).fmt(s...
http://rosettacode.org/wiki/Roots_of_a_quadratic_function
Roots of a quadratic function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Write a program to find the roots of a quadratic equation, i.e., solve the equation a x 2 + b x + c = 0 {\displaystyle ax^{2}+bx+c=0} . Your program must correctly handle n...
#zkl
zkl
fcn quadratic(a,b,c){ b=b.toFloat(); println("Roots of a quadratic function %s, %s, %s".fmt(a,b,c)); d,a2:=(b*b - 4*a*c), a+a; if(d>0){ sd:=d.sqrt(); println(" the real roots are %s and %s".fmt((-b + sd)/a2,(-b - sd)/a2)); } else if(d==0) println(" the single root is ",-b/a2); else{ ...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   ' uses in place encoding/decoding Sub rot13(ByRef s As String) If s = "" Then Exit Sub Dim code As Integer For i As Integer = 0 To Len(s) - 1 Select Case As Const s[i] Case 65 To 90 '' A to Z code = s[i] + 13 If code > 90 Then code -= 26 s[i] = code ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations int Size, Prime, I, Kill; char Flag; [Size:= IntIn(0); Flag:= Reserve(Size+1); for I:= 2 to Size do Flag(I):= true; for I:= 2 to Size do if Flag(I) then \found a prime [Prime:= I; IntOut(0, Prime); CrLf(0); ...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#Plain_English
Plain English
To run: Start up. Make an example haystack. Find "b" in the example haystack giving a count. Destroy the example haystack. Write "The index of ""b"" is " then the count on the console. Wait for the escape key. Shut down.   A needle is a string.   Some hay is some strings.   A bale is a thing with some hay.   A haystack...
http://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity
Rosetta Code/Rank languages by popularity
Rosetta Code/Rank languages by popularity You are encouraged to solve this task according to the task description, using any language you may know. Task Sort the most popular computer programming languages based in number of members in Rosetta Code categories. Sample output on 01 juin 2022 at 14:13 +02 Rank: 1 (1,...
#TUSCRIPT
TUSCRIPT
$$ MODE TUSCRIPT remotedata = REQUEST ("http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000") allmembers=allnames="" COMPILE LOOP d=remotedata IF (d.sw."<li>") THEN name=EXTRACT (d,":<<a<><%>>:"|,":<</a>>:") IF (name.eq."Language users") CYCLE IF (name.sw."Unimplemented tasks") CYCLE IF (nam...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Cowgol
Cowgol
include "cowgol.coh"; include "argv.coh";   # Encode the given number as a Roman numeral sub decimalToRoman(num: uint16, buf: [uint8]): (rslt: [uint8]) is # return the start of the buffer for easy printing rslt := buf;   # Add string to buffer sub Add(str: [uint8]) is while [str] != 0 loop ...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#ECL
ECL
  MapChar(STRING1 c) := CASE(c,'M'=>1000,'D'=>500,'C'=>100,'L'=>50,'X'=>10,'V'=>5,'I'=>1,0);   RomanDecode(STRING s) := FUNCTION dsS := DATASET([{s}],{STRING Inp}); R := { INTEGER2 i; };   R Trans1(dsS le,INTEGER pos) := TRANSFORM SELF.i := MapChar(le.Inp[pos]) * IF ( MapChar(le.Inp[pos]) < MapChar(le.Inp[pos...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Objeck
Objeck
  bundle Default { class Roots { function : f(x : Float) ~ Float { return (x*x*x - 3.0*x*x + 2.0*x); }   function : Main(args : String[]) ~ Nil { step := 0.001; start := -1.0; stop := 3.0; value := f(start); sign := (value > 0);   if(0.0 = value) { ...
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Kotlin
Kotlin
// version 1.2.10   import java.util.Random   const val choices = "rpsq" val rand = Random()   var pWins = 0 // player wins var cWins = 0 // computer wins var draws = 0 // neither wins var games = 0 // games played val pFreqs = arrayOf(0, 0, 0) // pla...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Kotlin
Kotlin
tailrec fun runLengthEncoding(text:String,prev:String=""):String { if (text.isEmpty()){ return prev } val initialChar = text.get(0) val count = text.takeWhile{ it==initialChar }.count() return runLengthEncoding(text.substring(count),prev + "$count$initialChar" ) }   fun main(args: Array<Stri...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#FunL
FunL
import io.{lines, stdin}   def rot13( s ) = buf = StringBuilder()   for c <- s if isalpha( c ) n = ((ord(c) and 0x1F) - 1 + 13)%26 + 1   buf.append( chr(n or (if isupper(c) then 64 else 96)) ) else buf.append( c )   buf.toString()   def rot13lines( ls ) = for l <- ls println( rot13...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Yabasic
Yabasic
#!/usr/bin/yabasic   // --------------------------- // Prime Sieve Benchmark -- // "Shootout" Version -- // --------------------------- // usage: // yabasic sieve8k.yab 90000     SIZE = 8192 ONN = 1 : OFF = 0 dim flags(SIZE)   sub main()   cmd = peek("arguments") if cmd = 1 then iterations = val(p...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#PowerBASIC
PowerBASIC
FUNCTION PBMAIN () AS LONG DIM haystack(54) AS STRING ARRAY ASSIGN haystack() = "foo", "bar", "baz", "quux", "quuux", "quuuux", _ "bazola", "ztesch", "foo", "bar", "thud", "grunt", "foo", _ "bar", "bletch", "foo", "bar", "fum", "fred", "jim", _ "sheila", "barne...
http://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity
Rosetta Code/Rank languages by popularity
Rosetta Code/Rank languages by popularity You are encouraged to solve this task according to the task description, using any language you may know. Task Sort the most popular computer programming languages based in number of members in Rosetta Code categories. Sample output on 01 juin 2022 at 14:13 +02 Rank: 1 (1,...
#UnixPipes
UnixPipes
curl 'http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000' | sed -nre 's/^<li.*title="Category:([^"(]+)".*\(([0-9]+) members\).*/\2 - \1/p' | sort -nr | awk '{printf "%2d. %s\n",NR,$0}'
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#D
D
string toRoman(int n) pure nothrow in { assert(n < 5000); } body { static immutable weights = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; static immutable symbols = ["M","CM","D","CD","C","XC","L", "XL","X","IX","V","IV","I"];   ...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Eiffel
Eiffel
class APPLICATION   create make   feature {NONE} -- Initialization   make local numbers: ARRAY [STRING] do numbers := <<"MCMXC", "MMVIII", "MDCLXVI", -- 1990 2008 1666 "MMMCLIX", "MCMLXXVII", "MMX">> -- 3159 1977 2010 across numbers as ...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#OCaml
OCaml
let bracket u v = ((u > 0.0) && (v < 0.0)) || ((u < 0.0) && (v > 0.0));;   let xtol a b = (a = b);; (* or use |a-b| < epsilon *)   let rec regula_falsi a b fa fb f = if xtol a b then (a, fa) else let c = (fb*.a -. fa*.b) /. (fb -. fa) in let fc = f c in if fc = 0.0 then (c, fc) else if bracket fa fc then ...
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Lasso
Lasso
session_start('user') session_addvar('user', 'historic_choices') session_addvar('user', 'win_record') session_addvar('user', 'plays') var(historic_choices)->isNotA(::map) ? var(historic_choices = map('rock'=0, 'paper'=0, 'scissors'=0)) var(plays)->isNotA(::integer) ? var(plays = 0) var(win_record)->isNotA(::array) ? va...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Lasso
Lasso
define rle(str::string)::string => { local(orig = #str->values->asCopy,newi=array, newc=array, compiled=string) while(#orig->size) => { if(not #newi->size) => { #newi->insert(1) #newc->insert(#orig->first) #orig->remove(1) else if(#orig->first == #newc->last) => { #newi->get(#newi->size) += 1 e...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#GAP
GAP
rot13 := function(s) local upper, lower, c, n, t; upper := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; lower := "abcdefghijklmnopqrstuvwxyz"; t := [ ]; for c in s do n := Position(upper, c); if n <> fail then Add(t, upper[((n+12) mod 26) + 1]); else n := Position(lower, c); if n <> fail then ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Zig
Zig
  const std = @import("std"); const stdout = std.io.getStdOut().outStream();   pub fn main() !void { try sieve(1000); }   // using a comptime limit ensures that there's no need for dynamic memory. fn sieve(comptime limit: usize) !void { var prime = [_]bool{true} ** limit; prime[0] = false; prime[1] = fa...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#PowerShell
PowerShell
  function index($haystack,$needle) { $index = $haystack.IndexOf($needle) if($index -eq -1) { Write-Warning "$needle is absent" } else { $index }   } $haystack = @("word", "phrase", "preface", "title", "house", "line", "chapter", "page", "book", "house") index $haystack "house" index $ha...
http://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity
Rosetta Code/Rank languages by popularity
Rosetta Code/Rank languages by popularity You are encouraged to solve this task according to the task description, using any language you may know. Task Sort the most popular computer programming languages based in number of members in Rosetta Code categories. Sample output on 01 juin 2022 at 14:13 +02 Rank: 1 (1,...
#VBScript
VBScript
''''''''''''''''''''''''''''''''''''''''''''' ' Rosetta Code/Rank Languages by Popularity ' ' VBScript Implementation ' '...........................................' 'API Links (From C Code) URL1 = "http://www.rosettacode.org/mw/api.php?format=json&action=query&generator=categorymembe...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Delphi
Delphi
program RomanNumeralsEncode;   {$APPTYPE CONSOLE}   function IntegerToRoman(aValue: Integer): string; var i: Integer; const WEIGHTS: array[0..12] of Integer = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1); SYMBOLS: array[0..12] of string = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV'...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Elena
Elena
import extensions; import system'collections; import system'routines;   static RomanDictionary = Dictionary.new() .setAt("I".toChar(), 1) .setAt("V".toChar(), 5) .setAt("X".toChar(), 10) .setAt("L".toChar(), ...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Octave
Octave
a = [ 1, -3, 2, 0 ]; r = roots(a); % let's print it for i = 1:3 n = polyval(a, r(i)); printf("x%d = %f (%f", i, r(i), n); if (n != 0.0) printf(" not"); endif printf(" exact)\n"); endfor
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Liberty_BASIC
Liberty BASIC
  dim rps( 2), g$( 3)   g$( 0) ="rock": g$( 1) ="paper": g$( 2) ="scissors" global total   total =0: draw =0: pwin =0: cwin =0   rps( 0) =1: rps( 1) =1: rps( 2) =1 ' at first computer will play all three with equal probability   c =int( 3 *rnd( 1)) ' first time, computer response...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Liberty_BASIC
Liberty BASIC
mainwin 100 20   'In$ ="aaaaaaaaaaaaaaaaaccbbbbbbbbbbbbbbba" ' testing... In$ ="WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW" ' Out$= "12W1B12W3B24W1B14W"   Out$ =Encoded$( In$) Inv$ =Decoded$( Out$)   print " Supplied string ="; In$ Print " RLE version ="; Out$ ...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Gema
Gema
/[a-mA-M]/=@int-char{@add{@char-int{$1};13}} /[n-zN-Z]/=@int-char{@sub{@char-int{$1};13}}
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#zkl
zkl
fcn sieve(limit){ composite:=Data(limit+1).fill(1); // bucket of bytes set to 1 (prime) (2).pump(limit.toFloat().sqrt()+1, Void, // Void==no results, just loop composite.get, Void.Filter, // if prime, zero multiples 'wrap(n){ [n*n..limit,n].pump(Void,composite.set.fp1(0)) }); //composite[n*p]=0 ...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#Prolog
Prolog
search_a_list(N1, N2) :- L = ["Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", "Charlie", "Bush", "Boz", "Zag"],   write('List is :'), maplist(my_write, L), nl, nl,   ( nth1(Ind1, L, N1) -> format('~s is in position ~w~n', [N1, Ind1]) ; format('~s is not present~n', [N1])), ( nth1(Ind2, L, N2) -> ...
http://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity
Rosetta Code/Rank languages by popularity
Rosetta Code/Rank languages by popularity You are encouraged to solve this task according to the task description, using any language you may know. Task Sort the most popular computer programming languages based in number of members in Rosetta Code categories. Sample output on 01 juin 2022 at 14:13 +02 Rank: 1 (1,...
#Wren
Wren
/* rc_rank_languages_by_popularity.wren */   import "./pattern" for Pattern import "./fmt" for Fmt   var CURLOPT_URL = 10002 var CURLOPT_FOLLOWLOCATION = 52 var CURLOPT_WRITEFUNCTION = 20011 var CURLOPT_WRITEDATA = 10001   foreign class Buffer { construct new() {} // C will allocate buffer of a suitable size   ...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#DWScript
DWScript
const weights = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; const symbols = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];   function toRoman(n : Integer) : String; var i, w : Integer; begin for i := 0 to weights.High do begin w := weights[i]; while n >= w do begi...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Elixir
Elixir
defmodule Roman_numeral do def decode([]), do: 0 def decode([x]), do: to_value(x) def decode([h1, h2 | rest]) do case {to_value(h1), to_value(h2)} do {v1, v2} when v1 < v2 -> v2 - v1 + decode(rest) {v1, _} -> v1 + decode([h2 | rest]) end end   defp to_value(?M), do: 1000 defp to_value(?...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Oforth
Oforth
: findRoots(f, a, b, st) | x y lasty | a f perform dup ->y ->lasty   a b st step: x [ x f perform -> y y ==0 ifTrue: [ System.Out "Root found at " << x << cr ] else: [ y lasty * sgn -1 == ifTrue: [ System.Out "Root near " << x << cr ] ] y ->lasty ] ;   : f(x) x 3 pow x sq 3 * - x 2...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#ooRexx
ooRexx
/* REXX program to solve a cubic polynom equation a*x**3+b*x**2+c*x+d =(x-x1)*(x-x2)*(x-x3) */ Numeric Digits 16 pi3=Rxcalcpi()/3 Parse Value '1 -3 2 0' with a b c d p=3*a*c-b**2 q=2*b**3-9*a*b*c+27*a**2*d det=q**2+4*p**3 say 'p='p say 'q='q Say 'det='det If det<0 Then Do phi=Rxcalcarccos(-q/(2*rxCalcsqrt(-p**3)),16...
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Locomotive_Basic
Locomotive Basic
10 mode 1:defint a-z:randomize time 20 rps$="rps" 30 msg$(1)="Rock breaks scissors" 40 msg$(2)="Paper covers rock" 50 msg$(3)="Scissors cut paper" 60 print "Rock Paper Scissors":print 70 print "Enter r, p, or s as your play." 80 print "Running score shown as <your wins>:<my wins>" 90 achoice=rnd*2.99+.5 ' get integer b...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#LiveCode
LiveCode
function rlEncode str local charCount put 1 into charCount repeat with i = 1 to the length of str if char i of str = char (i + 1) of str then add 1 to charCount else put char i of str & charCount after rle put 1 into charCount end if end repeat...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#GML
GML
#define rot13 var in, out, i, working; in = argument0; out = ""; for (i = 1; i <= string_length(in); i += 1) { working = ord(string_char_at(in, i)); if ((working > 64) && (working < 91)) { working += 13; if (working > 90) { working -= 26; } ...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#PureBasic
PureBasic
If OpenConsole() ; Open a simple console to interact with user NewList Straws.s() Define Straw$, target$="TBA" Define found   Restore haystack ; Read in all the straws of the haystack. Repeat Read.s Straw$ If Straw$<>"" AddElement(Straws()) Straws()=UCase(Straw$) Continue Else ...
http://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity
Rosetta Code/Rank languages by popularity
Rosetta Code/Rank languages by popularity You are encouraged to solve this task according to the task description, using any language you may know. Task Sort the most popular computer programming languages based in number of members in Rosetta Code categories. Sample output on 01 juin 2022 at 14:13 +02 Rank: 1 (1,...
#zkl
zkl
var [const] CURL=Import("zklCurl"), YAJL=Import("zklYAJL")[0];   fcn getLangCounts(language){ // -->( (count,lang), ...) continueValue,tasks,curl := "",List(), CURL(); // "nm\0nm\0...." do{ // eg 5 times page:=curl.get(("http://rosettacode.org/mw/api.php?" "format=json" "&action=query" "&gener...
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#EasyLang
EasyLang
values[] = [ 1000 900 500 400 100 90 50 40 10 9 5 4 1 ] symbol$[] = [ "M" "CM" "D" "CD" "C" "XC" "L" "XL" "X" "IX" "V" "IV" "I" ] func num2rom num . rom$ . rom$ = "" for i range len values[] while num >= values[i] rom$ &= symbol$[i] num -= values[i] . . . call num2rom 1990 r$ print r$ call num...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Emacs_Lisp
Emacs Lisp
(defun ro2ar (RN) "Translate a roman number RN into arabic number. Its argument RN is wether a symbol, wether a list. Returns the arabic number. (ro2ar 'C) gives 100, (ro2ar '(X X I V)) gives 24" (cond ((eq RN 'M) 1000) ((eq RN 'D) 500) ((eq RN 'C) 100) ((eq RN 'L) 50) ((eq RN 'X) 10) ...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#PARI.2FGP
PARI/GP
polroots(x^3-3*x^2+2*x)
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Lua
Lua
function cpuMove() local totalChance = record.R + record.P + record.S if totalChance == 0 then -- First game, unweighted random local choice = math.random(1, 3) if choice == 1 then return "R" end if choice == 2 then return "P" end if choice == 3 then return "S" end end local choice = math.ran...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Logo
Logo
to encode :str [:out "||] [:count 0] [:last first :str] if empty? :str [output (word :out :count :last)] if equal? first :str :last [output (encode bf :str :out :count+1 :last)] output (encode bf :str (word :out :count :last) 1 first :str) end   to reps :n :w output ifelse :n = 0 ["||] [word :w reps :n-1 :w] en...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Go
Go
package main   import ( "fmt" "strings" )   func rot13char(c rune) rune { if c >= 'a' && c <= 'm' || c >= 'A' && c <= 'M' { return c + 13 } else if c >= 'n' && c <= 'z' || c >= 'N' && c <= 'Z' { return c - 13 } return c }   func rot13(s string) string { return strings.Map(rot...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#Python
Python
haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]   for needle in ("Washington","Bush"): try: print haystack.index(needle), needle except ValueError, value_error: print needle,"is not in haystack"
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#ECL
ECL
RomanEncode(UNSIGNED Int) := FUNCTION SetWeights := [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; SetSymbols := ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']; ProcessRec := RECORD UNSIGNED val; STRING Roman; END; dsWeights  := DATASET(13,TRANSFORM(ProcessRec,SELF.va...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Erlang
Erlang
  -module( roman_numerals ).   -export( [decode_from_string/1]).   to_value($M) -> 1000; to_value($D) -> 500; to_value($C) -> 100; to_value($L) -> 50; to_value($X) -> 10; to_value($V) -> 5; to_value($I) -> 1.   decode_from_string([]) -> 0; decode_from_string([H1]) -> to_value(H1); decode_from_string([H1, H2...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Pascal
Pascal
Program RootsFunction;   var e, x, step, value: double; s: boolean; i, limit: integer; x1, x2, d: double;   function f(const x: double): double; begin f := x*x*x - 3*x*x + 2*x; end;   begin x := -1; step := 1.0e-6; e := 1.0e-9; s := (f(x) > 0);   writeln('Version 1: simply stepping ...
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
DynamicModule[{record, play, text = "\nRock-paper-scissors\n", choices = {"Rock", "Paper", "Scissors"}}, Evaluate[record /@ choices] = {1, 1, 1}; play[x_] := Module[{y = RandomChoice[record /@ choices -> RotateLeft@choices]}, record[x]++; text = "Your Choice:" <> x <> "\nComputer's Choice:" <> y <> "\...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#Lua
Lua
local C, Ct, R, Cf, Cc = lpeg.C, lpeg.Ct, lpeg.R, lpeg.Cf, lpeg.Cc astable = Ct(C(1)^0)   function compress(t) local ret = {} for i, v in ipairs(t) do if t[i-1] and v == t[i-1] then ret[#ret - 1] = ret[#ret - 1] + 1 else ret[#ret + 1] = 1 ret[#ret + 1] = v end end ...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Golo
Golo
#!/usr/bin/env golosh ---- This module encrypts strings by rotating each character by 13. ---- module Rot13   augment java.lang.Character {   function rot13 = |this| -> match { when this >= 'a' and this <= 'z' then charValue((this - 'a' + 13) % 26 + 'a') when this >= 'A' and this <= 'Z' then charValue((this -...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#R
R
find.needle <- function(haystack, needle="needle", return.last.index.too=FALSE) { indices <- which(haystack %in% needle) if(length(indices)==0) stop("no needles in the haystack") if(return.last.index.too) range(indices) else min(indices) }
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Eiffel
Eiffel
class APPLICATION   create make   feature {NONE} -- Initialization   make local numbers: ARRAY [INTEGER] do numbers := <<1990, 2008, 1666, 3159, 1977, 2010>> -- "MCMXC", "MMVIII", "MDCLXVI", "MMMCLIX", "MCMLXXVII", "MMX" across numbers as n loop print (n.item.out + " in decimal Arabic numeral...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#ERRE
ERRE
  PROGRAM ROMAN2ARAB   DIM R%[7]   PROCEDURE TOARAB(ROMAN$->ANS%) LOCAL I%,J%,P%,N% FOR I%=LEN(ROMAN$) TO 1 STEP -1 DO J%=INSTR("IVXLCDM",MID$(ROMAN$,I%,1)) IF J%=0 THEN ANS%=-9999  ! illegal character EXIT PROCEDURE END IF IF J%>=P% THEN N...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Perl
Perl
sub f { my $x = shift;   return ($x * $x * $x - 3*$x*$x + 2*$x); }   my $step = 0.001; # Smaller step values produce more accurate and precise results my $start = -1; my $stop = 3; my $value = &f($start); my $sign = $value > 0;   # Check for root at start   print "Root found at $start\n" if ( 0 == $valu...
http://rosettacode.org/wiki/Rock-paper-scissors
Rock-paper-scissors
Task Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules: ...
#Mercury
Mercury
:- module rps. :- interface. :- import_module io. :- pred main(io::di, io::uo) is det. :- implementation. :- use_module random, exception. :- import_module list, string.   :- type play ---> rock  ; paper  ; scissors.   :- pred beats(play, play). :- mode beats(in, in) is semidet. beats(rock, sci...
http://rosettacode.org/wiki/Run-length_encoding
Run-length encoding
Run-length encoding You are encouraged to solve this task according to the task description, using any language you may know. Task Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression...
#M2000_Interpreter
M2000 Interpreter
  Module RLE_example { inp$="WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW" Print "Input: ";inp$ Function RLE$(r$){ Function rle_run$(&r$) { if len(r$)=0 then exit p=1 c$=left$(r$,1) while c$=mid$(r$, p, 1) {p++} =format$("{0}{1}",p-1, c$) r$=mid$(r$, p) } def repl$ wh...
http://rosettacode.org/wiki/Rot-13
Rot-13
Task Implement a   rot-13   function   (or procedure, class, subroutine, or other "callable" object as appropriate to your programming environment). Optionally wrap this function in a utility program   (like tr,   which acts like a common UNIX utility, performing a line-by-line rot-13 encoding of every line of inpu...
#Groovy
Groovy
def rot13 = { String s -> (s as List).collect { ch -> switch (ch) { case ('a'..'m') + ('A'..'M'): return (((ch as char) + 13) as char) case ('n'..'z') + ('N'..'Z'): return (((ch as char) - 13) as char) default: return ch ...
http://rosettacode.org/wiki/Search_a_list
Search a list
Task[edit] Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Extra credit Return the largest index to a needle that has multiple occurrences in ...
#Racket
Racket
(define (index xs y) (for/first ([(x i) (in-indexed xs)] #:when (equal? x y)) i))
http://rosettacode.org/wiki/Roman_numerals/Encode
Roman numerals/Encode
Task Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero. In Roman numeral...
#Ela
Ela
open number string math   digit x y z k = [[x],[x,x],[x,x,x],[x,y],[y],[y,x],[y,x,x],[y,x,x,x],[x,z]] : (toInt k - 1)   toRoman 0 = "" toRoman x | x < 0 = fail "Negative roman numeral" | x >= 1000 = 'M' :: toRoman (x - 1000) | x >= 100 = let (q,r) = x `divrem` 100 in ...
http://rosettacode.org/wiki/Roman_numerals/Decode
Roman numerals/Decode
Task Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decima...
#Euphoria
Euphoria
constant symbols = "MDCLXVI", weights = {1000,500,100,50,10,5,1} function romanDec(sequence roman) integer n, lastval, arabic lastval = 0 arabic = 0 for i = length(roman) to 1 by -1 do n = find(roman[i],symbols) if n then n = weights[n] end if if n < lastval t...
http://rosettacode.org/wiki/Roots_of_a_function
Roots of a function
Task Create a program that finds and outputs the roots of a given function, range and (if applicable) step width. The program should identify whether the root is exact or approximate. For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x
#Phix
Phix
procedure print_roots(integer f, atom start, stop, step) -- -- Print approximate roots of f between x=start and x=stop, using -- sign changes as an indicator that a root has been encountered. -- atom x = start, y = 0 puts(1,"-----\n") while x<=stop do atom last_y = y y = f...