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/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Befunge
Befunge
0246*+00p20#v_:#`2#g+#0:#0<>\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v >-#11#\0#50#< g2-:00p4v >\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3< ^02_>#`>#< 2 5 3 1 0 \1-:#^\_^#:-1\+<00_@#:>#<$< (On the ?|A partridge in a pear tree.||&first% andL day of Christmas,|My true l ove gave to me:2|Two turtle do...
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#Raku
Raku
say 'Hiding the cursor for 5 seconds...'; run 'tput', 'civis'; sleep 5; run 'tput', 'cvvis';
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#REXX
REXX
/*REXX pgm calls a function in a shared library (regutil) to hide/show cursor.*/ z=rxfuncadd('sysloadfuncs', "regutil", 'sysloadfuncs') /*add a function lib.*/ if z\==0 then do /*test the return cod*/ say 'return code' z "from rxfuncadd" /*tell about bad RC....
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#Ring
Ring
  # Project : Terminal control/Hiding the cursor   load "stdlib.ring" # Linux ? "Hide Cursor using tput utility" system("tput civis") # Invisible sleep(10) ? "Show Cursor using tput utility" system("tput cnorm") # Normal  
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#Ruby
Ruby
require "curses" include Curses   init_screen begin curs_set(1) #visible cursor sleep 3 curs_set(0) #invisible cursor sleep 3 curs_set(1) #visible cursor sleep 3 ensure close_screen end
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#Scala
Scala
object Main extends App { print("\u001B[?25l") // hide cursor Thread.sleep(2000) // wait 2 seconds before redisplaying cursor print("\u001B[?25h") // display cursor Thread.sleep(2000) // wait 2 more seconds before exiting }
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#Raku
Raku
say "normal"; run "tput", "rev"; say "reversed"; run "tput", "sgr0"; say "normal";
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#REXX
REXX
/*REXX program demonstrates the showing of reverse video to the display terminal. */ @day = 'day' @night = 'night'   call scrwrite , 1, @day, , , 7 /*display to terminal: white on black.*/ call scrwrite , 1+length(@day), @night, , , 112 /* " " " black " white.*/   exit 0 ...
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#Ring
Ring
  nverse = char(17)+char(128)+char(17)+char(15) normal = char(17)+char(128+15)+char(17)+char(0) see inverse + " inverse " + normal + " video"  
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#Ruby
Ruby
puts "\033[7mReversed\033[m Normal"
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#Scala
Scala
object Main extends App { println("\u001B[7mInverse\u001B[m Normal") }
http://rosettacode.org/wiki/Terminal_control/Dimensions
Terminal control/Dimensions
Determine the height and width of the terminal, and store this information into variables for subsequent use.
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. terminal-dimensions.   DATA DIVISION. WORKING-STORAGE SECTION. 01 num-lines PIC 9(3). 01 num-cols PIC 9(3).   SCREEN SECTION. 01 display-screen. 03 LINE 01 COL 01 PIC 9(3) FROM num-lines. 03 LINE 01 ...
http://rosettacode.org/wiki/Terminal_control/Dimensions
Terminal control/Dimensions
Determine the height and width of the terminal, and store this information into variables for subsequent use.
#Common_Lisp
Common Lisp
(defun screen-dimensions () (with-screen (scr :input-blocking t :input-echoing nil :cursor-visible nil) (let ((width (width scr)) (height (height scr))) (format scr "The current terminal screen is ~A lines high, ~A columns wide.~%~%" height width) (refresh scr) ;; wait for keypress...
http://rosettacode.org/wiki/Terminal_control/Cursor_movement
Terminal control/Cursor movement
Task Demonstrate how to achieve movement of the terminal cursor: how to move the cursor one position to the left how to move the cursor one position to the right how to move the cursor up one line (without affecting its horizontal position) how to move the cursor down one line (without affecting its horizontal po...
#Action.21
Action!
PROC Wait(BYTE frames) BYTE RTCLOK=$14 frames==+RTCLOK WHILE frames#RTCLOK DO OD RETURN   PROC Main() BYTE d=[50], CH=$02FC, ;Internal hardware value for last key pressed ROWCRS=$0054 ;Current cursor row CARD COLCRS=$0055 ;Current cursor column   Graphics(0) Position(2,2) Print("Press any ke...
http://rosettacode.org/wiki/Terminal_control/Cursor_movement
Terminal control/Cursor movement
Task Demonstrate how to achieve movement of the terminal cursor: how to move the cursor one position to the left how to move the cursor one position to the right how to move the cursor up one line (without affecting its horizontal position) how to move the cursor down one line (without affecting its horizontal po...
#Ada
Ada
with Ada.Text_Io;   with Ansi;   procedure Movement is use Ada.Text_Io; begin Put (Ansi.Store); Put (Ansi.Position (Row => 20, Column => 40));   for A in 1 .. 15 loop Put (Ansi.Back); delay 0.020; end loop;   for A in 1 .. 15 loop Put (Ansi.Up); delay 0.050; end loop;   f...
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#C.2FC.2B.2B
C/C++
#include <stdio.h> int main() { printf("\033[6;3HHello\n"); return 0; }
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#C.23
C#
static void Main(string[] args) { Console.SetCursorPosition(3, 6); Console.Write("Hello"); }
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. cursor-positioning.   PROCEDURE DIVISION. DISPLAY "Hello" AT LINE 6, COL 3   GOBACK .
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#Common_Lisp
Common Lisp
(defun cursor-positioning () (with-screen (scr :input-blocking t :input-echoing nil :cursor-visible nil) (move scr 5 2) (princ "Hello" scr) (refresh scr) ;; wait for keypress (get-char scr)))
http://rosettacode.org/wiki/Ternary_logic
Ternary logic
This page uses content from Wikipedia. The original article was at Ternary logic. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In logic, a three-valued logic (also trivalent, ternary, or trinary...
#C
C
#include <stdio.h>   typedef enum { TRITTRUE, /* In this enum, equivalent to integer value 0 */ TRITMAYBE, /* In this enum, equivalent to integer value 1 */ TRITFALSE /* In this enum, equivalent to integer value 2 */ } trit;   /* We can trivially find the result of the operation by passing the trinary values...
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#J
J
'£' £ '札幌' 札幌
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Java
Java
import java.io.PrintStream; import java.io.UnsupportedEncodingException;   public class Main { public static void main(String[] args) throws UnsupportedEncodingException { PrintStream writer = new PrintStream(System.out, true, "UTF-8"); writer.println("£"); writer.println("札幌"); } }
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Julia
Julia
println("£") println("\302\243"); # works if your terminal is utf-8  
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Kotlin
Kotlin
// version 1.1.2   fun main(args:Array<String>) = println("£")
http://rosettacode.org/wiki/Text_processing/1
Text processing/1
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. Often data is produced by one program, in the wrong format for later use by another program or person. In these situations another pr...
#Clojure
Clojure
  (ns rosettacode.textprocessing1 (:require [clojure.string :as str]))   (defn parse-line [s] (let [[date & data-toks] (str/split s #"\s+")] {:date date  :hour-vals (for [[v flag] (partition 2 data-toks)] {:val (Double. v)  :flag (Long. flag)})}))   (defn analyze-line [m...
http://rosettacode.org/wiki/The_ISAAC_Cipher
The ISAAC Cipher
ISAAC is a cryptographically secure pseudo-random number generator (CSPRNG) and stream cipher. It was developed by Bob Jenkins from 1993 (http://burtleburtle.net/bob/rand/isaac.html) and placed in the Public Domain. ISAAC is fast - especially when optimised - and portable to most architectures in nearly all programming...
#Modula-2
Modula-2
  MODULE RosettaIsaac;   FROM Strings IMPORT Length, Assign, Append; FROM STextIO IMPORT WriteString, WriteLn; FROM Conversions IMPORT CardBaseToStr;   CONST MaxStrLength = 256;   TYPE TMode = (iEncrypt, iDecrypt); TString = ARRAY [0 .. MaxStrLength - 1] OF CHAR; TCardIndexedFrom0To7 = ARRAY [0 .. 7] OF C...
http://rosettacode.org/wiki/Test_integerness
Test integerness
Mathematically, the integers Z are included in the rational numbers Q, which are included in the real numbers R, which can be generalized to the complex numbers C. This means that each of those larger sets, and the data types used to represent them, include some integers. Task[edit] Given a rational, real, or co...
#PARI.2FGP
PARI/GP
isInteger(z)=real(z)==real(z)\1 && imag(z)==imag(z)\1; apply(isInteger, [7, I, 1.7 + I, 10.0 + I, 1.0 - 7.0 * I])
http://rosettacode.org/wiki/Test_integerness
Test integerness
Mathematically, the integers Z are included in the rational numbers Q, which are included in the real numbers R, which can be generalized to the complex numbers C. This means that each of those larger sets, and the data types used to represent them, include some integers. Task[edit] Given a rational, real, or co...
#Perl
Perl
use Math::Complex;   sub is_int { my $number = shift;   if (ref $number eq 'Math::Complex') { return 0 if $number->Im != 0; $number = $number->Re; }   return int($number) == $number; }   for (5, 4.1, sqrt(2), sqrt(4), 1.1e10, 3.0-0.0*i, 4-3*i, 5.6+0*i) { printf "%20s is%s an integer\...
http://rosettacode.org/wiki/Text_processing/Max_licenses_in_use
Text processing/Max licenses in use
A company currently pays a fixed sum for the use of a particular licensed software package.   In determining if it has a good deal it decides to calculate its maximum use of the software from its license management log file. Assume the software's licensing daemon faithfully records a checkout event when a copy of the ...
#Picat
Picat
import util.   go => Jobs = read_file_lines("mlijobs.txt"), Counts = asum(Jobs).to_array, % convert to array for speed Max = max(Counts), MaxIxs = [I : I in 1..Counts.length, Counts[I] == Max], printf("Max number of licenses is %d.\n", Max), printf("Interval:\n%w\n", [Jobs[J,15..33] : J in MaxIxs].join("\n"...
http://rosettacode.org/wiki/Text_processing/Max_licenses_in_use
Text processing/Max licenses in use
A company currently pays a fixed sum for the use of a particular licensed software package.   In determining if it has a good deal it decides to calculate its maximum use of the software from its license management log file. Assume the software's licensing daemon faithfully records a checkout event when a copy of the ...
#PicoLisp
PicoLisp
#!/usr/bin/picolisp /usr/lib/picolisp/lib.l   (zero Count MaxCount)   (in (opt) (while (split (line) " ") (case (pack (cadr (setq Line @))) (IN (dec 'Count) ) (OUT (let Time (cadddr Line) (cond ((> (inc 'Count) MaxCount) ...
http://rosettacode.org/wiki/Test_a_function
Test a function
Task Using a well-known testing-specific library/module/suite for your language, write some tests for your language's entry in Palindrome. If your language does not have a testing specific library well known to the language's community then state this or omit the language.
#Julia
Julia
using Base.Test include("Palindrome_detection.jl")   # Simple test @test palindrome("abcdcba") @test !palindrome("abd")   # Test sets @testset "palindromes" begin @test palindrome("aaaaa") @test palindrome("abcba") @test palindrome("1") @test palindrome("12321") end   @testset "non-palindromes" begin ...
http://rosettacode.org/wiki/Test_a_function
Test a function
Task Using a well-known testing-specific library/module/suite for your language, write some tests for your language's entry in Palindrome. If your language does not have a testing specific library well known to the language's community then state this or omit the language.
#Kotlin
Kotlin
// version 1.1.3   fun isPalindrome(s: String) = (s == s.reversed())   fun main(args: Array<String>) { val testCases = listOf("racecar", "alice", "eertree", "david") for (testCase in testCases) { try { assert(isPalindrome(testCase)) { "$testCase is not a palindrome" } } catch...
http://rosettacode.org/wiki/Text_processing/2
Text processing/2
The following task concerns data that came from a pollution monitoring station with twenty-four instruments monitoring twenty-four aspects of pollution in the air. Periodically a record is added to the file, each record being a line of 49 fields separated by white-space, which can be one or more space or tab characters...
#zkl
zkl
// the RegExp engine has a low limit on groups so // I can't use it to select all fields, only verify them re:=RegExp(0'|^(\d+-\d+-\d+)| + 0'|\s+\d+\.\d+\s+-*\d+| * 24 + ".+$"); w:=[1..].zip(File("readings.txt")); //-->lazy (line #,line) reg datep,N, good=0, dd=0; foreach n,line in (w){ N=n; // since n is lo...
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#Sidef
Sidef
print "\a";
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#SNUSP
SNUSP
$+++++++.#
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#Standard_ML
Standard ML
val () = print "\a"
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#Tcl
Tcl
puts -nonewline "\a";flush stdout
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Bracmat
Bracmat
( first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelveth  : ?days & "A partridge in a pear tree." "Two turtle doves and" "Three french hens," "Four calling birds," "Five golden rings," "S...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#C
C
  #include<stdio.h>   int main() { int i,j;   char days[12][10] = { "First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth", "Eleventh", "Twelfth" };   char gifts[12...
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#Tcl
Tcl
  proc cursorVisibility {{state normal}} { switch -- $state { invisible {set op civis} visible {set op cvvis} normal {set op cnorm} } exec -- >@stdout tput $op }  
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#UNIX_Shell
UNIX Shell
tput civis # Hide the cursor sleep 5 # Sleep for 5 seconds tput cnorm # Show the cursor
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#Wren
Wren
import "timer" for Timer   System.print("\e[?25l") Timer.sleep(3000) System.print("\e[?25h") Timer.sleep(3000)
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations   proc ShowCur(On); \Turn flashing cursor on or off int On; \true = cursor on; false = cursor off int CpuReg; [CpuReg:= GetReg; \access CPU registers CpuReg(0):= $0100; \AX:= $0100 CpuReg(2):= if On then $0007 else $2000; SoftInt($1...
http://rosettacode.org/wiki/Terminal_control/Hiding_the_cursor
Terminal control/Hiding the cursor
The task is to hide the cursor and show it again.
#zkl
zkl
print("\e[?25l"); Atomic.sleep(3); print("\e[?25h");
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#Standard_ML
Standard ML
val () = print "\^[[7mReversed\^[[m Normal\n"
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#Tcl
Tcl
# Get how the terminal wants to do things... set videoSeq(reverse) [exec tput rev] set videoSeq(normal) [exec tput rmso] proc reverseVideo str { global videoSeq return "$videoSeq(reverse)${str}$videoSeq(normal)" }   # The things to print set inReverse "foo" set inNormal "bar"   # Print those words puts "[revers...
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#TPP
TPP
--revon This is inverse --revoff This is normal
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#UNIX_Shell
UNIX Shell
#!/bin/sh tput mr # foo is reversed echo 'foo' tput me # bar is normal video echo 'bar'
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#Wren
Wren
System.print("\e[7mInverse") System.print("\e[0mNormal")
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#XPL0
XPL0
include c:\cxpl\codes; [Attrib($70); Text(6, "Inverse"); Attrib($07); Text(6, " Video"); CrLf(6); ]
http://rosettacode.org/wiki/Terminal_control/Dimensions
Terminal control/Dimensions
Determine the height and width of the terminal, and store this information into variables for subsequent use.
#Euphoria
Euphoria
include graphics.e   sequence vc integer term_height, term_width   vc = video_config()   term_height = vc[VC_LINES] term_width = vc[VC_COLUMNS]   printf(1,"Terminal height is %d\n",term_height) printf(1,"Terminal width is %d\n",term_width)
http://rosettacode.org/wiki/Terminal_control/Dimensions
Terminal control/Dimensions
Determine the height and width of the terminal, and store this information into variables for subsequent use.
#F.23
F#
open System   let bufferHeight = Console.BufferHeight let bufferWidth = Console.BufferWidth let windowHeight = Console.WindowHeight let windowWidth = Console.WindowWidth   Console.Write("Buffer Height: ") Console.WriteLine(bufferHeight) Console.Write("Buffer Width: ") Console.WriteLine(bufferWidth) Console.Write("Windo...
http://rosettacode.org/wiki/Terminal_control/Dimensions
Terminal control/Dimensions
Determine the height and width of the terminal, and store this information into variables for subsequent use.
#Forth
Forth
variable term-width variable term-height   s" gforth" environment? [if] 2drop form ( height width ) [else] \ SwiftForth get-size ( width height ) swap [then] term-width ! term-height !
http://rosettacode.org/wiki/Terminal_control/Dimensions
Terminal control/Dimensions
Determine the height and width of the terminal, and store this information into variables for subsequent use.
#FreeBASIC
FreeBASIC
Dim As Integer w, h, p, bpp, tasa Dim driver_name As String Screeninfo w, h, p, bpp, , tasa   Print !"Informaci¢n sobre el escritorio (terminal):\n" Print " Ancho de la terminal: "; w; " (pixel)" Print "Altura de la terminal: "; h; " (pixel)" Print " Profundidad de color: "; p; " (bits)" Print " Tasa de refresco: "...
http://rosettacode.org/wiki/Terminal_control/Coloured_text
Terminal control/Coloured text
Task Display a word in various colours on the terminal. The system palette, or colours such as Red, Green, Blue, Magenta, Cyan, and Yellow can be used. Optionally demonstrate: How the system should determine if the terminal supports colour Setting of the background colour How to cause blinking or flashing (if ...
#8086_Assembly
8086 Assembly
.model small .stack 1024 .data .code start:   mov ax,@data mov ds,ax   mov ax,@code mov es,ax     cld ;String functions are set to auto-increment   mov ax,13h ;select 320x200 VGA int 10h   mov ah,0Eh mov al,'A' ...
http://rosettacode.org/wiki/Terminal_control/Cursor_movement
Terminal control/Cursor movement
Task Demonstrate how to achieve movement of the terminal cursor: how to move the cursor one position to the left how to move the cursor one position to the right how to move the cursor up one line (without affecting its horizontal position) how to move the cursor down one line (without affecting its horizontal po...
#ARM_Assembly
ARM Assembly
    /* ARM assembly Raspberry PI */ /* program cursorMove.s */   /* Constantes */ .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ WRITE, 4 @ Linux syscall   /* Initialized data */ .data szMessStartPgm: ...
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#D
D
Position the Cursor: \033[<L>;<C>H or \033[<L>;<C>f puts the cursor at line L and column C.
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#Elena
Elena
public program() { console.setCursorPosition(3,6).write("Hello") }
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#Euphoria
Euphoria
position(6,3) puts(1,"Hello")
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#F.23
F#
open System   Console.SetCursorPosition(3, 6) Console.Write("Hello")
http://rosettacode.org/wiki/Ternary_logic
Ternary logic
This page uses content from Wikipedia. The original article was at Ternary logic. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In logic, a three-valued logic (also trivalent, ternary, or trinary...
#C.23
C#
using System;   /// <summary> /// Extension methods on nullable bool. /// </summary> /// <remarks> /// The operators !, & and | are predefined. /// </remarks> public static class NullableBoolExtension { public static bool? Implies(this bool? left, bool? right) { return !left | right; }   public ...
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Lasso
Lasso
stdout(' £ ')
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Locomotive_Basic
Locomotive Basic
10 PRINT CHR$(163)
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Lua
Lua
print(string.char(156))
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
FromCharacterCode[{163}]
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static GBP = '\u00a3' -- unicode code point say GBP GBP = '£' -- if the editor's up to it say GBP ...
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Nim
Nim
echo "£" echo "札幌"   import unicode echo Rune(0xa3)
http://rosettacode.org/wiki/Text_processing/1
Text processing/1
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. Often data is produced by one program, in the wrong format for later use by another program or person. In these situations another pr...
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. data-munging.   ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT input-file ASSIGN TO INPUT-FILE-PATH ORGANIZATION LINE SEQUENTIAL FILE STATUS file-status.   DATA DIVISION. FILE...
http://rosettacode.org/wiki/The_ISAAC_Cipher
The ISAAC Cipher
ISAAC is a cryptographically secure pseudo-random number generator (CSPRNG) and stream cipher. It was developed by Bob Jenkins from 1993 (http://burtleburtle.net/bob/rand/isaac.html) and placed in the Public Domain. ISAAC is fast - especially when optimised - and portable to most architectures in nearly all programming...
#Nim
Nim
import strutils   type   IMode = enum iEncrypt, iDecrypt   State = object # Internal. mm: array[256, uint32] aa, bb, cc: uint32 # External. randrsl: array[256, uint32] randcnt: uint32     proc isaac(s: var State) =   inc s.cc # "cc" just gets incremented once per 256 results s.bb ...
http://rosettacode.org/wiki/Test_integerness
Test integerness
Mathematically, the integers Z are included in the rational numbers Q, which are included in the real numbers R, which can be generalized to the complex numbers C. This means that each of those larger sets, and the data types used to represent them, include some integers. Task[edit] Given a rational, real, or co...
#Pascal
Pascal
program integerness(output);   { determines whether a `complex` also fits in `integer` ---------------- } function isRealIntegral(protected x: complex): Boolean; begin { It constitutes an error if no value for `trunc(x)` exists, } { thus check re(x) is in the range -maxInt..maxInt first. } isRealIntegral := (im(x) =...
http://rosettacode.org/wiki/Text_processing/Max_licenses_in_use
Text processing/Max licenses in use
A company currently pays a fixed sum for the use of a particular licensed software package.   In determining if it has a good deal it decides to calculate its maximum use of the software from its license management log file. Assume the software's licensing daemon faithfully records a checkout event when a copy of the ...
#PL.2FI
PL/I
  text3: procedure options (main); /* 19 November 2011 */ declare line character (80) varying; declare (nout, max_nout) fixed; declare saveline character (80) varying controlled; declare k fixed binary; declare in file input;   open file (in) title ('/TEXT-MAX.DAT,TYPE(TEXT),RECSIZE(80)' );   on en...
http://rosettacode.org/wiki/Test_a_function
Test a function
Task Using a well-known testing-specific library/module/suite for your language, write some tests for your language's entry in Palindrome. If your language does not have a testing specific library well known to the language's community then state this or omit the language.
#Lasso
Lasso
// Taken from the Lasso entry in Palindrome page define isPalindrome(text::string) => {   local(_text = string(#text)) // need to make copy to get rid of reference issues   #_text -> replace(regexp(`(?:$|\W)+`), -ignorecase)   local(reversed = string(#_text)) #reversed -> reverse   return #_text == ...
http://rosettacode.org/wiki/Test_a_function
Test a function
Task Using a well-known testing-specific library/module/suite for your language, write some tests for your language's entry in Palindrome. If your language does not have a testing specific library well known to the language's community then state this or omit the language.
#Lua
Lua
assert( ispalindrome("ABCBA") ) assert( ispalindrome("ABCDE") )
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#UNIX_Shell
UNIX Shell
#!/bin/sh # Ring the terminal bell # echo "\a" # does not work in some shells tput bel
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#Wren
Wren
System.print("\a")
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#X86_Assembly
X86 Assembly
;Assemble with: tasm; tlink /t .model tiny .code org 100h  ;.com files start here start: mov ah, 02h  ;character output mov dl, 07h  ;bell code int 21h  ;call MS-DOS ret  ;return to MS-DOS end...
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#XPL0
XPL0
code ChOut=8; ChOut(0,7)
http://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell
Terminal control/Ringing the terminal bell
Task Make the terminal running the program ring its "bell". On modern terminal emulators, this may be done by playing some other sound which might or might not be configurable, or by flashing the title bar or inverting the colors of the screen, but was classically a physical bell within the terminal.   It is usua...
#zkl
zkl
print("\x07");
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#C.23
C#
using System;   public class TwelveDaysOfChristmas {   public static void Main() {   string[] days = new string[12] { "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth", };   string[] gifts = new string...
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#Z80_Assembly
Z80 Assembly
.org &8000 PrintChar equ &BB5A InvertTextColors equ &BB9C     ;main   call InvertTextColors   ld hl, HelloAddr call PrintString   call InvertTextColors   ld hl,HelloAddr jp PrintString ;and return to basic after that.     HelloAddr: byte "Hello",0   PrintString: ld a,(hl) or a ret z call PrintChar inc hl jp PrintS...
http://rosettacode.org/wiki/Terminal_control/Inverse_video
Terminal control/Inverse video
Task Display a word in inverse video   (or reverse video)   followed by a word in normal video.
#zkl
zkl
println("\e[7mReversed\e[m Normal");
http://rosettacode.org/wiki/Terminal_control/Dimensions
Terminal control/Dimensions
Determine the height and width of the terminal, and store this information into variables for subsequent use.
#Go
Go
package main   import ( "fmt" "os"   "golang.org/x/crypto/ssh/terminal" )   func main() { w, h, err := terminal.GetSize(int(os.Stdout.Fd())) if err != nil { fmt.Println(err) return } fmt.Println(h, w) }
http://rosettacode.org/wiki/Terminal_control/Dimensions
Terminal control/Dimensions
Determine the height and width of the terminal, and store this information into variables for subsequent use.
#J
J
_2 {.qsmsize_jijs_''
http://rosettacode.org/wiki/Terminal_control/Coloured_text
Terminal control/Coloured text
Task Display a word in various colours on the terminal. The system palette, or colours such as Red, Green, Blue, Magenta, Cyan, and Yellow can be used. Optionally demonstrate: How the system should determine if the terminal supports colour Setting of the background colour How to cause blinking or flashing (if ...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program colorterminal64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstant...
http://rosettacode.org/wiki/Terminal_control/Coloured_text
Terminal control/Coloured text
Task Display a word in various colours on the terminal. The system palette, or colours such as Red, Green, Blue, Magenta, Cyan, and Yellow can be used. Optionally demonstrate: How the system should determine if the terminal supports colour Setting of the background colour How to cause blinking or flashing (if ...
#Ada
Ada
with Ada.Text_Io;   with Ansi;   procedure Coloured is use Ada.Text_Io; subtype Ansi_Colors is Ansi.Colors range Ansi.Black .. Ansi.Colors'Last; -- Avoid default begin for Fg_Color in Ansi_Colors loop Put ("Rosetta "); Put (Ansi.Foreground (Fg_Color)); for Bg_Color in Ansi_Colors loop ...
http://rosettacode.org/wiki/Terminal_control/Cursor_movement
Terminal control/Cursor movement
Task Demonstrate how to achieve movement of the terminal cursor: how to move the cursor one position to the left how to move the cursor one position to the right how to move the cursor up one line (without affecting its horizontal position) how to move the cursor down one line (without affecting its horizontal po...
#AutoHotkey
AutoHotkey
DllCall("AllocConsole") hConsole:=DllCall("GetConsoleWindow","UPtr") Stdout:=FileOpen(DllCall("GetStdHandle", "int", -11, "ptr"), "h `n") Stdin:=FileOpen(DllCall("GetStdHandle", "int", -10, "ptr"), "h `n")   ;move the cursor one position to the left GetPos(x,y) SetPos(x-1)   ;move the cursor one position to the right G...
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#Forth
Forth
2 5 at-xy ." Hello"
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#Fortran
Fortran
program textposition use kernel32 implicit none integer(HANDLE) :: hConsole integer(BOOL) :: q   hConsole = GetStdHandle(STD_OUTPUT_HANDLE) q = SetConsoleCursorPosition(hConsole, T_COORD(3, 6)) q = WriteConsole(hConsole, loc("Hello"), 5, NULL, NULL) end program
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#FreeBASIC
FreeBASIC
Locate 6, 3 : Print "Hello" Sleep
http://rosettacode.org/wiki/Terminal_control/Cursor_positioning
Terminal control/Cursor positioning
Task Move the cursor to column   3,   row   6,   and display the word   "Hello"   (without the quotes),   so that the letter   H   is in column   3   on row   6.
#Go
Go
package main   import ( "bytes" "fmt" "os" "os/exec" )   func main() { cmd := exec.Command("tput", "-S") cmd.Stdin = bytes.NewBufferString("clear\ncup 5 2") cmd.Stdout = os.Stdout cmd.Run() fmt.Println("Hello") }
http://rosettacode.org/wiki/Ternary_logic
Ternary logic
This page uses content from Wikipedia. The original article was at Ternary logic. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In logic, a three-valued logic (also trivalent, ternary, or trinary...
#C.2B.2B
C++
#include <iostream> #include <stdlib.h>   class trit { public: static const trit False, Maybe, True;   trit operator !() const { return static_cast<Value>(-value); }   trit operator &&(const trit &b) const { return (value < b.value) ? value : b.value; }   trit operator ||(const t...
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Objeck
Objeck
class Program { function : Main(args : String[]) ~ Nil { "£"->PrintLine(); } }
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Pascal
Pascal
program pound; uses crt; begin write(chr( 163 )); end.  
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Perl
Perl
use feature 'say';   # OK as is say '£';   # these need 'binmode needed to surpress warning about 'wide' char binmode STDOUT, ":utf8"; say "\N{FULLWIDTH POUND SIGN}"; say "\x{FFE1}"; say chr 0xffe1;
http://rosettacode.org/wiki/Terminal_control/Display_an_extended_character
Terminal control/Display an extended character
Task Display an extended (non ASCII) character onto the terminal. Specifically, display a   £   (GBP currency sign).
#Phix
Phix
puts(1,"£")
http://rosettacode.org/wiki/Text_processing/1
Text processing/1
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. Often data is produced by one program, in the wrong format for later use by another program or person. In these situations another pr...
#Common_Lisp
Common Lisp
(defvar *invalid-count*) (defvar *max-invalid*) (defvar *max-invalid-date*) (defvar *total-sum*) (defvar *total-valid*)   (defun read-flag (stream date) (let ((flag (read stream))) (if (plusp flag) (setf *invalid-count* 0) (when (< *max-invalid* (incf *invalid-count*)) (setf *max-invalid...
http://rosettacode.org/wiki/The_ISAAC_Cipher
The ISAAC Cipher
ISAAC is a cryptographically secure pseudo-random number generator (CSPRNG) and stream cipher. It was developed by Bob Jenkins from 1993 (http://burtleburtle.net/bob/rand/isaac.html) and placed in the Public Domain. ISAAC is fast - especially when optimised - and portable to most architectures in nearly all programming...
#Pascal
Pascal
  PROGRAM RosettaIsaac; USES StrUtils;   TYPE iMode = (iEncrypt, iDecrypt);   // TASK globals VAR msg : String = 'a Top Secret secret'; key : String = 'this is my secret key'; xctx: String = ''; // XOR ciphertext mctx: String = ''; // MOD ciphertext xptx: String = ''; // XOR decryption (plaintext) mptx:...
http://rosettacode.org/wiki/Test_integerness
Test integerness
Mathematically, the integers Z are included in the rational numbers Q, which are included in the real numbers R, which can be generalized to the complex numbers C. This means that each of those larger sets, and the data types used to represent them, include some integers. Task[edit] Given a rational, real, or co...
#Phix
Phix
?integer(3.5+3.5) -- true ?integer(3.5+3.4) -- false
http://rosettacode.org/wiki/Test_integerness
Test integerness
Mathematically, the integers Z are included in the rational numbers Q, which are included in the real numbers R, which can be generalized to the complex numbers C. This means that each of those larger sets, and the data types used to represent them, include some integers. Task[edit] Given a rational, real, or co...
#PicoLisp
PicoLisp
  (de int? (N) (= N (* 1.0 (/ N 1.0)))) #returns T or NIL   (de integer? (N) (and (= N (* 1.0 (/ N 1.0))) N)) #returns value of N or NIL   (scl 4) #-> 4 # *Scl the global which holds 1.0 #-> 10000 (int? 1.0) #-> T (int? 1) #-> NIL # 1 with a scale of 4 is same as 0.0001 which is not an Integer (int? -1.0) #-> T (i...
http://rosettacode.org/wiki/Text_processing/Max_licenses_in_use
Text processing/Max licenses in use
A company currently pays a fixed sum for the use of a particular licensed software package.   In determining if it has a good deal it decides to calculate its maximum use of the software from its license management log file. Assume the software's licensing daemon faithfully records a checkout event when a copy of the ...
#PowerShell
PowerShell
  [int]$count = 0 [int]$maxCount = 0 [datetime[]]$times = @()   $jobs = Get-Content -Path ".\mlijobs.txt" | ForEach-Object { [string[]]$fields = $_.Split(" ",[StringSplitOptions]::RemoveEmptyEntries) [datetime]$datetime = Get-Date $fields[3].Replace("_"," ") [PSCustomObject]@{ State = $fields[1] ...