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/Water_collected_between_towers
Water collected between towers
Task In a two-dimensional world, we begin with any bar-chart (or row of close-packed 'towers', each of unit width), and then it rains, completely filling all convex enclosures in the chart with water. 9 ██ 9 ██ 8 ██ 8 ██ 7 ██ ...
#zkl
zkl
fcn waterCollected(walls){ // compile max wall heights from left to right and right to left // then each pair is left/right wall of that cell. // Then the min of each wall pair == water height for that cell scanl(walls,(0).max) // scan to right, f is max(0,a,b) .zipWith((0).MAX.min, // f is ...
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...
#Cowgol
Cowgol
include "cowgol.coh";   record Vector is x: int32; # Cowgol does not have floating point types, y: int32; # but for the examples it does not matter. z: int32; end record;   sub print_signed(n: int32) is if n < 0 then print_char('-'); n := -n; end if; print_i32(n as uint32); e...
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...
#Fortran
Fortran
program isin use ctype implicit none character(20) :: test(7) = ["US0378331005 ", & "US0373831005 ", & "U50378331005 ", & "US03378331005 ", & "AU0000XVGZ...
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...
#Ela
Ela
open random number list   vdc bs n = vdc' 0.0 1.0 n where vdc' v d n | n > 0 = vdc' v' d' n' | else = v where d' = d * bs rem = n % bs n' = truncate (n / bs) v' = v + rem / d'
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...
#Elixir
Elixir
defmodule Van_der_corput do def sequence( n, base \\ 2 ) do "0." <> (Integer.to_string(n, base) |> String.reverse ) end   def float( n, base \\ 2 ) do Integer.digits(n, base) |> Enum.reduce(0, fn i,acc -> (i + acc) / base end) end   def fraction( n, base \\ 2 ) do str = Integer.to_string(n, 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...
#Apex
Apex
EncodingUtil.urlDecode('http%3A%2F%2Ffoo%20bar%2F', 'UTF-8'); EncodingUtil.urlDecode('google.com/search?q=%60Abdu%27l-Bah%C3%A1', '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...
#AppleScript
AppleScript
AST URL decode "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
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
#ALGOL_W
ALGOL W
begin string(80) s; integer n; write( "Enter a string > " ); read( s ); write( "Enter an integer> " ); read( n ) end.
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
#Amazing_Hopper
Amazing Hopper
  #include <flow.h>   #import lib/input.bas.lib #include include/flow-input.h   DEF-MAIN(argv,argc) CLR-SCR MSET( número, cadena ) LOCATE(2,2), PRNL( "Input an string : "), LOC-COL(20), LET( cadena := READ-STRING( cadena ) ) LOCATE(3,2), PRNL( "Input an integer: "), LOC-COL(20), LET( número := INT( VAL(READ...
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
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program inputWin64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM...
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...
#Ada
Ada
with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Strings.UTF_Encoding.Wide_Wide_Strings; with Ada.Integer_Text_IO; with Ada.Text_IO; with Ada.Wide_Wide_Text_IO;   procedure UTF8_Encode_And_Decode is package TIO renames Ada.Text_IO; package WWTIO renames Ada.Wide_Wide_Text_IO; package WWS renames Ada.Str...
http://rosettacode.org/wiki/Use_another_language_to_call_a_function
Use another language to call a function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. This task is inverse to the task Call foreign language function. Consider the following C program: #include <stdio.h>   extern int Query (char * Data, size_t * Length);   int main (i...
#C.2B.2B
C++
#include <string> using std::string;   // C++ functions with extern "C" can get called from C. extern "C" int Query (char *Data, size_t *Length) { const string Message = "Here am I";   // Check that Message fits in Data. if (*Length < Message.length()) return false; // C++ converts bool to int.   *Le...
http://rosettacode.org/wiki/Use_another_language_to_call_a_function
Use another language to call a function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. This task is inverse to the task Call foreign language function. Consider the following C program: #include <stdio.h>   extern int Query (char * Data, size_t * Length);   int main (i...
#COBOL
COBOL
identification division. program-id. Query.   environment division. configuration section. special-names. call-convention 0 is extern.   repository. function all intrinsic.   data division. working-storage section. 01 query-result. ...
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...
#F.23
F#
open System open System.Text.RegularExpressions   let writeline n v = if String.IsNullOrEmpty(v) then () else printfn "%-15s %s" n v   let toUri = fun s -> Uri(s.ToString()) let urisFromString = (Regex(@"\S+").Matches) >> Seq.cast >> (Seq.map toUri)   urisFromString """ foo://example.com:8042/over/there?name=ferret...
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...
#AWK
AWK
BEGIN { for (i = 0; i <= 255; i++) ord[sprintf("%c", i)] = i }   # Encode string with application/x-www-form-urlencoded escapes. function escape(str, c, len, res) { len = length(str) res = "" for (i = 1; i <= len; i++) { c = substr(str, i, 1); if (c ~ /[0-9A-Za-z]/) #if (c ~ /[-._*0-9A-Za-z]/) res = r...
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...
#BBC_BASIC
BBC BASIC
PRINT FNurlencode("http://foo bar/") END   DEF FNurlencode(url$) LOCAL c%, i% WHILE i% < LEN(url$) i% += 1 c% = ASCMID$(url$, i%) IF c%<&30 OR c%>&7A OR c%>&39 AND c%<&41 OR c%>&5A AND c%<&61 THEN url$ = LEFT$(url$,i%-1) + "%" + RIGHT$("0"+STR$~c%,2) + MID...
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
#C
C
int j;
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
#C.23
C#
int j;
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 ...
#Comal
Comal
0010 DIM eck#(0:1000) 0020 FOR i#:=1 TO 999 DO 0030 j#:=i#-1 0040 WHILE j#>0 AND eck#(i#)<>eck#(j#) DO j#:-1 0050 IF j#<>0 THEN eck#(i#+1):=i#-j# 0060 ENDFOR i# 0070 ZONE 5 0080 FOR i#:=1 TO 10 DO PRINT eck#(i#), 0090 PRINT 0100 FOR i#:=991 TO 1000 DO PRINT eck#(i#), 0110 PRINT 0120 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 ...
#Common_Lisp
Common Lisp
  ;;Tested using CLISP   (defun VanEck (x) (reverse (VanEckh x 0 0 '(0))))   (defun VanEckh (final index curr lst) (if (eq index final) lst (VanEckh final (+ index 1) (howfar curr lst) (cons curr lst))))   (defun howfar (x lst) (howfarh x lst 0))   (defun howfarh (x lst runningtotal) (cond ((null lst) 0) ((...
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...
#J
J
  Filter=: (#~`)(`:6) odd =: 2&| even =: -.@:odd factors =: [: ([: /:~ [: */"1 ([: x: [) ^"1 [: > [: , [: { [: <@:i.@>: ])/ __ q: ] digits =: 10&(#.inv) tally =: # : [: half =: -: : [: even_number_of_digits =: even@:tally@:digits same_digits =: digits@:[ -:&(/:~) ,&digits/@:] assert 1 -: 1234 same_digits 23 14 assert 0...
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...
#Io
Io
printAll := method(call message arguments foreach(println))
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...
#J
J
A=:2 B=:3 C=:5 sum=:+/ sum 1,A,B,4,C 15
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Rust
Rust
use std::mem;   fn main() { // Specify type assert_eq!(4, mem::size_of::<i32>());   // Provide a value let arr: [u16; 3] = [1, 2, 3]; assert_eq!(6, mem::size_of_val(&arr)); }  
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Scala
Scala
def nBytes(x: Double) = ((Math.log(x) / Math.log(2) + 1e-10).round + 1) / 8   val primitives: List[(Any, Long)] = List((Byte, Byte.MaxValue), (Short, Short.MaxValue), (Int, Int.MaxValue), (Long, Long.MaxValue))   primitives.foreach(t => println(f"A Scala ${t._1.toString.drop(13)}%-5s has ${n...
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Swift
Swift
sizeofValue(x)
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Tcl
Tcl
string bytelength $var
http://rosettacode.org/wiki/Vector
Vector
Task Implement a Vector class (or a set of functions) that models a Physical Vector. The four basic operations and a pretty print function should be implemented. The Vector may be initialized in any reasonable way. Start and end points, and direction Angular coefficient and value (length) The four operations to...
#PicoLisp
PicoLisp
(de add (A B) (mapcar + A B) ) (de sub (A B) (mapcar - A B) ) (de mul (A B) (mapcar '((X) (* X B)) A) ) (de div (A B) (mapcar '((X) (*/ X B)) A) ) (let (X (5 7) Y (2 3)) (println (add X Y)) (println (sub X Y)) (println (mul X 11)) (println (div X 2)) )
http://rosettacode.org/wiki/Vector
Vector
Task Implement a Vector class (or a set of functions) that models a Physical Vector. The four basic operations and a pretty print function should be implemented. The Vector may be initialized in any reasonable way. Start and end points, and direction Angular coefficient and value (length) The four operations to...
#PL.2FI
PL/I
*process source attributes xref or(!); vectors: Proc Options(main); Dcl (v,w,x,y,z) Dec Float(9) Complex; real(v)=12; imag(v)=-3; Put Edit(pp(v))(Skip,a); real(v)=6-1; imag(v)=4-1; Put Edit(pp(v))(Skip,a); real(v)=2*cosd(45); imag(v)=2*sind(45); Put Edit(pp(v))(Skip,a);   w=v+v; Put Ed...
http://rosettacode.org/wiki/Vigen%C3%A8re_cipher
Vigenère cipher
Task Implement a   Vigenère cypher,   both encryption and decryption. The program should handle keys and text of unequal length, and should capitalize everything and discard non-alphabetic characters. (If your program handles non-alphabetic characters in another way, make a note of it.) Related tasks   Caesar ...
#PureBasic
PureBasic
Procedure prepString(text.s, Array letters(1)) ;convert characters to an ordinal (0-25) and remove non-alphabetic characters, ;returns dimension size of result array letters() Protected *letter.Character, index Dim letters(Len(text)) text = UCase(text) *letter = @text While *letter\c Select *letter\c ...
http://rosettacode.org/wiki/Walk_a_directory/Recursively
Walk a directory/Recursively
Task Walk a given directory tree and print files matching a given pattern. Note: This task is for recursive methods.   These tasks should read an entire directory tree, not a single directory. Note: Please be careful when running any code examples found here. Related task   Walk a directory/Non-recursively   ...
#Wren
Wren
import "io" for Directory, File import "/pattern" for Pattern import "/sort" for Sort   var walk // recursive function walk = Fn.new { |dir, pattern, found| if (!Directory.exists(dir)) Fiber.abort("Directory %(dir) does not exist.") var files = Directory.list(dir) for (f in files) { var path = dir +...
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...
#Crystal
Crystal
class Vector property x, y, z   def initialize(@x : Int64, @y : Int64, @z : Int64) end   def dot_product(other : Vector) (self.x * other.x) + (self.y * other.y) + (self.z * other.z) end   def cross_product(other : Vector) Vector.new(self.y * other.z - self.z * other.y, self.z * other.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...
#FreeBASIC
FreeBASIC
' version 27-10-2016 ' compile with: fbc -s console   #Ifndef TRUE ' define true and false for older freebasic versions #Define FALSE 0 #Define TRUE Not FALSE #EndIf   Function luhntest(cardnr As String) As Long   cardnr = Trim(cardnr) ' remove spaces   Dim As String reverse_nr = cardnr Dim...
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...
#Erlang
Erlang
  -module( van_der_corput ).   -export( [sequence/1, sequence/2, task/0] ).   sequence( N ) -> sequence( N, 2 ).   sequence( 0, _Base ) -> 0.0; sequence( N, Base ) -> erlang:list_to_float( "0." ++ lists:flatten([erlang:integer_to_list(X) || X <- sequence_loop(N, Base)]) ).   task() -> [task(X) || X <- lists:seq(2, 5)]....
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...
#Arturo
Arturo
print decode.url "http%3A%2F%2Ffoo%20bar%2F" print decode.url "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...
#AutoHotkey
AutoHotkey
encURL := "http%3A%2F%2Ffoo%20bar%2F" SetFormat, Integer, hex Loop Parse, encURL If A_LoopField = `% reading := 2, read := "" else if reading { read .= A_LoopField, --reading if not reading out .= Chr("0x" . read) } else out .= A_LoopField MsgBox % out ; http://foo bar/  
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...
#11l
11l
T.enum EntryType EMPTY ENABLED DISABLED COMMENT IGNORE   T Entry EntryType etype String name String value   F (etype, name = ‘’, value = ‘’) .etype = etype .name = name .value = value   T Config String path [Entry] entries   F (path) .path = path L(=line...
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
#APL
APL
str←⍞ 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
#ARM_Assembly
ARM Assembly
    /* ARM assembly Raspberry PI */ /* program inputText.s */   /* Constantes */ .equ BUFFERSIZE, 100 .equ STDIN, 0 @ Linux input console .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ READ, 3 @ Linux syscall .equ WRITE, 4 @ Linux syscall /* Initialized data *...
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
#Ada
Ada
with Gtk.Button; use Gtk.Button; with Gtk.GEntry; use Gtk.GEntry; with Gtk.Label; use Gtk.Label; with Gtk.Window; use Gtk.Window; with Gtk.Widget; use Gtk.Widget; with Gtk.Table; use Gtk.Table;   with Gtk.Handlers; with Gtk.Main;   procedure Graphic_Input is Window  : Gtk_Window; Grid  : Gtk_Tnetable; ...
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...
#ATS
ATS
(*   UTF-8 encoding and decoding in ATS2.   This is adapted from library code I wrote long ago and actually handles the original 1-to-6-byte encoding, as well. Valid Unicode requires only 1 to 4 bytes.   What is remarkable about the following rather lengthy code is its use of proofs of what is and what is n...
http://rosettacode.org/wiki/Use_another_language_to_call_a_function
Use another language to call a function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. This task is inverse to the task Call foreign language function. Consider the following C program: #include <stdio.h>   extern int Query (char * Data, size_t * Length);   int main (i...
#D
D
import core.stdc.string;   extern(C) bool query(char *data, size_t *length) pure nothrow { immutable text = "Here am I";   if (*length < text.length) { *length = 0; // Also clears length. return false; } else { memcpy(data, text.ptr, text.length); *length = text.length; ...
http://rosettacode.org/wiki/Use_another_language_to_call_a_function
Use another language to call a function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. This task is inverse to the task Call foreign language function. Consider the following C program: #include <stdio.h>   extern int Query (char * Data, size_t * Length);   int main (i...
#Delphi
Delphi
  function Query(Buffer: PChar; var Size: Int64): LongBool; const Text = 'Hello World!'; begin If not Assigned(Buffer) Then begin Size := 0; Result := False; Exit; end; If Size < Length(Text) Then begin Size := 0; Result := False; Exit; end;   ...
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...
#Go
Go
package main   import ( "fmt" "log" "net" "net/url" )   func main() { for _, in := range []string{ "foo://example.com:8042/over/there?name=ferret#nose", "urn:example:animal:ferret:nose", "jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true", "ftp://ftp.is.co.za/rfc/rfc1808.txt", "http...
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...
#Bracmat
Bracmat
( ( encode = encoded exceptions octet string .  !arg:(?exceptions.?string) & :?encoded & @( !string  :  ? ( %@?octet ? &  !encoded (  !octet  : ( ~<0:~>9 ...
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...
#C
C
#include <stdio.h> #include <ctype.h>   char rfc3986[256] = {0}; char html5[256] = {0};   /* caller responsible for memory */ void encode(const char *s, char *enc, char *tb) { for (; *s; s++) { if (tb[*s]) sprintf(enc, "%c", tb[*s]); else sprintf(enc, "%%%02X", *s); while (*++enc); } }   int main() { co...
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
#C.2B.2B
C++
int a;
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
#Cach.C3.A9_ObjectScript
Caché ObjectScript
set MyStr = "A string" set MyInt = 4 set MyFloat = 1.3
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 ...
#Cowgol
Cowgol
include "cowgol.coh";   sub print_list(ptr: [uint16], n: uint8) is while n > 0 loop print_i16([ptr]); print_char(' '); n := n - 1; ptr := @next ptr; end loop; print_nl(); end sub;   const LIMIT := 1000; var eck: uint16[LIMIT]; MemZero(&eck as [uint8], @bytesof eck); var i: @i...
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 ...
#D
D
import std.stdio;   void vanEck(int firstIndex, int lastIndex) { int[int] vanEckMap; int last = 0; if (firstIndex == 1) { writefln("VanEck[%d] = %d", 1, 0); } for (int n = 2; n <= lastIndex; n++) { int vanEck = last in vanEckMap ? n - vanEckMap[last] : 0; vanEckMap[last] = n;...
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...
#Java
Java
import java.util.Arrays; import java.util.HashSet;   public class VampireNumbers{ private static int numDigits(long num){ return Long.toString(Math.abs(num)).length(); }   private static boolean fangCheck(long orig, long fang1, long fang2){ if(Long.toString(fang1).endsWith("0") && Long.toStr...
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...
#Java
Java
public static void printAll(Object... things){ // "things" is an Object[] for(Object i:things){ System.out.println(i); } }
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...
#JavaScript
JavaScript
function printAll() { for (var i=0; i<arguments.length; i++) print(arguments[i]) } printAll(4, 3, 5, 6, 4, 3); printAll(4, 3, 5); printAll("Rosetta", "Code", "Is", "Awesome!");
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Toka
Toka
char-size . cell-size .
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT,{} string="somerandomstring" size=SIZE(string) length=LENGTH(string)   PRINT "string: ",string PRINT "has size: ",size PRINT "and length: ",length  
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#TXR
TXR
1> (prof 1) (1 0 0 0)
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#UNIX_Shell
UNIX Shell
# In the shell all variables are stored as strings, so we use the same technique # as for finding the length of a string: greeting='Hello, world!' greetinglength=`printf '%s' "$greeting" | wc -c` echo "The greeting is $greetinglength characters in length"
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Ursala
Ursala
#import std   #cast %nL   examples = <weight 'hello',mpfr..prec 1.0E+0>
http://rosettacode.org/wiki/Vector
Vector
Task Implement a Vector class (or a set of functions) that models a Physical Vector. The four basic operations and a pretty print function should be implemented. The Vector may be initialized in any reasonable way. Start and end points, and direction Angular coefficient and value (length) The four operations to...
#PowerShell
PowerShell
$V1 = New-Object System.Windows.Vector ( 2.5, 3.4 ) $V2 = New-Object System.Windows.Vector ( -6, 2 ) $V1 $V2 $V1 + $V2 $V1 - $V2 $V1 * 3 $V1 / 8
http://rosettacode.org/wiki/Vector
Vector
Task Implement a Vector class (or a set of functions) that models a Physical Vector. The four basic operations and a pretty print function should be implemented. The Vector may be initialized in any reasonable way. Start and end points, and direction Angular coefficient and value (length) The four operations to...
#Processing
Processing
PVector v1 = new PVector(5, 7); PVector v2 = new PVector(2, 3);   println(v1.x, v1.y, v1.mag(), v1.heading(),'\n');   // static methods println(PVector.add(v1, v2)); println(PVector.sub(v1, v2)); println(PVector.mult(v1, 11)); println(PVector.div(v1, 2), '\n');   // object methods println(v1.sub(v1)); println(v1.add(v2...
http://rosettacode.org/wiki/Vigen%C3%A8re_cipher
Vigenère cipher
Task Implement a   Vigenère cypher,   both encryption and decryption. The program should handle keys and text of unequal length, and should capitalize everything and discard non-alphabetic characters. (If your program handles non-alphabetic characters in another way, make a note of it.) Related tasks   Caesar ...
#Python
Python
'''Vigenere encryption and decryption'''   from itertools import starmap, cycle     def encrypt(message, key): '''Vigenere encryption of message using key.'''   # Converted to uppercase. # Non-alpha characters stripped out. message = filter(str.isalpha, message.upper())   def enc(c, k): '''S...
http://rosettacode.org/wiki/Walk_a_directory/Recursively
Walk a directory/Recursively
Task Walk a given directory tree and print files matching a given pattern. Note: This task is for recursive methods.   These tasks should read an entire directory tree, not a single directory. Note: Please be careful when running any code examples found here. Related task   Walk a directory/Non-recursively   ...
#zkl
zkl
d:=File.globular("..","s*.zkl")
http://rosettacode.org/wiki/Walk_a_directory/Recursively
Walk a directory/Recursively
Task Walk a given directory tree and print files matching a given pattern. Note: This task is for recursive methods.   These tasks should read an entire directory tree, not a single directory. Note: Please be careful when running any code examples found here. Related task   Walk a directory/Non-recursively   ...
#Zsh
Zsh
setopt GLOB_DOTS print -l -- **/*.txt
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...
#D
D
import std.stdio, std.conv, std.numeric;   struct V3 { union { immutable struct { double x, y, z; } immutable double[3] v; }   double dot(in V3 rhs) const pure nothrow /*@safe*/ @nogc { return dotProduct(v, rhs.v); }   V3 cross(in V3 rhs) const pure nothrow @safe @nogc { ...
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...
#Go
Go
package main   import "regexp"   var r = regexp.MustCompile(`^[A-Z]{2}[A-Z0-9]{9}\d$`)   var inc = [2][10]int{ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}, }   func ValidISIN(n string) bool { if !r.MatchString(n) { return false } var sum, p int for i := 10; i >= 0; i-- { p = 1 - p if d :=...
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...
#ERRE
ERRE
PROGRAM VAN_DER_CORPUT   ! ! for rosettacode.org !   PROCEDURE VDC(N%,B%->RES) LOCAL V,S% S%=1 WHILE N%>0 DO S%*=B% V+=(N% MOD B%)/S% N%=N% DIV B% END WHILE RES=V END PROCEDURE   BEGIN FOR BASE%=2 TO 5 DO PRINT("Base";STR$(BASE%);":") FOR NUMBE...
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...
#Euphoria
Euphoria
function vdc(integer n, atom base) atom vdc, denom, rem vdc = 0 denom = 1 while n do denom *= base rem = remainder(n,base) n = floor(n/base) vdc += rem / denom end while return vdc end function   for i = 2 to 5 do printf(1,"Base %d\n",i) for j = 0 to 9 do ...
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...
#AWK
AWK
  # syntax: awk ' BEGIN { str = "http%3A%2F%2Ffoo%20bar%2F" # "http://foo bar/" printf("%s\n",str) len=length(str) for (i=1;i<=len;i++) { if ( substr(str,i,1) == "%") { L = substr(str,1,i-1) # chars to left of "%" M = substr(str,i+1,2) # 2 chars to right of "%" R = substr(...
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...
#AutoHotkey
AutoHotkey
; Author: AlephX, Aug 17 2011 data = %A_scriptdir%\rosettaconfig.txt outdata = %A_scriptdir%\rosettaconfig.tmp FileDelete, %outdata%   NUMBEROFBANANAS := 1024 numberofstrawberries := 560 NEEDSPEELING = "0" FAVOURITEFRUIT := "bananas" SEEDSREMOVED = "1" BOOL0 = "0" BOOL1 = "1" NUMBER1 := 1 number0 := 0 STRINGA := "strin...
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
#Arturo
Arturo
str: input "Enter a string: " num: to :integer input "Enter an integer: "   print ["Got:" str "," 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
#AutoHotkey
AutoHotkey
DllCall("AllocConsole") FileAppend, please type something`n, CONOUT$ FileReadLine, line, CONIN$, 1 msgbox % line FileAppend, please type '75000'`n, CONOUT$ FileReadLine, line, CONIN$, 1 msgbox % line
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
#AppleScript
AppleScript
set input to text returned of (display dialog "Enter text:" default answer "")
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
#AutoHotkey
AutoHotkey
InputBox, String, Input, Enter a string: InputBox, Int, Input, Enter an int: Msgbox, You entered "%String%" and "%Int%"
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...
#AutoHotkey
AutoHotkey
Encode_UTF(hex){ Bytes := hex>=0x10000 ? 4 : hex>=0x0800 ? 3 : hex>=0x0080 ? 2 : hex>=0x0001 ? 1 : 0 Prefix := [0, 0xC0, 0xE0, 0xF0] loop % Bytes { if (A_Index < Bytes) UTFCode := Format("{:X}", (hex&0x3F) + 0x80) . UTFCode ; 3F=00111111, 80=10000000 else UTFCode := Format("{:X}", hex + Prefix[Bytes]) . ...
http://rosettacode.org/wiki/Use_another_language_to_call_a_function
Use another language to call a function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. This task is inverse to the task Call foreign language function. Consider the following C program: #include <stdio.h>   extern int Query (char * Data, size_t * Length);   int main (i...
#Fortran
Fortran
  !----------------------------------------------------------------------- !Function !----------------------------------------------------------------------- function fortran_query(data, length) result(answer) bind(c, name='Query') use, intrinsic :: iso_c_binding, only: c_char, c_int, c_size_t, c_null_char impl...
http://rosettacode.org/wiki/Use_another_language_to_call_a_function
Use another language to call a function
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. This task is inverse to the task Call foreign language function. Consider the following C program: #include <stdio.h>   extern int Query (char * Data, size_t * Length);   int main (i...
#Go
Go
#include <stdio.h> #include "_cgo_export.h"   void Run() { char Buffer [1024]; size_t Size = sizeof (Buffer);   if (0 == Query (Buffer, &Size)) ...
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...
#Groovy
Groovy
import java.net.URI   [ "foo://example.com:8042/over/there?name=ferret#nose", "urn:example:animal:ferret:nose", "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=...
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...
#Haskell
Haskell
module Main (main) where   import Data.Foldable (for_) import Network.URI ( URI , URIAuth , parseURI , uriAuthority , uriFragment , uriPath , uriPort ...
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...
#C.23
C#
using System;   namespace URLEncode { internal class Program { private static void Main(string[] args) { Console.WriteLine(Encode("http://foo bar/")); }   private static string Encode(string uri) { return Uri.EscapeDataString(uri); } } ...
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...
#C.2B.2B
C++
#include <QByteArray> #include <iostream>   int main( ) { QByteArray text ( "http://foo bar/" ) ; QByteArray encoded( text.toPercentEncoding( ) ) ; std::cout << encoded.data( ) << '\n' ; return 0 ; }
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
#ChucK
ChucK
int a;
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
#Clojure
Clojure
(declare foo)
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 ...
#Delphi
Delphi
/* Fill array with Van Eck sequence */ proc nonrec make_eck([*] word eck) void: int i, j, max; max := dim(eck,1)-1; for i from 0 upto max do eck[i] := 0 od;   for i from 0 upto max-1 do j := i - 1; while j >= 0 and eck[i] ~= eck[j] do j := j - 1 od; if j >= 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 ...
#Draco
Draco
/* Fill array with Van Eck sequence */ proc nonrec make_eck([*] word eck) void: int i, j, max; max := dim(eck,1)-1; for i from 0 upto max do eck[i] := 0 od;   for i from 0 upto max-1 do j := i - 1; while j >= 0 and eck[i] ~= eck[j] do j := j - 1 od; if j >= 0 ...
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...
#jq
jq
def count(s): reduce s as $x (0; .+1);   # To take advantage of gojq's arbitrary-precision integer arithmetic: def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);   # Output: a possibly empty array of pairs def factor_pairs: . as $n | ($n / (10 | power($n|tostring|length / 2) - 1)) as $first | [range...
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...
#Julia
Julia
  function divisors{T<:Integer}(n::T)  !isprime(n) || return [one(T), n] d = [one(T)] for (k, v) in factor(n) e = T[k^i for i in 1:v] append!(d, vec([i*j for i in d, j in e])) end sort(d) end   function vampirefangs{T<:Integer}(n::T) fangs = T[] isvampire = false vdcnt = 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...
#jq
jq
def demo: .[];
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...
#Julia
Julia
  julia> print_each(X...) = for x in X; println(x); end   julia> print_each(1, "hello", 23.4) 1 hello 23.4  
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Vala
Vala
void main(){ /* you can replace the int below with any of the vala supported datatypes see the vala documentation for valid datatypes. */ print(@"$(sizeof(int))\n"); }
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Vlang
Vlang
sizeof(i64)
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Wren
Wren
print frnfn_size("uint8") //1 print frnfn_size("int8") //1 print frnfn_size("uint16") //2 print frnfn_size("int16") //2 print frnfn_size("uint32") //4 print frnfn_size("int32") //4 print frnfn_size("uint64") //8 print frnfn_size("int64") //8 print frnfn_size("float") //4 print frnfn_size("double") //8 print f...
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#Yabasic
Yabasic
print frnfn_size("uint8") //1 print frnfn_size("int8") //1 print frnfn_size("uint16") //2 print frnfn_size("int16") //2 print frnfn_size("uint32") //4 print frnfn_size("int32") //4 print frnfn_size("uint64") //8 print frnfn_size("int64") //8 print frnfn_size("float") //4 print frnfn_size("double") //8 print f...
http://rosettacode.org/wiki/Variable_size/Get
Variable size/Get
Demonstrate how to get the size of a variable. See also: Host introspection
#XPL0
XPL0
include c:\cxpl\codes; int Size; int A, B; real X, Y; [Size:= addr B - addr A; IntOut(0, Size); CrLf(0); Size:= addr Y - addr X; IntOut(0, Size); CrLf(0); ]
http://rosettacode.org/wiki/Vector
Vector
Task Implement a Vector class (or a set of functions) that models a Physical Vector. The four basic operations and a pretty print function should be implemented. The Vector may be initialized in any reasonable way. Start and end points, and direction Angular coefficient and value (length) The four operations to...
#Python
Python
class Vector: def __init__(self,m,value): self.m = m self.value = value self.angle = math.degrees(math.atan(self.m)) self.x = self.value * math.sin(math.radians(self.angle)) self.y = self.value * math.cos(math.radians(self.angle))   def __add__(self,vector): """ ...
http://rosettacode.org/wiki/Vigen%C3%A8re_cipher
Vigenère cipher
Task Implement a   Vigenère cypher,   both encryption and decryption. The program should handle keys and text of unequal length, and should capitalize everything and discard non-alphabetic characters. (If your program handles non-alphabetic characters in another way, make a note of it.) Related tasks   Caesar ...
#Quackery
Quackery
[ [] swap witheach [ upper dup char A char Z 1+ within iff join else drop ] ] is onlycaps ( $ --> $ )   [ onlycaps [] swap witheach [ char A - join ] ] is cipherdisk ( $ --> [ )   [ [] swap witheach [ 26 swap - join ] ] is decipheri...
http://rosettacode.org/wiki/Vigen%C3%A8re_cipher
Vigenère cipher
Task Implement a   Vigenère cypher,   both encryption and decryption. The program should handle keys and text of unequal length, and should capitalize everything and discard non-alphabetic characters. (If your program handles non-alphabetic characters in another way, make a note of it.) Related tasks   Caesar ...
#R
R
mod1 = function(v, n) # mod1(1:20, 6) => 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 ((v - 1) %% n) + 1   str2ints = function(s) as.integer(Filter(Negate(is.na), factor(levels = LETTERS, strsplit(toupper(s), "")[[1]])))   vigen = function(input, key, decrypt = F) {input = str2ints(input) key = re...
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...
#Delphi
Delphi
  (lib 'math)   (define (scalar-triple-product a b c) (dot-product a (cross-product b c)))   (define (vector-triple-product a b c) (cross-product a (cross-product b c)))   (define a #(3 4 5)) (define b #(4 3 5)) (define c #(-5 -12 -13))   (cross-product a b) → #( 5 5 -7) (dot-product a b) → 49 (scalar-tripl...
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...
#Groovy
Groovy
CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'   int checksum(String prefix) { def digits = prefix.toUpperCase().collect { CHARS.indexOf(it).toString() }.sum() def groups = digits.collect { CHARS.indexOf(it) }.inject([[], []]) { acc, i -> [acc[1], acc[0] + i] } def ds = groups[1].collect { (2 * it).toString...
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...
#F.23
F#
open System   let vdc n b = let rec loop n denom acc = if n > 0l then let m, remainder = Math.DivRem(n, b) loop m (denom * b) (acc + (float remainder) / (float (denom * b))) else acc loop n 1 0.0     [<EntryPoint>] let main argv = printfn "%A" [ for n in 0 .. 9 -> (vd...
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...
#Factor
Factor
USING: formatting fry io kernel math math.functions math.parser math.ranges sequences ; IN: rosetta-code.van-der-corput   : vdc ( n base -- x ) [ >base string>digits <reversed> ] [ nip '[ 1 + neg _ swap ^ * ] ] 2bi map-index sum ;   : vdc-demo ( -- ) 2 5 [a,b] [ dup "Base %d: " printf 10 <iota> ...