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/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #Lingo | Lingo | put urlencode("http://foo bar/")
-- "http%3a%2f%2ffoo+bar%2f" |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #LiveCode | LiveCode | urlEncode("http://foo bar/")
-- http%3A%2F%2Ffoo+bar%2F |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #HolyC | HolyC | U8 i; |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #Icon_and_Unicon | Icon and Unicon | global gvar # a global
procedure main(arglist) # arglist is a parameter of main
local a,b,i,x # a, b, i, x are locals withing main
static y # a static (silly in main)
x := arglist[1]
a := 1.0
i := 10
b := [x,a,i,b]
# ... rest of program
end |
http://rosettacode.org/wiki/Van_Eck_sequence | Van Eck sequence | The sequence is generated by following this pseudo-code:
A: The first term is zero.
Repeatedly apply:
If the last term is *new* to the sequence so far then:
B: The next term is zero.
Otherwise:
C: The next term is how far back this last term occured previously.
Example
Using ... | #Python | Python | def van_eck():
n, seen, val = 0, {}, 0
while True:
yield val
last = {val: n}
val = n - seen.get(val, n)
seen.update(last)
n += 1
#%%
if __name__ == '__main__':
print("Van Eck: first 10 terms: ", list(islice(van_eck(), 10)))
print("Van Eck: terms 991 - 1000:", lis... |
http://rosettacode.org/wiki/Vampire_number | Vampire number | A vampire number is a natural decimal number with an even number of digits, that can be factored into two integers.
These two factors are called the fangs, and must have the following properties:
they each contain half the number of the decimal digits of the original number
together they consist of exactl... | #zkl | zkl | fcn fangs(N){ //-->if Vampire number: (N,(a,b,c,...)), where a*x==N
var [const] tens=[0 .. 18].pump(List,(10.0).pow,"toInt");
(half:=N.numDigits) : if (_.isOdd) return(T);;
half/=2; digits:=N.toString().sort();
lo:=tens[half-1].max((N+tens[half])/(tens[half]));
hi:=(N/lo).min(N.toFloat().sqrt());
fs... |
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #Python | Python | def print_all(*things):
for x in things:
print x |
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #Qi | Qi |
(define varargs-func
A -> (print A))
(define varargs
[varargs | Args] -> [varargs-func [list | Args]]
A -> A)
(sugar in varargs 1)
|
http://rosettacode.org/wiki/Vector_products | Vector products | A vector is defined as having three dimensions as being represented by an ordered collection of three numbers: (X, Y, Z).
If you imagine a graph with the x and y axis being at right angles to each other and having a third, z axis coming out of the page, then a triplet of numbers, (X, Y, Z) would repr... | #Go | Go | package main
import "fmt"
type vector struct {
x, y, z float64
}
var (
a = vector{3, 4, 5}
b = vector{4, 3, 5}
c = vector{-5, -12, -13}
)
func dot(a, b vector) float64 {
return a.x*b.x + a.y*b.y + a.z*b.z
}
func cross(a, b vector) vector {
return vector{a.y*b.z - a.z*b.y, a.z*b.x - a.x... |
http://rosettacode.org/wiki/Validate_International_Securities_Identification_Number | Validate International Securities Identification Number | An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.
Task
Write a function or program that takes a string as input, and checks whether it is a valid ISIN.
It is only valid if it has the correct format, and the embedded c... | #Ring | Ring |
# Project : Validate International Securities Identification Number
decimals(0)
test = ["US0378331005",
"US0373831005",
"U50378331005",
"US03378331005",
"AU0000XVGZA3",
"AU0000VXGZA3",
"FR0000988040"]
for n = 1 to len(test)
testold = test[n... |
http://rosettacode.org/wiki/Validate_International_Securities_Identification_Number | Validate International Securities Identification Number | An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.
Task
Write a function or program that takes a string as input, and checks whether it is a valid ISIN.
It is only valid if it has the correct format, and the embedded c... | #Ruby | Ruby | RE = /\A[A-Z]{2}[A-Z0-9]{9}[0-9]{1}\z/
def valid_isin?(str)
return false unless str =~ RE
luhn(str.chars.map{|c| c.to_i(36)}.join)
end
p %w(US0378331005
US0373831005
U50378331005
US03378331005
AU0000XVGZA3
AU0000VXGZA3
FR0000988040).map{|tc| valid_isin?(tc) }
# => [true, false, false, false, true, true, tru... |
http://rosettacode.org/wiki/Van_der_Corput_sequence | Van der Corput sequence | When counting integers in binary, if you put a (binary) point to the righEasyLangt of the count then the column immediately to the left denotes a digit with a multiplier of
2
0
{\displaystyle 2^{0}}
; the digit in the next column to the left has a multiplier of
2
1
{\displaystyle 2^{1}}
; and so o... | #PicoLisp | PicoLisp | (scl 6)
(de vdc (N B)
(default B 2)
(let (R 0 A 1.0)
(until (=0 N)
(inc 'R (* (setq A (/ A B)) (% N B)))
(setq N (/ N B)) )
R ) )
(for B (2 3 4)
(prinl "Base: " B)
(for N (range 0 9)
(prinl N ": " (round (vdc N B) 4)) ) ) |
http://rosettacode.org/wiki/Van_der_Corput_sequence | Van der Corput sequence | When counting integers in binary, if you put a (binary) point to the righEasyLangt of the count then the column immediately to the left denotes a digit with a multiplier of
2
0
{\displaystyle 2^{0}}
; the digit in the next column to the left has a multiplier of
2
1
{\displaystyle 2^{1}}
; and so o... | #PL.2FI | PL/I |
vdcb: procedure (an) returns (bit (31)); /* 6 July 2012 */
declare an fixed binary (31);
declare (n, i) fixed binary (31);
declare v bit (31) varying;
n = an; v = ''b;
do i = 1 by 1 while (n > 0);
if iand(n, 1) = 1 then v = v || '1'b; else v = v || '0'b;
n = isrl(n, 1);
end;
return ... |
http://rosettacode.org/wiki/URL_decoding | URL decoding | This task (the reverse of URL encoding and distinct from URL parser) is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.
Test cases
The encoded string "http%3A%2F%2Ffoo%20bar%2F" should be reverted to the unencoded form "http://foo bar/".
Th... | #Kotlin | Kotlin | // version 1.1.2
import java.net.URLDecoder
fun main(args: Array<String>) {
val encoded = arrayOf("http%3A%2F%2Ffoo%20bar%2F", "google.com/search?q=%60Abdu%27l-Bah%C3%A1")
for (e in encoded) println(URLDecoder.decode(e, "UTF-8"))
} |
http://rosettacode.org/wiki/URL_decoding | URL decoding | This task (the reverse of URL encoding and distinct from URL parser) is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.
Test cases
The encoded string "http%3A%2F%2Ffoo%20bar%2F" should be reverted to the unencoded form "http://foo bar/".
Th... | #Ksh | Ksh |
url_decode()
{
decode="${*//+/ }"
eval print -r -- "\$'${decode//'%'@(??)/'\'x\1"'\$'"}'" 2>/dev/null
}
url_decode "http%3A%2F%2Ffoo%20bar%2F"
url_decode "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
|
http://rosettacode.org/wiki/UPC | UPC | Goal
Convert UPC bar codes to decimal.
Specifically:
The UPC standard is actually a collection of standards -- physical standards, data format standards, product reference standards...
Here, in this task, we will focus on some of the data format standards, with an imaginary physical+electrical implementati... | #Julia | Julia | const pat1 = (" ## #", " ## #", " # ##", " #### #", " # ##",
" ## #", " # ####", " ### ##", " ## ###", " # ##")
const pat2 = [replace(x, r"[# ]" => (x) -> x == " " ? "#" : " ") for x in pat1]
const ptod1 = Dict((b => a - 1) for (a, b) in enumerate(pat1))
const ptod2 = Dict((b => a - 1) for (a,... |
http://rosettacode.org/wiki/Update_a_configuration_file | Update a configuration file | We have a configuration file as follows:
# This is a configuration file in standard configuration file format
#
# Lines begininning with a hash or a semicolon are ignored by the application
# program. Blank lines are also ignored by the application program.
# The first word on each non comment line is the configurati... | #PHP | PHP | <?php
$conf = file_get_contents('update-conf-file.txt');
// Disable the needspeeling option (using a semicolon prefix)
$conf = preg_replace('/^(needspeeling)(|\s*\S*)$/mi', '; $1', $conf);
// Enable the seedsremoved option by removing the semicolon and any leading whitespace
$conf = preg_replace('/^;?\s*(seedsrem... |
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #Fortran | Fortran | character(20) :: s
integer :: i
print*, "Enter a string (max 20 characters)"
read*, s
print*, "Enter the integer 75000"
read*, i |
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
Dim s As String
Dim i AS Integer
Input "Please enter a string : "; s
Do
Input "Please enter 75000 : "; i
Loop Until i = 75000
Print
Print s, i
Sleep |
http://rosettacode.org/wiki/User_input/Graphical | User input/Graphical |
In this task, the goal is to input a string and the integer 75000, from graphical user interface.
See also: User input/Text
| #M2000_Interpreter | M2000 Interpreter |
Module CheckIt {
Def aName$="No Name", Num$
\\ we open a new stack, and hold old
Stack New {
If Ask$("Give your name:",,,,,aName$)="OK" Then Read aName$
If Ask$("Give a Number: (75000)",,,,,"")="OK" Then Read Num$
if Num$<>"75000" or aName$="" Then loop
}
... |
http://rosettacode.org/wiki/User_input/Graphical | User input/Graphical |
In this task, the goal is to input a string and the integer 75000, from graphical user interface.
See also: User input/Text
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | str = InputString["Input a string"]; nb =
InputString["Input a number"]; Print[str, " " , ToString@nb] |
http://rosettacode.org/wiki/UTF-8_encode_and_decode | UTF-8 encode and decode | As described in UTF-8 and in Wikipedia, UTF-8 is a popular encoding of (multi-byte) Unicode code-points into eight-bit octets.
The goal of this task is to write a encoder that takes a unicode code-point (an integer representing a unicode character) and returns a sequence of 1-4 bytes representing that character in the... | #Nim | Nim | import unicode, sequtils, strformat, strutils
const UChars = ["\u0041", "\u00F6", "\u0416", "\u20AC", "\u{1D11E}"]
proc toSeqByte(r: Rune): seq[byte] =
let s = r.toUTF8
result = @(s.toOpenArrayByte(0, s.high))
proc toRune(s: seq[byte]): Rune =
s.mapIt(chr(it)).join().toRunes[0]
echo "Character Unicode U... |
http://rosettacode.org/wiki/UTF-8_encode_and_decode | UTF-8 encode and decode | As described in UTF-8 and in Wikipedia, UTF-8 is a popular encoding of (multi-byte) Unicode code-points into eight-bit octets.
The goal of this task is to write a encoder that takes a unicode code-point (an integer representing a unicode character) and returns a sequence of 1-4 bytes representing that character in the... | #Perl | Perl | #!/usr/bin/perl
use strict;
use warnings;
use Unicode::UCD 'charinfo'; # getting the unicode name of the character
use utf8; # using non-ascii-characters in source code
binmode STDOUT, ":encoding(UTF-8)"; # printing non-ascii-characters to screen
my @chars = map {ord} qw/A ö Ж € 𝄞... |
http://rosettacode.org/wiki/URL_parser | URL parser | URLs are strings with a simple syntax:
scheme://[username:password@]domain[:port]/path?query_string#fragment_id
Task
Parse a well-formed URL to retrieve the relevant information: scheme, domain, path, ...
Note: this task has nothing to do with URL encoding or URL decoding.
According to the standards, t... | #Scala | Scala | import java.net.URI
object WebAddressParser extends App {
parseAddress("foo://example.com:8042/over/there?name=ferret#nose")
parseAddress("ftp://ftp.is.co.za/rfc/rfc1808.txt")
parseAddress("http://example.com/?a=1&b=2+2&c=3&c=4&d=%65%6e%63%6F%64%65%64")
parseAddress("http://www.ietf.org/rfc/rfc2396.txt#head... |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #Lua | Lua | function encodeChar(chr)
return string.format("%%%X",string.byte(chr))
end
function encodeString(str)
local output, t = string.gsub(str,"[^%w]",encodeChar)
return output
end
-- will print "http%3A%2F%2Ffoo%20bar%2F"
print(encodeString("http://foo bar/")) |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #M2000_Interpreter | M2000 Interpreter |
Module Checkit {
Function decodeUrl$(a$) {
DIM a$()
a$()=Piece$(a$, "%")
if len(a$())=1 then =str$(a$):exit
k=each(a$(),2)
acc$=str$(a$(0))
While k {
acc$+=str$(Chr$(Eval("0x"+left... |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #J | J | val=. 0 |
http://rosettacode.org/wiki/Van_Eck_sequence | Van Eck sequence | The sequence is generated by following this pseudo-code:
A: The first term is zero.
Repeatedly apply:
If the last term is *new* to the sequence so far then:
B: The next term is zero.
Otherwise:
C: The next term is how far back this last term occured previously.
Example
Using ... | #Quackery | Quackery | [ ' [ 0 ]
swap 1 - times
[ dup behead swap find
1+ 2dup swap found *
swap join ]
reverse ] is van-eck ( n --> [ )
10 van-eck echo cr
1000 van-eck -10 split echo drop |
http://rosettacode.org/wiki/Van_Eck_sequence | Van Eck sequence | The sequence is generated by following this pseudo-code:
A: The first term is zero.
Repeatedly apply:
If the last term is *new* to the sequence so far then:
B: The next term is zero.
Otherwise:
C: The next term is how far back this last term occured previously.
Example
Using ... | #Racket | Racket | #lang racket
(require racket/stream)
(define (van-eck)
(define (next val n seen)
(define val1 (- n (hash-ref seen val n)))
(stream-cons val (next val1 (+ n 1) (hash-set seen val n))))
(next 0 0 (hash)))
(define (get m n s)
(stream->list
(stream-take (stream-tail s m)
(- n m))))
"F... |
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #Quackery | Quackery | [ pack witheach
[ echo$ cr ] ] is counted-echo$ ( $ ... n --> )
[ this ] is marker ( --> m )
[ []
[ swap dup marker oats
iff drop done
nested swap join
again ] ] is gather ( m x ... --> [ )
[ gather witheach
[ echo$ cr ] ] is ... |
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #R | R | printallargs1 <- function(...) list(...)
printallargs1(1:5, "abc", TRUE)
# [[1]]
# [1] 1 2 3 4 5
#
# [[2]]
# [1] "abc"
#
# [[3]]
# [1] TRUE |
http://rosettacode.org/wiki/Vector_products | Vector products | A vector is defined as having three dimensions as being represented by an ordered collection of three numbers: (X, Y, Z).
If you imagine a graph with the x and y axis being at right angles to each other and having a third, z axis coming out of the page, then a triplet of numbers, (X, Y, Z) would repr... | #Groovy | Groovy | def pairwiseOperation = { x, y, Closure binaryOp ->
assert x && y && x.size() == y.size()
[x, y].transpose().collect(binaryOp)
}
def pwMult = pairwiseOperation.rcurry { it[0] * it[1] }
def dotProduct = { x, y ->
assert x && y && x.size() == y.size()
pwMult(x, y).sum()
} |
http://rosettacode.org/wiki/Validate_International_Securities_Identification_Number | Validate International Securities Identification Number | An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.
Task
Write a function or program that takes a string as input, and checks whether it is a valid ISIN.
It is only valid if it has the correct format, and the embedded c... | #Rust | Rust | extern crate luhn_cc;
use luhn_cc::compute_luhn;
fn main() {
assert_eq!(validate_isin("US0378331005"), true);
assert_eq!(validate_isin("US0373831005"), false);
assert_eq!(validate_isin("U50378331005"), false);
assert_eq!(validate_isin("US03378331005"), false);
assert_eq!(validate_isin("AU0000XVG... |
http://rosettacode.org/wiki/Validate_International_Securities_Identification_Number | Validate International Securities Identification Number | An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.
Task
Write a function or program that takes a string as input, and checks whether it is a valid ISIN.
It is only valid if it has the correct format, and the embedded c... | #SAS | SAS | data test;
length isin $20 ok $1;
input isin;
keep isin ok;
array s{24};
link isin;
return;
isin:
ok="N";
n=length(isin);
if n=12 then do;
j=0;
do i=1 to n;
k=rank(substr(isin,i,1));
if k>=48 & k<=57 then do;
if i<3 then return;
j+1;
s{j}=k-48;
end;
... |
http://rosettacode.org/wiki/Van_der_Corput_sequence | Van der Corput sequence | When counting integers in binary, if you put a (binary) point to the righEasyLangt of the count then the column immediately to the left denotes a digit with a multiplier of
2
0
{\displaystyle 2^{0}}
; the digit in the next column to the left has a multiplier of
2
1
{\displaystyle 2^{1}}
; and so o... | #Prolog | Prolog | % vdc( N, Base, Out )
% Out = the Van der Corput representation of N in given Base
vdc( 0, _, [] ).
vdc( N, Base, Out ) :-
Nr is mod(N, Base),
Nq is N // Base,
vdc( Nq, Base, Tmp ),
Out = [Nr|Tmp].
% Writes every element of a list to stdout; no newlines
write_list( [] ).
write_list( [H|T] ) :-
wri... |
http://rosettacode.org/wiki/URL_decoding | URL decoding | This task (the reverse of URL encoding and distinct from URL parser) is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.
Test cases
The encoded string "http%3A%2F%2Ffoo%20bar%2F" should be reverted to the unencoded form "http://foo bar/".
Th... | #Lambdatalk | Lambdatalk |
1) define a new javascript primitive:
{script
LAMBDATALK.DICT['decodeURIComponent'] = function() {
return decodeURIComponent( arguments[0].trim() );
};
}
2) and use it:
{decodeURIComponent http%3A%2F%2Ffoo%20bar%2F}
-> http://foo bar/
|
http://rosettacode.org/wiki/URL_decoding | URL decoding | This task (the reverse of URL encoding and distinct from URL parser) is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.
Test cases
The encoded string "http%3A%2F%2Ffoo%20bar%2F" should be reverted to the unencoded form "http://foo bar/".
Th... | #Lasso | Lasso | bytes('http%3A%2F%2Ffoo%20bar%2F') -> decodeurl |
http://rosettacode.org/wiki/UPC | UPC | Goal
Convert UPC bar codes to decimal.
Specifically:
The UPC standard is actually a collection of standards -- physical standards, data format standards, product reference standards...
Here, in this task, we will focus on some of the data format standards, with an imaginary physical+electrical implementati... | #Kotlin | Kotlin | val LEFT_DIGITS = mapOf(
" ## #" to 0,
" ## #" to 1,
" # ##" to 2,
" #### #" to 3,
" # ##" to 4,
" ## #" to 5,
" # ####" to 6,
" ### ##" to 7,
" ## ###" to 8,
" # ##" to 9
)
val RIGHT_DIGITS = LEFT_DIGITS.mapKeys {
it.key.replace(' ', 's').replace('#', ' ').replac... |
http://rosettacode.org/wiki/Update_a_configuration_file | Update a configuration file | We have a configuration file as follows:
# This is a configuration file in standard configuration file format
#
# Lines begininning with a hash or a semicolon are ignored by the application
# program. Blank lines are also ignored by the application program.
# The first word on each non comment line is the configurati... | #PicoLisp | PicoLisp | (let Data # Read all data
(in "config"
(make
(until (eof)
(link (trim (split (line) " "))) ) ) )
(setq Data # Fix comments
(mapcar
'((L)
(while (head '(";" ";") (car L))
(pop L) )
(if (= '(";") (car L))
L
... |
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #Frink | Frink |
s = input["Enter a string: "]
i = parseInt[input["Enter an integer: "]]
|
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #Go | Go | package main
import "fmt"
func main() {
var s string
var i int
if _, err := fmt.Scan(&s, &i); err == nil && i == 75000 {
fmt.Println("good")
} else {
fmt.Println("wrong")
}
} |
http://rosettacode.org/wiki/User_input/Graphical | User input/Graphical |
In this task, the goal is to input a string and the integer 75000, from graphical user interface.
See also: User input/Text
| #Nanoquery | Nanoquery | import Nanoquery.Util.Windows
// a function to handle the main window closing
def finish(caller, event)
exit
end
// create a window
w = new(Window, "Input").setTitle("Input")
w.setSize(320, 190)
w.setHandler(w.closing, finish)
// create two labels to go next to the input boxes
stringlabel = new(Label).setParent(... |
http://rosettacode.org/wiki/User_input/Graphical | User input/Graphical |
In this task, the goal is to input a string and the integer 75000, from graphical user interface.
See also: User input/Text
| #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
import javax.swing.JOptionPane
unumber = 0
ustring = ''
do
unumber = Integer.parseInt(JOptionPane.showInputDialog("Enter an Integer"))
ustring = JOptionPane.showInputDialog("Enter a String")
catch ex = Exception
ex.printStackTrace
en... |
http://rosettacode.org/wiki/UTF-8_encode_and_decode | UTF-8 encode and decode | As described in UTF-8 and in Wikipedia, UTF-8 is a popular encoding of (multi-byte) Unicode code-points into eight-bit octets.
The goal of this task is to write a encoder that takes a unicode code-point (an integer representing a unicode character) and returns a sequence of 1-4 bytes representing that character in the... | #Phix | Phix | constant tests = {#0041, #00F6, #0416, #20AC, #1D11E}
function hex(sequence s, string fmt) -- output helper
return join(apply(true,sprintf,{{fmt},s}),',')
end function
for i=1 to length(tests) do
integer codepoint = tests[i]
sequence s = utf32_to_utf8({codepoint}),
r = utf8_to_utf32(s)
... |
http://rosettacode.org/wiki/URL_parser | URL parser | URLs are strings with a simple syntax:
scheme://[username:password@]domain[:port]/path?query_string#fragment_id
Task
Parse a well-formed URL to retrieve the relevant information: scheme, domain, path, ...
Note: this task has nothing to do with URL encoding or URL decoding.
According to the standards, t... | #Tcl | Tcl | package require uri
package require uri::urn
# a little bit of trickery to format results:
proc pdict {d} {
array set \t $d
parray \t
}
proc parse_uri {uri} {
regexp {^(.*?):(.*)$} $uri -> scheme rest
if {$scheme in $::uri::schemes} {
# uri already knows how to split it:
set parts [u... |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #Maple | Maple | URL:-Escape("http://foo bar/"); |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | URLEncoding[url_] :=
StringReplace[url,
x : Except[
Join[CharacterRange["0", "9"], CharacterRange["a", "z"],
CharacterRange["A", "Z"]]] :>
StringJoin[("%" ~~ #) & /@
IntegerString[ToCharacterCode[x, "UTF8"], 16]]] |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #Java | Java | int a;
double b;
AClassNameHere c; |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #JavaScript | JavaScript | [] unstack |
http://rosettacode.org/wiki/Van_Eck_sequence | Van Eck sequence | The sequence is generated by following this pseudo-code:
A: The first term is zero.
Repeatedly apply:
If the last term is *new* to the sequence so far then:
B: The next term is zero.
Otherwise:
C: The next term is how far back this last term occured previously.
Example
Using ... | #Raku | Raku | sub n-van-ecks ($init) {
$init, -> $i, {
state %v;
state $k;
$k++;
my $t = %v{$i}.defined ?? $k - %v{$i} !! 0;
%v{$i} = $k;
$t
} ... *
}
for <
A181391 0
A171911 1
A171912 2
A171913 3
A171914 4
A171915 5
A171916 6
A171917 7
A1... |
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #Racket | Racket |
-> (define (vfun . xs) (for-each displayln xs))
-> (vfun)
-> (vfun 1)
1
-> (vfun 1 2 3 4)
1
2
3
4
-> (apply vfun (range 10 15))
10
11
12
13
14
|
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #Raku | Raku | sub foo {
.say for @_;
say .key, ': ', .value for %_;
}
foo 1, 2, command => 'buckle my shoe',
3, 4, order => 'knock at the door'; |
http://rosettacode.org/wiki/Vector_products | Vector products | A vector is defined as having three dimensions as being represented by an ordered collection of three numbers: (X, Y, Z).
If you imagine a graph with the x and y axis being at right angles to each other and having a third, z axis coming out of the page, then a triplet of numbers, (X, Y, Z) would repr... | #Haskell | Haskell | import Data.Monoid ((<>))
type Vector a = [a]
type Scalar a = a
a, b, c, d :: Vector Int
a = [3, 4, 5]
b = [4, 3, 5]
c = [-5, -12, -13]
d = [3, 4, 5, 6]
dot
:: (Num t)
=> Vector t -> Vector t -> Scalar t
dot u v
| length u == length v = sum $ zipWith (*) u v
| otherwise = error "Dotted Vectors mus... |
http://rosettacode.org/wiki/Validate_International_Securities_Identification_Number | Validate International Securities Identification Number | An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.
Task
Write a function or program that takes a string as input, and checks whether it is a valid ISIN.
It is only valid if it has the correct format, and the embedded c... | #Scala | Scala | object Isin extends App {
val isins = Seq("US0378331005", "US0373831005", "U50378331005",
"US03378331005", "AU0000XVGZA3","AU0000VXGZA3", "FR0000988040")
private def ISINtest(isin: String): Boolean = {
val isin0 = isin.trim.toUpperCase
def luhnTestS(number: String): Boolean = {
def luhnTestN... |
http://rosettacode.org/wiki/Van_der_Corput_sequence | Van der Corput sequence | When counting integers in binary, if you put a (binary) point to the righEasyLangt of the count then the column immediately to the left denotes a digit with a multiplier of
2
0
{\displaystyle 2^{0}}
; the digit in the next column to the left has a multiplier of
2
1
{\displaystyle 2^{1}}
; and so o... | #PureBasic | PureBasic | Procedure.d nBase(n.i,b.i)
Define r.d,s.i=1
While n
s*b
r+(Mod(n,b)/s)
n=Int(n/b)
Wend
ProcedureReturn r
EndProcedure
Define.i b,c
OpenConsole("van der Corput - Sequence")
For b=2 To 5
Print("Base "+Str(b)+": ")
For c=0 To 9
Print(StrD(nBase(c,b),5)+~"\t")
Next
PrintN("")
N... |
http://rosettacode.org/wiki/Van_der_Corput_sequence | Van der Corput sequence | When counting integers in binary, if you put a (binary) point to the righEasyLangt of the count then the column immediately to the left denotes a digit with a multiplier of
2
0
{\displaystyle 2^{0}}
; the digit in the next column to the left has a multiplier of
2
1
{\displaystyle 2^{1}}
; and so o... | #Python | Python | def vdc(n, base=2):
vdc, denom = 0,1
while n:
denom *= base
n, remainder = divmod(n, base)
vdc += remainder / denom
return vdc |
http://rosettacode.org/wiki/URL_decoding | URL decoding | This task (the reverse of URL encoding and distinct from URL parser) is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.
Test cases
The encoded string "http%3A%2F%2Ffoo%20bar%2F" should be reverted to the unencoded form "http://foo bar/".
Th... | #Liberty_BASIC | Liberty BASIC |
dim lookUp$( 256)
for i =0 to 256
lookUp$( i) ="%" +dechex$( i)
next i
url$ ="http%3A%2F%2Ffoo%20bar%2F"
print "Supplied URL '"; url$; "'"
print "As string '"; url2string$( url$); "'"
end
function url2string$( i$)
for j =1 to len( i$)
c$ =mid$( i$, j, 1)
... |
http://rosettacode.org/wiki/URL_decoding | URL decoding | This task (the reverse of URL encoding and distinct from URL parser) is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.
Test cases
The encoded string "http%3A%2F%2Ffoo%20bar%2F" should be reverted to the unencoded form "http://foo bar/".
Th... | #Lingo | Lingo | ----------------------------------------
-- URL decodes a string
-- @param {string} str
-- @return {string}
----------------------------------------
on urldecode (str)
res = ""
ba = bytearray()
len = str.length
repeat with i = 1 to len
c = str.char[i]
if (c = "%") then
-- fas... |
http://rosettacode.org/wiki/UPC | UPC | Goal
Convert UPC bar codes to decimal.
Specifically:
The UPC standard is actually a collection of standards -- physical standards, data format standards, product reference standards...
Here, in this task, we will focus on some of the data format standards, with an imaginary physical+electrical implementati... | #Ksh | Ksh | #!/bin/ksh
# Find the corresponding UPC decimal representation of each, rejecting the error
# # Variables:
#
UPC_data_file="../upc.data"
END_SEQ='# #' # Start and End sequence
MID_SEQ=' # # ' # Middle sequence
typeset -a CHK_ARR=( 3 1 3 1 3 1 3 1 3 1 3 1 )
integer bpd=7 # Number of bits per digit
integer numdig=... |
http://rosettacode.org/wiki/Update_a_configuration_file | Update a configuration file | We have a configuration file as follows:
# This is a configuration file in standard configuration file format
#
# Lines begininning with a hash or a semicolon are ignored by the application
# program. Blank lines are also ignored by the application program.
# The first word on each non comment line is the configurati... | #PowerShell | PowerShell |
function Update-ConfigurationFile
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$false,
Position=0)]
[ValidateScript({Test-Path $_})]
[string]
$Path = ".\config.txt",
[Parameter(Mandatory=$false)]
[string]
$FavouriteFruit,
... |
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #Groovy | Groovy | word = System.in.readLine()
num = System.in.readLine().toInteger() |
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #Haskell | Haskell | import System.IO (hFlush, stdout)
main = do
putStr "Enter a string: "
hFlush stdout
str <- getLine
putStr "Enter an integer: "
hFlush stdout
num <- readLn :: IO Int
putStrLn $ str ++ (show num) |
http://rosettacode.org/wiki/User_input/Graphical | User input/Graphical |
In this task, the goal is to input a string and the integer 75000, from graphical user interface.
See also: User input/Text
| #NewLISP | NewLISP | ; file: input-gui.lsp
; url: http://rosettacode.org/wiki/User_input/Graphical
; author: oofoe 2012-02-02
; Colours
(setq ok '(.8 1 .8) fail '(1 .5 .5))
; Load library and initialize GUI server:
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(gs:init)
; Validation Callback
; There is a bug in the "gs... |
http://rosettacode.org/wiki/UTF-8_encode_and_decode | UTF-8 encode and decode | As described in UTF-8 and in Wikipedia, UTF-8 is a popular encoding of (multi-byte) Unicode code-points into eight-bit octets.
The goal of this task is to write a encoder that takes a unicode code-point (an integer representing a unicode character) and returns a sequence of 1-4 bytes representing that character in the... | #Processing | Processing | import java.nio.charset.StandardCharsets;
Integer[] code_points = {0x0041, 0x00F6, 0x0416, 0x20AC, 0x1D11E};
void setup() {
size(850, 230);
background(255);
fill(0);
textSize(16);
int tel_1 = 80;
int tel_2 = 50;
text("Char Name Unicode ... |
http://rosettacode.org/wiki/URL_parser | URL parser | URLs are strings with a simple syntax:
scheme://[username:password@]domain[:port]/path?query_string#fragment_id
Task
Parse a well-formed URL to retrieve the relevant information: scheme, domain, path, ...
Note: this task has nothing to do with URL encoding or URL decoding.
According to the standards, t... | #VBScript | VBScript |
Function parse_url(url)
parse_url = "URL: " & url
If InStr(url,"//") Then
'parse the scheme
scheme = Split(url,"//")
parse_url = parse_url & vbcrlf & "Scheme: " & Mid(scheme(0),1,Len(scheme(0))-1)
'parse the domain
domain = Split(scheme(1),"/")
'check if the domain includes a username, password, and por... |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #MATLAB_.2F_Octave | MATLAB / Octave | function u = urlencoding(s)
u = '';
for k = 1:length(s),
if isalnum(s(k))
u(end+1) = s(k);
else
u=[u,'%',dec2hex(s(k)+0)];
end;
end
end |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
/* -------------------------------------------------------------------------- */
testcase()
say
say 'RFC3986'
testcase('RFC3986')
say
say 'HTML5'
testcase('HTML5')
say
return
/* -------------------------------------------... |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #Joy | Joy | [] unstack |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #jq | jq | jq -n '1 as $x | (2 as $x | $x) | $x' |
http://rosettacode.org/wiki/Van_Eck_sequence | Van Eck sequence | The sequence is generated by following this pseudo-code:
A: The first term is zero.
Repeatedly apply:
If the last term is *new* to the sequence so far then:
B: The next term is zero.
Otherwise:
C: The next term is how far back this last term occured previously.
Example
Using ... | #REXX | REXX | /*REXX pgm generates/displays the 'start ──► end' elements of the Van Eck sequence.*/
parse arg LO HI $ . /*obtain optional arguments from the CL*/
if LO=='' | LO=="," then LO= 1 /*Not specified? Then use the default.*/
if HI=='' | HI=="," then HI= 10 ... |
http://rosettacode.org/wiki/Van_Eck_sequence | Van Eck sequence | The sequence is generated by following this pseudo-code:
A: The first term is zero.
Repeatedly apply:
If the last term is *new* to the sequence so far then:
B: The next term is zero.
Otherwise:
C: The next term is how far back this last term occured previously.
Example
Using ... | #Ruby | Ruby | van_eck = Enumerator.new do |y|
ar = [0]
loop do
y << (term = ar.last) # yield
ar << (ar.count(term)==1 ? 0 : ar.size - 1 - ar[0..-2].rindex(term))
end
end
ve = van_eck.take(1000)
p ve.first(10), ve.last(10)
|
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #RapidQ | RapidQ | SUBI printAll (...)
FOR i = 1 TO ParamValCount
PRINT ParamVal(i)
NEXT i
FOR i = 1 TO ParamStrCount
PRINT ParamStr$(i)
NEXT i
END SUBI
printAll 4, 3, 5, 6, 4, 3
printAll 4, 3, 5
printAll "Rosetta", "Code", "Is", "Awesome!" |
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #REALbasic | REALbasic |
Sub PrintArgs(ParamArray Args() As String)
For i As Integer = 0 To Ubound(Args)
Print(Args(i))
Next
End Sub
|
http://rosettacode.org/wiki/Vector_products | Vector products | A vector is defined as having three dimensions as being represented by an ordered collection of three numbers: (X, Y, Z).
If you imagine a graph with the x and y axis being at right angles to each other and having a third, z axis coming out of the page, then a triplet of numbers, (X, Y, Z) would repr... | #Icon_and_Unicon | Icon and Unicon | # record type to store a 3D vector
record Vector3D(x, y, z)
# procedure to display vector as a string
procedure toString (vector)
return "(" || vector.x || ", " || vector.y || ", " || vector.z || ")"
end
procedure dotProduct (a, b)
return a.x * b.x + a.y * b.y + a.z * b.z
end
procedure crossProduct (a, b)
x... |
http://rosettacode.org/wiki/Validate_International_Securities_Identification_Number | Validate International Securities Identification Number | An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.
Task
Write a function or program that takes a string as input, and checks whether it is a valid ISIN.
It is only valid if it has the correct format, and the embedded c... | #SQL_PL | SQL PL |
--#SET TERMINATOR @
SET SERVEROUTPUT ON @
CREATE OR REPLACE FUNCTION VALIDATE_ISIN (
IN IDENTIFIER VARCHAR(12)
) RETURNS SMALLINT
-- ) RETURNS BOOLEAN
BEGIN
DECLARE CHECKSUM_FUNC CHAR(1);
DECLARE CONVERTED VARCHAR(24);
DECLARE I SMALLINT;
DECLARE LENGTH SMALLINT;
DECLARE RET SMALLINT DEFAULT 1;
-... |
http://rosettacode.org/wiki/Van_der_Corput_sequence | Van der Corput sequence | When counting integers in binary, if you put a (binary) point to the righEasyLangt of the count then the column immediately to the left denotes a digit with a multiplier of
2
0
{\displaystyle 2^{0}}
; the digit in the next column to the left has a multiplier of
2
1
{\displaystyle 2^{1}}
; and so o... | #Quackery | Quackery | [ $ "bigrat.qky" loadfile ] now!
[ [] swap
[ dup while
base share /mod
rot join swap
again ]
drop ] is digits ( n --> [ )
[ base put
digits reverse
dup 0 swap
witheach
[ base share rot * + ]
base take rot size **
reduce ] ... |
http://rosettacode.org/wiki/Van_der_Corput_sequence | Van der Corput sequence | When counting integers in binary, if you put a (binary) point to the righEasyLangt of the count then the column immediately to the left denotes a digit with a multiplier of
2
0
{\displaystyle 2^{0}}
; the digit in the next column to the left has a multiplier of
2
1
{\displaystyle 2^{1}}
; and so o... | #Racket | Racket | #lang racket
(define (van-der-Corput n base)
(if (zero? n)
0
(let-values ([(q r) (quotient/remainder n base)])
(/ (+ r (van-der-Corput q base))
base)))) |
http://rosettacode.org/wiki/URL_decoding | URL decoding | This task (the reverse of URL encoding and distinct from URL parser) is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.
Test cases
The encoded string "http%3A%2F%2Ffoo%20bar%2F" should be reverted to the unencoded form "http://foo bar/".
Th... | #LiveCode | LiveCode | put urlDecode("http%3A%2F%2Ffoo%20bar%2F") & cr & \
urlDecode("google.com/search?q=%60Abdu%27l-Bah%C3%A1") |
http://rosettacode.org/wiki/URL_decoding | URL decoding | This task (the reverse of URL encoding and distinct from URL parser) is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.
Test cases
The encoded string "http%3A%2F%2Ffoo%20bar%2F" should be reverted to the unencoded form "http://foo bar/".
Th... | #Lua | Lua | function decodeChar(hex)
return string.char(tonumber(hex,16))
end
function decodeString(str)
local output, t = string.gsub(str,"%%(%x%x)",decodeChar)
return output
end
-- will print "http://foo bar/"
print(decodeString("http%3A%2F%2Ffoo%20bar%2F")) |
http://rosettacode.org/wiki/UPC | UPC | Goal
Convert UPC bar codes to decimal.
Specifically:
The UPC standard is actually a collection of standards -- physical standards, data format standards, product reference standards...
Here, in this task, we will focus on some of the data format standards, with an imaginary physical+electrical implementati... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | s=" # # # ## # ## # ## ### ## ### ## #### # # # ## ## # # ## ## ### # ## ## ### # # #
# # # ## ## # #### # # ## # ## # ## # # # ### # ### ## ## ### # # ### ### # # #
# # # # # ### # # # # # # # # # # ## # ## # ## # ## # # ###... |
http://rosettacode.org/wiki/Update_a_configuration_file | Update a configuration file | We have a configuration file as follows:
# This is a configuration file in standard configuration file format
#
# Lines begininning with a hash or a semicolon are ignored by the application
# program. Blank lines are also ignored by the application program.
# The first word on each non comment line is the configurati... | #Python | Python | #!/usr/bin/env python
#----------------------------------------------------------------------------
# STANDARD MODULES
#----------------------------------------------------------------------------
import re
import string
#----------------------------------------------------------------------------
# GLOBAL: VARIA... |
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #hexiscript | hexiscript | print "Enter a string: "
let s scan str
print "Enter a number: "
let n scan int |
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #HolyC | HolyC | U8 *s;
s = GetStr("Enter a string: ");
U32 *n;
do {
n = GetStr("Enter 75000: ");
} while(Str2I64(n) != 75000);
Print("Your string: %s\n", s);
Print("75000: %d\n", Str2I64(n)); |
http://rosettacode.org/wiki/User_input/Graphical | User input/Graphical |
In this task, the goal is to input a string and the integer 75000, from graphical user interface.
See also: User input/Text
| #Nim | Nim | import strutils
import gintro/[glib, gobject, gtk, gio]
type MainWindow = ref object of ApplicationWindow
strEntry: Entry
intEntry: SpinButton
#---------------------------------------------------------------------------------------------------
proc displayValues(strval: string; intval: int) =
## Display a d... |
http://rosettacode.org/wiki/User_input/Graphical | User input/Graphical |
In this task, the goal is to input a string and the integer 75000, from graphical user interface.
See also: User input/Text
| #Oz | Oz | functor
import
Application
QTk at 'x-oz://system/wp/QTk.ozf'
System
define
Number NumberWidget
Text
StatusLabel
WindowClosed
GUI = td(action:OnClose
return:WindowClosed
lr(label(text:"Enter some text:" width:20)
entry(return:Text glue:ew)
glue:ew)
lr(label(text:"Ent... |
http://rosettacode.org/wiki/UTF-8_encode_and_decode | UTF-8 encode and decode | As described in UTF-8 and in Wikipedia, UTF-8 is a popular encoding of (multi-byte) Unicode code-points into eight-bit octets.
The goal of this task is to write a encoder that takes a unicode code-point (an integer representing a unicode character) and returns a sequence of 1-4 bytes representing that character in the... | #PureBasic | PureBasic | #UTF8_codePointMaxByteCount = 4 ;UTF-8 encoding uses only a maximum of 4 bytes to encode a codepoint
Procedure UTF8_encode(x, Array encoded_codepoint.a(1)) ;x is codepoint to encode, the array will contain output
;Array encoded_codepoint() is used for output.
;After encode element zero holds the count of signific... |
http://rosettacode.org/wiki/URL_parser | URL parser | URLs are strings with a simple syntax:
scheme://[username:password@]domain[:port]/path?query_string#fragment_id
Task
Parse a well-formed URL to retrieve the relevant information: scheme, domain, path, ...
Note: this task has nothing to do with URL encoding or URL decoding.
According to the standards, t... | #Vlang | Vlang | import net.urllib
const urls = ['jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true',
'ftp://ftp.is.co.za/rfc/rfc1808.txt',
'http://www.ietf.org/rfc/rfc2396.txt#header1',
'ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two',
'mailto:John.Doe@example.com',
'news:comp.infosystems.w... |
http://rosettacode.org/wiki/URL_parser | URL parser | URLs are strings with a simple syntax:
scheme://[username:password@]domain[:port]/path?query_string#fragment_id
Task
Parse a well-formed URL to retrieve the relevant information: scheme, domain, path, ...
Note: this task has nothing to do with URL encoding or URL decoding.
According to the standards, t... | #Wren | Wren | var urlParse = Fn.new { |url|
var parseUrl = "URL = " + url
var index
if ((index = url.indexOf("//")) && index >= 0 && url[0...index].count { |c| c == ":" } == 1) {
// parse the scheme
var scheme = url.split("//")
parseUrl = parseUrl + "\n" + "Scheme = " + scheme[0][0..-2]
... |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #NewLISP | NewLISP | ;; simple encoder
;; (source http://www.newlisp.org/index.cgi?page=Code_Snippets)
(define (url-encode str)
(replace {([^a-zA-Z0-9])} str (format "%%%2X" (char $1)) 0))
(url-encode "http://foo bar/") |
http://rosettacode.org/wiki/URL_encoding | URL encoding | Task
Provide a function or mechanism to convert a provided string into URL encoding representation.
In URL encoding, special characters, control characters and extended characters
are converted into a percent symbol followed by a two digit hexadecimal code,
So a space character encodes into %20 within the string.
Fo... | #Nim | Nim | import cgi
echo encodeUrl("http://foo/bar/") |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #Julia | Julia | #declaration/assignment, declaration is optional
x::Int32 = 1
#datatypes are inferred dynamically, but can also be set thru convert functions and datatype literals
x = 1 #x is inferred as Int, which is Int32 for 32-bit machines, Int64 for 64-bit machines
#variable reference
julia>x
1
x = int8(1) #x is of type Int8
x ... |
http://rosettacode.org/wiki/Variables | Variables | Task
Demonstrate a language's methods of:
variable declaration
initialization
assignment
datatypes
scope
referencing, and
other variable related facilities
| #Kotlin | Kotlin | // version 1.0.6
fun main(args: Array<String>) {
/* read-only variables */
val i = 3 // type inferred to be Int
val d = 2.4 // type inferred to be double
val sh: Short = 2 // type specified as Short
val ch = 'A' // type inferred to be Char
val bt: Byte = 1 // type spec... |
http://rosettacode.org/wiki/Van_Eck_sequence | Van Eck sequence | The sequence is generated by following this pseudo-code:
A: The first term is zero.
Repeatedly apply:
If the last term is *new* to the sequence so far then:
B: The next term is zero.
Otherwise:
C: The next term is how far back this last term occured previously.
Example
Using ... | #Rust | Rust | fn van_eck_sequence() -> impl std::iter::Iterator<Item = i32> {
let mut index = 0;
let mut last_term = 0;
let mut last_pos = std::collections::HashMap::new();
std::iter::from_fn(move || {
let result = last_term;
let mut next_term = 0;
if let Some(v) = last_pos.get_mut(&last_term)... |
http://rosettacode.org/wiki/Van_Eck_sequence | Van Eck sequence | The sequence is generated by following this pseudo-code:
A: The first term is zero.
Repeatedly apply:
If the last term is *new* to the sequence so far then:
B: The next term is zero.
Otherwise:
C: The next term is how far back this last term occured previously.
Example
Using ... | #Scala | Scala |
object VanEck extends App {
def vanEck(n: Int): List[Int] = {
def vanEck(values: List[Int]): List[Int] =
if (values.size < n)
vanEck(math.max(0, values.indexOf(values.head, 1)) :: values)
else
values
vanEck(List(0)).reverse
}
val vanEck1000 = vanEck(1000)
println(s"... |
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #REBOL | REBOL | rebol [
Title: "Variadic Arguments"
]
print-all: func [
args [block!] {the arguments to print}
] [
foreach arg args [print arg]
]
print-all [rebol works this way] |
http://rosettacode.org/wiki/Variadic_function | Variadic function | Task
Create a function which takes in a variable number of arguments and prints each one on its own line.
Also show, if possible in your language, how to call the function on a list of arguments constructed at runtime.
Functions of this type are also known as Variadic Functions.
Related task
Call a function... | #REXX | REXX | print_all: procedure /* [↓] is the # of args passed.*/
do j=1 for arg()
say arg(j)
end /*j*/
return |
http://rosettacode.org/wiki/Vector_products | Vector products | A vector is defined as having three dimensions as being represented by an ordered collection of three numbers: (X, Y, Z).
If you imagine a graph with the x and y axis being at right angles to each other and having a third, z axis coming out of the page, then a triplet of numbers, (X, Y, Z) would repr... | #J | J | cross=: (1&|.@[ * 2&|.@]) - 2&|.@[ * 1&|.@] |
http://rosettacode.org/wiki/Validate_International_Securities_Identification_Number | Validate International Securities Identification Number | An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.
Task
Write a function or program that takes a string as input, and checks whether it is a valid ISIN.
It is only valid if it has the correct format, and the embedded c... | #Tcl | Tcl | package require Tcl 8.6 ;# mostly needed for [assert]. Substitute a simpler one or a NOP if required. |
http://rosettacode.org/wiki/Validate_International_Securities_Identification_Number | Validate International Securities Identification Number | An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.
Task
Write a function or program that takes a string as input, and checks whether it is a valid ISIN.
It is only valid if it has the correct format, and the embedded c... | #Transact-SQL | Transact-SQL |
CREATE FUNCTION dbo._ISINCheck( @strISIN VarChar(40) )
RETURNS bit
AS
BEGIN
--*** Test an ISIN code and return 1 if it is valid, 0 if invalid.
DECLARE @bValid bit;
SET @bValid = CASE WHEN @strISIN LIKE '[A-Z][A-Z][A-Z,0-9][A-Z,0-9][A-Z,0-9][A-Z,0-9][A-Z,0-9][A-Z,0-9][A-Z,0-9][A-Z,0-9][A-Z,0-9][0-9]' THEN 1 ELSE 0 ... |
http://rosettacode.org/wiki/Van_der_Corput_sequence | Van der Corput sequence | When counting integers in binary, if you put a (binary) point to the righEasyLangt of the count then the column immediately to the left denotes a digit with a multiplier of
2
0
{\displaystyle 2^{0}}
; the digit in the next column to the left has a multiplier of
2
1
{\displaystyle 2^{1}}
; and so o... | #Raku | Raku | constant VdC = map { :2("0." ~ .base(2).flip) }, ^Inf;
.say for VdC[^16]; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.