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/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 ... | #Perl | Perl | #!/usr/bin/perl
use strict; # see https://rosettacode.org/wiki/Hunt_the_Wumpus
use warnings;
use List::Util qw( shuffle );
$| = 1;
my %tunnels = qw(A BKT B ACL C BDM D CEN E DFO F EGP G FHQ H GIR I HJS
J IKT K AJL L BKM M CLN N DMO O ENP P FOQ Q GPR R HQS S IRT T AJS);
my ($you, $wumpus, $bat1, $bat2, $pit1, $pit... |
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... | #Raku | Raku | multi sub base ( Real $num, Int $radix where -37 < * < -1, :$precision = -15 ) {
return '0' unless $num;
my $value = $num;
my $result = '';
my $place = 0;
my $upper-bound = 1 / (-$radix + 1);
my $lower-bound = $radix * $upper-bound;
$value = $num / $radix ** ++$place until $lower-bound <... |
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
| #Liberty_BASIC | Liberty BASIC |
WindowWidth =411
w =320
WindowHeight =356
h =240
open "Noise" for graphics_nsb as #w
#w "trapclose [quit]"
#w "down"
print "Creating BMP header"
'bitmap header, 320x240 pixels 256 colors
data 66,77,54,48,1,0,0,0,0,0,54,4,0,0,40,0,0,0,64,1
data 0,0,240,0,0,0,1,0,8,0,0,0,0,0,0,44,1,0,0,... |
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... | #PicoLisp | PicoLisp | (scl 3)
(de ppmConvolution (Ppm Kernel)
(let (Len (length (car Kernel)) Radius (/ Len 2))
(make
(chain (head Radius Ppm))
(for (Y Ppm T (cdr Y))
(NIL (nth Y Len)
(chain (tail Radius Y)) )
(link
(make
(chain (head Rad... |
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... | #Python | Python | #!/bin/python
from PIL import Image, ImageFilter
if __name__=="__main__":
im = Image.open("test.jpg")
kernelValues = [-2,-1,0,-1,1,1,0,1,2] #emboss
kernel = ImageFilter.Kernel((3,3), kernelValues)
im2 = im.filter(kernel)
im2.show() |
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... | #GAP | GAP | InfiniteLoop := function()
local n;
n := 1;
while true do
Display(n);
n := n + 1;
od;
end;
# Prepare some coffee
InfiniteLoop(); |
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... | #Go | Go | package main
import "fmt"
func main() {
for i := 1;; i++ {
fmt.Println(i)
}
} |
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... | #OpenEdge.2FProgress | OpenEdge/Progress | MESSAGE
1.0 / 0.0 SKIP
-1.0 / 0.0 SKIP(1)
( 1.0 / 0.0 ) = ( -1.0 / 0.0 )
VIEW-AS ALERT-BOX. |
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... | #OxygenBasic | OxygenBasic |
print 1.5e-400 '0
print 1.5e400 '#INF
print -1.5e400 '#-INF
print 0/-1.5 '-0
print 1.5/0 '#INF
print -1.5/0 '#-INF
print 0/0 '#qNAN
function f() as double
return -1.5/0
end function
print f '#-INF
|
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... | #Oz | Oz | declare
PosInf = 1./0.
NegInf = ~1./0.
in
{Show PosInf}
{Show NegInf}
%% some assertion
42. / PosInf = 0.
42. / NegInf = 0.
PosInf * PosInf = PosInf
PosInf * NegInf = NegInf
NegInf * NegInf = PosInf |
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... | #Visual_Basic | Visual Basic | 'Binary Integer overflow - vb6 - 28/02/2017
Dim i As Long '32-bit signed integer
i = -(-2147483647 - 1) '=-2147483648 ?! bug
i = -Int(-2147483647 - 1) '=-2147483648 ?! bug
i = 0 - (-2147483647 - 1) 'Run-time error '6' : Overflow
i = -2147483647: i = -(i - 1) 'Run-t... |
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... | #Visual_Basic_.NET | Visual Basic .NET | Constant expression not representable in type 'Integer/Long/UInteger'
|
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.
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | stream = OpenRead["file.txt"];
While[a != EndOfFile, Read[stream, Word]];
Close[stream] |
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.
| #MAXScript | MAXScript | fn ReadAFile FileName =
(
local in_file = openfile FileName
while not eof in_file do
(
--Do stuff in here--
print (readline in_file)
)
close in_file
) |
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... | #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
files="file1'file2'file3"
LOOP file=files
ERROR/STOP CREATE (file,seq-o,-std-)
ENDLOOP
content1="it is what it is"
content2="what is it"
content3="it is a banana"
FILE/ERASE "file1" = content1
FILE/ERASE "file2" = content2
FILE/ERASE "file3" = content3
ASK "search for": search=""
IF (search==... |
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... | #UNIX_Shell | UNIX Shell | #!/bin/ksh
typeset -A INDEX
function index {
typeset num=0
for file in "$@"; do
tr -s '[:punct:]' ' ' < "$file" | while read line; do
for token in $line; do
INDEX[$token][$num]=$file
done
done
((++num))
done
}
function search {
for token in "$@"; do
for file in "${INDEX[$... |
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... | #Smalltalk | Smalltalk | | s v t sum hm |
"uncomment the following to see what happens if bloop exists"
"Smalltalk at: #bloop put: -10."
s := Smalltalk version.
(s =~ '(\d+)\.(\d+)\.(\d+)')
ifMatched: [:match |
v := (( (match at: 1) asInteger ) * 100) +
(( (match at: 2) asInteger ) * 10) +
( (match at: 3) as... |
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... | #Quackery | Quackery | [ stack ] is survivors ( --> s )
[ stack ] is prisoners ( --> s )
[ stack ] is executioner-actions ( --> s )
[ [] swap times [ i^ join ]
prisoners put ] is make-prisoners ( n --> )
[ pr... |
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... | #C | C |
%{
/*
compilation and example on a GNU linux system:
$ flex --case-insensitive --noyywrap --outfile=cia.c source.l
$ make LOADLIBES=-lfl cia
$ ./cia < unixdict.txt
I before E when not preceded by C: plausible
E before I when preceded by C: implausible
Overall, the rule is: implausibl... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Clojure | Clojure | (str (inc (Integer/parseInt "1234"))) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #CMake | CMake | set(string "1599")
math(EXPR string "${string} + 1")
message(STATUS "${string}") |
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 |... | #Clipper | Clipper | Function Compare(a, b)
IF a < b
? "A is less than B"
ELSEIF a > b
? "A is more than B"
ELSE
? "A equals B"
ENDIF
Return Nil
|
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 |... | #Clojure | Clojure | (let [[a b] (repeatedly read)]
(doseq [[op string] [[< "less than"]
[> "greater than"]
[= "equal to"]]]
(when (op a b)
(println (str a " is " string " " b))))) |
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
| #Harbour | Harbour | #include "inkey.ch" |
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
| #Haskell | Haskell | -- Due to Haskell's module system, textual includes are rarely needed. In
-- general, one will import a module, like so:
import SomeModule
-- For actual textual inclusion, alternate methods are available. The Glasgow
-- Haskell Compiler runs the C preprocessor on source code, so #include may be
-- used:
#include "SomeM... |
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
| #HTML | HTML | <iframe src="foobar.html">
Sorry: Your browser cannot show the included content.</iframe> |
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... | #Raku | Raku | class Animal {}
class Dog is Animal {}
class Cat is Animal {}
class Lab is Dog {}
class Collie is Dog {}
say Collie.^parents; # undefined type object
say Collie.new.^parents; # instantiated object |
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... | #REBOL | REBOL | rebol [
Title: "Inheritance"
URL: http://rosettacode.org/wiki/Inheritance
]
; REBOL provides subclassing through its prototype mechanism:
Animal: make object! [
legs: 4
]
Dog: make Animal [
says: "Woof!"
]
Cat: make Animal [
says: "Meow..."
]
Lab: make Dog []
Collie: make Dog []
; Demonstrate inherited p... |
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... | #Ring | Ring |
Class Animal
Class Dog from Animal
Class Cat from Animal
Class Lab from Dog
Class Collie from 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... | #C | C | #include <alloca.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define V(cc, exp) if (!strncmp(iban, cc, 2)) return len == exp
/* Validate country code against expected length. */
int valid_cc(const char *iban, int len)
{
V("AL", 28); V("AD", 24); V("AT", 20); V("AZ", 28); V("... |
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... | #Delphi | Delphi |
// Generate humble numbers. Nigel Galloway: June 18th., 2020
let fN g=let mutable n=1UL in (fun()->n<-n*g;n)
let fI (n:uint64) g=let mutable q=n in (fun()->let t=q in q<-n*g();t)
let fG n g=let mutable vn,vg=n(),g() in fun()->match vg<vn with true->let t=vg in vg<-g();t |_->let t=vn in vn<-n();t
let rec ... |
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
⋮
⋮
⋮
⋱
... | #AutoHotkey | AutoHotkey | msgbox % Clipboard := I(6)
return
I(n){
r := "--`n" , s := " "
loop % n
{
k := A_index , r .= "| "
loop % n
r .= A_index=k ? "1, " : "0, "
r := RTrim(r, " ,") , r .= " |`n"
}
loop % 4*n
s .= " "
return Rtrim(r,"`n") "`n" s "--"
} |
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 ... | #Phix | Phix |
/**
* Simple text based dungeon game in Prolog.
*
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies GmbH makes no warranties
* regarding the provided information. XLOG Technologies GmbH assumes
* no liability that any problems mi... |
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... | #Ruby | Ruby | # Convert a quarter-imaginary base value (as a string) into a base 10 Gaussian integer.
def base2i_decode(qi)
return 0 if qi == '0'
md = qi.match(/^(?<int>[0-3]+)(?:\.(?<frc>[0-3]+))?$/)
raise 'ill-formed quarter-imaginary base value' if !md
ls_pow = md[:frc] ? -(md[:frc].length) : 0
value = 0
(md[:int] +... |
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
| #Maple | Maple |
a:=0;
t:=time[real]();
while a< 50 do
a:=a+1;
data := Matrix(`<|>`(`<,>`(Statistics:-Sample(Uniform(0, 1), [1000, 2])), LinearAlgebra:-RandomVector(1000, generator = rand(0 .. 2))));
f := plots:-pointplot(data[NULL .. NULL, 1], data[NULL .. NULL, 2], symbolsize = 20, symbol = solidbox, colorscheme = ["valuesplit",... |
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
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language |
time = AbsoluteTime[]; Animate[
Column[{Row[{"FPS: ", Round[n/(AbsoluteTime[] - time)]}],
RandomImage[1, {320, 240}]}], {n, 1, Infinity, 1}]
|
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... | #Racket | Racket | #lang typed/racket
(require images/flomap racket/flonum)
(provide flomap-convolve)
(: perfect-square? (Nonnegative-Fixnum -> (U Nonnegative-Fixnum #f)))
(define (perfect-square? n)
(define rt-n (integer-sqrt n))
(and (= n (sqr rt-n)) rt-n))
(: flomap-convolve (flomap FlVector -> flomap))
(define (flomap-convo... |
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... | #Raku | Raku | use PDL:from<Perl5>;
use PDL::Image2D:from<Perl5>;
my $kernel = pdl [[-2, -1, 0],[-1, 1, 1], [0, 1, 2]]; # emboss
my $image = rpic 'frog.png';
my $smoothed = conv2d $image, $kernel, {Boundary => 'Truncate'};
wpic $smoothed, 'frog_convolution.png'; |
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... | #Gridscript | Gridscript |
#INTEGER SEQUENCE.
@width
@height 1
(1,1):START
(3,1):STORE 1
(5,1):CHECKPOINT 0
(7,1):PRINT
(9,1):INCREMENT
(11,1):GOTO 0
|
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... | #Groovy | Groovy | // 32-bit 2's-complement signed integer (int/Integer)
for (def i = 1; i > 0; i++) { println i }
// 64-bit 2's-complement signed integer (long/Long)
for (def i = 1L; i > 0; i+=1L) { println i }
// Arbitrarily-long binary signed integer (BigInteger)
for (def i = 1g; ; i+=1g) { println i } |
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... | #PARI.2FGP | PARI/GP | +oo |
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... | #Pascal | Pascal | my $x = 0 + "inf";
my $y = 0 + "+inf"; |
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... | #Perl | Perl | my $x = 0 + "inf";
my $y = 0 + "+inf"; |
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... | #Phix | Phix | with javascript_semantics
constant infinity = 1e300*1e300
? 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... | #Wren | Wren | var exprs = [-4294967295, 3000000000 + 3000000000, 2147483647 - 4294967295, 65537 * 65537]
for (expr in exprs) System.print(expr >> 0) |
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... | #XPL0 | XPL0 | int N;
[N:= -(-2147483647-1);
IntOut(0, N); CrLf(0);
N:= 2000000000 + 2000000000;
IntOut(0, N); CrLf(0);
N:= -2147483647 - 2147483647;
IntOut(0, N); CrLf(0);
N:= 46341 * 46341;
IntOut(0, N); CrLf(0);
N:= (-2147483647-1)/-1;
IntOut(0, N); CrLf(0);
] |
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... | #Z80_Assembly | Z80 Assembly | ld a,&7F
add 1
jp pe,ErrorHandler ;pe = parity even, but in this case it represents overflow set |
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.
| #Mercury | Mercury |
:- module input_loop.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
main(!IO) :-
io.stdin_stream(Stdin, !IO),
io.stdout_stream(Stdout, !IO),
read_and_print_lines(Stdin, Stdout, !IO).
:- pred read_and_print_lines(io.text_input_stream::in,
io.text_out... |
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.
| #mIRC_Scripting_Language | mIRC Scripting Language | var %n = 1
while (%n <= $lines(input.txt)) {
write output.txt $read(input.txt,%n)
inc %n
} |
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... | #Wren | Wren | import "/ioutil" for FileUtil, Input
import "/pattern" for Pattern
import "/str" for Str
import "os" for Process
var invIndex = {}
var fileNames = []
var splitter = Pattern.new("+1/W")
class Location {
construct new(fileName, wordNum) {
_fileName = fileName
_wordNum = wordNum
}
toStrin... |
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... | #Tcl | Tcl | package require Tcl 8.4 ; # throws an error if older
if {[info exists bloop] && [llength [info functions abs]]} {
puts [expr abs($bloop)]
} |
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... | #TI-89_BASIC | TI-89 BASIC | ()
Prgm
Local l, i, vers
getConfg() → l
For i,1,dim(l),2
If l[i] = "OS Version" or l[i] = "Version" Then
l[i + 1] → vers
Disp "Version: " & vers
If expr(right(vers, 4)) < 2005 Then © Lousy parsing strategy
Disp vers & " is too old"
Stop
EndIf
EndIf
EndFor
If ... |
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... | #R | R | jose <-function(s, r,n){
y <- 0:(r-1)
for (i in (r+1):n)
y <- (y + s) %% i
return(y)
}
> jose(3,1,41) # r is the number of remained prisoner.
[1] 30 |
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... | #C.23 | C# | using System;
using System.Collections.Generic;
using System.IO;
namespace IBeforeE {
class Program {
static bool IsOppPlausibleWord(string word) {
if (!word.Contains("c") && word.Contains("ei")) {
return true;
}
if (word.Contains("cie")) {
... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #COBOL | COBOL | PROGRAM-ID. increment-num-str.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 str PIC X(5) VALUE "12345".
01 num REDEFINES str PIC 9(5).
PROCEDURE DIVISION.
DISPLAY str
ADD 1 TO num
DISPLAY str
... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Common_Lisp | Common Lisp | (princ-to-string (1+ (parse-integer "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 |... | #CMake | CMake | # Define A and B as integers. For example:
# cmake -DA=3 -DB=5 -P compare.cmake
# The comparisons can take variable names, or they can take numbers.
# So these act all the same:
# A LESS B
# ${A} LESS ${B}
# A LESS ${B}
# ${A} LESS B
if(A LESS B)
message(STATUS "${A} is less than ${B}")
endif()
if(A EQU... |
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
| #Icon_and_Unicon | Icon and Unicon | $include "filename.icn" |
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
| #IWBASIC | IWBASIC | $INCLUDE "ishelllink.inc" |
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
| #J | J | require 'myheader.ijs' |
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... | #Ruby | Ruby | class Animal
#functions go here...
def self.inherited(subclass)
puts "new subclass of #{self}: #{subclass}"
end
end
class Dog < Animal
#functions go here...
end
class Cat < Animal
#functions go here...
end
class Lab < Dog
#functions go here...
end
class Collie < Dog
#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... | #Rust | Rust | trait Animal {}
trait Cat: Animal {}
trait Dog: Animal {}
trait Lab: Dog {}
trait Collie: Dog {} |
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... | #Scala | Scala | class Animal
class Dog extends Animal
class Cat extends Animal
class Lab extends Dog
class Collie extends 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... | #C.23 | C# | public class IbanValidator : IValidateTypes
{
public ValidationResult Validate(string value)
{
// Check if value is missing
if (string.IsNullOrEmpty(value))
return ValidationResult.ValueMissing;
if (value.Length < 2)
return Va... |
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... | #F.23 | F# |
// Generate humble numbers. Nigel Galloway: June 18th., 2020
let fN g=let mutable n=1UL in (fun()->n<-n*g;n)
let fI (n:uint64) g=let mutable q=n in (fun()->let t=q in q<-n*g();t)
let fG n g=let mutable vn,vg=n(),g() in fun()->match vg<vn with true->let t=vg in vg<-g();t |_->let t=vn in vn<-n();t
let rec ... |
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
⋮
⋮
⋮
⋱
... | #AWK | AWK |
# syntax: GAWK -f IDENTITY_MATRIX.AWK size
BEGIN {
size = ARGV[1]
if (size !~ /^[0-9]+$/) {
print("size invalid or missing from command line")
exit(1)
}
for (i=1; i<=size; i++) {
for (j=1; j<=size; j++) {
x = (i == j) ? 1 : 0
printf("%2d",x) # print
arr[i,j] =... |
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 ... | #Prolog | Prolog |
/**
* Simple text based dungeon game in Prolog.
*
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies GmbH makes no warranties
* regarding the provided information. XLOG Technologies GmbH assumes
* no liability that any problems mi... |
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... | #Sidef | Sidef | func base (Number num, Number radix { _ ~~ (-36 .. -2) }, precision = -15) -> String {
num || return '0'
var place = 0
var result = ''
var value = num
var upper_bound = 1/(-radix + 1)
var lower_bound = radix*upper_bound
while (!(lower_bound <= value) || !(value < upper_bound)) {
... |
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
| #MAXScript | MAXScript |
try destroydialog testRollout catch ()
fn randomBitmap width height =
(
local newBmp = bitmap width height
for row = 0 to (height-1) do
(
local pixels = for i in 1 to width collect (white*random 0 1)
setpixels newBmp [0,row] pixels
)
return newBmp
)
rollout testRollout "Test" width:320 height:240
(
... |
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
| #Nim | Nim | import times
import opengl
import opengl/glut
const
W = 320
H = 240
SLen = W * H div sizeof(int)
var
frame = 0
bits: array[SLen, uint]
last, start: Time
#---------------------------------------------------------------------------------------------------
proc render() {.cdecl.} =
## Render the wi... |
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... | #Ruby | Ruby | class Pixmap
# Apply a convolution kernel to a whole image
def convolute(kernel)
newimg = Pixmap.new(@width, @height)
pb = ProgressBar.new(@width) if $DEBUG
@width.times do |x|
@height.times do |y|
apply_kernel(x, y, kernel, newimg)
end
pb.update(x) if $DEBUG
end
pb.clo... |
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... | #GUISS | GUISS | Start,Programs,Accessories,Calculator,
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Butto... |
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... | #GW-BASIC | GW-BASIC | 10 A#=1
20 PRINT A#
30 A#=A#+1
40 GOTO 20 |
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... | #Phixmonti | Phixmonti | 1e300 dup * tostr "inf" == if "Infinity" print endif |
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... | #PHP | PHP | INF |
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... | #PicoLisp | PicoLisp | (load "@lib/math.l")
: (exp 1000.0)
-> T |
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... | #PL.2FI | PL/I |
declare x float, y float (15), z float (18);
put skip list (huge(x), huge(y), huge(z));
|
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... | #zkl | zkl | print("Signed 64-bit:\n");
println(-(-9223372036854775807-1));
println(5000000000000000000+5000000000000000000);
println(-9223372036854775807 - 9223372036854775807);
println(3037000500 * 3037000500);
println((-9223372036854775807-1) / -1); |
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.
| #ML.2FI | ML/I | |
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.
| #Modula-2 | Modula-2 | PROCEDURE ReadName (VAR str : ARRAY OF CHAR);
VAR n : CARDINAL;
ch, endch : CHAR;
BEGIN
REPEAT
InOut.Read (ch);
Exhausted := InOut.EOF ();
IF Exhausted THEN RETURN END
UNTIL ch > ' '; (* Eliminate whitespace *)
IF ch = '[' THEN e... |
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... | #Toka | Toka | VERSION 101 > [ bye ] ifFalse |
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... | #UNIX_Shell | UNIX Shell | case ${.sh.version} in
*93[[:alpha:]]+*) :;; #this appears to be ksh93, we're OK
*) echo "version appears to be too old"
exit # otherwise, bail out
;;
esac
if [[ -z ${bloop+bloop has a value} ]]; then
print "no bloop variable"
elsif (( abs(1) )); then
print -- $(( abs(blo... |
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... | #Racket | Racket | #lang racket
(define (josephus n k (m 0))
(for/fold ((m (add1 m)))
((a (in-range (add1 m) (add1 n))))
(remainder (+ m k) a)))
(josephus 41 3) ; ->30 |
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... | #C.2B.2B | C++ | #include <iostream>
#include <fstream>
#include <string>
#include <tuple>
#include <vector>
#include <stdexcept>
#include <boost/regex.hpp>
struct Claim {
Claim(const std::string& name) : name_(name), pro_(0), against_(0), propats_(), againstpats_() {
}
void add_pro(const std::string& pa... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Component_Pascal | Component Pascal |
MODULE Operations;
IMPORT StdLog,Args,Strings;
PROCEDURE IncString(s: ARRAY OF CHAR): LONGINT;
VAR
resp: LONGINT;
done: INTEGER;
BEGIN
Strings.StringToLInt(s,resp,done);
INC(resp);
RETURN resp
END IncString;
PROCEDURE DoIncString*;
VAR
p: Args.Params;
BEGIN
Args.Get(p);
IF p.argc > 0 THEN
StdLog.String(... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #D | D | void main() {
import std.string;
immutable s = "12349".succ;
assert(s == "12350");
} |
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 |... | #COBOL | COBOL | IDENTIFICATION DIVISION.
PROGRAM-ID. Int-Compare.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(10).
01 B PIC 9(10).
PROCEDURE DIVISION.
DISPLAY "First number: " WITH NO ADVANCING
ACCEPT A
DISPLAY "Second number: " WITH NO ADVA... |
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
| #Java | Java | public class Class1 extends Class2
{
//code here
} |
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
| #JavaScript | JavaScript | var s = document.createElement('script');
s.type = 'application/javascript';
// path to the desired file
s.src = 'http://code.jquery.com/jquery-1.6.2.js';
document.body.appendChild(s); |
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
| #jq | jq | include "gort";
hello |
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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const type: Animal is new struct
# ...
end struct;
const type: Dog is sub Animal struct
# ...
end struct;
const type: Lab is sub Dog struct
# ...
end struct;
const type: Collie is sub Dog struct
# ...
end struct;
const type: Cat is sub Animal struct
# ..... |
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... | #Self | Self | 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... | #Sidef | Sidef | class Animal {};
class Dog << Animal {};
class Cat << Animal {};
class Lab << Dog {};
class Collie << Dog {}; |
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... | #Simula | Simula | begin
class Animal;
! instance variables;
begin
! methods;
end;
Animal class Dog;
begin
end;
Animal class Cat;
begin
end;
Dog class Lab;
begin
end;
Dog class Collie;
begin
end;
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... | #C.2B.2B | C++ | #include <string>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <map>
#include <algorithm>
#include <cctype>
using namespace boost::algorithm;
bool isValid(const std::string &ibanstring) {
static std::map<std::string, int> countrycodes {
{"AL", 28}, {"AD", 24}, {"AT", 20}, {"AZ", 28... |
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... | #Factor | Factor | USING: accessors assocs combinators deques dlists formatting fry
generalizations io kernel make math math.functions math.order
prettyprint sequences tools.memory.private ;
IN: rosetta-code.humble-numbers
TUPLE: humble-iterator 2s 3s 5s 7s digits
{ #digits initial: 1 } { target initial: 10 } ;
: <humble-iterator... |
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... | #FreeBASIC | FreeBASIC | Function IsHumble(i As Integer) As Boolean
If i <= 1 Then Return True
If i Mod 2 = 0 Then Return IsHumble(i \ 2)
If i Mod 3 = 0 Then Return IsHumble(i \ 3)
If i Mod 5 = 0 Then Return IsHumble(i \ 5)
If i Mod 7 = 0 Then Return IsHumble(i \ 7)
Return False
End Function
Const limiteMax = 7574
Dim... |
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
⋮
⋮
⋮
⋱
... | #Bash | Bash |
for i in `seq $1`;do printf '%*s\n' $1|tr ' ' '0'|sed "s/0/1/$i";done
|
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 ... | #Python | Python |
import random
class WumpusGame(object):
def __init__(self, edges=[]):
# Create arbitrary caves from a list of edges (see the end of the script for example).
if edges:
cave = {}
N = max([edges[i][0] for i in range(len(edges))])
for i in range(N):
exits = [edge[1] for edge in edges if edge[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... | #Visual_Basic_.NET | Visual Basic .NET | Imports System.Text
Module Module1
Class Complex : Implements IFormattable
Private ReadOnly real As Double
Private ReadOnly imag As Double
Public Sub New(r As Double, i As Double)
real = r
imag = i
End Sub
Public Sub New(r As Integer, i As Inte... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.