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_Name_Game | The Name Game | Write a program that accepts a name as input and outputs the lyrics to the Shirley Ellis song "The Name Game".
The regular verse
Unless your name begins with a vowel (A, E, I, O, U), 'B', 'F' or 'M' you don't have to care about special rules.
The verse for the name 'Gary' would be like this:
Gary, Gary, bo-bary... | #UNIX_Shell | UNIX Shell | #!/usr/bin/env bash
namegame() {
local name=$1 b=b f=f m=m
local rhyme=${name#[^AaEeIiOoUu]}
while [[ $rhyme == [^AaEeIiOoUuYy]* ]]; do
rhyme=${rhyme#?}
done
if [[ "$rhyme" == [AEIOU]* ]]; then
rhyme=$(tr A-Z a-z <<<"$rhyme")
fi
if [[ $name == [Bb]* ]]; then
b=
fi
if [[ $name == [Ff]* ]]; ... |
http://rosettacode.org/wiki/The_Name_Game | The Name Game | Write a program that accepts a name as input and outputs the lyrics to the Shirley Ellis song "The Name Game".
The regular verse
Unless your name begins with a vowel (A, E, I, O, U), 'B', 'F' or 'M' you don't have to care about special rules.
The verse for the name 'Gary' would be like this:
Gary, Gary, bo-bary... | #VBA | VBA | Option Explicit
Sub Main()
Dim a, r, i As Integer
Const SCHEM As String = "(X), (X), bo-b(Y)^Banana-fana fo-f(Y)^Fee-fi-mo-m(Y)^(X)!^"
'init
a = Array("GaRY", "Earl", "Billy", "Felix", "Mary", "Mike", "Frank")
'compute
r = TheGameName(a, SCHEM)
'return
For i = LBound(r) To UBound(r)
Debug.Prin... |
http://rosettacode.org/wiki/Textonyms | Textonyms | When entering text on a phone's digital pad it is possible that a particular combination of digits corresponds to more than one word. Such are called textonyms.
Assuming the digit keys are mapped to letters as follows:
2 -> ABC
3 -> DEF
4 -> GHI
5 -> JKL
6 -> MNO
7 -> PQRS
8 -> TUV
9 -... | #zkl | zkl | URL:="http://www.puzzlers.org/pub/wordlists/unixdict.txt";
var ZC=Import("zklCurl");
var keypad=Dictionary(
"a",2,"b",2,"c",2, "d",3,"e",3,"f",3, "g",4,"h",4,"i",4,
"j",5,"k",5,"l",5, "m",6,"n",6,"o",6, "p",7,"q",7,"r",7,"s",7,
"t",8,"u",8,"v",8, "w",9,"x",9,"y",9,"z",9);
//fcn numerate(word){ word.toLowe... |
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 ... | #Haskell | Haskell |
import Data.List
main = do
f <- readFile "./../Puzzels/Rosetta/inout.txt"
let (ioo,dt) = unzip. map ((\(_:io:_:t:_)-> (io,t)). words) . lines $ f
cio = drop 1 . scanl (\c io -> if io == "IN" then pred c else succ c) 0 $ ioo
mo = maximum cio
putStrLn $ "Maximum simultaneous license use is " ++ sho... |
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.
| #ACL2 | ACL2 | (defun reverse-split-at-r (xs i ys)
(if (zp i)
(mv xs ys)
(reverse-split-at-r (rest xs) (1- i)
(cons (first xs) ys))))
(defun reverse-split-at (xs i)
(reverse-split-at-r xs i nil))
(defun is-palindrome (str)
(let* ((lngth (length str))
(idx (floor lngth 2)))
... |
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... | #Phix | Phix | -- demo\rosetta\TextProcessing2.exw
with javascript_semantics -- (include version/first of next three lines only)
include readings.e -- global constant lines, or:
--assert(write_lines("readings.txt",lines)!=-1) -- first run, then:
--constant lines = read_lines("readings.txt")
include builtins\timedate.e
integer all... |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Nim | Nim | import os, strutils
if "utf" in getEnv("LANG").toLower:
echo "Unicode is supported on this terminal and U+25B3 is: △"
else:
echo "Unicode is not supported on this terminal." |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Perl | Perl | die "Terminal can't handle UTF-8"
unless $ENV{LC_ALL} =~ /utf-8/i or $ENV{LC_CTYPE} =~ /utf-8/i or $ENV{LANG} =~ /utf-8/i;
print "△ \n"; |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Phix | Phix | with javascript_semantics
include builtins\cffi.e
constant tGSH = """
HANDLE WINAPI GetStdHandle(
_In_ DWORD nStdHandle
);
""",
tSCOCP = """
BOOL WINAPI SetConsoleOutputCP(
_In_ UINT wCodePageID
);
""",
STD_OUTPUT_HANDLE = -11,
CP_UTF8 = 65001,
envset = {"LANG","LC_ALL","LC_CTYPE"}
atom k32 = NULL, xGetStd... |
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... | #AWK | AWK | BEGIN {
print "\a" # Ring the bell
} |
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... | #BASIC | BASIC | 10 PRINT CHR$ (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... | #Batch_File | Batch File | @echo off
for /f %%. in ('forfiles /m "%~nx0" /c "cmd /c echo 0x07"') do set bell=%%.
echo %bell% |
http://rosettacode.org/wiki/The_Name_Game | The Name Game | Write a program that accepts a name as input and outputs the lyrics to the Shirley Ellis song "The Name Game".
The regular verse
Unless your name begins with a vowel (A, E, I, O, U), 'B', 'F' or 'M' you don't have to care about special rules.
The verse for the name 'Gary' would be like this:
Gary, Gary, bo-bary... | #Visual_Basic_.NET | Visual Basic .NET | Option Strict On
Imports System.Text
Module Module1
Sub PrintVerse(name As String)
Dim sb As New StringBuilder(name.ToLower())
sb(0) = Char.ToUpper(sb(0))
Dim x = sb.ToString()
Dim y = If("AEIOU".IndexOf(x(0)) > -1, x.ToLower(), x.Substring(1))
Dim b = "b" + y
... |
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... | #11l | 11l | F isint(f)
R Complex(f).imag == 0 & fract(Complex(f).real) == 0
print([Complex(1.0), 2, (3.0 + 0.0i), 4.1, (3 + 4i), (5.6 + 0i)].map(f -> isint(f)))
print(isint(25.000000))
print(isint(24.999999))
print(isint(25.000100))
print(isint(-5e-2))
print(isint(Float.infinity))
print(isint(5.0 + 0.0i))
print(isint(5 - 5i)) |
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 ... | #HicEst | HicEst | CHARACTER Licenses="Licenses.txt"
REAL :: counts(1), Top10(10)
OPEN(FIle=Licenses, fmt='8x,A3,3x,A19,Nb ,', LENgth=lines)
ALLOCATE(counts, lines)
counts(1) = 1
DO line = 2, lines
counts(line) = counts(line-1) + 1 - 2*(Licenses(line,1)=='IN')
ENDDO
SORT(Vector=counts, Descending=1, Index=Top10)
DO i = 1, LEN(... |
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.
| #Ada | Ada | with Ada.Text_IO;
procedure Test_Function is
function Palindrome (Text : String) return Boolean is
begin
for Offset in 0 .. Text'Length / 2 - 1 loop
if Text (Text'First + Offset) /= Text (Text'Last - Offset) then
return False;
end if;
end loop;
return True;
e... |
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.
| #Arturo | Arturo | palindrome?: function [s][
s = reverse s
]
tests: [
[true? palindrome? "aba"]
[false? palindrome? "ab" ]
]
loop tests => ensure |
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... | #PHP | PHP | $handle = fopen("readings.txt", "rb");
$missformcount = 0;
$totalcount = 0;
$dates = array();
while (!feof($handle)) {
$buffer = fgets($handle);
$line = preg_replace('/\s+/',' ',$buffer);
$line = explode(' ',trim($line));
$datepattern = '/^\d{4}-\d{2}-\d{2}$/';
$valpattern = '/^\d+\.{1}\d{3}$/';
$flagpattern =... |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #PicoLisp | PicoLisp | (if (sub? "UTF-8" (or (sys "LC_ALL") (sys "LC_CTYPE") (sys "LANG")))
(prinl (char (hex "25b3")))
(quit "UTF-8 capable terminal required") ) |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Python | Python | import sys
if "UTF-8" in sys.stdout.encoding:
print("△")
else:
raise Exception("Terminal can't handle UTF-8") |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #R | R | if (any(grepl("UTF", toupper(Sys.getenv(c("LANG", "LC_ALL", "LC_CTYPE")))))) {
cat("Unicode is supported on this terminal and U+25B3 is : \u25b3\n")
} else {
cat("Unicode is not supported on this terminal.")
} |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Racket | Racket |
#lang racket
(displayln
(if (regexp-match? #px"(?i:utf-?8)"
(or (getenv "LC_ALL") (getenv "LC_CTYPE") (getenv "LANG")))
"\u25b3" "No Unicode detected."))
|
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... | #BBC_BASIC | BBC BASIC | VDU 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... | #Bc | Bc | 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... | #beeswax | beeswax | _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... | #Befunge | Befunge | 7,@ |
http://rosettacode.org/wiki/The_Name_Game | The Name Game | Write a program that accepts a name as input and outputs the lyrics to the Shirley Ellis song "The Name Game".
The regular verse
Unless your name begins with a vowel (A, E, I, O, U), 'B', 'F' or 'M' you don't have to care about special rules.
The verse for the name 'Gary' would be like this:
Gary, Gary, bo-bary... | #Wren | Wren | import "/str" for Str
var printVerse = Fn.new { |name|
var x = Str.capitalize(Str.lower(name))
var z = x[0]
var y = "AEIOU".contains(z) ? Str.lower(x) : x[1..-1]
var b = "b%(y)"
var f = "f%(y)"
var m = "m%(y)"
if (z == "B") {
b = y
} else if (z == "F") {
f = y
} els... |
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... | #ALGOL_68 | ALGOL 68 | # set the required precision of LONG LONG values using #
# "PR precision n PR" if required #
PR precision 24 PR
# returns TRUE if v has an integer value, FALSE otherwise #
OP ISINT = ( LONG LONG COMPL v )BOOL:
IF im OF v /= 0 THEN
# v has an imaginary part #
FALSE
ELSE
... |
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 ... | #Icon_and_Unicon | Icon and Unicon | procedure main(A)
maxCount := count := 0
every !&input ? case tab(upto('@')) of {
"License OUT ": {
maxTime := (maxCount <:= (count +:= 1), [])
put(maxTime, (maxCount = count, ="@ ", tab(find(" for "))))
}
"License IN ": count -:= (count > 0, 1) # E... |
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.
| #AutoHotkey | AutoHotkey | ; assert.ahk
;; assert(a, b, test=2)
assert(a, b="blank", test=0)
{
if (b = "blank")
{
if !a
msgbox % "blank value"
return 0
}
if equal_list(a, b, "`n")
return 0
else
msgbox % test . ":`n" . a . "`nexpected:`n" . b
}
!r::reload
;; equal_list(a, b, delimiter)
equal_list(a, b, deli... |
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.
| #Brat | Brat | include :assert
palindrome? = { str |
str = str.downcase.sub /\s+/ ""
str == str.reverse
}
setup name: "palindrome test" {
test "is a palindrome" {
assert { palindrome? "abba" }
}
test "is not a palindrome" {
assert_false { palindrome? "abb" }
}
test "is not a string" {
assert_fail {... |
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... | #Picat | Picat | import util.
go =>
Readings = [split(Record) : Record in read_file_lines("readings.txt")],
DateStamps = new_map(),
GoodReadings = 0,
foreach({Rec,Id} in zip(Readings,1..Readings.length))
if Rec.length != 49 then printf("Entry %d has bad_length %d\n", Id, Rec.length) end,
Date = Rec[1],
if DateStam... |
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... | #PicoLisp | PicoLisp | #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
(load "@lib/misc.l")
(in (opt)
(until (eof)
(let Lst (split (line) "^I")
(unless
(and
(= 49 (length Lst)) # Check total length
($dat (car Lst) "-") # Check for valid date
(fully ... |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Raku | Raku | die "Terminal can't handle UTF-8"
unless first(*.defined, %*ENV<LC_ALL LC_CTYPE LANG>) ~~ /:i 'utf-8'/;
say "△"; |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Ruby | Ruby | #encoding: UTF-8 # superfluous in Ruby >1.9.3
if ENV.values_at("LC_ALL","LC_CTYPE","LANG").compact.first.include?("UTF-8")
puts "△"
else
raise "Terminal can't handle UTF-8"
end
|
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Scala | Scala | scala> println(s"Unicode is supported on this terminal and U+25B3 is : \u25b3")
Unicode is supported on this terminal and U+25B3 is : △ |
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... | #Bracmat | Bracmat | \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... | #Brainf.2A.2A.2A | Brainf*** | I
+
+ +
+++
+-+-+
. |
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... | #C | C | #include <stdio.h>
int main() {
printf("\a");
return 0;
} |
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... | #C.23 | C# | // the simple version:
System.Console.Write("\a"); // will beep
System.Threading.Thread.Sleep(1000); // will wait for 1 second
System.Console.Beep(); // will beep a second time
System.Threading.Thread.Sleep(1000);
// System.Console.Beep() also accepts (int)hertz and (int)duration in milliseconds:
System.Console.Beep(... |
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... | #C | C |
/* Known to compile and work with tcc in win32 & gcc on Linux (with warnings)
------------------------------------------------------------------------------
readable.c: My random number generator, ISAAC.
(c) Bob Jenkins, March 1996, Public Domain
You may use this code in any way you wish, and it is free. No warrante... |
http://rosettacode.org/wiki/The_Name_Game | The Name Game | Write a program that accepts a name as input and outputs the lyrics to the Shirley Ellis song "The Name Game".
The regular verse
Unless your name begins with a vowel (A, E, I, O, U), 'B', 'F' or 'M' you don't have to care about special rules.
The verse for the name 'Gary' would be like this:
Gary, Gary, bo-bary... | #zkl | zkl | fcn printVerse(name){
z,x := name[0].toLower(), z.toUpper() + name[1,*].toLower();
y:=( if("aeiou".holds(z)) name.toLower() else x[1,*] );
b,f,m := T("b","f","m").apply('wrap(c){ z==c and y or c+y });
println("%s, %s, bo-%s".fmt(x,x,b));
println("Banana-fana fo-",f);
println("Fee-fi-mo-",m);
printl... |
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... | #AWK | AWK |
# syntax: GAWK -f TEST_INTEGERNESS.AWK
BEGIN {
n = split("25.000000,24.999999,25.000100,-2.1e120,-5e-2,NaN,Inf,-0.05",arr,",")
for (i=1; i<=n; i++) {
s = arr[i]
x = (s == int(s)) ? 1 : 0
printf("%d %s\n",x,s)
}
exit(0)
}
|
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... | #C | C |
#include <stdio.h>
#include <complex.h>
#include <math.h>
/* Testing macros */
#define FMTSPEC(arg) _Generic((arg), \
float: "%f", double: "%f", \
long double: "%Lf", unsigned int: "%u", \
unsigned long: "%lu", unsigned long long: "%llu", \
int: "%d", long: "%ld", long long: "%lld", \
default: "... |
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 ... | #J | J | require 'files'
'I D' =: (8 ; 14+i.19) {"1 &.> <'m' fread 'licenses.txt' NB. read file as matrix, select columns
lu =: +/\ _1 ^ 'OI' i. I NB. Number of licenses in use at any given time
mx =: (I.@:= >./) lu NB. Indicies of maxima
NB... |
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.
| #C | C | #include <assert.h>
int IsPalindrome(char *Str);
int main()
{
assert(IsPalindrome("racecar"));
assert(IsPalindrome("alice"));
}
|
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.
| #C.23 | C# |
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PalindromeDetector.ConsoleApp;
namespace PalindromeDetector.VisualStudioTests
{
[TestClass]
public class VSTests
{
[TestMethod]
public void PalindromeDetectorCanUnderstandPalindrome()
{
//Microsoft.VisualStudio... |
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... | #PL.2FI | PL/I |
/* To process readings produced by automatic reading stations. */
check: procedure options (main);
declare 1 date, 2 (yy, mm, dd) character (2),
(j1, j2) character (1);
declare old_date character (6);
declare line character (330) varying;
declare R(24) fixed decimal, Machine(24) fixed binary;... |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "environment.s7i";
include "console.s7i";
const proc: main is func
begin
if pos(lower(getenv("LANG")), "utf") <> 0 or
pos(lower(getenv("LC_ALL")), "utf") <> 0 or
pos(lower(getenv("LC_CTYPE")), "utf") <> 0 then
writeln(STD_CONSOLE, "Unicode is supported o... |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Sidef | Sidef | if (/\bUTF-?8/i ~~ [ENV{"LC_ALL","LC_CTYPE","LANG"}]) {
say "△"
} else {
die "Terminal can't handle UTF-8.\n";
} |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Tcl | Tcl | # Check if we're using one of the UTF or "unicode" encodings
if {[string match utf-* [encoding system]] || [string match *unicode* [encoding system]]} {
puts "\u25b3"
} else {
error "terminal does not support unicode (probably)"
} |
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... | #C.2B.2B | C++ | #include <iostream>
int main() {
std::cout << "\a";
return 0;
} |
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... | #Clojure | Clojure | (println (char 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... | #COBOL | COBOL | DISPLAY SPACE WITH BELL |
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... | #C.23 | C# |
using System;
namespace cipher {
static class Cipher {
// external results
static uint[] randrsl = new uint[256];
static uint randcnt;
// internal state
static uint[] mm = new uint[256];
static uint aa=0, bb=0, cc=0;
static void isaac() {
uint i,x,y;
cc++; // cc just gets incremented once per 256... |
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... | #C.23 | C# |
namespace Test_integerness
{
class Program
{
public static void Main(string[] args)
{
Console.Clear();
Console.WriteLine();
Console.WriteLine(" ***************************************************");
Console.WriteLine(" * *");
Console.WriteLine(" * ... |
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 ... | #Java | Java | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
public class License {
public static void main(String[] args) throws FileNotFoundException, IOException{
BufferedReader in = new BufferedReader(new FileReader(... |
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.
| #C.2B.2B | C++ | #include <algorithm>
#include <string>
constexpr bool is_palindrome(std::string_view s)
{
return std::equal(s.begin(), s.begin()+s.length()/2, s.rbegin());
}
|
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.
| #Clojure | Clojure |
(use 'clojure.test)
(deftest test-palindrome?
(is (palindrome? "amanaplanacanalpanama"))
(is (not (palindrome? "Test 1, 2, 3")))
(run-tests)
|
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... | #PowerShell | PowerShell | $dateHash = @{}
$goodLineCount = 0
get-content c:\temp\readings.txt |
ForEach-Object {
$line = $_.split(" |`t",2)
if ($dateHash.containskey($line[0])) {
$line[0] + " is duplicated"
} else {
$dateHash.add($line[0], $line[1])
}
$readings = $line[1].split... |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #UNIX_Shell | UNIX Shell | unicode_tty() {
# LC_ALL supersedes LC_CTYPE, which supersedes LANG.
# Set $1 to environment value.
case y in
${LC_ALL:+y}) set -- "$LC_ALL";;
${LC_CTYPE:+y}) set -- "$LC_CTYPE";;
${LANG:+y}) set -- "$LANG";;
y) return 1;; # Assume "C" locale not UTF-8.
esac
# We use 'case' to perform pattern mat... |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #Wren | Wren | /* terminal_control_unicode_output.wren */
class C {
foreign static isUnicodeSupported
}
if (C.isUnicodeSupported) {
System.print("Unicode is supported on this terminal and U+25B3 is : \u25b3")
} else {
System.print("Unicode is not supported on this terminal.")
} |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #zkl | zkl | if(System.isUnix and T("LC_CTYPE","LC_LANG","LANG").apply(System.getenv)
.filter().filter("holds","UTF"))
println("This terminal supports UTF-8 (\U25B3;)");
else println("I have doubts about UTF-8 on this terminal."); |
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... | #Common_Lisp | Common Lisp |
(format t "~C" (code-char 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... | #D | D | void main() {
import std.stdio;
writeln('\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... | #Delphi | Delphi | program TerminalBell;
{$APPTYPE CONSOLE}
begin
Writeln(#7);
end. |
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... | #11l | 11l | V gifts = |‘A partridge in a pear tree.
Two turtle doves
Three french hens
Four calling birds
Five golden rings
Six geese a-laying
Seven swans a-swimming
Eight maids a-milking
Nine ladies dancing
Ten lords a-leap... |
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... | #C.2B.2B | C++ |
#include <iomanip>
#include <iostream>
#include <sstream>
using namespace std;
enum CipherMode {ENCRYPT, DECRYPT};
// External results
uint32_t randRsl[256];
uint32_t randCnt;
// Internal state
uint32_t mm[256];
uint32_t aa = 0, bb = 0, cc = 0;
void isaac()
{
++cc; // cc just gets incremented once p... |
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... | #C.2B.2B | C++ |
#include <complex>
#include <math.h>
#include <iostream>
template<class Type>
struct Precision
{
public:
static Type GetEps()
{
return eps;
}
static void SetEps(Type e)
{
eps = e;
}
private:
static Type eps;
};
template<class Type> Type Precision<Type>::eps = static_cast<Type>(1E-7);
template<cla... |
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 ... | #JavaScript | JavaScript | var file_system = new ActiveXObject("Scripting.FileSystemObject");
var fh = file_system.openTextFile('mlijobs.txt', 1); // 1 == open for reading
var in_use = 0, max_in_use = -1, max_in_use_at = [];
while ( ! fh.atEndOfStream) {
var line = fh.readline();
if (line.substr(8,3) == "OUT") {
in_use++;
... |
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.
| #Common_Lisp | Common Lisp |
(defpackage :rosetta
(:use :cl
:fiveam))
(in-package :rosetta)
(defun palindromep (string)
(string= string (reverse string)))
;; A suite of tests are declared with DEF-SUITE
(def-suite palindrome-suite :description "Tests for PALINDROMEP")
;; Tests following IN-SUITE are in the defined suite of test... |
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... | #PureBasic | PureBasic | Define filename.s = "readings.txt"
#instrumentCount = 24
Enumeration
#exp_date
#exp_instruments
#exp_instrumentStatus
EndEnumeration
Structure duplicate
date.s
firstLine.i
line.i
EndStructure
NewMap dates() ;records line date occurs first
NewList duplicated.duplicate()
NewList syntaxError()
Define goo... |
http://rosettacode.org/wiki/Terminal_control/Unicode_output | Terminal control/Unicode output | The task is to check that the terminal supports Unicode output, before outputting a Unicode character. If the terminal supports Unicode, then the terminal should output a Unicode delta (U+25b3). If the terminal does not support Unicode, then an appropriate error should be raised.
Note that it is permissible to use sys... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 REM There is no Unicode delta in ROM
20 REM So we first define a custom character
30 FOR l=0 TO 7
40 READ n
50 POKE USR "d"+l,n
60 NEXT l
70 REM our custom character is a user defined d
80 PRINT CHR$(147): REM this outputs our delta
9500 REM data for our custom delta
9510 DATA 0,0,8,20,34,65,127,0
|
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... | #E | E | print("\u0007") |
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... | #Emacs_Lisp | Emacs Lisp | (ding) ;; ring the bell
(beep) ;; the same thing |
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... | #8080_Assembly | 8080 Assembly | CR: equ 13
LF: equ 10
puts: equ 9 ; CP/M function to write a string to the console
bdos: equ 5 ; CP/M entry point
org 100h
mvi e,0 ; Start with first verse
;;; Print verse
verse: lxi h,onthe ; On the
call pstr
lxi h,ordtab
call ptabs ; Nth
lxi h,doc
call pstr ; day of Christmas, my true love gave to me
lxi h,... |
http://rosettacode.org/wiki/Terminal_control/Preserve_screen | Terminal control/Preserve screen |
Task
Clear the screen, output something on the display, and then restore the screen to the preserved state that it was in before the task was carried out.
There is no requirement to change the font or kerning in this task, however character decorations and attributes are expected to be preserved. If the implement... | #11l | 11l | print("\033[?1049h\033[H")
print(‘Alternate buffer!’)
L(i) (5.<0).step(-1)
print(‘Going back in: ’i)
sleep(1)
print("\033[?1049l") |
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... | #Common_Lisp | Common Lisp | (defpackage isaac
(:use cl))
(in-package isaac)
(deftype uint32 () '(unsigned-byte 32))
(deftype arru32 () '(simple-array uint32))
(defstruct state
(randrsl (make-array 256 :element-type 'uint32) :type arru32)
(randcnt 0 :type uint32)
(mm (make-array 256 :element-type 'uint32) :type arru32)
(aa 0 :type ... |
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... | #COBOL | COBOL | IDENTIFICATION DIVISION.
PROGRAM-ID. INTEGERNESS-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INTEGERS-OR-ARE-THEY.
05 POSSIBLE-INTEGER PIC S9(9)V9(9).
05 DEFINITE-INTEGER PIC S9(9).
01 COMPLEX-NUMBER.
05 REAL-PART PIC S9(9)V9(9).
05 IMAGINARY-PART PIC S9(9)V9(9).
PROCEDURE DIVISION.
T... |
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 ... | #jq | jq | # Input: an array of strings
def max_licenses_in_use:
# state: [in_use = 0, max_in_use = -1, max_in_use_at = [] ]
reduce .[] as $line
([0, -1, [] ];
($line|split(" ")) as $line
| if $line[1] == "OUT" then
.[0] += 1 # in_use++;
| if .[0] > .[1] ... |
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 ... | #Julia | Julia | function maximumsimultlicenses(io::IO)
out, maxout, maxtimes = 0, -1, String[]
for job in readlines(io)
out += ifelse(occursin("OUT", job), 1, -1)
if out > maxout
maxout = out
empty!(maxtimes)
end
if out == maxout
push!(maxtimes, split(job)[4])... |
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.
| #Crystal | Crystal | require "spec"
describe "palindrome" do
it "returns true for a word that's palindromic" do
palindrome("racecar").should be_true
end
it "returns false for a word that's not palindromic" do
palindrome("goodbye").should be_false
end
end
def palindrome(s)
s == s.reverse
end |
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.
| #D | D | unittest {
assert(isPalindrome("racecar"));
assert(isPalindrome("bob"));
assert(!isPalindrome("alice"));
} |
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... | #Python | Python | import re
import zipfile
import StringIO
def munge2(readings):
datePat = re.compile(r'\d{4}-\d{2}-\d{2}')
valuPat = re.compile(r'[-+]?\d+\.\d+')
statPat = re.compile(r'-?\d+')
allOk, totalLines = 0, 0
datestamps = set([])
for line in readings:
totalLines += 1
fields = line.split('\t')
... |
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... | #F.23 | F# | open System
Console.Beep() |
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... | #Factor | Factor | USE: io
"\u{7}" print |
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... | #Forth | Forth | 7 emit |
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... | #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
Print !"\a"
Sleep |
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... | #8086_Assembly | 8086 Assembly | CR: equ 10
LF: equ 13
puts: equ 9 ; MS-DOS syscall to print string
cpu 8086
bits 16
org 100h
section .text
xor cx,cx ; Start with first verse
verse: mov dx,onthe ; On the...
call pstr
mov si,ord.tab ; Nth
call ptabs
mov dx,doc ; day of Christmas, my true love
call pstr ; gave to me...
mov si,vrs.tab ; the ... |
http://rosettacode.org/wiki/Terminal_control/Preserve_screen | Terminal control/Preserve screen |
Task
Clear the screen, output something on the display, and then restore the screen to the preserved state that it was in before the task was carried out.
There is no requirement to change the font or kerning in this task, however character decorations and attributes are expected to be preserved. If the implement... | #Action.21 | Action! | PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN
PROC Main()
INT size=[960]
BYTE ARRAY buffer(size)
BYTE POINTER ptr
Graphics(0)
Position(2,10)
Print("This is the original screen content.")
Wait(200)
ptr=PeekC(88)
MoveBlock(buffer,ptr,size) ;copy scre... |
http://rosettacode.org/wiki/Terminal_control/Preserve_screen | Terminal control/Preserve screen |
Task
Clear the screen, output something on the display, and then restore the screen to the preserved state that it was in before the task was carried out.
There is no requirement to change the font or kerning in this task, however character decorations and attributes are expected to be preserved. If the implement... | #Applesoft_BASIC | Applesoft BASIC | 10 LET FF = 255:FE = FF - 1
11 LET FD = 253:FC = FD - 1
12 POKE FC, 0 : POKE FE, 0
13 LET R = 768:H = PEEK (116)
14 IF PEEK (R) = 162 GOTO 40
15 LET L = PEEK (115) > 0
16 LET H = H - 4 - L
17 HIMEM:H*256
18 LET A = 10:B = 11:C = 12
19 LET D = 13:E = 14:Z = 256
20 POKE R + 0,162: REMLDX
21 PO... |
http://rosettacode.org/wiki/Terminal_control/Preserve_screen | Terminal control/Preserve screen |
Task
Clear the screen, output something on the display, and then restore the screen to the preserved state that it was in before the task was carried out.
There is no requirement to change the font or kerning in this task, however character decorations and attributes are expected to be preserved. If the implement... | #BBC_BASIC | BBC BASIC | PRINT "This is the original screen"
OSCLI "GSAVE """ + @tmp$ + "bbcsave"""
WAIT 200
CLS
PRINT "This is the new screen, following a CLS"
WAIT 200
OSCLI "DISPLAY """ + @tmp$ + "bbcsave""" |
http://rosettacode.org/wiki/Terminal_control/Preserve_screen | Terminal control/Preserve screen |
Task
Clear the screen, output something on the display, and then restore the screen to the preserved state that it was in before the task was carried out.
There is no requirement to change the font or kerning in this task, however character decorations and attributes are expected to be preserved. If the implement... | #Befunge | Befunge | "h9401?["39*>:#,_"...erotser ot >retnE< sserPH["39*>:#,_~$"l9401?["39*>:#,_@ |
http://rosettacode.org/wiki/Terminal_control/Preserve_screen | Terminal control/Preserve screen |
Task
Clear the screen, output something on the display, and then restore the screen to the preserved state that it was in before the task was carried out.
There is no requirement to change the font or kerning in this task, however character decorations and attributes are expected to be preserved. If the implement... | #C | C | #include <stdio.h>
#include <unistd.h>
int main()
{
int i;
printf("\033[?1049h\033[H");
printf("Alternate screen buffer\n");
for (i = 5; i; i--) {
printf("\rgoing back in %d...", i);
fflush(stdout);
sleep(1);
}
printf("\033[?1049l");
return 0;
} |
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... | #D | D | import std.algorithm: min;
import std.algorithm: copy;
import std.typetuple: TypeTuple;
import std.typecons: staticIota;
struct ISAAC {
// External results.
private uint[mm.length] randResult;
private uint randCount;
// Internal state.
private uint[256] mm;
private uint aa, bb, cc;
p... |
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... | #D | D | import std.complex;
import std.math;
import std.meta;
import std.stdio;
import std.traits;
void main() {
print(25.000000);
print(24.999999);
print(24.999999, 0.00001);
print(25.000100);
print(-2.1e120);
print(-5e-2);
print(real.nan);
print(real.infinity);
print(5.0+0.0i);
print... |
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 ... | #K | K | r:m@&a=x:|/a:+\{:[x[8+!3]~"OUT";1;-1]}'m:0:"mlijobs.txt";
`0:,/"Maximum simultaneous license use is ",$x;
`0:" at the following times:\n";`0:r[;14+!19] |
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 ... | #Kotlin | Kotlin | // version 1.1.51
import java.io.File
fun main(args: Array<String>) {
val filePath = "mlijobs.txt"
var licenses = 0
var maxLicenses = 0
val dates = mutableListOf<String>()
val f = File(filePath)
f.forEachLine { line ->
if (line.startsWith("License OUT")) {
licenses++
... |
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.
| #Delphi | Delphi | Assert(IsPalindrome('salàlas'), 'salàlas is a valid palindrome');
Assert(IsPalindrome('Ingirumimusnocteetconsumimurigni'), 'Ingirumimusnocteetconsumimurigni is a valid palindrome');
Assert(not IsPalindrome('123'), '123 is not a valid palindrome'); |
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.
| #E | E | #!/usr/bin/env rune
? def isPalindrome(string :String) {
> def upper := string.toUpperCase()
> def last := upper.size() - 1
> for i => c ? (upper[last - i] != c) in upper(0, upper.size() // 2) {
> return false
> }
> return true
> }
? isPalindrome("")
# value: true
? isPalindrome("a")
# value: true
... |
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.