- The snippets are under the CC-BY-SA license.
- Please consider keeping a bookmark
- (instead of printing)
VB | |||
---|---|---|---|
1 |
Print a literal string on standard output
|
||
2 |
Loop to execute some code a constant number of times
|
||
3 |
Like a function which doesn't return any value, thus has only side effects (e.g. Print to standard output)
|
||
4 |
Create a function which returns the square of an integer
|
||
5 |
Declare a container type for two floating-point numbers x and y
|
|
|
6 |
Do something with each item x of the list (or array) items, regardless indexes.
|
||
7 |
Print each index i with its value x from an array-like collection items
|
Alternative implementation:
|
|
8 |
Create a new map object x, and provide some (key, value) pairs as initial content.
|
||
10 |
Generate a random permutation of the elements of list x
|
||
11 |
The list x must be non-empty.
|
||
12 |
Check if the list contains the value x.
list is an iterable finite container. |
||
14 |
Pick a random number greater than or equals to a, strictly inferior to b. Precondition : a < b.
|
|
|
19 |
Reverse the order of the elements of the list x.
This may reverse "in-place" and destroy the original ordering. |
||
21 |
Swap the values of the variables a and b
|
||
22 |
Extract the integer value i from its string representation s (in radix 10)
|
||
24 |
Declare a new string s and initialize it with the literal value "ネコ" (which means "cat" in japanese)
|
||
26 |
Declare and initialize a matrix x having m rows and n columns, containing real numbers.
|
||
28 |
Sort the elements of the list (or array-like collection) items in ascending order of x.p, where p is a field of the type Item of the objects in items.
|
||
31 |
Create the recursive function f which returns the factorial of the non-negative integer i, calculated from f(i-1)
|
|
|
35 |
Implement a function compose (A -> C) with parameters f (A -> B) and g (B -> C), which returns the composition function g ∘ f
|
||
36 |
Implement a function compose which returns composition function g ∘ f for any functions f and g having exactly 1 parameter.
|
||
38 |
Find substring t consisting in characters i (included) to j (excluded) of string s.
Character indices start at 0 unless specified otherwise. Make sure that multibyte characters are properly handled. |
||
39 |
Set the boolean ok to true if the string word is contained in string s as a substring, or to false otherwise.
|
||
41 |
Create the string t containing the same characters as the string s, in reverse order.
The original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory. |
||
43 |
Look for a negative value v in 2D integer matrix m. Print it and stop searching.
|
Alternative implementation:
Alternative implementation:
|
|
44 |
Insert the element x at position i in the list s. Further elements must be shifted to the right.
|
|
|
45 |
Sleep for 5 seconds in current thread, before proceeding with the next instructions.
|
||
47 |
Create string t consisting in the 5 last characters of string s.
Make sure that multibyte characters are properly handled. |
||
48 |
Assign to variable s a string literal consisting in several lines of text, including newlines.
|
||
50 |
Write a loop that has no end clause.
|
|
|
51 |
Determine whether the map m contains an entry for the key k
|
||
53 |
Concatenate elements of string list x joined by the separator ", " to create a single string y.
|
||
54 |
Calculate the sum s of the integer list or array x.
|
||
55 |
Create the string representation s (in radix 10) of the integer value i.
|
||
58 |
Create the string lines from the content of the file with filename f.
|
||
61 |
Assign to the variable d the current date/time value, in the most standard type.
|
||
63 |
Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping. |
||
74 |
Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.
|
||
78 |
Execute a block once, then execute it again as long as boolean condition c is true.
|
||
87 |
Exit immediately.
If some extra cleanup work is executed by the program runtime (not by the OS itself), describe it. |
||
96 |
Set the boolean b to true if string s starts with prefix prefix, false otherwise.
|
|
|
99 |
Assign to the string x the value of the fields (year, month, day) of the date d, in format YYYY-MM-DD.
|
||
110 |
Set the boolean blank to true if the string s is empty, or null, or contains only whitespace ; false otherwise.
|
||
116 |
Remove all occurrences of string w from string s1, and store the result in s2.
|
||
117 |
Set n to the number of elements of the list x.
|
|
|
119 |
Remove duplicates from the list x.
Explain if the original order is preserved. |
||
122 |
Create an enumerated type Suit with 4 possible values SPADES, HEARTS, DIAMONDS, CLUBS.
|
||
131 |
Execute f1 if condition c1 is true, or else f2 if condition c2 is true, or else f3 if condition c3 is true.
Don't evaluate a condition when a previous condition was true. |
||
134 |
Declare and initialize a new list items, containing 3 elements a, b, c.
|
|
|
137 |
Set the boolean b to true if the string s contains only characters in the range '0'..'9', false otherwise.
|
||
145 |
Print message msg, prepended by current date and time.
Explain what behavior is idiomatic: to stdout or stderr, and what the date format is. |
|
|
157 |
Initialize a constant planet with string value "Earth".
|
||
163 |
Print all the list elements, two by two, assuming list length is even.
|
||
165 |
Assign to the variable x the last element of the list items.
|
|
|
169 |
Assign to the integer n the number of characters of the string s.
Make sure that multibyte characters are properly handled. n can be different from the number of bytes of s. |
||
171 |
Append the element x to the list s.
|
|
|
184 |
Assign to t a string representing the day, month and year of the day after the current date.
|
||
196 |
Given an integer array a of size n, pass the first, third, fifth and seventh, ... up to the m th element to a routine foo which sets all these elements to 42.
|
||
197 |
Retrieve the contents of file at path into a list of strings lines, in which each element is a line of the file.
|
||
205 |
Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".
|
|
|
206 |
Execute different procedures foo, bar, baz and barfl if the string str contains the name of the respective procedure. Do it in a way natural to the language.
|
||
219 |
Create the string t from the value of string s with each sequence of spaces replaced by a single space.
Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines. |
||
220 |
Create t consisting of 3 values having different types.
Explain if the elements of t are strongly typed or not. |
||
224 |
Insert the element x at the beginning of the list items.
|
|
|
225 |
Declare an optional integer argument x to procedure f, printing out "Present" and its value if it is present, "Not present" otherwise
|
||
234 |
Assign to the string s the standard base64 encoding of the byte array data, as specified by RFC 4648.
|
||
235 |
Assign to byte array data the bytes represented by the base64 string s, as specified by RFC 4648.
|
||
237 |
Assign to c the result of (a xor b)
|
||
245 |
Print the value of object x having custom type T, for log or debug.
|
|
|
256 |
Print the numbers 5, 4, ..., 0 (included), one line per number.
|
|
|
258 |
Convert the string values from list a into a list of integers b.
|
||
268 |
Define a type vector containing three floating point numbers x, y, and z. Write a user-defined operator x that calculates the cross product of two vectors a and b.
|
|
|
289 |
Create the string s by concatenating the strings a and b.
|
||
299 |
Write a line of comments.
This line will not be compiled or executed. |
|