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... | #Julia | Julia | import Compat: uppercasefirst
function printverse(name::AbstractString)
X = uppercasefirst(lowercase(name))
Y = X[1] ∈ ('A', 'E', 'I', 'O', 'U') ? X : SubString(X, 2)
b = X[1] == 'B' ? "" : "b"
f = X[1] == 'F' ? "" : "f"
m = X[1] == 'M' ? "" : "m"
println("""\
$(X), $(X), bo-$b$(Y)
Ban... |
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... | #Kotlin | Kotlin | // version 1.2.31
fun printVerse(name: String) {
val x = name.toLowerCase().capitalize()
val y = if (x[0] in "AEIOU") x.toLowerCase() else x.substring(1)
var b = "b$y"
var f = "f$y"
var m = "m$y"
when (x[0]) {
'B' -> b = "$y"
'F' -> f = "$y"
'M' -> m = "$y"
e... |
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 -... | #Kotlin | Kotlin | // version 1.1.4-3
import java.io.File
val wordList = "unixdict.txt"
val url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
const val DIGITS = "22233344455566677778889999"
val map = mutableMapOf<String, MutableList<String>>()
fun processList() {
var countValid = 0
val f = File(wordList)
va... |
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 ... | #COBOL | COBOL | IDENTIFICATION DIVISION.
PROGRAM-ID. max-licenses-in-use.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT license-file ASSIGN "mlijobs.txt"
ORGANIZATION LINE SEQUENTIAL
FILE STATUS file-status.
DATA DIVISION.
... |
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... | #Go | Go | package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"strings"
"time"
)
const (
filename = "readings.txt"
readings = 24 // per line
fields = readings*2 + 1 // per line
dateFormat = "2006-01-02"
)
func main() {
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
... |
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... | #Lua | Lua | function printVerse(name)
local sb = string.lower(name)
sb = sb:gsub("^%l", string.upper)
local x = sb
local x0 = x:sub(1,1)
local y
if x0 == 'A' or x0 == 'E' or x0 == 'I' or x0 == 'O' or x0 == 'U' then
y = string.lower(x)
else
y = x:sub(2)
end
local b = "b" .. y
... |
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 -... | #Lua | Lua | -- Global variables
http = require("socket.http")
keys = {"VOICEMAIL", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}
dictFile = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
-- Return the sequence of keys required to type a given word
function keySequence (str)
local sequence, noMatch, letter =... |
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 ... | #Common_Lisp | Common Lisp | (defun max-licenses (&optional (logfile "mlijobs.txt"))
(with-open-file (log logfile :direction :input)
(do ((current-logs 0) (max-logs 0) (max-log-times '())
(line #1=(read-line log nil nil) #1#))
((null line)
(format t "~&Maximum simultaneous license use is ~w at the ~
... |
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... | #Haskell | Haskell |
import Data.List (nub, (\\))
data Record = Record {date :: String, recs :: [(Double, Int)]}
duplicatedDates rs = rs \\ nub rs
goodRecords = filter ((== 24) . length . filter ((>= 1) . snd) . recs)
parseLine l = let ws = words l in Record (head ws) (mapRecords (tail ws))
mapRecords [] = []
mapRecords [_] = e... |
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... | #M2000_Interpreter | M2000 Interpreter | song$=format$("\r\n{0}, {0}, bo-{2}{1}\r\nBanana-fana fo-{3}{1}\r\nFee-fi-mo-{4}{1}\r\n{0}!\r\n")
|
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... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | ClearAll[NameGame]
NameGame[n_] := Module[{y, b, f, m},
If[StringStartsQ[ToLowerCase[n], "a" | "e" | "i" | "u" | "o"],
y = ToLowerCase[n]
,
y = StringDrop[n, 1]
];
b = "b" <> y;
f = "f" <> y;
m = "m" <> y;
Switch[ToLowerCase@StringTake[n, 1],
"b", b = y,
"f", f = y,
"m", m = y
];
Str... |
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 -... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | ClearAll[Numerify,rls]
rls={"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};
Numerify[s_String]:=Characters[ToUpperCase[s]]/.rls
dict=Once[Import["http://www.rosettacode.org/wiki/Texton... |
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 -... | #MiniScript | MiniScript | import "listUtil"
import "mapUtil"
groups = "abc def ghi jkl mno pqrs tuv wxyz".split
charToNum = {}
for i in groups.indexes
for ch in groups[i]
charToNum[ch] = i + 2
end for
end for
words = file.readLines("/sys/data/englishWords.txt")
wordToNum = function(word)
parts = word.split("")
parts.apply function(c... |
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 ... | #D | D | void main() {
import std.stdio;
int nOut, maxOut = -1;
string[] maxTimes;
foreach (string job; lines(File("mlijobs.txt"))) {
nOut += (job[8] == 'O') ? 1 : -1;
if (nOut > maxOut) {
maxOut = nOut;
maxTimes = null;
}
if (nOut == maxOut)
... |
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... | #Icon_and_Unicon | Icon and Unicon | procedure main(A)
dups := set()
goodRecords := 0
lastDate := badFile := &null
f := A[1] | "readings.txt"
fin := open(f) | stop("Cannot open file '",f,"'")
while (fields := 0, badReading := &null, line := read(fin)) do {
line ? {
ldate := tab(many(&digits ++ '-')) | (badFile... |
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... | #min | min | ("AEIOU" "" split swap in?) :vowel?
(
:Name
Name "" split first :L
Name lowercase :name (L vowel?) (name "" split rest "" join @name) unless
"b" :B
"f" :F
"m" :M
(
((L "B" ==) ("" @B))
((L "F" ==) ("" @F))
((L "M" ==) ("" @M))
) case
"$1, $1, bo-$3$2\nBanana-fana fo-$4$2\nFee-fi-mo-$5$2\... |
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... | #Modula-2 | Modula-2 | MODULE NameGame;
FROM Strings IMPORT Concat;
FROM ExStrings IMPORT Lowercase;
FROM Terminal IMPORT WriteString, WriteLn, ReadChar;
PROCEDURE PrintVerse(name : ARRAY OF CHAR);
TYPE String = ARRAY[0..64] OF CHAR;
VAR y,b,f,m : String;
BEGIN
Lowercase(name);
CASE name[0] OF
'a','e','i','o','u' : y := n... |
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 -... | #Nim | Nim | import algorithm, sequtils, strformat, strutils, tables
const
WordList = "unixdict.txt"
Url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
Digits = "22233344455566677778889999"
proc processList(wordFile: string) =
var mapping: Table[string, seq[string]]
var countValid = 0
for word in wor... |
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 -... | #Perl | Perl | my $src = 'unixdict.txt';
# filter word-file for valid input, transform to low-case
open $fh, "<", $src;
@words = grep { /^[a-zA-Z]+$/ } <$fh>;
map { tr/A-Z/a-z/ } @words;
# translate words to dials
map { tr/abcdefghijklmnopqrstuvwxyz/22233344455566677778889999/ } @dials = @words;
# get unique values (modify @di... |
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 ... | #E | E | var out := 0
var maxOut := 0
var maxTimes := []
def events := ["OUT " => 1, "IN " => -1]
for line in <file:mlijobs.txt> {
def `License @{via (events.fetch) delta}@@ @time for job @num$\n` := line
out += delta
if (out > maxOut) {
maxOut := out
maxTimes := []
}
if (out == maxOut... |
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... | #J | J | require 'tables/dsv dates'
dat=: TAB readdsv jpath '~temp/readings.txt'
Dates=: getdate"1 >{."1 dat
Vals=: _99 ". >(1 + +: i.24){"1 dat
Flags=: _99 ". >(2 + +: i.24){"1 dat
# Dates NB. Total # lines
5471
+/ *./"1 ] 0 = Dates NB. # lines with invalid date formats
0
... |
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... | #Nanoquery | Nanoquery | def print_verse(n)
l = {"b", "f", "m"}
s = n.substring(1)
if lower(n[0]) in l
ind = l[lower(n[0])]
l[ind] = ""
else if n[0] in {"A", "E", "I", "O", "U"}
s = lower(n)
end
println format("%s, %s, bo-%s%s", n, n, l[0], s)
... |
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... | #Nim | Nim | import strutils
const
StdFmt = "$1, $1, bo-b$2\nBanana-fana fo-f$2\nFee-fi-mo-m$2\n$1!"
WovelFmt = "$1, $1, bo-b$2\nBanana-fana fo-f$2\nFee-fi-mo-m$2\n$1!"
BFmt = "$1, $1, bo-$2\nBanana-fana fo-f$2\nFee-fi-mo-m$2\n$1!"
FFmt = "$1, $1, bo-b$2\nBanana-fana fo-$2\nFee-fi-mo-m$2\n$1!"
MFmt = "$1, $1, bo-b$2\nBa... |
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 -... | #Phix | Phix | with javascript_semantics
sequence digit = repeat(-1,255)
digit['a'..'c'] = '2'
digit['d'..'f'] = '3'
digit['g'..'i'] = '4'
digit['j'..'l'] = '5'
digit['m'..'o'] = '6'
digit['p'..'s'] = '7'
digit['t'..'v'] = '8'
digit['w'..'z'] = '9'
function dig... |
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 ... | #Eiffel | Eiffel |
class
APPLICATION
create
make
feature
make
-- Max Licences used.
local
count: INTEGER
max_count: INTEGER
date: STRING
do
read_list
create date.make_empty
across
data as d
l... |
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... | #Java | Java | import java.util.*;
import java.util.regex.*;
import java.io.*;
public class DataMunging2 {
public static final Pattern e = Pattern.compile("\\s+");
public static void main(String[] args) {
try {
BufferedReader infile = new BufferedReader(new FileReader(args[0]));
List<Stri... |
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... | #Perl | Perl | sub printVerse {
$x = ucfirst lc shift;
$x0 = substr $x, 0, 1;
$y = $x0 =~ /[AEIOU]/ ? lc $x : substr $x, 1;
$b = $x0 eq 'B' ? $y : 'b' . $y;
$f = $x0 eq 'F' ? $y : 'f' . $y;
$m = $x0 eq 'M' ? $y : 'm' . $y;
print "$x, $x, bo-$b\n" .
"Banana-fana fo-$f\n" .
"Fee-fi... |
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 -... | #PowerShell | PowerShell |
$url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
$file = "$env:TEMP\unixdict.txt"
(New-Object System.Net.WebClient).DownloadFile($url, $file)
$unixdict = Get-Content -Path $file
[string]$alpha = "abcdefghijklmnopqrstuvwxyz"
[string]$digit = "22233344455566677778889999"
$table = [ordered]@{}
for ($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 ... | #Erlang | Erlang |
-module( text_processing_max_licenses ).
-export( [out_dates_from_file/1, task/0] ).
out_dates_from_file( Name ) ->
{ok, Binary} = file:read_file( Name ),
Lines = binary:split( Binary, <<"\n">>, [global] ),
{_N, _Date, Dict} = lists:foldl( fun out_dates/2, {0, "", dict:new()}, Lines ),
[{X, dict:f... |
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... | #JavaScript | JavaScript | // wrap up the counter variables in a closure.
function analyze_func(filename) {
var dates_seen = {};
var format_bad = 0;
var records_all = 0;
var records_good = 0;
return function() {
var fh = new ActiveXObject("Scripting.FileSystemObject").openTextFile(filename, 1); // 1 = for reading
... |
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... | #Arturo | Arturo | canHandleUnicode?: function [][
any? @[
if key? env "LC_ALL" -> contains? lower get env "LC_ALL" "utf-8"
if key? env "LC_CTYPE" -> contains? lower get env "LC_CTYPE" "utf-8"
if key? env "LANG" -> contains? lower get env "LANG" "utf-8"
]
]
if? canHandleUnicode? ->
print "Te... |
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... | #Phix | Phix | constant fmt = """
%s, %s, bo-%s
Banana-fana fo-%s
Fee-fi-mo-%s
%s!
"""
procedure printVerse(string name)
string x = lower(name)
integer x1 = upper(x[1]),
vowel = find(x1,"AEIUO")!=0
string y = x[2-vowel..$],
b = 'b'&y, f = 'f'&y, m = 'm'&y
x[1] = x1
switch x1 do
cas... |
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 -... | #Python | Python | from collections import defaultdict
import urllib.request
CH2NUM = {ch: str(num) for num, chars in enumerate('abc def ghi jkl mno pqrs tuv wxyz'.split(), 2) for ch in chars}
URL = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
def getwords(url):
return urllib.request.urlopen(url).read().decode("utf-8").low... |
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 ... | #Euphoria | Euphoria | function split(sequence s, integer c)
sequence out
integer first, delim
out = {}
first = 1
while first <= length(s) do
delim = find_from(c, s, first)
if delim = 0 then
delim = length(s) + 1
end if
out = append(out, s[first..delim-1])
first = delim ... |
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... | #jq | jq | $ jq -R '[splits("[ \t]+")]' Text_processing_2.txt |
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... | #Julia | Julia |
dupdate = df[nonunique(df[:,[:Date]]),:][:Date]
println("The following rows have duplicate DATESTAMP:")
println(df[df[:Date] .== dupdate,:])
println("All values good in these rows:")
println(df[df[:ValidValues] .== 24,:])
|
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... | #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")
;Full Unicode-support font needed
e:=SetConsoleOutputCP(65001)
if (e && A_IsUnicode)
{
Print("△ - Unicode delta... |
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... | #Picat | Picat |
print_name_game(Name), Name = [V|Rest], membchk(V, ['A', 'E', 'I', 'O', 'U']) =>
L = to_lowercase(V),
Low = [L|Rest],
print_verse(Name, [b|Low], [f|Low], [m|Low]).
print_name_game(Name), Name = ['B'|Rest] =>
print_verse(Name, Rest, [f|Rest], [m|Rest]).
print_name_game(Name), Name = ['F'|Rest] =>
... |
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... | #PowerShell | PowerShell |
## Clear Host from old Ouput
Clear-Host
$Name = Read-Host "Please enter your name"
$Char = ($name.ToUpper())[0]
IF (($Char -eq "A") -or ($Char -eq "E") -or ($Char -eq "I") -or ($Char -eq "O") -or ($Char -eq "U"))
{
Write-Host "$Name, $Name, bo-b$($Name.ToLower())"
}
else
{
IF ($Char -eq "B")
{
... |
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 -... | #Racket | Racket | #lang racket
(module+ test (require tests/eli-tester))
(module+ test
(test
(map char->sms-digit (string->list "ABCDEFGHIJKLMNOPQRSTUVWXYZ."))
=> (list 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 7 8 8 8 9 9 9 9 #f)))
(define char->sms-digit
(match-lambda
[(? char-lower-case? (app char-upcase C)) (char->sms-digi... |
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 -... | #Raku | Raku | my $src = 'unixdict.txt';
my @words = slurp($src).lines.grep(/ ^ <alpha>+ $ /);
my @dials = @words.classify: {
.trans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
=> '2223334445556667777888999922233344455566677778889999');
}
my @textonyms = @dials.grep(*.value > 1);
say qq:to 'END';
Th... |
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 ... | #Factor | Factor | USING: kernel sequences splitting math accessors io.encodings.ascii
io.files math.parser io ;
IN: maxlicenses
TUPLE: maxlicense max-count current-count times ;
<PRIVATE
: <maxlicense> ( -- max ) -1 0 V{ } clone \ maxlicense boa ; inline
: out? ( line -- ? ) [ "OUT" ] dip subseq? ; inline
: line-time ( line --... |
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... | #Kotlin | Kotlin | // version 1.2.31
import java.io.File
fun main(args: Array<String>) {
val rx = Regex("""\s+""")
val file = File("readings.txt")
var count = 0
var invalid = 0
var allGood = 0
var map = mutableMapOf<String, Int>()
file.forEachLine { line ->
count++
val fields = line.split(r... |
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... | #AWK | AWK | #!/usr/bin/awk -f
BEGIN {
unicodeterm=1 # Assume Unicode support
if (ENVIRON["LC_ALL"] !~ "UTF") {
if (ENVIRON["LC_ALL"] != ""
unicodeterm=0 # LC_ALL is the boss, and it says nay
else {
# Check other locale settings if LC_ALL override not set
if (ENVIRON["LC_CTYPE"] !~ "UTF") {
... |
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... | #BaCon | BaCon | ' Determine if the terminal supports Unicode
' if so display delta, if not display error message
LET lc$ = GETENVIRON$("LANG")
IF INSTR(LCASE$(lc$), "utf8") != 0 THEN
PRINT UTF8$(0x25B3)
ELSE
EPRINT "Sorry, terminal is not testing as unicode ready"
END IF |
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... | #Prolog | Prolog | map_name1(C, Cs, C, Cs).
map_name1(C, Cs, Fc, [Fc,C|Cs]) :- member(C, ['a','e','i','o','u']).
map_name1(C, Cs, Fc, [Fc|Cs]) :-
\+ member(C, ['a','e','i','o','u']),
dif(C, Fc).
map_name(C, Cs, Fc, Name) :-
map_name1(C, Cs, Fc, NChars),
atom_chars(Name, NChars).
song(Name) :-
string_lower(Name, L... |
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 -... | #REXX | REXX | /*REXX program counts and displays the number of textonyms that are in a dictionary file*/
parse arg iFID . /*obtain optional fileID from the C.L. */
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT' /*Not specified? Then use the default.*/
@.= 0 ... |
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 ... | #Forth | Forth |
20 constant date-size
create max-dates date-size 100 * allot
variable max-out
variable counter
stdin value input
: process ( addr len -- )
8 /string
over 3 s" OUT" compare 0= if
1 counter +!
counter @ max-out @ > if
counter @ max-out !
drop 5 + date-size max-dates place
else counter @... |
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... | #Lua | Lua | filename = "readings.txt"
io.input( filename )
dates = {}
duplicated, bad_format = {}, {}
num_good_records, lines_total = 0, 0
while true do
line = io.read( "*line" )
if line == nil then break end
lines_total = lines_total + 1
date = string.match( line, "%d+%-%d+%-%d+" )
if dates[date] ~= ni... |
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... | #BBC_BASIC | BBC BASIC | VDU 23,22,640;512;8,16,16,128+8 : REM Enable UTF-8 mode
*FONT Arial Unicode MS,36
PRINT CHR$(&E2)+CHR$(&96)+CHR$(&B3) |
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... | #C | C |
#include<stdlib.h>
#include<stdio.h>
int
main ()
{
int i;
char *str = getenv ("LANG");
for (i = 0; str[i + 2] != 00; i++)
{
if ((str[i] == 'u' && str[i + 1] == 't' && str[i + 2] == 'f')
|| (str[i] == 'U' && str[i + 1] == 'T' && str[i + 2] == 'F'))
{
printf
(... |
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... | #Python | Python | def print_verse(n):
l = ['b', 'f', 'm']
s = n[1:]
if str.lower(n[0]) in l:
l[l.index(str.lower(n[0]))] = ''
elif n[0] in ['A', 'E', 'I', 'O', 'U']:
s = str.lower(n)
print('{0}, {0}, bo-{2}{1}\nBanana-fana fo-{3}{1}\nFee-fi-mo-{4}{1}\n{0}!\n'.format(n, s, *l))
# Assume that the name... |
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... | #q | q | game_ssr:{[Name]
V:raze 1 lower\"AEIOUY"; / vowels
tn:lower((Name in V)?1b) _ Name; / truncated Name
s3:{1(-1_)\x,"o-",x}lower first Name; / 3rd ssr
s:"$1, $1, bo-b$2\nBanana-fana-fo-f$2\nFee-fimo-m$2\n$1!\n\n";
(s... |
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 -... | #Ruby | Ruby |
CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
NUMS = "22233344455566677778889999" * 2
dict = "unixdict.txt"
textonyms = File.open(dict){|f| f.map(&:chomp).group_by {|word| word.tr(CHARS, NUMS) } }
puts "There are #{File.readlines(dict).size} words in #{dict} which can be represented by the digi... |
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 -... | #Rust | Rust | use std::collections::HashMap;
use std::fs::File;
use std::io::{self, BufRead};
fn text_char(ch: char) -> Option<char> {
match ch {
'a' | 'b' | 'c' => Some('2'),
'd' | 'e' | 'f' => Some('3'),
'g' | 'h' | 'i' => Some('4'),
'j' | 'k' | 'l' => Some('5'),
'm' | 'n' | 'o' => Som... |
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 ... | #Fortran | Fortran |
PROGRAM MAX_LICENSES
IMPLICIT NONE
INTEGER :: out=0, maxout=0, maxcount=0, err
CHARACTER(50) :: line
CHARACTER(19) :: maxtime(100)
OPEN (UNIT=5, FILE="Licenses.txt", STATUS="OLD", IOSTAT=err)
IF (err > 0) THEN
WRITE(*,*) "Error opening file Licenses.txt"
STOP
END IF
DO
R... |
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... | #M2000_Interpreter | M2000 Interpreter | Module TestThis {
Document a$, exp$
\\ automatic find the enconding and the line break
Load.doc a$, "readings.txt"
m=0
n=doc.par(a$)
k=list
nl$={
}
l=0
exp$=format$("Records: {0}", n)+nl$
For i=1 to n
b$=paragraph$(a$, i)
If exist(k,Left$(b$, 10)) then
m++ : where=eval(k)
exp$=format$("Duplicate fo... |
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... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | data = Import["Readings.txt","TSV"]; Print["duplicated dates: "];
Select[Tally@data[[;;,1]], #[[2]]>1&][[;;,1]]//Column
Print["number of good records: ", Count[(Times@@#[[3;;All;;2]])& /@ data, 1],
" (out of a total of ", Length[data], ")"] |
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... | #Clojure | Clojure |
(if-not (empty? (filter #(and (not (nil? %)) (.contains (.toUpperCase %) "UTF"))
(map #(System/getenv %) ["LANG" "LC_ALL" "LC_CTYPE"])))
"Unicode is supported on this terminal and U+25B3 is : \u25b3"
"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... | #Common_Lisp | Common Lisp |
(defun my-getenv (name &optional default)
#+CMU
(let ((x (assoc name ext:*environment-list*
:test #'string=)))
(if x (cdr x) default))
#-CMU
(or
#+Allegro (sys:getenv name)
#+CLISP (ext:getenv name)
#+ECL (si:getenv name)
#+SBCL (sb-unix::posix-getenv name)
#+ABCL (ge... |
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... | #Raku | Raku | sub mangle ($name, $initial) {
my $fl = $name.lc.substr(0,1);
$fl ~~ /<[aeiou]>/
?? $initial~$name.lc
!! $fl eq $initial
?? $name.substr(1)
!! $initial~$name.substr(1)
}
sub name-game (Str $name) {
qq:to/NAME-GAME/;
$name, $name, bo-{ mangle $name, 'b' }
Banana-fana fo-{ mangle $na... |
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 -... | #Sidef | Sidef | var words = ARGF.grep(/^[[:alpha:]]+\z/);
var dials = words.group_by {
.tr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'2223334445556667777888999922233344455566677778889999');
}
var textonyms = dials.grep_v { .len > 1 };
say <<-END;
There are #{words.len} words which can be represented... |
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 ... | #FreeBASIC | FreeBASIC | Const CRLF = Chr(13) & Chr(10)
Dim As String currline, maxtime
Dim As Integer counter = 0, max = 0
Dim As String filename = "mlijobs.txt"
Open filename For Input As #1
While Not Eof(1)
Line Input #1, currline
If Mid(currline,9,3) = "OUT" Then
counter += 1
Else
counter -= 1
End If
... |
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... | #MATLAB_.2F_Octave | MATLAB / Octave | function [val,count] = readdat(configfile)
% READDAT reads readings.txt file
%
% The value of boolean parameters can be tested with
% exist(parameter,'var')
if nargin<1,
filename = 'readings.txt';
end;
fid = fopen(filename);
if fid<0, error('cannot open file %s\n',a); end;
[val,count] = fscanf(fid,'%04d-... |
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... | #Elixir | Elixir |
if ["LANG", "LC_CTYPE", "LC_ALL"]
|> Enum.map(&System.get_env/1)
|> Enum.any?(&(&1 != nil and String.contains?(&1, "UTF")))
do
IO.puts "This terminal supports Unicode: \x{25b3}"
else
raise "This terminal does not support Unicode."
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... | #FreeBASIC | FreeBASIC | Print "Terminal handle unicode and U+25B3 is: "; WChr(&H25B3) |
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... | #FunL | FunL | if map( v -> System.getenv(v), ["LC_ALL", "LC_CTYPE", "LANG"]).filter( (!= null) ).exists( ('UTF' in) )
println( '\u25b3' )
else
println( 'Unicode not supported' ) |
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... | #Go | Go | package main
import (
"fmt"
"os"
"strings"
)
func main() {
lang := strings.ToUpper(os.Getenv("LANG"))
if strings.Contains(lang, "UTF") {
fmt.Printf("This terminal supports unicode and U+25b3 is : %c\n", '\u25b3')
} else {
fmt.Println("This terminal does not support unicode")
... |
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... | #11l | 11l | print("\a") |
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... | #REXX | REXX | /*REXX program displays the lyrics of the song "The Name Game" by Shirley Ellis. */
parse arg $ /*obtain optional argument(s) from C.L.*/
if $='' then $="gAry, eARL, billy, FeLix, MarY" /*Not specified? Then use the default.*/
... |
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 -... | #Swift | Swift | import Foundation
func textCharacter(_ ch: Character) -> Character? {
switch (ch) {
case "a", "b", "c":
return "2"
case "d", "e", "f":
return "3"
case "g", "h", "i":
return "4"
case "j", "k", "l":
return "5"
case "m", "n", "o":
return "6"
case "p", "... |
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 -... | #Tcl | Tcl | set keymap {
2 -> ABC
3 -> DEF
4 -> GHI
5 -> JKL
6 -> MNO
7 -> PQRS
8 -> TUV
9 -> WXYZ
}
set url http://www.puzzlers.org/pub/wordlists/unixdict.txt
set report {
There are %1$s words in %2$s which can be represented by the digit key mapping.
They require %3$s digit combinations to r... |
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 ... | #Gema | Gema |
@set{count;0};@set{max;0}
License OUT \@ * *\n=@incr{count}@testmax{${count},*}
License IN \@ * *\n=@decr{count}
\Z=@report{${max},${times${max}}}
testmax:*,*=@cmpn{${max};$1;@set{max;$1};;}@append{times${count};$2\n}
report:*,*=Maximum simultaneous license use is * at\n*
|
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... | #Nim | Nim | import strutils, tables
const NumFields = 49
const DateField = 0
const FlagGoodValue = 1
var badRecords: int # Number of records that have invalid formatted values.
var totalRecords: int # Total number of records in the file.
var badInstruments: int # Total number of records that have at least one instr... |
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... | #Haskell | Haskell | import System.Environment
import Data.List
import Data.Char
import Data.Maybe
main = do
x <- mapM lookupEnv ["LANG", "LC_ALL", "LC_CTYPE"]
if any (isInfixOf "UTF". map toUpper) $ catMaybes x
then putStrLn "UTF supported: \x25b3"
else putStrLn "UTF not supported"
|
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... | #jq | jq | def has_unicode_support:
def utf: if . == null then false else contains("UTF") or contains("utf") end;
env.LC_ALL
| if utf then true
elif . != null and . != "" then false
elif env.LC_CTYPE | utf then true
else env.LANG | utf
end ;
def task:
if has_unicode_support then "\u25b3"
else error("HW... |
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... | #Jsish | Jsish | /* Terminal Control/Unicode, in Jsish */
var utf = false;
for (var envar of ['LC_ALL', 'LC_CTYPE', 'LANG']) {
var val = Util.getenv(envar);
if (val && (val.search(/utf/i) > 0)) {
utf = true;
break;
}
}
puts((utf) ? '\u25b3' : 'Unicode support not detected');
/*
=!EXPECTSTART!=
△
=!EXPE... |
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... | #6800_Assembly | 6800 Assembly | .cr 6800
.tf bel6800.obj,AP1
.lf bel6800
;=====================================================;
; Ring the Bell for the Motorola 6800 ;
; by barrym 2013-03-31 ;
;-----------------------------------------------------;
; Rings the bell of an ascii... |
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... | #8086_Assembly | 8086 Assembly | .model small
.stack 1024
.data
.code
start: mov ah, 02h ;character output
mov dl, 07h ;bell code
int 21h ;call MS-DOS
mov ax, 4C00h ;exit
int 21h ;return to MS-DOS
end start |
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... | #Ruby | Ruby | #!/usr/bin/env ruby
def print_verse(name)
first_letter_and_consonants_re = /^.[^aeiyou]*/i
full_name = name.capitalize # X
suffixed = case full_name[0] # Y
when 'A','E','I','O','U'
name.downcase
else
full_name.sub(first_letter_and_consonants_re, '')... |
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 -... | #VBScript | VBScript | Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
"\unixdict.txt",1)
Set objKeyMap = CreateObject("Scripting.Dictionary")
With objKeyMap
.Add "ABC", "2" : .Add "DEF", "3" : .Add "GHI", "4" : .Add "JKL", "5"
.Add "MNO",... |
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 ... | #Go | Go | package main
import (
"bufio"
"bytes"
"fmt"
"log"
"os"
)
const (
filename = "mlijobs.txt"
inoutField = 1
timeField = 3
numFields = 7
)
func main() {
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer file.Close()
var ml, out in... |
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... | #OCaml | OCaml | #load "str.cma"
open Str
let strip_cr str =
let last = pred (String.length str) in
if str.[last] <> '\r' then str else String.sub str 0 last
let map_records =
let rec aux acc = function
| value::flag::tail ->
let e = (float_of_string value, int_of_string flag) in
aux (e::acc) tail
| [_... |
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... | #Julia | Julia |
c = '\u25b3'
if ismatch(r"UTF", get(ENV, "LANG", ""))
println("This output device supports Unicode: ", c)
else
println("This output device does not support Unicode.")
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... | #Kotlin | Kotlin | // version 1.1.2
fun main(args: Array<String>) {
val supportsUnicode = "UTF" in System.getenv("LANG").toUpperCase()
if (supportsUnicode)
println("This terminal supports unicode and U+25b3 is : \u25b3")
else
println("This terminal does not support unicode")
} |
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... | #Lasso | Lasso | local(env_vars = sys_environ -> join('###'))
if(#env_vars >> regexp(`(LANG|LC_ALL|LC_CTYPE).*?UTF.*?###`)) => {
stdout('UTF supported \u25b3')
else
stdout('This terminal does not support UTF')
} |
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... | #M2000_Interpreter | M2000 Interpreter |
Module CheckIt {
If IsWine then Font "DejaVu Sans"
Cls
Report format$("\u25B3")
Keyboard 0x25B3, format$("\u25B3")
\\ report use kerning
Report Key$+"T"+Key$
Keyboard 0x25B3, format$("\u25B3")
Print Key$;"T";Key$
}
Checkit
|
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... | #Action.21 | Action! | PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN
PROC Main()
BYTE
i,n=[3],
CH=$02FC ;Internal hardware value for last key pressed
PrintF("Press any key to hear %B bells...",n)
DO UNTIL CH#$FF OD
CH=$FF
FOR i=1 TO n
DO
Put(253) ;buzzer
Wait(2... |
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... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Latin_1;
procedure Bell is
begin
Put(Ada.Characters.Latin_1.BEL);
end 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... | #Scala | Scala | object NameGame extends App {
private def printVerse(name: String): Unit = {
val x = name.toLowerCase.capitalize
val y = if ("AEIOU" contains x.head) x.toLowerCase else x.tail
val (b, f, m) = x.head match {
case 'B' => (y, "f" + y, "m" + y)
case 'F' => ("b" + y, y, "m" + y)
case 'M' ... |
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 -... | #Wren | Wren | import "io" for File
import "/str" for Char, Str
import "/sort" for Sort
import "/fmt" for Fmt
var wordList = "unixdict.txt"
var DIGITS = "22233344455566677778889999"
var map = {}
var countValid = 0
var words = File.read(wordList).trimEnd().split("\n")
for (word in words) {
var valid = true
var sb = ""
fo... |
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 ... | #Groovy | Groovy | def max = 0
def dates = []
def licenses = [:]
new File('licenseFile.txt').eachLine { line ->
(line =~ /License (\w+)\s+@ ([\d\/_:]+) for job (\d+)/).each { matcher, action, date, job ->
switch (action) {
case 'IN':
assert licenses[job] != null : "License has not been checked out for $job... |
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... | #Perl | Perl | use List::MoreUtils 'natatime';
use constant FIELDS => 49;
binmode STDIN, ':crlf';
# Read the newlines properly even if we're not running on
# Windows.
my ($line, $good_records, %dates) = (0, 0);
while (<>)
{++$line;
my @fs = split /\s+/;
@fs == FIELDS or die "$line: Bad number of fields.\n";
for... |
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... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | If[StringMatchQ[$CharacterEncoding, "UTF*"], Print[FromCharacterCode[30000]], Print["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... | #Mercury | Mercury | :- module unicode_output.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module list.
:- import_module maybe.
:- import_module string.
main(!IO) :-
list.map_foldl(io.get_environment_var, ["LANG", "LC_ALL", "LC_CTYPE"], EnvValues, !IO),
( if
... |
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... | #Nemerle | Nemerle | using System.Console;
module UnicodeOut
{
Main() : void
{
if (OutputEncoding.ToString() == "System.Text.UTF8Encoding") Write("Δ")
else Write("Console encoding may not support Unicode characters.");
}
} |
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... | #Applescript | Applescript | 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... | #Arturo | Arturo | 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... | #Asymptote | Asymptote | 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... | #AutoHotkey | AutoHotkey |
fileappend, `a, *
|
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.