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/Interactive_programming_(repl) | Interactive programming (repl) | Many language implementations come with an interactive mode.
This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.
An interactive mode may also be known as a command mode, a read-eval-print loop (REPL), or a shell.
Task
Show how to start this... | #SNOBOL4 | SNOBOL4 | >spitbol code
SPITBOL-386 Release 3.7(ver 1.30.20) Serial xxxxx
...
Enter SPITBOL statements:
? define('f(a,b,s)'):(z);f f = a s s b:(return);z
Success
?= f('Rosetta','Code',':')
Rosetta::Code
Success
?end
>
|
http://rosettacode.org/wiki/Interactive_programming_(repl) | Interactive programming (repl) | Many language implementations come with an interactive mode.
This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.
An interactive mode may also be known as a command mode, a read-eval-print loop (REPL), or a shell.
Task
Show how to start this... | #Standard_ML | Standard ML | $ sml
Standard ML of New Jersey v110.67 [built: Fri Jul 4 09:00:58 2008]
- fun f (s1, s2, sep) = String.concatWith sep [s1, "", s2];
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
val f = fn : string * string * string -> string
- f ("Rosetta", "Code", ":");
val it = "Rosetta::Code" : string... |
http://rosettacode.org/wiki/ISBN13_check_digit | ISBN13 check digit | Task
Validate the check digit of an ISBN-13 code:
Multiply every other digit by 3.
Add these numbers and the other digits.
Take the remainder of this number after division by 10.
If it is 0, the ISBN-13 check digit is correct.
Use the following codes for testing:
978-1734314502 (good)
... | #XPL0 | XPL0 | include xpllib; \contains StrLen function
proc ISBN13(Str); \Show if International Standard Book Number is good
char Str;
int Sum, Cnt, Dig, I;
[Sum:= 0; Cnt:= 0;
for I:= 0 to StrLen(Str)-1 do
[Dig:= Str(I) - ^0;
if Dig>=0 & Dig<=9 then
[Sum:= Sum + Dig;
Cnt:= Cnt + 1;
... |
http://rosettacode.org/wiki/I_before_E_except_after_C | I before E except after C | The phrase "I before E, except after C" is a
widely known mnemonic which is supposed to help when spelling English words.
Task
Using the word list from http://wiki.puzzlers.org/pub/wordlists/unixdict.txt,
check if the two sub-clauses of the phrase are plausible individually:
"I before E when not pre... | #AutoHotkey | AutoHotkey | WordList := URL_ToVar("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
WordList := RegExReplace(WordList, "i)cie", "", cieN)
WordList := RegExReplace(WordList, "i)cei", "", ceiN)
RegExReplace(WordList, "i)ie", "", ieN)
RegExReplace(WordList, "i)ei", "", eiN)
cei := ceiN / cieN > 2 ? "plausible" : "implausible"
... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #BBC_BASIC | BBC BASIC | num$ = "567"
REPEAT
PRINT num$
PROCinc$(num$)
UNTIL FALSE
END
DEF PROCinc$(RETURN n$)
LOCAL A$, I%
I% = LEN(n$)
REPEAT
A$ = CHR$(ASCMID$(n$,I%) + 1)
IF A$=":" A$ = "0"
MID$(n$,I%,1) = A$
I% -= 1
UNTIL A$<>"0" OR I%=0... |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Brat | Brat | first = ask("First integer: ").to_i
second = ask("Second integer: ").to_i
when { first > second } { p "#{first} is greater than #{second}" }
{ first < second } { p "#{first} is less than #{second}" }
{ first == second } { p "#{first} is equal to #{second}" } |
http://rosettacode.org/wiki/Include_a_file | Include a file | Task
Demonstrate the language's ability to include source code from other files.
See Also
Compiler/Simple file inclusion pre processor
| #D.C3.A9j.C3.A0_Vu | Déjà Vu | #with the module system:
!import!foo
#passing a file name (only works with compiled bytecode files):
!run-file "/path/file.vu" |
http://rosettacode.org/wiki/Inheritance/Single | Inheritance/Single | This task is about derived types; for implementation inheritance, see Polymorphism.
Inheritance is an operation of type algebra that creates a new type from one or several parent types.
The obtained type is called derived type.
It inherits some of the properties of its parent types.
Usually inherited properties... | #Objeck | Objeck | class Animal
{ #~ ... ~# }
class Dog from Animal
{ #~ ... ~# }
class Lab from Dog
{ #~ ... ~# }
class Collie from Dog
{ #~ ... ~# }
class Cat from Animal
{ #~ ... ~# } |
http://rosettacode.org/wiki/Inheritance/Single | Inheritance/Single | This task is about derived types; for implementation inheritance, see Polymorphism.
Inheritance is an operation of type algebra that creates a new type from one or several parent types.
The obtained type is called derived type.
It inherits some of the properties of its parent types.
Usually inherited properties... | #Objective-C | Objective-C | @interface Animal : NSObject
{
// ...
}
// ...
@end
@interface Dog : Animal
{
// ...
}
// ...
@end
@interface Lab : Dog
{
// ...
}
// ...
@end
@interface Collie : Dog
{
// ...
}
// ...
@end
@interface Cat : Animal
{
// ...
}
// ...
@end |
http://rosettacode.org/wiki/IBAN | IBAN |
This page uses content from Wikipedia. The original article was at IBAN. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
The International Bank Account Number (IBAN) is an internationally agree... | #Arturo | Arturo | ibanSize: #[
AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16
BH: 22, BA: 20, BR: 29, BG: 22, CR: 21, HR: 21, CY: 28
CZ: 24, DK: 18, DO: 28, EE: 20, FO: 18, FI: 18, FR: 27
GE: 22, DE: 22, GI: 23, GR: 27, GL: 18, GT: 28, HU: 28
IS: 26, IE: 22, IL: 23, IT: 27, KZ: 20, KW: 30, LV: 21
LB: 28, LI: 21, LT: 20, ... |
http://rosettacode.org/wiki/Humble_numbers | Humble numbers | Humble numbers are positive integers which have no prime factors > 7.
Humble numbers are also called 7-smooth numbers, and sometimes called highly composite,
although this conflicts with another meaning of highly composite numbers.
Another way to express the above is:
humble = 2i × 3j × 5k... | #ALGOL_W | ALGOL W | begin % find some Humble numbers - numbers with no prime factors above 7 %
% returns the minimum of a and b %
integer procedure min ( integer value a, b ) ; if a < b then a else b;
% find and print Humble Numbers %
integer MAX_HUMB... |
http://rosettacode.org/wiki/Humble_numbers | Humble numbers | Humble numbers are positive integers which have no prime factors > 7.
Humble numbers are also called 7-smooth numbers, and sometimes called highly composite,
although this conflicts with another meaning of highly composite numbers.
Another way to express the above is:
humble = 2i × 3j × 5k... | #AWK | AWK |
# syntax: GAWK -f HUMBLE_NUMBERS.AWK
#
# sorting:
# PROCINFO["sorted_in"] is used by GAWK
# SORTTYPE is used by Thompson Automation's TAWK
#
BEGIN {
PROCINFO["sorted_in"] = "@ind_num_asc" ; SORTTYPE = 1
n = 1
for (; count<5193; n++) {
if (is_humble(n)) {
arr[length(n)]++
if (coun... |
http://rosettacode.org/wiki/Identity_matrix | Identity matrix | Task
Build an identity matrix of a size known at run-time.
An identity matrix is a square matrix of size n × n,
where the diagonal elements are all 1s (ones),
and all the other elements are all 0s (zeroes).
I
n
=
[
1
0
0
⋯
0
0
1
0
⋯
0
0
0
1
⋯
0
⋮
⋮
⋮
⋱
... | #ALGOL_W | ALGOL W | begin
% set m to an identity matrix of size s %
procedure makeIdentity( real array m ( *, * )
; integer value s
) ;
for i := 1 until s do begin
for j := 1 until s do m( i, j ) := 0.0;
m( i, i ... |
http://rosettacode.org/wiki/Hunt_the_Wumpus | Hunt the Wumpus | This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion.
Create a simple implementation of the classic textual game Hunt The Wumpus.
The rules are:
The game is set in a cave that consists ... | #Go | Go | package main
import (
"bufio"
"fmt"
"log"
"math/rand"
"os"
"strconv"
"strings"
"time"
)
var cave = map[int][3]int{
1: {2, 3, 4}, 2: {1, 5, 6}, 3: {1, 7, 8}, 4: {1, 9, 10}, 5: {2, 9, 11},
6: {2, 7, 12}, 7: {3, 6, 13}, 8: {3, 10, 14}, 9: {4, 5, 15}, 10: {4, 8, 16},
11: {5, ... |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #Raku | Raku | given (0..0x1fffd).chrs {
say "Lowercase: ", .comb(/<:Ll>/);
say "Uppercase: ", .comb(/<:Lu>/);
say "Titlecase: ", .comb(/<:Lt>/);
} |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #REXX | REXX | /*REXX program determines what characters are lowercase and uppercase (Latin) letters.*/
$L= /*set lowercase alphabet string to null*/
$U= /* " uppercase " " " " */
do #=0 for 2**8 ... |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #Ring | Ring | # Project : Idiomatically determine all the lowercase and uppercase letters
aList = "a":"z"
see "Lower case : "
for n=1 to len(aList)
see aList[n]
next
see nl
see "Upper case : "
aList = "A":"Z"
for n=1 to len(aList)
see aList[n]
next |
http://rosettacode.org/wiki/Imaginary_base_numbers | Imaginary base numbers | Imaginary base numbers are a non-standard positional numeral system which uses an imaginary number as its radix. The most common is quater-imaginary with radix 2i.
The quater-imaginary numeral system was first proposed by Donald Knuth in 1955 as a submission for a high school science talent search. [Ref.]
Other imagi... | #Modula-2 | Modula-2 | MODULE ImaginaryBase;
FROM FormatString IMPORT FormatString;
FROM RealMath IMPORT round;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
(* Helper *)
TYPE
String = ARRAY[0..10] OF CHAR;
StringBuilder = RECORD
buf : String;
ptr : CARDINAL;
END;
PROCEDURE ToChar(n : INTEGER) : CHAR;
... |
http://rosettacode.org/wiki/Image_noise | Image noise | Generate a random black and white 320x240 image continuously,
showing FPS (frames per second).
A sample image
| #Go | Go | package main
import (
"code.google.com/p/x-go-binding/ui/x11"
"fmt"
"image"
"image/color"
"image/draw"
"log"
"os"
"time"
)
var randcol = genrandcol()
func genrandcol() <-chan color.Color {
c := make(chan color.Color)
go func() {
for {
select {
... |
http://rosettacode.org/wiki/Image_convolution | Image convolution | One class of image digital filters is described by a rectangular matrix of real coefficients called kernel convoluted in a sliding window of image pixels. Usually the kernel is square
K
k
l
{\displaystyle K_{kl}}
, where k, l are in the range -R,-R+1,..,R-1,R. W=2R+1 is the kernel width. The filter determine... | #Maple | Maple | pic:=Import("smiling_dog.jpg"):
mask := Matrix([[1,2,3],[4,5,6],[7,8,9]]);
pic := ImageTools:-Convolution(pic, mask); |
http://rosettacode.org/wiki/Image_convolution | Image convolution | One class of image digital filters is described by a rectangular matrix of real coefficients called kernel convoluted in a sliding window of image pixels. Usually the kernel is square
K
k
l
{\displaystyle K_{kl}}
, where k, l are in the range -R,-R+1,..,R-1,R. W=2R+1 is the kernel width. The filter determine... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | img = Import[NotebookDirectory[] <> "Lenna50.jpg"];
kernel = {{0, -1, 0}, {-1, 4, -1}, {0, -1, 0}};
ImageConvolve[img, kernel]
ImageConvolve[img, GaussianMatrix[35] ]
ImageConvolve[img, BoxMatrix[1] ] |
http://rosettacode.org/wiki/Integer_sequence | Integer sequence | Task
Create a program that, when run, would display all integers from 1 to ∞ (or any relevant implementation limit), in sequence (i.e. 1, 2, 3, 4, etc) if given enough time.
An example may not be able to reach arbitrarily-large numbers based on implementations limits. For example, if integer... | #Factor | Factor | USE: lists.lazy
1 lfrom [ . ] leach |
http://rosettacode.org/wiki/Integer_sequence | Integer sequence | Task
Create a program that, when run, would display all integers from 1 to ∞ (or any relevant implementation limit), in sequence (i.e. 1, 2, 3, 4, etc) if given enough time.
An example may not be able to reach arbitrarily-large numbers based on implementations limits. For example, if integer... | #Fantom | Fantom |
class Main
{
public static Void main()
{
i := 1
while (true)
{
echo (i)
i += 1
}
}
}
|
http://rosettacode.org/wiki/Infinity | Infinity | Task
Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity. Otherwise, return the largest possible po... | #Lambdatalk | Lambdatalk |
{/ 1 0}
-> Infinity
{/ 1 Infinity}
-> 0
{< {pow 10 100} Infinity}
-> true
{< {pow 10 1000} Infinity}
-> false
|
http://rosettacode.org/wiki/Infinity | Infinity | Task
Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity. Otherwise, return the largest possible po... | #Lasso | Lasso | infinity
'<br />'
infinity -> type |
http://rosettacode.org/wiki/Infinity | Infinity | Task
Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity. Otherwise, return the largest possible po... | #Lingo | Lingo | x = (1-power(2, -53)) * power(2, 1023) * 2
put ilk(x), x
-- #float 1.79769313486232e308
x = (1-power(2, -53)) * power(2, 1023) * 3
put ilk(x), x, -x
-- #float INF -INF |
http://rosettacode.org/wiki/Integer_overflow | Integer overflow | Some languages support one or more integer types of the underlying processor.
This integer types have fixed size; usually 8-bit, 16-bit, 32-bit, or 64-bit.
The integers supported by such a type can be signed or unsigned.
Arithmetic for machine level integers can often be done by single CPU instruct... | #Ruby | Ruby | 2.1.1 :001 > a = 2**62 -1
=> 4611686018427387903
2.1.1 :002 > a.class
=> Fixnum
2.1.1 :003 > (b = a + 1).class
=> Bignum
2.1.1 :004 > (b-1).class
=> Fixnum
|
http://rosettacode.org/wiki/Integer_overflow | Integer overflow | Some languages support one or more integer types of the underlying processor.
This integer types have fixed size; usually 8-bit, 16-bit, 32-bit, or 64-bit.
The integers supported by such a type can be signed or unsigned.
Arithmetic for machine level integers can often be done by single CPU instruct... | #Rust | Rust | error: attempt to divide with overflow
--> src/main.rs:3:23
|
3 | let i32_5 : i32 = (-2_147_483_647 - 1) / -1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[deny(const_err)]` on by default
|
http://rosettacode.org/wiki/Input_loop | Input loop | Input loop is part of Short Circuit's Console Program Basics selection.
Task
Read from a text stream either word-by-word or line-by-line until the stream runs out of data.
The stream will have an unknown amount of data on it.
| #Kotlin | Kotlin | // version 1.1
import java.util.*
fun main(args: Array<String>) {
println("Keep entering text or the word 'quit' to end the program:")
val sc = Scanner(System.`in`)
val words = mutableListOf<String>()
while (true) {
val input: String = sc.next()
if (input.trim().toLowerCase() == "qui... |
http://rosettacode.org/wiki/Input_loop | Input loop | Input loop is part of Short Circuit's Console Program Basics selection.
Task
Read from a text stream either word-by-word or line-by-line until the stream runs out of data.
The stream will have an unknown amount of data on it.
| #Lang5 | Lang5 | : read-lines do read . "\n" . eof if break then loop ;
: ==>contents
'< swap open 'fh set fh fin read-lines fh close ;
'file.txt ==>contents |
http://rosettacode.org/wiki/Inverted_index | Inverted index | An Inverted Index is a data structure used to create full text search.
Task
Given a set of text files, implement a program to create an inverted index.
Also create a user interface to do a search using that inverted index which returns a list of files that contain the query term / terms.
The search index can be i... | #REXX | REXX | /*REXX program illustrates building a simple inverted index and a method of word find.*/
@.= /*a dictionary of words (so far). */
!= /*a list of found words (so far). */
call invertI 0, 'BURMA0.TXT' ... |
http://rosettacode.org/wiki/Introspection | Introspection | Task
verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old.
check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop).
Extra credit
Repor... | #R | R |
if(getRversion() < "2.14.1")
{
warning("Your version of R is older than 2.14.1")
q() # exit R, with the option to cancel
} |
http://rosettacode.org/wiki/Introspection | Introspection | Task
verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old.
check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop).
Extra credit
Repor... | #Racket | Racket |
#lang racket
(unless (string<=? "5.3" (version)) (error "ancient version"))
|
http://rosettacode.org/wiki/Josephus_problem | Josephus problem | Josephus problem is a math puzzle with a grim description:
n
{\displaystyle n}
prisoners are standing on a circle, sequentially numbered from
0
{\displaystyle 0}
to
n
−
1
{\displaystyle n-1}
.
An executioner walks along the circle, starting from prisoner
0
{\displaystyle 0}
,
removing eve... | #PL.2FI | PL/I | *process or(!) source attributes xref;
joseph: Proc Options(main);
/* REXX **************************************************************
* 15.11.2012 Walter Pachl - my own solution
* 16.11.2012 Walter Pachl generalized n prisoners + w killing distance
* and s=number of survivors
* 03.05.2... |
http://rosettacode.org/wiki/Interactive_programming_(repl) | Interactive programming (repl) | Many language implementations come with an interactive mode.
This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.
An interactive mode may also be known as a command mode, a read-eval-print loop (REPL), or a shell.
Task
Show how to start this... | #Tcl | Tcl | $ tclsh
% proc f {s1 s2 sep} {
append result $s1 $sep $sep $s2
}
% f Rosetta Code :
Rosetta::Code
% exit |
http://rosettacode.org/wiki/Interactive_programming_(repl) | Interactive programming (repl) | Many language implementations come with an interactive mode.
This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.
An interactive mode may also be known as a command mode, a read-eval-print loop (REPL), or a shell.
Task
Show how to start this... | #TI-89_BASIC | TI-89 BASIC | ■ x & s & s & y → f(x,y,s)
Done
■ f("Rosetta", "Code", ":")
"Rosetta::Code" |
http://rosettacode.org/wiki/Interactive_programming_(repl) | Interactive programming (repl) | Many language implementations come with an interactive mode.
This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.
An interactive mode may also be known as a command mode, a read-eval-print loop (REPL), or a shell.
Task
Show how to start this... | #UNIX_Shell | UNIX Shell | $ sh
sh-3.2$ concat() { echo "$1$3$3$2"; }
sh-3.2$ concat Rosetta Code :
Rosetta::Code
sh-3.2$ |
http://rosettacode.org/wiki/ISBN13_check_digit | ISBN13 check digit | Task
Validate the check digit of an ISBN-13 code:
Multiply every other digit by 3.
Add these numbers and the other digits.
Take the remainder of this number after division by 10.
If it is 0, the ISBN-13 check digit is correct.
Use the following codes for testing:
978-1734314502 (good)
... | #zkl | zkl | fcn ISBN13_check(isbn){ // "978-1734314502", throws on invalid digits
var [const] one3=("13"*6 + 1).split("").apply("toInt"); // examine 13 digits
// one3=("13"*6) if you want to calculate what the check digit should be
one3.zipWith('*,isbn - " -").sum(0) % 10 == 0
} |
http://rosettacode.org/wiki/I_before_E_except_after_C | I before E except after C | The phrase "I before E, except after C" is a
widely known mnemonic which is supposed to help when spelling English words.
Task
Using the word list from http://wiki.puzzlers.org/pub/wordlists/unixdict.txt,
check if the two sub-clauses of the phrase are plausible individually:
"I before E when not pre... | #AWK | AWK | #!/usr/bin/awk -f
/.ei/ {nei+=cnt($3)}
/cei/ {cei+=cnt($3)}
/.ie/ {nie+=cnt($3)}
/cie/ {cie+=cnt($3)}
function cnt(c) {
if (c<1) return 1;
return c;
}
END {
printf("cie: %i\nnie: %i\ncei: %i\nnei: %i\n",cie,nie-cie,cei,nei-cei);
v = v2 = "";
if (nie < 3 * cie) {
v =" not";
}
print "I before E when no... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Boo | Boo | s = "1234"
s = (int.Parse(s) + 1).ToString() |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #BQN | BQN | 1•Repr∘+•BQN "1234" |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Burlesque | Burlesque |
blsq ) "5 6"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
The first one is less than the second one
blsq ) "6 6"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
They... |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #C | C | #include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
if (a < b)
printf("%d is less than %d\n", a, b);
if (a == b)
printf("%d is equal to %d\n", a, b);
if (a > b)
printf("%d is greater than %d\n", a, b);
return 0;
} |
http://rosettacode.org/wiki/Include_a_file | Include a file | Task
Demonstrate the language's ability to include source code from other files.
See Also
Compiler/Simple file inclusion pre processor
| #Emacs_Lisp | Emacs Lisp |
(defun sum (ls)
(apply '+ ls) )
|
http://rosettacode.org/wiki/Include_a_file | Include a file | Task
Demonstrate the language's ability to include source code from other files.
See Also
Compiler/Simple file inclusion pre processor
| #Erlang | Erlang |
-include("my_header.hrl"). % Includes the file at my_header.erl
|
http://rosettacode.org/wiki/Include_a_file | Include a file | Task
Demonstrate the language's ability to include source code from other files.
See Also
Compiler/Simple file inclusion pre processor
| #Euphoria | Euphoria |
include my_header.e
|
http://rosettacode.org/wiki/Inheritance/Single | Inheritance/Single | This task is about derived types; for implementation inheritance, see Polymorphism.
Inheritance is an operation of type algebra that creates a new type from one or several parent types.
The obtained type is called derived type.
It inherits some of the properties of its parent types.
Usually inherited properties... | #OCaml | OCaml | class animal =
object (self)
(*functions go here...*)
end |
http://rosettacode.org/wiki/Inheritance/Single | Inheritance/Single | This task is about derived types; for implementation inheritance, see Polymorphism.
Inheritance is an operation of type algebra that creates a new type from one or several parent types.
The obtained type is called derived type.
It inherits some of the properties of its parent types.
Usually inherited properties... | #Oforth | Oforth | Object Class new: Animal
Animal Class new: Cat
Animal Class new: Dog
Dog Class new: Lab
Dog Class new: Collie |
http://rosettacode.org/wiki/Inheritance/Single | Inheritance/Single | This task is about derived types; for implementation inheritance, see Polymorphism.
Inheritance is an operation of type algebra that creates a new type from one or several parent types.
The obtained type is called derived type.
It inherits some of the properties of its parent types.
Usually inherited properties... | #ooRexx | ooRexx |
-- subclass of object by default
::class animal
::class cat subclass animal
::class dog subclass animal
::class lab subclass dog
::class collie subclass dog
|
http://rosettacode.org/wiki/IBAN | IBAN |
This page uses content from Wikipedia. The original article was at IBAN. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
The International Bank Account Number (IBAN) is an internationally agree... | #AutoHotkey | AutoHotkey | IBANs := ["GB82 WEST 1234 5698 7654 32"
, "gb82 WEST 1234 5698 7654 32"
, "GB82WEST12345698765432"
, "GB82 WEST 234 5698 7654 32"
, "GB82 WEST 1234 5698 7654 33"
, "AE82 WEST 1234 5698 7654 32"]
for k, v in IBANs
Output .= v " is" (ValidIBAN(v) ? "" : " not") " valid.`n"
MsgBox, % Output
ValidIBAN(n) {
static ... |
http://rosettacode.org/wiki/Humble_numbers | Humble numbers | Humble numbers are positive integers which have no prime factors > 7.
Humble numbers are also called 7-smooth numbers, and sometimes called highly composite,
although this conflicts with another meaning of highly composite numbers.
Another way to express the above is:
humble = 2i × 3j × 5k... | #C | C | #include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
bool isHumble(int i) {
if (i <= 1) return true;
if (i % 2 == 0) return isHumble(i / 2);
if (i % 3 == 0) return isHumble(i / 3);
if (i % 5 == 0) return isHumble(i / 5);
if (i % 7 == 0) return isHumble(i / 7);
return... |
http://rosettacode.org/wiki/Identity_matrix | Identity matrix | Task
Build an identity matrix of a size known at run-time.
An identity matrix is a square matrix of size n × n,
where the diagonal elements are all 1s (ones),
and all the other elements are all 0s (zeroes).
I
n
=
[
1
0
0
⋯
0
0
1
0
⋯
0
0
0
1
⋯
0
⋮
⋮
⋮
⋱
... | #APL | APL |
∘.=⍨⍳3
1 0 0
0 1 0
0 0 1
|
http://rosettacode.org/wiki/Hunt_the_Wumpus | Hunt the Wumpus | This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion.
Create a simple implementation of the classic textual game Hunt The Wumpus.
The rules are:
The game is set in a cave that consists ... | #Haskell | Haskell | import System.Random
import System.IO
import Data.List
import Data.Char
import Control.Monad
-- Rooms
cave :: [[Int]]
cave = [
[1,4,7], [0,2,9], [1,3,11], [2,4,13], [0,3,5],
[4,6,14], [5,7,16], [0,6,8], [7,9,17], [1,8,10],
[9,11,18], [2,10,12], [11,13,19], [3,12,14], [5,13,15],
[14,... |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #Ruby | Ruby | puts "Lowercase:", [*"a".."z"].join, "Uppercase:", [*"A".."Z"].join |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #Rust | Rust | fn main() {
println!(
"Lowercase letters: {}",
(b'a'..=b'z').map(|c| c as char).collect::<String>()
);
println!(
"Uppercase letters: {}",
(b'A'..=b'Z').map(|c| c as char).collect::<String>()
);
}
|
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #Scala | Scala | object IdiomaticallyDetermineLowercaseUppercase extends App {
println("Upper case: "
+ (0 to 0x10FFFF).map(_.toChar).filter(_.isUpper).take(72).mkString + "...")
println("Lower case: "
+ (0 to 0x10FFFF).map(_.toChar).filter(_.isLower).take(72).mkString + "...")
} |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #Tcl | Tcl | for {set c 0} {$c <= 0xffff} {incr c} {
set ch [format "%c" $c]
if {[string is upper $ch]} {lappend upper $ch}
if {[string is lower $ch]} {lappend lower $ch}
}
puts "Upper: $upper"
puts "Lower: $lower" |
http://rosettacode.org/wiki/Imaginary_base_numbers | Imaginary base numbers | Imaginary base numbers are a non-standard positional numeral system which uses an imaginary number as its radix. The most common is quater-imaginary with radix 2i.
The quater-imaginary numeral system was first proposed by Donald Knuth in 1955 as a submission for a high school science talent search. [Ref.]
Other imagi... | #Nim | Nim | import algorithm, complex, math, strformat, strutils
const
TwoI = complex(0.0, 2.0)
InvTwoI = inv(TwoI)
type QuaterImaginery = object
b2i: string
# Conversions between digit character and digit value.
template digitChar(n: range[0..9]): range['0'..'9'] = chr(n + ord('0'))
template digitValue(c: range['0'..'... |
http://rosettacode.org/wiki/Image_noise | Image noise | Generate a random black and white 320x240 image continuously,
showing FPS (frames per second).
A sample image
| #Haskell | Haskell | cabal install glfw-b |
http://rosettacode.org/wiki/Image_noise | Image noise | Generate a random black and white 320x240 image continuously,
showing FPS (frames per second).
A sample image
| #Icon_and_Unicon | Icon and Unicon | link printf
procedure main()
&window := open("B&W noise 320x240","g","size=320,240","bg=white","fg=black") |
stop("Open window failed ")
runtime := 10 # seconds to run
sec := &now
frames := 0
until (&now - sec) >= runtime do {
s := "320,#"
every 1 to 240 & 1 to 320/4 do s ||... |
http://rosettacode.org/wiki/Image_convolution | Image convolution | One class of image digital filters is described by a rectangular matrix of real coefficients called kernel convoluted in a sliding window of image pixels. Usually the kernel is square
K
k
l
{\displaystyle K_{kl}}
, where k, l are in the range -R,-R+1,..,R-1,R. W=2R+1 is the kernel width. The filter determine... | #MATLAB | MATLAB | function testConvImage
Im = [1 2 1 5 5 ; ...
1 2 7 9 9 ; ...
5 5 5 5 5 ; ...
5 2 2 2 2 ; ...
1 1 1 1 1 ]; % Sample image for example illustration only
Ker = [1 2 1 ; ...
2 4 2 ; ...
1 2 1 ]; % Gaussian smoothing (without normalizing)
... |
http://rosettacode.org/wiki/Integer_sequence | Integer sequence | Task
Create a program that, when run, would display all integers from 1 to ∞ (or any relevant implementation limit), in sequence (i.e. 1, 2, 3, 4, etc) if given enough time.
An example may not be able to reach arbitrarily-large numbers based on implementations limits. For example, if integer... | #Fermat | Fermat | n:=0;
while 1 do !n;!' '; n:=n+1 od |
http://rosettacode.org/wiki/Integer_sequence | Integer sequence | Task
Create a program that, when run, would display all integers from 1 to ∞ (or any relevant implementation limit), in sequence (i.e. 1, 2, 3, 4, etc) if given enough time.
An example may not be able to reach arbitrarily-large numbers based on implementations limits. For example, if integer... | #Fish | Fish | 0>:n1+v
^o" "< |
http://rosettacode.org/wiki/Infinity | Infinity | Task
Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity. Otherwise, return the largest possible po... | #Lua | Lua |
function infinity()
return 1/0 --lua uses unboxed C floats for all numbers
end
|
http://rosettacode.org/wiki/Infinity | Infinity | Task
Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity. Otherwise, return the largest possible po... | #M2000_Interpreter | M2000 Interpreter |
Rem : locale 1033
Module CheckIt {
Form 66,40
Cls 5
Pen 14
\\ Ensure True/False for Print boolean (else -1/0)
\\ from m2000 console use statement Switches without Set.
\\ use Monitor statement to see all switches.
Set Switches "+SBL"
IF version<9.4 then exit
IF ve... |
http://rosettacode.org/wiki/Infinity | Infinity | Task
Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity. Otherwise, return the largest possible po... | #Maple | Maple |
> proc() Float(infinity) end();
Float(infinity)
|
http://rosettacode.org/wiki/Infinity | Infinity | Task
Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity. Otherwise, return the largest possible po... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | Sum[1/n^2,{n,Infinity}]
1/Infinity
Integrate[Exp[-x^2], {x, -Infinity, Infinity}]
10^100 < Infinity |
http://rosettacode.org/wiki/Integer_overflow | Integer overflow | Some languages support one or more integer types of the underlying processor.
This integer types have fixed size; usually 8-bit, 16-bit, 32-bit, or 64-bit.
The integers supported by such a type can be signed or unsigned.
Arithmetic for machine level integers can often be done by single CPU instruct... | #Scala | Scala | import Math.{addExact => ++, multiplyExact => **, negateExact => ~~, subtractExact => --}
def requireOverflow(f: => Unit) =
try {f; println("Undetected overflow")} catch{case e: Exception => /* caught */}
println("Testing overflow detection for 32-bit unsigned integers")
requireOverflow(~~(--(~~(2147483647), 1)))... |
http://rosettacode.org/wiki/Integer_overflow | Integer overflow | Some languages support one or more integer types of the underlying processor.
This integer types have fixed size; usually 8-bit, 16-bit, 32-bit, or 64-bit.
The integers supported by such a type can be signed or unsigned.
Arithmetic for machine level integers can often be done by single CPU instruct... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: writeResult (ref func integer: expression) is func
begin
block
writeln(expression);
exception
catch OVERFLOW_ERROR: writeln("OVERFLOW_ERROR");
end block;
end func;
const proc: main is func
begin
writeResult(-(-9223372036854775807-1));
write... |
http://rosettacode.org/wiki/Input_loop | Input loop | Input loop is part of Short Circuit's Console Program Basics selection.
Task
Read from a text stream either word-by-word or line-by-line until the stream runs out of data.
The stream will have an unknown amount of data on it.
| #Lasso | Lasso |
local(
myfile = file('//path/to/file.txt'),
textresult = array
)
#myfile -> foreachline => {
#textresult -> insert(#1)
}
#textresult -> join('<br />') |
http://rosettacode.org/wiki/Input_loop | Input loop | Input loop is part of Short Circuit's Console Program Basics selection.
Task
Read from a text stream either word-by-word or line-by-line until the stream runs out of data.
The stream will have an unknown amount of data on it.
| #Liberty_BASIC | Liberty BASIC |
filedialog "Open","*.txt",file$
if file$="" then end
open file$ for input as #f
while not(eof(#f))
line input #f, t$
print t$
wend
close #f
end |
http://rosettacode.org/wiki/Inverted_index | Inverted index | An Inverted Index is a data structure used to create full text search.
Task
Given a set of text files, implement a program to create an inverted index.
Also create a user interface to do a search using that inverted index which returns a list of files that contain the query term / terms.
The search index can be i... | #Ruby | Ruby | if File.exist? "index.dat"
@data = Marshal.load open("index.dat")
else
@data = {}
end
# Let's give the string class the ability to tokenize itsself into lowercase
# words with no punctuation.
class String
def index_sanitize
self.split.collect do |token|
token.downcase.gsub(/\W/, '')
end
end
end
... |
http://rosettacode.org/wiki/Introspection | Introspection | Task
verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old.
check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop).
Extra credit
Repor... | #Raku | Raku | my $bloop = -123;
if MY::{'$bloop'}.defined and CORE::{'&abs'}.defined { say abs $bloop }
my @ints = ($_ when Int for PROCESS::.values);
say "Number of PROCESS vars of type Int: ", +@ints;
say "PROCESS vars of type Int add up to ", [+] @ints; |
http://rosettacode.org/wiki/Introspection | Introspection | Task
verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old.
check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop).
Extra credit
Repor... | #Raven | Raven | VERSION 0 prefer 20071104 <
if 'version >= 20071104 required' print bye
'bloop' GLOBAL keys in && 'abs' CORE keys in
if bloop abs print |
http://rosettacode.org/wiki/Josephus_problem | Josephus problem | Josephus problem is a math puzzle with a grim description:
n
{\displaystyle n}
prisoners are standing on a circle, sequentially numbered from
0
{\displaystyle 0}
to
n
−
1
{\displaystyle n-1}
.
An executioner walks along the circle, starting from prisoner
0
{\displaystyle 0}
,
removing eve... | #PowerShell | PowerShell |
function Get-JosephusPrisoners ( [int]$N, [int]$K )
{
# Just for convenience
$End = $N - 1
# Create circle of prisoners
$Prisoners = New-Object System.Collections.ArrayList ( , (0..$End) )
# For each starting point of the reducing circle...
ForEach ( $Start in 0..($End - 1) )
... |
http://rosettacode.org/wiki/Interactive_programming_(repl) | Interactive programming (repl) | Many language implementations come with an interactive mode.
This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.
An interactive mode may also be known as a command mode, a read-eval-print loop (REPL), or a shell.
Task
Show how to start this... | #Ursa | Ursa | $ java -jar ursa.jar
cygnus/x ursa v0.76 (default, release 1)
[Oracle Corporation JVM 1.8.0_91 on Linux 3.16.0-4-686-pae i386]
> def f (string s1, string s2, string sep)
.. return (+ s1 sep sep s2)
..end
> out (f "Rosetta" "Code" ":") endl console
Rosetta::Code
> _ |
http://rosettacode.org/wiki/Interactive_programming_(repl) | Interactive programming (repl) | Many language implementations come with an interactive mode.
This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.
An interactive mode may also be known as a command mode, a read-eval-print loop (REPL), or a shell.
Task
Show how to start this... | #Vedit_macro_language | Vedit macro language | RS(100, "RS(10, @1) RS(10, @3, APPEND) RS(10, @3, APPEND) RS(10, @2, APPEND)") |
http://rosettacode.org/wiki/Interactive_programming_(repl) | Interactive programming (repl) | Many language implementations come with an interactive mode.
This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions.
An interactive mode may also be known as a command mode, a read-eval-print loop (REPL), or a shell.
Task
Show how to start this... | #XLISP | XLISP | XLISP 3.3, September 6, 2002 Copyright (c) 1984-2002, by David Betz
[1] (defun f (a b sep)
(string-append a sep sep b))
F
[2] (f "Rosetta" "Code" ":")
"Rosetta::Code"
[3] |
http://rosettacode.org/wiki/I_before_E_except_after_C | I before E except after C | The phrase "I before E, except after C" is a
widely known mnemonic which is supposed to help when spelling English words.
Task
Using the word list from http://wiki.puzzlers.org/pub/wordlists/unixdict.txt,
check if the two sub-clauses of the phrase are plausible individually:
"I before E when not pre... | #Batch_File | Batch File | ::I before E except after C task from Rosetta Code Wiki
::Batch File Implementation
@echo off
setlocal enabledelayedexpansion
::Initialization
set ie=0
set ei=0
set cie=0
set cei=0
set propos1=FALSE
set propos2=FALSE
set propos3=FALSE
::Do the matching
for /f %%X in (unixdict.txt) do (
set word=%%X
if not "!wo... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Bracmat | Bracmat | (n=35664871829866234762187538073934873121878/6172839450617283945)
&!n+1:?n
&out$!n
35664871829866234762193710913385490405823/6172839450617283945
|
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Brat | Brat | #Convert to integer, increment, then back to string
p ("100".to_i + 1).to_s #Prints 101 |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #C.23 | C# | using System;
class Program
{
static void Main()
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
if (a < b)
Console.WriteLine("{0} is less than {1}", a, b);
if (a == b)
Console.WriteLine("{0} equals {1}", a, b);
if... |
http://rosettacode.org/wiki/Include_a_file | Include a file | Task
Demonstrate the language's ability to include source code from other files.
See Also
Compiler/Simple file inclusion pre processor
| #Factor | Factor |
USING: vocaba vocabb... ;
|
http://rosettacode.org/wiki/Include_a_file | Include a file | Task
Demonstrate the language's ability to include source code from other files.
See Also
Compiler/Simple file inclusion pre processor
| #Forth | Forth | include matrix.fs |
http://rosettacode.org/wiki/Include_a_file | Include a file | Task
Demonstrate the language's ability to include source code from other files.
See Also
Compiler/Simple file inclusion pre processor
| #Fortran | Fortran | include ''char-literal-constant'' |
http://rosettacode.org/wiki/Inheritance/Single | Inheritance/Single | This task is about derived types; for implementation inheritance, see Polymorphism.
Inheritance is an operation of type algebra that creates a new type from one or several parent types.
The obtained type is called derived type.
It inherits some of the properties of its parent types.
Usually inherited properties... | #OxygenBasic | OxygenBasic |
class animal
method show() as string
return "Animal "
end method
end Class
class dog
from Animal
method show() as string
return animal.show()+"dog "
end method
end Class
class cat
from animal
method show() as string
return animal.show()+"cat "
end method
end Class
class Lab
from dog
me... |
http://rosettacode.org/wiki/Inheritance/Single | Inheritance/Single | This task is about derived types; for implementation inheritance, see Polymorphism.
Inheritance is an operation of type algebra that creates a new type from one or several parent types.
The obtained type is called derived type.
It inherits some of the properties of its parent types.
Usually inherited properties... | #Oz | Oz | class Animal
%% ...
end
class Dog from Animal
%% ...
end
class Lab from Dog
%% ...
end
class Collie from Dog
%% ...
end
class Cat from Animal
%% ...
end |
http://rosettacode.org/wiki/Inheritance/Single | Inheritance/Single | This task is about derived types; for implementation inheritance, see Polymorphism.
Inheritance is an operation of type algebra that creates a new type from one or several parent types.
The obtained type is called derived type.
It inherits some of the properties of its parent types.
Usually inherited properties... | #Pascal | Pascal | package Animal;
#functions go here...
1; |
http://rosettacode.org/wiki/IBAN | IBAN |
This page uses content from Wikipedia. The original article was at IBAN. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
The International Bank Account Number (IBAN) is an internationally agree... | #AWK | AWK |
@load "ordchr"
function invalid() { print("INVALID " $0); next }
function valid() { print("VALID__ " $0) }
BEGIN {
ccibanlen["AL"] = 28; ccibanlen["AD"] = 24; ccibanlen["AT"] = 20;
ccibanlen["AZ"] = 28; ccibanlen["BH"] = 22; ccibanlen["BA"] = 20;
ccibanlen["BR"] = 29; ccibanlen["BG"] = 22; cciba... |
http://rosettacode.org/wiki/Humble_numbers | Humble numbers | Humble numbers are positive integers which have no prime factors > 7.
Humble numbers are also called 7-smooth numbers, and sometimes called highly composite,
although this conflicts with another meaning of highly composite numbers.
Another way to express the above is:
humble = 2i × 3j × 5k... | #C.23 | C# | using System;
using System.Collections.Generic;
namespace HumbleNumbers {
class Program {
static bool IsHumble(int i) {
if (i <= 1) return true;
if (i % 2 == 0) return IsHumble(i / 2);
if (i % 3 == 0) return IsHumble(i / 3);
if (i % 5 == 0) return IsHumble(i... |
http://rosettacode.org/wiki/Identity_matrix | Identity matrix | Task
Build an identity matrix of a size known at run-time.
An identity matrix is a square matrix of size n × n,
where the diagonal elements are all 1s (ones),
and all the other elements are all 0s (zeroes).
I
n
=
[
1
0
0
⋯
0
0
1
0
⋯
0
0
0
1
⋯
0
⋮
⋮
⋮
⋱
... | #AppleScript | AppleScript | --------------------- IDENTITY MATRIX ----------------------
-- identityMatrix :: Int -> [(0|1)]
on identityMatrix(n)
set xs to enumFromTo(1, n)
script row
on |λ|(x)
script col
on |λ|(i)
if i = x then
1
else
... |
http://rosettacode.org/wiki/Hunt_the_Wumpus | Hunt the Wumpus | This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion.
Create a simple implementation of the classic textual game Hunt The Wumpus.
The rules are:
The game is set in a cave that consists ... | #IS-BASIC | IS-BASIC | 100 PROGRAM "Wumpus.bas"
110 RANDOMIZE
120 NUMERIC RO(1 TO 20,1 TO 3),LO(1 TO 20),WPOS
130 LET ARROWS=5:LET L=1
140 CALL INIT
150 DO
160 PRINT :PRINT "You are in room";L
170 PRINT "Tunnels lead to ";RO(L,1);RO(L,2);RO(L,3)
180 IF MON(1) THEN PRINT "You smell something terrible nearby."
190 IF MON(2) OR MON(3)... |
http://rosettacode.org/wiki/Hunt_the_Wumpus | Hunt the Wumpus | This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion.
Create a simple implementation of the classic textual game Hunt The Wumpus.
The rules are:
The game is set in a cave that consists ... | #Java | Java | const starttxt = """
ATTENTION ALL WUMPUS LOVERS!!!
THERE ARE NOW TWO ADDITIONS TO THE WUMPUS FAMILY
OF PROGRAMS.
WUMP2: SOME DIFFERENT CAVE ARRANGEMENTS
WUMP3: DIFFERENT HAZARDS
"""
const helptxt = """
WELCOME TO 'HUNT THE WUMPUS'
THE WUMPUS LIVES IN A CAVE OF 20 ROOMS. ... |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #Wren | Wren | for (i in 97..122) System.write(String.fromByte(i))
System.print()
for (i in 65..90) System.write(String.fromByte(i))
System.print() |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #XBS | XBS | func printChars(from,to,st){
set arr=[];
for(c=from;to;1){
arr->push(string.byte(c));
}
log(st," ",arr);
del arr;
}
printChars(0x61,0x7a,"lowercase");
printChars(0x41,0x5a,"UPPERCASE"); |
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters | Idiomatically determine all the lowercase and uppercase letters |
Idiomatically determine all the lowercase and uppercase letters (of the Latin [English] alphabet) being used currently by a computer programming language.
The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other).
Task requirements
Display the set of... | #XPL0 | XPL0 | char C;
[for C:= 0 to 255 do
if C >=^a & C<=^z then ChOut(0, C);
CrLf(0);
for C:= 0 to 255 do
if C >=^A & C<=^Z then ChOut(0, C);
CrLf(0);
] |
http://rosettacode.org/wiki/Imaginary_base_numbers | Imaginary base numbers | Imaginary base numbers are a non-standard positional numeral system which uses an imaginary number as its radix. The most common is quater-imaginary with radix 2i.
The quater-imaginary numeral system was first proposed by Donald Knuth in 1955 as a submission for a high school science talent search. [Ref.]
Other imagi... | #Perl | Perl | use strict;
use warnings;
use feature 'say';
use Math::Complex;
use List::AllUtils qw(sum mesh);
use ntheory qw<todigitstring fromdigits>;
sub zip {
my($a,$b) = @_;
my($la, $lb) = (length $a, length $b);
my $l = '0' x abs $la - $lb;
$a .= $l if $la < $lb;
$b .= $l if $lb < $la;
(join('', mes... |
http://rosettacode.org/wiki/Image_noise | Image noise | Generate a random black and white 320x240 image continuously,
showing FPS (frames per second).
A sample image
| #J | J | coclass'example'
(coinsert[require)'jzopengl'
P=: 0 : 0
pc p nosize;
xywh 0 0 160 120;cc c isigraph opengl;
pas 0 0;pcenter;
rem form end;
pshow;
timer 1;
)
timestamp=: (6!:8'') %~ 6!:9
create=:3 :0
ogl=:''conew'jzopengl'
frames=:0
start=: timestamp''
sys_timer_base_=: ''1 :('p_c_paint_',(;coname''),'_'... |
http://rosettacode.org/wiki/Image_noise | Image noise | Generate a random black and white 320x240 image continuously,
showing FPS (frames per second).
A sample image
| #Java | Java | import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.Arrays;
import java.util.Random;
import javax.swing.*;
public class ImageNoise {
int framecount = 0;
int fps = 0;
BufferedImage image;
Kernel kernel;
ConvolveOp cop;
JFrame frame = new JFrame("Java Image Nois... |
http://rosettacode.org/wiki/Image_convolution | Image convolution | One class of image digital filters is described by a rectangular matrix of real coefficients called kernel convoluted in a sliding window of image pixels. Usually the kernel is square
K
k
l
{\displaystyle K_{kl}}
, where k, l are in the range -R,-R+1,..,R-1,R. W=2R+1 is the kernel width. The filter determine... | #Nim | Nim | import math, lenientops, strutils
import nimPNG, bitmap, grayscale_image
type ConvolutionFilter = object
kernel: seq[seq[float]]
divisor: float
offset: float
name: string
func convolve[T: Image|GrayImage](img: T; filter: ConvolutionFilter): T =
assert not img.isNil
assert filter.divisor.classify != fc... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.