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... | #PicoLisp | PicoLisp | (de urlEncodeTooMuch (Str)
(pack
(mapcar
'((C)
(if (or (>= "9" C "0") (>= "Z" (uppc C) "A"))
C
(list '% (hex (char C))) ) )
(chop Str) ) ) ) |
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
| #M2000_Interpreter | M2000 Interpreter |
\\ M2000 use inference to state the type of a new variable, at run time
\\ We can use literals of a numeric type
\\ @ for Decimal
\\ # for Currency
\\ ~ for Single
\\ & for Long (32bit)
\\ % for Integer (16bit)
\\ Double and Boolean have no symboles
Module TopA {
Module Alfa {
Print A=10000, T... |
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
| #Maple | Maple | a := 1:
print ("a is "||a);
"a is 1" |
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 ... | #zkl | zkl | fcn vanEck(startAt=0){ // --> iterator
(startAt).walker(*).tweak(fcn(n,seen,rprev){
prev,t := rprev.value, n - seen.find(prev,n);
seen[prev] = n;
rprev.set(t);
t
}.fp1(Dictionary(),Ref(startAt))).push(startAt)
} |
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... | #Unicon | Unicon | f = %gP*=
#show+
main = f <'foo',12.5,('x','y'),100> |
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... | #Ursala | Ursala | f = %gP*=
#show+
main = f <'foo',12.5,('x','y'),100> |
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... | #V | V | [myfn
[zero? not] [swap puts pred]
while
].
100 200 300 400 500 3 myfn |
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... | #Kotlin | Kotlin | // version 1.1.2
class Vector3D(val x: Double, val y: Double, val z: Double) {
infix fun dot(v: Vector3D) = x * v.x + y * v.y + z * v.z
infix fun cross(v: Vector3D) =
Vector3D(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x)
fun scalarTriple(v: Vector3D, w: Vector3D) = this dot (v cro... |
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... | #zkl | zkl | fcn validateISIN(isin){
RegExp(String("^","[A-Z]"*2,"[A-Z0-9]"*9,"[0-9]$")).matches(isin) and
luhnTest(isin.split("").apply("toInt",36).concat().toInt())
}
fcn luhnTest(n){
0 == (n.split().reverse().reduce(fcn(s,n,clk){
s + if(clk.inc()%2) n else 2*n%10 + n/5 },0,Ref(1)) %10)
} |
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... | #Tcl | Tcl | proc digitReverse {n {base 2}} {
set n [expr {[set neg [expr {$n < 0}]] ? -$n : $n}]
set result 0.0
set bit [expr {1.0 / $base}]
for {} {$n > 0} {set n [expr {$n / $base}]} {
set result [expr {$result + $bit * ($n % $base)}]
set bit [expr {$bit / $base}]
}
return [expr {$neg ? -$result : $resu... |
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... | #VBA | VBA | Private Function vdc(ByVal n As Integer, BASE As Variant) As Variant
Dim res As String
Dim digit As Integer, g As Integer, denom As Integer
denom = 1
Do While n
denom = denom * BASE
digit = n Mod BASE
n = n \ BASE
res = res & CStr(digit) '+ "0"
Loop
vdc = IIf(Len(... |
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... | #Objective-C | Objective-C | NSString *encoded = @"http%3A%2F%2Ffoo%20bar%2F";
NSString *normal = [encoded stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", normal); |
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... | #OCaml | OCaml | $ ocaml
# #use "topfind";;
# #require "netstring";;
# Netencoding.Url.decode "http%3A%2F%2Ffoo%20bar%2F" ;;
- : string = "http://foo bar/" |
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... | #Racket | Racket | #lang racket
;; inspired by Kotlin
(define (is-#? c) (char=? c #\#))
(define left-digits
(for/hash ((i (in-naturals))
(c '((#f #f #t #t #f)
(#f #t #t #f #f)
(#f #t #f #f #t)
(#t #t #t #t #f)
(#t #f #f #f #t)
(... |
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... | #Wren | Wren | import "io" for File
import "/ioutil" for FileUtil
import "/dynamic" for Tuple
import "/str" for Str
var fields = ["favouriteFruit", "needsPeeling", "seedsRemoved", "numberOfBananas", "numberOfStrawberries"]
var ConfigData = Tuple.create("ConfigData", fields)
var updateConfigFile = Fn.new { |fileName, cData|
va... |
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
| #Lasso | Lasso | #!/usr/bin/lasso9
define read_input(prompt::string) => {
local(string)
// display prompt
stdout(#prompt)
// the following bits wait until the terminal gives you back a line of input
while(not #string or #string -> size == 0) => {
#string = file_stdin -> readsomebytes(1024, 1000)
}
#string -> replace(byte... |
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
| #Liberty_BASIC | Liberty BASIC | Input "Enter a string. ";string$
Input "Enter the value 75000.";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
| #Python | Python | import Tkinter,tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
string = tkSimpleDialog.askstring("String", "Enter a String")
|
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
| #Quackery | Quackery | $ \
import tkinter
import tkinter.simpledialog as tks
root = tkinter.Tk()
root.withdraw()
to_stack(tks.askinteger("Integer", "Enter a Number"))
string_to_stack(tks.askstring("String", "Enter a String"))
\ python
swap echo cr echo$ |
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... | #Swift | Swift | import Foundation
func encode(_ scalar: UnicodeScalar) -> Data {
return Data(String(scalar).utf8)
}
func decode(_ data: Data) -> UnicodeScalar? {
guard let string = String(data: data, encoding: .utf8) else {
assertionFailure("Failed to convert data to a valid String")
return nil
}
assert(string.unic... |
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... | #Tcl | Tcl | proc encoder int {
set u [format %c $int]
set bytes {}
foreach byte [split [encoding convertto utf-8 $u] ""] {
lappend bytes [format %02X [scan $byte %c]]
}
return $bytes
}
proc decoder bytes {
set str {}
foreach byte $bytes {
append str [format %c [scan $byte %x]]
}
return [encod... |
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... | #Pike | Pike | Protocols.HTTP.uri_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... | #Powershell | Powershell |
[uri]::EscapeDataString('http://foo bar/')
http%3A%2F%2Ffoo%20bar%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
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | x=value assign a value to the variable x
x=y=value assign a value to both x and y
x=. or Clear[x] remove any value assigned to x
lhs=rhs (immediate assignment) rhs is evaluated when the assignment is made
lhs:=rhs (delayed assignment) rhs is evaluated each time the value of lhs is requested |
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
| #MATLAB_.2F_Octave | MATLAB / Octave | a = 4; % declare variable and initialize double value,
s = 'abc'; % string
i8 = int8(5); % signed byte
u8 = uint8(5); % unsigned byte
i16 = int16(5); % signed 2 byte
u16 = uint16(5); % unsigned 2 byte integer
i32 = int32(5); % signed 4 byte integer
u32 = uin... |
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... | #Visual_Basic | Visual Basic | Option Explicit
'--------------------------------------------------
Sub varargs(ParamArray a())
Dim n As Long, m As Long
Debug.Assert VarType(a) = (vbVariant Or vbArray)
For n = LBound(a) To UBound(a)
If IsArray(a(n)) Then
For m = LBound(a(n)) To UBound(a(n))
Debug.Print a(n)... |
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... | #Vlang | Vlang | fn print_all(things ...string) {
for x in things {
println(x)
}
} |
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... | #Ksh | Ksh |
#!/bin/ksh
# Vector products
# # dot product (a scalar quantity) A • B = a1b1 + a2b2 + a3b3 + ...
# # cross product (a vector quantity) A x B = (a2b3 - a3b2, a3b1 - a1b3, a1b2 - a2b1)
# # scalar triple product (a scalar quantity) A • (B x C)
# # vector triple product (a vector quantity) A x (B x C)
# # Variabl... |
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... | #VBScript | VBScript | 'http://rosettacode.org/wiki/Van_der_Corput_sequence
'Van der Corput Sequence fucntion call = VanVanDerCorput(number,base)
Base2 = "0" : Base3 = "0" : Base4 = "0" : Base5 = "0"
Base6 = "0" : Base7 = "0" : Base8 = "0" : Base9 = "0"
l = 1
h = 1
Do Until l = 9
'Set h to the value of l after each function call
'as it... |
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... | #Visual_Basic_.NET | Visual Basic .NET | Module Module1
Function ToBase(n As Integer, b As Integer) As String
Dim result = ""
If b < 2 Or b > 16 Then
Throw New ArgumentException("The base is out of range")
End If
Do
Dim remainder = n Mod b
result = "0123456789ABCDEF"(remainder) + resu... |
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... | #ooRexx | ooRexx | /* Rexx */
X = 0
url. = ''
X = X + 1; url.0 = X; url.X = 'http%3A%2F%2Ffoo%20bar%2F'
X = X + 1; url.0 = X; url.X = 'mailto%3A%22Ivan%20Aim%22%20%3Civan%2Eaim%40email%2Ecom%3E'
X = X + 1; url.0 = X; url.X = '%6D%61%69%6C%74%6F%3A%22%49%72%6D%61%20%55%73%65%72%22%20%3C%69%72%6D%61%2E%75%73%65%72%40%6D%61%69%6C%... |
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... | #Perl | Perl | sub urldecode {
my $s = shift;
$s =~ tr/\+/ /;
$s =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/eg;
return $s;
}
print urldecode('http%3A%2F%2Ffoo+bar%2F')."\n";
|
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... | #Raku | Raku | sub decode_UPC ( Str $line ) {
constant @patterns1 = ' ## #', ' ## #', ' # ##', ' #### #', ' # ##',
' ## #', ' # ####', ' ### ##', ' ## ###', ' # ##';
constant @patterns2 = @patterns1».trans( '#' => ' ', ' ' => '#' );
constant %pattern_to_digit_1 = @patterns1.antipair... |
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
| #LIL | LIL | # User input/text, in LIL
write "Enter a string: "
set text [readline]
set num 0
while {[canread] && $num != 75000} {
write "Enter the number 75000: "
set num [readline]
}
print $text
print $num |
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
| #Logo | Logo | make "input readlist ; in: string 75000
show map "number? :input ; [false true]
make "input readword ; in: 75000
show :input + 123 ; 75123
make "input readword ; in: string 75000
show :input ; string 75000 |
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
| #R | R |
library(gWidgets)
options(guiToolkit="RGtk2") ## using gWidgtsRGtk2
w <- gwindow("Enter a string and a number")
lyt <- glayout(cont=w)
lyt[1,1] <- "Enter a string"
lyt[1,2] <- gedit("", cont=lyt)
lyt[2,1] <- "Enter 75000"
lyt[2,2] <- gedit("", cont=lyt)
lyt[3,2] <- gbutton("validate", cont=lyt, handler=function(h,.... |
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
| #Racket | Racket |
#lang racket
(require racket/gui)
(define str (get-text-from-user "Hi" "Enter a string"))
(message-box "Hi" (format "You entered: ~a" str))
(define n (get-text-from-user "Hi" "Enter a number"))
(message-box "Hi" (format "You entered: ~a"
(or (string->number n) "bogus text")))
|
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... | #VBA | VBA | Private Function unicode_2_utf8(x As Long) As Byte()
Dim y() As Byte
Dim r As Long
Select Case x
Case 0 To &H7F
ReDim y(0)
y(0) = x
Case &H80 To &H7FF
ReDim y(1)
y(0) = 192 + x \ 64
y(1) = 128 + x Mod 64
Case &H800 To &H7FFF... |
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... | #PureBasic | PureBasic | URL$ = URLEncoder("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... | #Python | Python | import urllib
s = 'http://foo/bar/'
s = urllib.quote(s) |
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
| #Mercury | Mercury | :- func name = string.
name = Name :-
Name = Title ++ " " ++ Given,
Title = "Dr.",
Given = "Bob". |
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
| #Modula-3 | Modula-3 | MODULE Foo EXPORTS Main;
IMPORT IO, Fmt;
VAR foo: INTEGER := 5; (* foo is global (to the module). *)
PROCEDURE Foo() =
VAR bar: INTEGER := 10; (* bar is local to the procedure Foo. *)
BEGIN
IO.Put("foo + bar = " & Fmt.Int(foo + bar) & "\n");
END Foo;
BEGIN
Foo();
END Foo. |
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... | #Vorpal | Vorpal | self.f = method(x, y[ ], z){
x.print()
for(i = 0, i < y.size(), i = i + 1){
('[' + y[i] + ']').print()
}
z.print()
}
self.f(1, 2, 3)
'---'.print()
self.f(1, 2, 3, 4)
'---'.print()
self.f(1, 2) |
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... | #Wren | Wren | var printArgs = Fn.new { |args| args.each { |arg| System.print(arg) } }
printArgs.call(["Mary", "had", "3", "little", "lambs"]) |
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... | #Lambdatalk | Lambdatalk |
{def dotProduct
{lambda {:a :b}
{+ {* {A.get 0 :a} {A.get 0 :b}}
{* {A.get 1 :a} {A.get 1 :b}}
{* {A.get 2 :a} {A.get 2 :b}}}}}
-> dotProduct
{def crossProduct
{lambda {:a :b}
{A.new {- {* {A.get 1 :a} {A.get 2 :b}}
{* {A.get 2 :a} {A.get 1 :b}}}
{- {* {A.get 2 :a} {A.get 0 :b}... |
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... | #Vlang | Vlang | fn v2(nn u32) f64 {
mut n:=nn
mut r := f64(0)
mut p := .5
for n > 0 {
if n&1 == 1 {
r += p
}
p *= .5
n >>= 1
}
return r
}
fn new_v(base u32) fn(u32) f64 {
invb := 1 / f64(base)
return fn[base,invb](nn u32) f64 {
mut n:=nn
mut ... |
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... | #Wren | Wren | var v2 = Fn.new { |n|
var p = 0.5
var r = 0
while (n > 0) {
if (n%2 == 1) r = r + p
p = p / 2
n = (n/2).floor
}
return r
}
var newV = Fn.new { |base|
var invb = 1 / base
return Fn.new { |n|
var p = invb
var r = 0
while (n > 0) {
r... |
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... | #Phix | Phix | --
-- demo\rosetta\decode_url.exw
-- ===========================
--
with javascript_semantics
function decode_url(string s)
integer skip = 0
string res = ""
for i=1 to length(s) do
if skip then
skip -= 1
else
integer ch = s[i]
if ch='%' then
sequen... |
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... | #REXX | REXX | /*REXX program to read/interpret UPC symbols and translate them to a numberic string.*/
#.0= ' ## #'
#.1= ' ## #'
#.2= ' # ##'
#.3= ' #### #'
#.4= ' # ##'
#.5= ' ## #'
#.6= ' # ####'
#.7= ' ### ##'
#.8= ' ## ... |
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
| #Logtalk | Logtalk |
:- object(user_input).
:- public(test/0).
test :-
repeat,
write('Enter an integer: '),
read(Integer),
integer(Integer),
!,
repeat,
write('Enter an atom: '),
read(Atom),
atom(Atom),
!.
:- end_object.
|
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
| #LOLCODE | LOLCODE | HAI 1.4
I HAS A string
GIMMEH string
I HAS A number
GIMMEH number
BTW converts number input to an integer
MAEK number A NUMBR
KTHXBYE
|
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
| #Raku | Raku | use GTK::Simple;
use GTK::Simple::App;
my GTK::Simple::App $app .= new( title => 'User Interaction' );
$app.border-width = 20;
$app.set-content(
GTK::Simple::VBox.new(
my $ = GTK::Simple::Label.new( text => 'Enter a string.' ),
my $str = GTK::Simple::Entry.new,
my $string =... |
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... | #Vlang | Vlang | import encoding.hex
fn decode(s string) ?[]u8 {
return hex.decode(s)
}
fn main() {
println("${'Char':-7} ${'Unicode':7}\tUTF-8 encoded\tDecoded")
for codepoint in [`A`, `ö`, `Ж`, `€`, `𝄞`] {
encoded := codepoint.bytes().hex()
decoded := decode(encoded)?
println("${codepoint:-7} 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... | #Wren | Wren | import "/fmt" for Fmt
var utf8_encode = Fn.new { |cp| String.fromCodePoint(cp).bytes.toList }
var utf8_decode = Fn.new { |b|
var mbMask = 0x3f // non-first bytes start 10 and carry 6 bits of data
var b0 = b[0]
if (b0 < 0x80) {
return b0
} else if (b0 < 0xe0) {
var b2Mask = 0x1f // fi... |
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... | #R | R | URLencode("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... | #Racket | Racket |
#lang racket
(require net/uri-codec)
(uri-encode "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
| #Nanoquery | Nanoquery | // variable definition and initialization/assignment
//
// variables are initialized when they are defined
a = 1
b = 2
c = null
// datatypes
//
// variables may contain any datatype, and this can be
// changed at any time by assigning a new value. they may
// also contain native java types
var = "a string"
var = 123
... |
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
| #Nim | Nim | var x: int = 3 # Declaration with type specification and initialization.
var y = 3 # Declaration with type inferred to "int".
var z: int # Variable is initialized to 0.
let a = 13 # Immutable variable.
# Using a var block to initi... |
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... | #XLISP | XLISP | (defun print-on-separate-lines (&rest xs)
(for-each print xs))
; test the function:
(print-on-separate-lines 'i 'am 'doing 'a 'great 'work 'so 'that 'i 'cannot 'come 'down)
; to use it on a list of arguments assembled at run time, first create your list
(define test '(why should the work cease whilst i leav... |
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... | #XPL0 | XPL0 | include c:\cxpl\codes; \intrinsic 'code' declarations
def IntSize=4; \number of bytes in an integer
proc Var(N...); \Display N strings passed as arguments
int N;
[N:= Reserve(N*IntSize); \reserve space for N string pointers
repeat Text(0,N(0)); CrLf(0); \display str... |
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... | #zkl | zkl | fcn f{vm.arglist.apply2("println")}
f("Mary","had","a","little"); |
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... | #Liberty_BASIC | Liberty BASIC | print "Vector products of 3-D vectors"
print "Dot product of 3,4,5 and 4,3,5 is "
print DotProduct( "3,4,5", "4,3,5")
print "Cross product of 3,4,5 and 4,3,5 is "
print CrossProduct$( "3,4,5", "4,3,5")
print "Scalar triple product of 3,4,5, 4,3,5 -5, -12, -13 is "
print ScalarTri... |
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... | #XPL0 | XPL0 | include c:\cxpl\codes; \intrinsic 'code' declarations
func real VdC(N); \Return Nth term of van der Corput sequence in base 2
int N;
real V, U;
[V:= 0.0; U:= 0.5;
repeat N:= N/2;
if rem(0) then V:= V+U;
U:= U/2.0;
until N=0;
return V;
];
int N;
for N:= 0 to 10-1 do
[IntOut(0, 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... | #zkl | zkl | fcn vdc(n,base=2){
vdc:=0.0; denom:=1;
while(n){ reg remainder;
denom *= base;
n, remainder = n.divr(base);
vdc += (remainder.toFloat() / denom);
}
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... | #PHP | PHP | <?php
$encoded = "http%3A%2F%2Ffoo%20bar%2F";
$unencoded = rawurldecode($encoded);
echo "The unencoded string is $unencoded !\n";
?> |
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... | #PicoLisp | PicoLisp | : (ht:Pack (chop "http%3A%2F%2Ffoo%20bar%2F") T)
-> "http://foo bar/" |
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... | #Ruby | Ruby | DIGIT_F = {
" ## #" => 0,
" ## #" => 1,
" # ##" => 2,
" #### #" => 3,
" # ##" => 4,
" ## #" => 5,
" # ####" => 6,
" ### ##" => 7,
" ## ###" => 8,
" # ##" => 9,
}
DIGIT_R = {
"### # " => 0,
"## ## " => 1,
"## ## " => 2,
"# # " => 3,
"# ### ... |
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
| #Lua | Lua | print('Enter a string: ')
s = io.stdin:read()
print('Enter a number: ')
i = tonumber(io.stdin:read())
|
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
| #M2000_Interpreter | M2000 Interpreter |
Module CheckIt {
Keyboard "75000"+chr$(13)
Input "Integer:", A%
\\ Input erase keyboard buffer, we can't place in first Keyboard keys for second input
Keyboard "Hello World"+Chr$(13)
Input "String:", A$
Print A%, A$
}
CheckIt
|
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
| #Rascal | Rascal | import vis::Render;
import vis::Figure;
public void UserInput2(){
integer = "";
string = "";
row1 = [text("Enter a string "),
textfield("",void(str s){string = s;}),
text(str(){return " This input box will give a string by definition.\n You entered <string>";})];
row2 = [text("Enter 75000"),
textfield... |
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
| #REBOL | REBOL | rebol [
Title: "Graphical User Input"
URL: http://rosettacode.org/wiki/User_Input_-_graphical
]
; Simple GUI's can be defined with 'layout', a special purpose dialect
; for specifying interfaces. In this case, I describe a gradient
; background with an instruction label, followed by the input fields
; and a validat... |
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... | #zkl | zkl | println("Char Unicode UTF-8");
foreach utf,unicode_int in (T( T("\U41;",0x41), T("\Uf6;",0xf6),
T("\U416;",0x416), T("\U20AC;",0x20ac), T("\U1D11E;",0x1d11e))){
utf_int:=utf.reduce(fcn(s,c){ 0x100*s + c.toAsc() },0);
char :=unicode_int.toString(-8); // Unicode int to UTF-8 string
// UTF-8 bytes to UTF... |
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... | #Raku | Raku | my $url = 'http://foo bar/';
say $url.subst(/<-alnum>/, *.ord.fmt("%%%02X"), :g); |
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... | #REALbasic | REALbasic |
Dim URL As String = "http://foo bar/"
URL = EncodeURLComponent(URL)
Print(URL)
|
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
| #Objeck | Objeck |
a : Int;
b : Int := 13;
c := 7;
|
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
| #OCaml | OCaml | let x = 28 |
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... | #Lingo | Lingo | a = vector(1,2,3)
b = vector(4,5,6)
put a * b
-- 32.0000
put a.dot(b)
-- 32.0000
put a.cross(b)
-- vector( -3.0000, 6.0000, -3.0000 ) |
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... | #Pike | Pike |
void main()
{
array encoded_urls = ({
"http%3A%2F%2Ffoo%20bar%2F",
"google.com/search?q=%60Abdu%27l-Bah%C3%A1"
});
foreach(encoded_urls, string url) {
string decoded = Protocols.HTTP.uri_decode( url );
write( string_to_utf8(decoded) +"\n" ); // Assume sink does UTF8
... |
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... | #PowerShell | PowerShell |
[System.Web.HttpUtility]::UrlDecode("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... | #Wren | Wren | import "/fmt" for Fmt
var digitL = {
" ## #": 0,
" ## #": 1,
" # ##": 2,
" #### #": 3,
" # ##": 4,
" ## #": 5,
" # ####": 6,
" ### ##": 7,
" ## ###": 8,
" # ##": 9
}
var digitR = {
"### # ": 0,
"## ## ": 1,
"## ## ": 2,
"# # ": 3,
"# ### ... |
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
| #MACRO-10 | MACRO-10 |
TITLE User Input
COMMENT !
User Input ** PDP-10 assembly language (kjx, 2022)
Assembler: MACRO-10 Operating system: TOPS-20
This program reads a string (maximum of 80 characters) and
a decimal number. The number is checked to be 75000. Invalid
input (like entering characters instead of ... |
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
| #Maple | Maple | printf("String:"); string_value := readline();
printf("Integer: "); int_value := parse(readline()); |
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
| #REXX | REXX | /*REXX pgm prompts (using the OS GUI) for a string & then prompts for a specific number.*/
#= 75000 /*the number that must be entered. */
x=
N=
do while x=' '; say /*string can't be blanks or null string*/
say 'Please enter a string: '
p... |
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
| #Ring | Ring |
Load "guilib.ring"
MyApp = New qApp {
num = 0
win1 = new qWidget() {
setwindowtitle("Hello World")
setGeometry(100,100,370,250)
btn1 = new qpushbutton(win1) {
setGeometry(130,20... |
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... | #REXX | REXX | /* Rexx */
do
call testcase
say
say RFC3986
call testcase RFC3986
say
say HTML5
call testcase HTML5
say
return
end
exit
/* -------------------------------------------------------------------------- */
encode:
procedure
do
parse arg url, varn .
parse upper var varn variation
drop RFC3986 HTML5... |
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
| #Oforth | Oforth | import: date
: testVariable
| a b c |
Date now ->a
a println ; |
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
| #ooRexx | ooRexx | a.=4711
Say 'before sub a.3='a.3
Call sub a.
Say ' after sub a.3='a.3
Exit
sub: Procedure
use Arg a.
a.3=3
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... | #Lua | Lua | Vector = {}
function Vector.new( _x, _y, _z )
return { x=_x, y=_y, z=_z }
end
function Vector.dot( A, B )
return A.x*B.x + A.y*B.y + A.z*B.z
end
function Vector.cross( A, B )
return { x = A.y*B.z - A.z*B.y,
y = A.z*B.x - A.x*B.z,
z = A.x*B.y - A.y*B.x }
end
function Vector.s... |
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... | #PureBasic | PureBasic | URL$ = URLDecoder("http%3A%2F%2Ffoo%20bar%2F")
Debug URL$ ; 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... | #Python | Python |
#Python 2.X
import urllib
print urllib.unquote("http%3A%2F%2Ffoo%20bar%2F")
#Python 3.5+
from urllib.parse import unquote
print(unquote('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... | #zkl | zkl | var lhd=Dictionary(), rhd=Dictionary();
[0..].zip(List(
"0 0 0 1 1 0 1", //--> "___##_#":0 "###__#_":0
"0 0 1 1 0 0 1",
"0 0 1 0 0 1 1",
"0 1 1 1 1 0 1",
"0 1 0 0 0 1 1",
"0 1 1 0 0 0 1",
"0 1 0 1 1 1 1",
"0 1 1 1 0 1 1",
"0 1 1 0 1 1 1",
"0 0 0 1 0 1 1") //--> "___#_##":9 ... |
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
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | mystring = InputString["give me a string please"];
myinteger = Input["give me an integer please"]; |
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
| #MATLAB | MATLAB | >> input('Input string: ')
Input string: 'Hello'
ans =
Hello
>> input('Input number: ')
Input number: 75000
ans =
75000
>> input('Input number, the number will be stored as a string: ','s')
Input number, the number will be stored as a string: 75000
ans =
75000 |
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
| #Ruby | Ruby | require 'tk'
def main
root = TkRoot.new
l1 = TkLabel.new(root, "text" => "input a string")
e1 = TkEntry.new(root)
l2 = TkLabel.new(root, "text" => "input the number 75000")
e2 = TkEntry.new(root) do
validate "focusout"
validatecommand lambda {e2.value.to_i == 75_000}
invalidcommand lambda {focu... |
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... | #Ruby | Ruby | require 'cgi'
puts CGI.escape("http://foo bar/").gsub("+", "%20")
# => "http%3A%2F%2Ffoo%20bar%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... | #Run_BASIC | Run BASIC | urlIn$ = "http://foo bar/"
for i = 1 to len(urlIn$)
a$ = mid$(urlIn$,i,1)
if (a$ >= "0" and a$ <= "9") _
or (a$ >= "A" and a$ <= "Z") _
or (a$ >= "a" and a$ <= "z") then url$ = url$ + a$ else url$ = url$ + "%"+dechex$(asc(a$))
next i
print urlIn$;" -> ";url$ |
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
| #Ol | Ol |
; Declare the symbol 'var1' and associate number 123 with it.
(define var1 123)
(print var1)
; ==> 123
; Reassociate number 321 with var1.
(define var1 321)
(print var1)
; Create function that prints value of var1 ...
(define (show)
(print var1))
; ... and eassociate number 42 with var1.
(define var1 42)
(pr... |
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
| #Openscad | Openscad |
mynumber=5+4; // This gives a value of nine
|
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... | #M2000_Interpreter | M2000 Interpreter |
Module checkit {
class Vector {
\\ by default are double
a,b,c
Property ToString$ {
Value {
link parent a,b,c to a,b,c
value$=format$("({0}, {1}, {2})",a,b,c)
... |
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... | #R | R | URLdecode("http%3A%2F%2Ffoo%20bar%2F") |
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.