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/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#PL.2FSQL
PL/SQL
DECLARE pi NUMBER := 4 * ATAN(1); radians NUMBER := pi / 4; degrees NUMBER := 45.0; BEGIN DBMS_OUTPUT.put_line(SIN(radians) || ' ' || SIN(degrees * pi/180) ); DBMS_OUTPUT.put_line(COS(radians) || ' ' || COS(degrees * pi/180) ); DBMS_OUTPUT.put_line(TAN(radians) || ' ' || TAN(degrees * pi/180) ); DBMS_OUTP...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Perl
Perl
sub preorder { my $t = shift or return (); return ($t->[0], preorder($t->[1]), preorder($t->[2])); }   sub inorder { my $t = shift or return (); return (inorder($t->[1]), $t->[0], inorder($t->[2])); }   sub postorder { my $t = shift or return (); return (postorder($t->[1]), postorder($t->[2]), $t->[0]); }   sub d...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#OCaml
OCaml
let words = String.split_on_char ',' "Hello,How,Are,You,Today" in String.concat "." words  
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Oforth
Oforth
"Hello,How,Are,You,Today" wordsWith(',') println
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#PowerShell
PowerShell
function New-Employee ($Name, $ID, $Salary, $Department) { New-Object PSObject ` | Add-Member -PassThru NoteProperty EmployeeName $Name ` | Add-Member -PassThru NoteProperty EmployeeID $ID ` | Add-Member -PassThru NoteProperty Salary $Salary ` | Add-Member -PassThru NoteProperty Depa...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#R
R
  rm(list=ls()) library(RColorBrewer)     # Create tic.tac.toe function.     tic.tac.toe <- function(name="Name", mode=0, type=0){   place.na <<- matrix(1:9, 3, 3) value <<- matrix(-3, 3, 3) k <<- 1 ; r <<- 0     # Make game board.     image(1:3, 1:3, matrix(sample(9), 3, 3), asp=c(1, 1), xaxt="n", ...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Haskell
Haskell
hanoi :: Integer -> a -> a -> a -> [(a, a)] hanoi 0 _ _ _ = [] hanoi n a b c = hanoi (n-1) a c b ++ [(a,b)] ++ hanoi (n-1) c b a
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Pop11
Pop11
sin(30) => cos(45) => tan(45) => arcsin(0.7) => arccos(0.7) => arctan(0.7) => ;;; switch to radians true -> popradians;   sin(pi*30/180) => cos(pi*45/180) => tan(pi*45/180) => arcsin(0.7) => arccos(0.7) => arctan(0.7) =>
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#PostScript
PostScript
  90 sin =   60 cos =   %tan of 45 degrees   45 sin 45 cos div =   %inverse tan ( arc tan of sqrt 3)   3 sqrt 1 atan =  
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Phix
Phix
constant VALUE = 1, LEFT = 2, RIGHT = 3 constant tree = {1, {2, {4, {7, 0, 0}, 0}, {5, 0, 0}}, {3, {6, {8, 0, 0}, {9, 0, 0}}, 0}} procedure preorder(object tree) if sequence(tree) then printf(1,"%d ",{tree[VA...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#ooRexx
ooRexx
text='Hello,How,Are,You,Today' do while text \= '' parse var text word1 ',' text call charout 'STDOUT:',word1'.' end
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#OpenEdge.2FProgress
OpenEdge/Progress
FUNCTION tokenizeString RETURNS CHAR ( i_c AS CHAR ):   DEF VAR ii AS INT. DEF VAR carray AS CHAR EXTENT. DEF VAR cresult AS CHAR.   EXTENT( carray ) = NUM-ENTRIES( i_c ).   DO ii = 1 TO NUM-ENTRIES( i_c ): carray[ ii ] = ENTRY( ii, i_c ). END.   DO ii = 1 TO EXTENT( carray ). ...
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Prolog
Prolog
% emp(name,id,salary,dpt) emp('Tyler Bennett','E10297',32000,'D101'). emp('John Rappl','E21437',47000,'D050'). emp('George Woltman','E00127',53500,'D101'). emp('Adam Smith','E63535',18000,'D202'). emp('Claire Buckman','E39876',27800,'D202'). emp('David McClellan','E04242',41500,'D101'). emp('Rich Holcomb','E01234',4950...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Racket
Racket
+ minimax.rkt -- Written in Lazy Racket, implements the general minimax algorythm as | given in Wikipedia. | Knows nothing about games. V + game.rkt -- Written in Lazy Racket, defines general classes for the game and players. | Knows nothing about tick-tac...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#HolyC
HolyC
U0 Move(U8 n, U8 from, U8 to, U8 via) { if (n > 0) { Move(n - 1, from, via, to); Print("Move disk from pole %d to pole %d\n", from, to); Move(n - 1, via, to, from); } }   Move(4, 1, 2, 3);
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#PowerShell
PowerShell
$rad = [Math]::PI / 4 $deg = 45 '{0,10} {1,10}' -f 'Radians','Degrees' '{0,10:N6} {1,10:N6}' -f [Math]::Sin($rad), [Math]::Sin($deg * [Math]::PI / 180) '{0,10:N6} {1,10:N6}' -f [Math]::Cos($rad), [Math]::Cos($deg * [Math]::PI / 180) '{0,10:N6} {1,10:N6}' -f [Math]::Tan($rad), [Math]::Tan($deg * [Math]::PI / 180) $temp ...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#PHP
PHP
class Node { private $left; private $right; private $value;   function __construct($value) { $this->value = $value; }   public function getLeft() { return $this->left; } public function getRight() { return $this->right; } public function getValue() { ...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Oz
Oz
for T in {String.tokens "Hello,How,Are,You,Today" &,} do {System.printInfo T#"."} end
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#PARI.2FGP
PARI/GP
  \\ Tokenize a string str according to 1 character delimiter d. Return a list of tokens. \\ Using ssubstr() from http://rosettacode.org/wiki/Substring#PARI.2FGP \\ tokenize() 3/5/16 aev tokenize(str,d)={ my(str=Str(str,d),vt=Vecsmall(str),d1=sasc(d),Lr=List(),sn=#str,v1,p1=1); for(i=p1,sn, v1=vt[i]; if(v1==d1, listput...
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#PureBasic
PureBasic
Structure Employees Name$ ID$ Salary.i Department$ EndStructure   Procedure displayTopEarners(List MyEmployees.Employees(), n) Protected filename$ = OpenFileRequester("Top rank per group", "DataFile.txt", "", 0) If ReadFile(0, filename$) Protected InData.Employees, txt.s, MaxNameLength   While Eof(...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Raku
Raku
my @board = 1..9; my @winning-positions = [0..2], [3..5], [6..8], [0,3,6], [1,4,7], [2,5,8], [0,4,8], [6,4,2];   sub get-winner() { for @winning-positions { return (@board[|$_][0], $_) if [eq] @board[|$_]; } }   sub free-indexes() { @board.keys.grep: { @board[$_] eq any(1..9) } }   sub ai-move() { given fr...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Icon_and_Unicon
Icon and Unicon
procedure main(arglist) hanoi(arglist[1]) | stop("Usage: hanoi n\n\rWhere n is the number of disks to move.") end   #procedure hanoi(n:integer, needle1:1, needle2:2) # unicon shorthand for icon code 1,2,3 below   procedure hanoi(n, needle1, needle2) #: solve towers of hanoi by moving n disks from needle 1 to needl...
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#PureBasic
PureBasic
OpenConsole()   Macro DegToRad(deg) deg*#PI/180 EndMacro Macro RadToDeg(rad) rad*180/#PI EndMacro   degree = 45 radians.f = #PI/4   PrintN(StrF(Sin(DegToRad(degree)))+" "+StrF(Sin(radians))) PrintN(StrF(Cos(DegToRad(degree)))+" "+StrF(Cos(radians))) PrintN(StrF(Tan(DegToRad(degree)))+" "+StrF(Tan(radians)))   ar...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#PicoLisp
PicoLisp
(de preorder (Node Fun) (when Node (Fun (car Node)) (preorder (cadr Node) Fun) (preorder (caddr Node) Fun) ) )   (de inorder (Node Fun) (when Node (inorder (cadr Node) Fun) (Fun (car Node)) (inorder (caddr Node) Fun) ) )   (de postorder (Node Fun) (when Node (postorder...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Pascal
Pascal
program TokenizeString;   {$mode objfpc}{$H+}   uses SysUtils, Classes; const TestString = 'Hello,How,Are,You,Today'; var Tokens: TStringList; I: Integer; begin // Uses FCL facilities, "harder" algorithm not implemented Tokens := TStringList.Create; try Tokens.Delimiter := ','; Tokens.DelimitedTex...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Perl
Perl
print join('.', split /,/, 'Hello,How,Are,You,Today'), "\n";
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Python
Python
from collections import defaultdict from heapq import nlargest   data = [('Employee Name', 'Employee ID', 'Salary', 'Department'), ('Tyler Bennett', 'E10297', 32000, 'D101'), ('John Rappl', 'E21437', 47000, 'D050'), ('George Woltman', 'E00127', 53500, 'D101'), ('Adam Smith', 'E63535', 18...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#REXX
REXX
/*REXX program plays (with a human) the tic─tac─toe game on an NxN grid. */ $= copies('─', 9) /*eyecatcher for error messages, prompt*/ oops = $ '***error*** ' /*literal for when an error happens. */ single = '│─┼'; jam= "║"; bar= '═'; j...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Inform_7
Inform 7
Hanoi is a room.   A post is a kind of supporter. A post is always fixed in place.   The left post, the middle post, and the right post are posts in Hanoi.   A disk is a kind of supporter. The red disk is a disk on the left post. The orange disk is a disk on the red disk. The yellow disk is a disk on the orange disk. T...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Io
Io
hanoi := method(n, from, to, via, if (n == 1) then ( writeln("Move from ", from, " to ", to) ) else ( hanoi(n - 1, from, via, to ) hanoi(1 , from, to , via ) hanoi(n - 1, via , to , from) ) )
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Python
Python
Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> from math import degrees, radians, sin, cos, tan, asin, acos, atan, pi >>> rad, deg = pi/4, 45.0 >>> print("Sine:", sin(rad), sin(radians(deg))) Sine: 0.707106781186547...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Prolog
Prolog
tree :- Tree= [1, [2, [4, [7, nil, nil], nil], [5, nil, nil]], [3, [6, [8, nil, nil], [9,nil, nil]], nil]],   write('preorder  : '), preorder(Tree), nl, write('inorder  : '), inorder(Tree), nl, write('postorder  : '), postorder(Tree), nl, write('le...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Phix
Phix
?join(split("Hello,How,Are,You,Today",","),".")
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Phixmonti
Phixmonti
/# "Hello,How,Are,You,Today" "," "." subst print #/ "Hello,How,Are,You,Today" "," " " subst split len for get print "." print endfor
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#R
R
dfr <- read.csv(tc <- textConnection( "Employee Name,Employee ID,Salary,Department Tyler Bennett,E10297,32000,D101 John Rappl,E21437,47000,D050 George Woltman,E00127,53500,D101 Adam Smith,E63535,18000,D202 Claire Buckman,E39876,27800,D202 David McClellan,E04242,41500,D101 Rich Holcomb,E01234,49500,D202 Nathan Adams,E41...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Ring
Ring
  Load "guilib.ring"   #Provide a list to save each button status in numeric readable format #0=nothing 1=X 2=O lst=[]   #Provide onScreen button status and style btns=[]   #Define who has the turn isXTurn=true     app=new qApp {   frmMain=new qMainWindow() { setWindowTitle("TicTacToe!") resize(...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Ioke
Ioke
= method(n, f, u, t, if(n < 2, "#{f} --> #{t}" println,   H(n - 1, f, t, u) "#{f} --> #{t}" println H(n - 1, u, f, t) ) )   hanoi = method(n, H(n, 1, 2, 3) )
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#IS-BASIC
IS-BASIC
100 PROGRAM "Hanoi.bas" 110 CALL HANOI(4,1,3,2) 120 DEF HANOI(DISK,FRO,TO,WITH) 130 IF DISK>0 THEN 140 CALL HANOI(DISK-1,FRO,WITH,TO) 150 PRINT "Move disk";DISK;"from";FRO;"to";TO 160 CALL HANOI(DISK-1,WITH,TO,FRO) 170 END IF 180 END DEF
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Quackery
Quackery
[ $" bigrat.qky' loadfile ] now!   [ 2646693125139304345 1684937174853026414 ] is pi/2 ( --> n/d )   [ 2dup 2dup 3 v** 2363 18183 v* v- 2over 5 v** 12671 4363920 v* v+ 2swap 1 1 2over 2 v** 445 12122 v* v+ 2...
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#R
R
deg <- function(radians) 180*radians/pi rad <- function(degrees) degrees*pi/180 sind <- function(ang) sin(rad(ang)) cosd <- function(ang) cos(rad(ang)) tand <- function(ang) tan(rad(ang)) asind <- function(v) deg(asin(v)) acosd <- function(v) deg(acos(v)) atand <- function(v) deg(atan(v))   r <- pi/3 rd <- deg(r)   pri...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#PureBasic
PureBasic
Structure node value.i *left.node *right.node EndStructure   Structure queue List q.i() EndStructure   DataSection tree: Data.s "1(2(4(7),5),3(6(8,9)))" EndDataSection   ;Convenient routine to interpret string data to construct a tree of integers. Procedure createTree(*n.node, *tPtr.Character) Protected n...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#PHP
PHP
<?php $str = 'Hello,How,Are,You,Today'; echo implode('.', explode(',', $str)); ?>
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Picat
Picat
import util.   go => S = "Hello,How,Are,You,Today", T = S.split(","), println(T), T.join(".").println(),    % As a one liner: S.split(",").join(".").println().
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Racket
Racket
#lang racket   (struct employee (name id salary dept)) (define employees (list (employee "Tyler Bennett" "E10297" 32000 "D101") (employee "John Rappl" "E21437" 47000 "D050") (employee "George Woltman" "E00127" 53500 "D101") (employee "Adam Smith" "E63535" 18000 "D202") (em...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Ruby
Ruby
module TicTacToe LINES = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]   class Game def initialize(player_1_class, player_2_class) @board = Array.new(10) # we ignore index 0 for convenience   @current_player_id = 0 @players = [player_1_class.new(self, "X"), player_2_class.n...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#J
J
H =: i.@,&2 ` (({&0 2 1,0 2,{&1 0 2)@$:@<:) @. * NB. tacit using anonymous recursion
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Racket
Racket
#lang racket (define radians (/ pi 4)) (define degrees 45)   (displayln (format "~a ~a" (sin radians) (sin (* degrees (/ pi 180)))))   (displayln (format "~a ~a" (cos radians) (cos (* degrees (/ pi 180)))))   (displayln (format "~a ~a" (tan radians) (tan (* degrees (/ pi 180)))))   (define arcsin (asin (sin radians))) ...
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Raku
Raku
# 20210212 Updated Raku programming solution   sub postfix:<°> (\ᵒ) { ᵒ × τ / 360 }   sub postfix:<㎭🡆°> (\ᶜ) { ᶜ / π × 180 }   say sin π/3 ; say sin 60° ;   say cos π/4 ; say cos 45° ;   say tan π/6 ; say tan 30° ;   ( asin(3.sqrt/2), acos(1/sqrt 2), atan(1/sqrt 3) )».&{ .say and .㎭🡆°.say }
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Python
Python
from collections import namedtuple   Node = namedtuple('Node', 'data, left, right') tree = Node(1, Node(2, Node(4, Node(7, None, None), None), Node(5, None, None)), Node(3, Node(6, ...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#PicoLisp
PicoLisp
(mapcar pack (split (chop "Hello,How,Are,You,Today") ",") )
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Pike
Pike
("Hello,How,Are,You,Today" / ",") * ".";
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Raku
Raku
my @data = do for q:to/---/.lines -> $line { E10297 32000 D101 Tyler Bennett E21437 47000 D050 John Rappl E00127 53500 D101 George Woltman E63535 18000 D202 Adam Smith E39876 27800 D202 Claire Buckman E04242 41500 D101 David McClellan ...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Run_BASIC
Run BASIC
' --------------------------- ' TIC TAC TOE ' --------------------------- winBox$ = "123 456 789 159 147 258 369 357" boxPos$ = "123 231 456 564 789 897 159 591 357 753 132 465 798 174 285 396 159 471 582 693 147 258 369 195 375" ai$ = "519628374" ox$ = "OX" [newGame] for i = 1 to 9 box$(i) = "" next i goto ...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Java
Java
public void move(int n, int from, int to, int via) { if (n == 1) { System.out.println("Move disk from pole " + from + " to pole " + to); } else { move(n - 1, from, via, to); move(1, from, to, via); move(n - 1, via, to, from); } }
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#RapidQ
RapidQ
$APPTYPE CONSOLE $TYPECHECK ON   SUB pause(prompt$) PRINT prompt$ DO SLEEP .1 LOOP UNTIL LEN(INKEY$) > 0 END SUB   'MAIN DEFDBL pi , radians , degrees , deg2rad pi = 4 * ATAN(1) deg2rad = pi / 180 radians = pi / 4 degrees = 45 * deg2rad   PRINT format$("%.6n" , SIN(radians)) + " " + format$("%.6n" ...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Qi
Qi
  (set *tree* [1 [2 [4 [7]] [5]] [3 [6 [8] [9]]]])   (define inorder [] -> [] [V] -> [V] [V L] -> (append (inorder L) [V]) [V L R] -> (append (inorder L) [V] (inorder R)))   (define po...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#PL.2FI
PL/I
tok: Proc Options(main); declare s character (100) initial ('Hello,How,Are,You,Today'); declare n fixed binary (31);   n = tally(s, ',')+1;   begin; declare table(n) character (50) varying; declare c character (1); declare (i, k) fixed binary (31);   table = ''; k = 1; do i = 1 to length(s); c = su...
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#REXX
REXX
/*REXX program displays the top N salaries in each department (internal table). */ parse arg topN . /*get optional # for the top N salaries*/ if topN=='' | topN=="," then topN= 1 /*Not specified? Then use the default.*/ say 'Finding the top ' topN " salaries in e...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Rust
Rust
  use GameState::{ComputerWin, Draw, PlayerWin, Playing};   use rand::prelude::*;   #[derive(PartialEq, Debug)] enum GameState { PlayerWin, ComputerWin, Draw, Playing, }   type Board = [[char; 3]; 3];   fn main() { let mut rng = StdRng::from_entropy();   let mut board: Board = [['1', '2', '3'], ...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#JavaScript
JavaScript
function move(n, a, b, c) { if (n > 0) { move(n-1, a, c, b); console.log("Move disk from " + a + " to " + c); move(n-1, b, a, c); } } move(4, "A", "B", "C");
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#REBOL
REBOL
rebol [ Title: "Trigonometric Functions" URL: http://rosettacode.org/wiki/Trigonometric_Functions ]   radians: pi / 4 degrees: 45.0   ; Unlike most languages, REBOL's trig functions work in degrees unless ; you specify differently.   print [sine/radians radians sine degrees] print [cosine/radians radians cosin...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Quackery
Quackery
[ this ] is nil ( --> [ )   [ ' [ 1 [ 2 [ 4 [ 7 nil nil ] nil ] [ 5 nil nil ] ] [ 3 [ 6 [ 8 nil nil ] [ 9 nil nil ] ] nil ] ] ] is tree ( --> [ )   [ dup nil = iff dr...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#PL.2FM
PL/M
100H: /* CP/M CALLS */ BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS; EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT; PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;   /* SPLIT A STRING ON CHARACTER 'SEP'. THE 'PARTS' ARRAY WILL CONTAIN POINTERS TO THE START OF EACH ELEME...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Plain_English
Plain English
To run: Start up. Split "Hello,How,Are,You,Today" into some string things given the comma byte. Join the string things with the period byte giving a string. Destroy the string things. Write the string on the console. Wait for the escape key. Shut down.   To join some string things with a byte giving a string: Get a str...
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Ring
Ring
  # Project : Top rank per group   load "stdlib.ring" salary = "Tyler Bennett,E10297,32000,D101 John Rappl,E21437,47000,D050 George Woltman,E00127,53500,D101 Adam Smith,E63535,18000,D202 Claire Buckman,E39876,27800,D202 David McClellan,E04242,41500,D101 Rich Holcomb,E01234,49500,D202 Nathan Adams,E41298,21900,D050 Rich...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Scala
Scala
package object tictactoe { val Human = 'X' val Computer = 'O' val BaseBoard = ('1' to '9').toList val WinnerLines = List((0,1,2), (3,4,5), (6,7,8), (0,3,6), (1,4,7), (2,5,8), (0,4,8), (2,4,6)) val randomGen = new util.Random(System.currentTimeMillis) }   package tictactoe {   class Board(aBoard : List[Char]...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Joy
Joy
DEFINE hanoi == [[rolldown] infra] dip [ [ [null] [pop pop] ] [ [dup2 [[rotate] infra] dip pred] [ [dup rest put] dip [[swap] infra] dip pred ] [] ] ] condnestrec.
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#REXX
REXX
┌──────────────────────────────────────────────────────────────────────────┐ │ One common method that ensures enough accuracy in REXX is specifying │ │ more precision (via NUMERIC DIGITS nnn) than is needed, and then │ │ displaying the number of digits that are desired, or the num...
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Ring
Ring
  pi = 3.14 decimals(8) see "sin(pi/4.0) = " + sin(pi/4.0) + nl see "cos(pi/4.0) = " + cos(pi/4.0) + nl see "tan(pi/4.0) = " + tan(pi/4.0)+ nl see "asin(sin(pi/4.0)) = " + asin(sin(pi/4.0)) + nl see "acos(cos(pi/4.0)) = " + acos(cos(pi/4.0)) + nl see "atan(tan(pi/4.0)) = " + atan(tan(pi/4.0)) + nl see "atan2(3,4) = ...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Racket
Racket
  #lang racket   (define the-tree ; Node: (list <data> <left> <right>) '(1 (2 (4 (7 #f #f) #f) (5 #f #f)) (3 (6 (8 #f #f) (9 #f #f)) #f)))   (define (preorder tree visit) (let loop ([t tree]) (when t (visit (car t)) (loop (cadr t)) (loop (caddr t))))) (define (inorder tree visit) (let loop ([t tree]) (whe...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Pop11
Pop11
;;; Make a list of strings from a string using space as separator lvars list; sysparse_string('the cat sat on the mat') -> list; ;;; print the list of strings list => ** [the cat sat on the mat]
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#PowerShell
PowerShell
$words = "Hello,How,Are,You,Today".Split(',') [string]::Join('.', $words)
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Ruby
Ruby
require "csv"   data = <<EOS Employee Name,Employee ID,Salary,Department Tyler Bennett,E10297,32000,D101 John Rappl,E21437,47000,D050 George Woltman,E00127,53500,D101 Adam Smith,E63535,18000,D202 Claire Buckman,E39876,27800,D202 David McClellan,E04242,41500,D101 Rich Holcomb,E01234,49500,D202 Nathan Adams,E41298,21900,...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Scilab
Scilab
function [] = startGame() //Board size and marks N = 3; marks = ["X" "O"];   //Creating empty board board = string(zeros(N,N)); for i = 1:(N*N) board(i) = ""; end   //Initialising players clc(); players= [%F %F]; players = playerSetup(marks);   //Console header ...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#jq
jq
# n is the number of disks to move from From to To def move(n; From; To; Via): if n > 0 then # move all but the largest at From to Via (according to the rules): move(n-1; From; Via; To), # ... so the largest disk at From is now free to move to its final destination: "Move disk from \(From) to \(To...
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Ruby
Ruby
radians = Math::PI / 4 degrees = 45.0   def deg2rad(d) d * Math::PI / 180 end   def rad2deg(r) r * 180 / Math::PI end   #sine puts "#{Math.sin(radians)} #{Math.sin(deg2rad(degrees))}" #cosine puts "#{Math.cos(radians)} #{Math.cos(deg2rad(degrees))}" #tangent puts "#{Math.tan(radians)} #{Math.tan(deg2rad(degrees))}"...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Raku
Raku
class TreeNode { has TreeNode $.parent; has TreeNode $.left; has TreeNode $.right; has $.value;   method pre-order { flat gather { take $.value; take $.left.pre-order if $.left; take $.right.pre-order if $.right } }   method in-order { ...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Prolog
Prolog
splitup(Sep,[token(B)|BL]) --> splitup(Sep,B,BL). splitup(Sep,[A|AL],B) --> [A], {\+ [A] = Sep }, splitup(Sep,AL,B). splitup(Sep,[],[B|BL]) --> Sep, splitup(Sep,B,BL). splitup(_Sep,[],[]) --> []. start :- phrase(splitup(",",Tokens),"Hello,How,Are,You,Today"), phrase(splitup(".",Tokens),Backtoget...
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Run_BASIC
Run BASIC
perSal$ = "Tyler Bennett,E10297,32000,D101 John Rappl,E21437,47000,D050; George Woltman,E00127,53500,D101 Adam Smith,E63535,18000,D202; Claire Buckman,E39876,27800,D202 David McClellan,E04242,41500,D101 Rich Holcomb,E01234,49500,D202 Nathan Adams,E41298,21900,D050 Richard Potter,E43128,15900,D101 David Motsinger,E27002...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#SQL
SQL
  --Setup DROP TABLE IF EXISTS board; CREATE TABLE board (p CHAR, r INTEGER, c INTEGER); INSERT INTO board VALUES('.', 0, 0),('.', 0, 1),('.', 0, 2),('.', 1, 0),('.', 1, 1),('.', 1, 2),('.', 2, 0),('.', 2, 1),('.', 2, 2);     -- Use a trigger for move events DROP TRIGGER IF EXISTS after_moved; CREATE TRIGGER after_move...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Jsish
Jsish
/* Towers of Hanoi, in Jsish */   function move(n, a, b, c) { if (n > 0) { move(n-1, a, c, b); puts("Move disk from " + a + " to " + c); move(n-1, b, a, c); } }   if (Interp.conf('unitTest')) move(4, "A", "B", "C");   /* =!EXPECTSTART!= Move disk from A to B Move disk from A to C Move disk from B to C M...
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Run_BASIC
Run BASIC
' Find these three ratios: Sine, Cosine, Tangent. (These ratios have NO units.)   deg = 45.0 ' Run BASIC works in radians; so, first convert deg to rad as shown in next line. rad = deg * (atn(1)/45) print "Ratios for a "; deg; " degree angle, (or "; rad; " radian angle.)" print "Sine: "; SIN(rad) print "Cosine...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#REBOL
REBOL
  tree: [1 [2 [4 [7 [] []] []] [5 [] []]] [3 [6 [8 [] []] [9 [] []]] []]] ; "compacted" version tree: [1 [2 [4 [7 ] ] [5 ]] [3 [6 [8 ] [9 ]] ]]   visit: func [tree [block!]][prin rejoin [first tree " "]] left: :second right: :third   preorder: func [tree [block!]][ if not empty? tree [visit tree] attempt [preorde...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Python
Python
text = "Hello,How,Are,You,Today" tokens = text.split(',') print ('.'.join(tokens))
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Q
Q
words: "," vs "Hello,How,Are,You,Today" "." sv words
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Rust
Rust
#[derive(Debug)] struct Employee<S> { // Allow S to be any suitable string representation id: S, name: S, department: S, salary: u32, }   impl<S> Employee<S> { fn new(name: S, id: S, salary: u32, department: S) -> Self { Self { id, name, department, ...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Swift
Swift
  import Darwin   enum Token : CustomStringConvertible { case cross, circle   func matches(tokens: [Token?]) -> Bool { for token in tokens { guard let t = token, t == self else { return false } } return true }   func emptyCell(in tokens: [Token?]) -> Int? { if tokens[0] == nil && tokens[1] ==...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Julia
Julia
  function solve(n::Integer, from::Integer, to::Integer, via::Integer) if n == 1 println("Move disk from $from to $to") else solve(n - 1, from, via, to) solve(1, from, to, via) solve(n - 1, via, to, from) end end   solve(4, 1, 2, 3)  
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#K
K
h:{[n;a;b;c]if[n>0;_f[n-1;a;c;b];`0:,//$($n,":",$a,"->",$b,"\n");_f[n-1;c;b;a]]} h[4;1;2;3] 1:1->3 2:1->2 1:3->2 3:1->3 1:2->1 2:2->3 1:1->3 4:1->2 1:3->2 2:3->1 1:2->1 3:3->2 1:1->3 2:1->2 1:3->2
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Rust
Rust
// 20210221 Rust programming solution   use std::f64::consts::PI;   fn main() { let angle_radians: f64 = PI/4.0; let angle_degrees: f64 = 45.0;   println!("{} {}", angle_radians.sin(), angle_degrees.to_radians().sin()); println!("{} {}", angle_radians.cos(), angle_degrees.to_radians().cos()); println!("{...
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#SAS
SAS
data _null_; pi = 4*atan(1); deg = 30; rad = pi/6; k = pi/180; x = 0.2;   a = sin(rad); b = sin(deg*k); put a b;   a = cos(rad); b = cos(deg*k); put a b;   a = tan(rad); b = tan(deg*k); put a b;   a=arsin(x); b=arsin(x)/k; put a b;   a=arcos(x); b=arcos(x)/k; put a b;   a=atan(x); b=atan(x)/k; put a b; run;
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#REXX
REXX
  /* REXX *************************************************************** * Tree traversal = 1 = / \ = / \ = / \ = 2 3 = / \ / = 4 5 6 = / / \ = 7 8 9 = = The correct output should look like this: = preorder: 1 2 4 7 5 3 6 8 9 =...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#QB64
QB64
a$ = "Hello,How,Are,You,Today" ' | Initialize original string. FOR na = 1 TO LEN(a$) ' | Start loop to count number of commas. IF MID$(a$, na, 1) = "," THEN nc = nc + 1 ' | For each comma, increment nc. NEXT ' | End of loop. DIM t$(nc) ' ...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#Quackery
Quackery
[ [] [] rot witheach [ dup char , = iff [ drop nested join [] ] else join ] nested join ] is tokenise ( $ --> [ )   [ witheach [ echo$ say "." ] ] is display ( [ --> )   $ "Hello,How,Are,You,Today" tokenise display
http://rosettacode.org/wiki/Top_rank_per_group
Top rank per group
Task Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source: Employee Name,Employee ID,Salary,Department Tyler Bennett...
#Scala
Scala
import scala.io.Source import scala.language.implicitConversions import scala.language.reflectiveCalls import scala.collection.immutable.TreeMap   object TopRank extends App { val topN = 3   val rawData = """Employee Name;Employee ID;Salary;Department |Tyler Bennett;E10297;32000;D101 |...
http://rosettacode.org/wiki/Tic-tac-toe
Tic-tac-toe
Task Play a game of tic-tac-toe. Ensure that legal moves are played and that a winning position is notified. Tic-tac-toe   is also known as:   naughts and crosses   tic tac toe   tick tack toe   three in a row   tres en rayo       and   Xs  and  Os See also   MathWorld™, Tic-Tac-Toe game.   Wikipedi...
#Tailspin
Tailspin
  processor Tic-Tac-Toe @: [1..9 -> (position:$) -> $::value];   source isWonOrDone [$@Tic-Tac-Toe(1..3) -> #, $@Tic-Tac-Toe(4..6) -> #, $@Tic-Tac-Toe(7..9) -> #, $@Tic-Tac-Toe(1..9:3) -> #, $@Tic-Tac-Toe(2..9:3) -> #, $@Tic-Tac-Toe(3..9:3) -> #, $@Tic-Tac-Toe([1,5,9]) -> #, $@Tic-Tac-Toe([3,5,7]) -...
http://rosettacode.org/wiki/Towers_of_Hanoi
Towers of Hanoi
Task Solve the   Towers of Hanoi   problem with recursion.
#Klingphix
Klingphix
include ..\Utilitys.tlhy   :moveDisc %B !B %C !C %A !A %n !n { n A C B } $n [ $n 1 - $A $B $C moveDisc ( "Move disc " $n " from pole " $A " to pole " $C ) lprint nl $n 1 - $B $C $A moveDisc ] if ;   { Move disc 3 from pole 1 to pole 3, with pole 2 as spare } 3 1 3 2 moveDisc   " " input
http://rosettacode.org/wiki/Trigonometric_functions
Trigonometric functions
Task If your language has a library or built-in functions for trigonometry, show examples of:   sine   cosine   tangent   inverses   (of the above) using the same angle in radians and degrees. For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that i...
#Scala
Scala
import scala.math._   object Gonio extends App { //Pi / 4 rad is 45 degrees. All answers should be the same. val radians = Pi / 4 val degrees = 45.0   println(s"${sin(radians)} ${sin(toRadians(degrees))}") //cosine println(s"${cos(radians)} ${cos(toRadians(degrees))}") //tangent println(s"${tan(radians)...
http://rosettacode.org/wiki/Tree_traversal
Tree traversal
Task Implement a binary tree where each node carries an integer,   and implement:   pre-order,   in-order,   post-order,     and   level-order   traversal. Use those traversals to output the following tree: 1 / \ / \ / \ 2 3 / \ / 4 5 6 / ...
#Ruby
Ruby
BinaryTreeNode = Struct.new(:value, :left, :right) do def self.from_array(nested_list) value, left, right = nested_list if value self.new(value, self.from_array(left), self.from_array(right)) end end   def walk_nodes(order, &block) order.each do |node| case node when :left then...
http://rosettacode.org/wiki/Tokenize_a_string
Tokenize a string
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. Other tasks related to string operations: Me...
#R
R
text <- "Hello,How,Are,You,Today" junk <- strsplit(text, split=",") print(paste(unlist(junk), collapse="."))