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/Image_noise | Image noise | Generate a random black and white 320x240 image continuously,
showing FPS (frames per second).
A sample image
| #OCaml | OCaml | let frames =
{ contents = 0 }
let t_acc =
{ contents = 0 }
let last_t =
{ contents = Sdltimer.get_ticks () }
let print_fps () =
let t = Sdltimer.get_ticks () in
let dt = t - !last_t in
t_acc := !t_acc + dt;
if !t_acc > 1000 then begin
let el_time = !t_acc / 1000 in
Printf.printf
"- fps... |
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... | #Tcl | Tcl | package require Tk
# Function for clamping values to those that we can use with colors
proc tcl::mathfunc::luma channel {
set channel [expr {round($channel)}]
if {$channel < 0} {
return 0
} elseif {$channel > 255} {
return 255
} else {
return $channel
}
}
# Applies a convolution kernel to produ... |
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... | #Haskell | Haskell | mapM_ print [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... | #HolyC | HolyC | U64 i = 0;
while (++i) Print("%d\n", 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... | #PostScript | PostScript | /infinity { 9 99 exp } def |
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... | #PowerShell | PowerShell | function infinity {
[double]::PositiveInfinity
} |
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... | #PureBasic | PureBasic | If OpenConsole()
Define.d a, b
b = 0
;positive infinity
PrintN(StrD(Infinity())) ;returns the value for positive infinity from builtin function
a = 1.0
PrintN(StrD(a / b)) ;calculation results in the value of positive infinity
;negative infinity
PrintN(StrD(-Infinity())) ;returns the value for neg... |
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-3 | Modula-3 | MODULE Output EXPORTS Main;
IMPORT Rd, Wr, Stdio;
VAR buf: TEXT;
<*FATAL ANY*>
BEGIN
WHILE NOT Rd.EOF(Stdio.stdin) DO
buf := Rd.GetLine(Stdio.stdin);
Wr.PutText(Stdio.stdout, buf);
END;
END Output. |
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.
| #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
-- Read from default input stream (console) until end of data
lines = ''
lines[0] = 0
lineNo = 0
loop label ioloop forever
inLine = ask
if inLine = null then leave ioloop -- stop on EOF (Try Ctrl-D on UNIX-like systems or Ctrl-Z on W... |
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... | #Ursala | Ursala | #import std
#import flo
#import lag
maybe_abs = math.|fabs (%QI flo)-:~&! 'abs'
#preprocess version==-[0.10.2]-?\<'wrong version'>!% *^0 ||~& -&
-&~&vitB,~&d.lexeme=='=',~&vhd.lexeme=='bloop',~&vthd.lexeme=='(evaluated)'&-,
&vthd.semantics:= !+ !+ maybe_abs+ ~&vthd.semantics.&iNHiNH&-
#cast %e
bloop = -1. |
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... | #VBA | VBA | If Application.Version < 15 Then Exit Sub |
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... | #Raku | Raku | sub Execute(@prisoner, $k) {
until @prisoner == 1 {
@prisoner.=rotate($k - 1);
@prisoner.shift;
}
}
my @prisoner = ^41;
Execute @prisoner, 3;
say "Prisoner {@prisoner} survived.";
# We don't have to use numbers. Any list will do:
my @dalton = <Joe Jack William Averell Rantanplan>;
Execute @dalton, 2;
s... |
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... | #Clojure | Clojure |
(ns i-before-e.core
(:require [clojure.string :as s])
(:gen-class))
(def patterns {:cie #"cie" :ie #"(?<!c)ie" :cei #"cei" :ei #"(?<!c)ei"})
(defn update-counts
"Given a map of counts of matching patterns and a word, increment any count if the word matches it's pattern."
[counts [word freq]]
(apply hash... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Delphi | Delphi | program IncrementNumericalString;
{$APPTYPE CONSOLE}
uses SysUtils;
const
STRING_VALUE = '12345';
begin
WriteLn(Format('"%s" + 1 = %d', [STRING_VALUE, StrToInt(STRING_VALUE) + 1]));
Readln;
end. |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Dyalect | Dyalect | var str = "42"
str = (parse(str) + 1).ToString()
//Another option:
str = (Integer(str) + 1).ToString()
//And another option using interpolation:
str = "\(parse(str) + 1)"
print(str) //Outputs 45 |
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 |... | #ColdFusion | ColdFusion | <cffunction name="CompareInteger">
<cfargument name="Integer1" type="numeric">
<cfargument name="Integer2" type="numeric">
<cfset VARIABLES.Result = "" >
<cfif ARGUMENTS.Integer1 LT ARGUMENTS.Integer2 >
<cfset VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is less than " & ARGUM... |
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
| #Jsish | Jsish | source('file');
require('module'); |
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
| #Julia | Julia | include("foo.jl") |
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
| #Kotlin | Kotlin | fun f() = println("f called") |
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... | #Slate | Slate | define: #Animal &parents: {Cloneable}.
define: #Dog &parents: {Animal}.
define: #Cat &parents: {Animal}.
define: #Lab &parents: {Dog}.
define: #Collie &parents: {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... | #Smalltalk | Smalltalk | Object subclass: #Animal
instanceVariableNames: ' ' "* space separated list of names *"
classVariableNames: ' '
poolDictionaries: ' '
category: ' ' !
"* declare methods here, separated with '!' *"
"* !Animal methodsFor: 'a category'! *"
"* methodName *"
"* method body! !"
!Animal subclass: #Dog
"* etc... |
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... | #Swift | Swift | class Animal {
// ...
}
class Dog : Animal {
// ...
}
class Lab : Dog {
// ...
}
class Collie : Dog {
// ...
}
class Cat : 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... | #Tcl | Tcl | package require TclOO
oo::class create Animal {
# ...
}
oo::class create Dog {
superclass Animal
# ...
}
oo::class create Cat {
superclass Animal
# ...
}
oo::class create Collie {
superclass Dog
# ...
}
oo::class create Lab {
superclass 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... | #Cach.C3.A9_ObjectScript | Caché ObjectScript | Class Utils.Validate [ Abstract ]
{
ClassMethod VerifyIBAN(pIBAN As %String = "") As %Boolean
{
// remove spaces and define parts
Set iban=$Translate(pIBAN, " ")
Set cc=$Extract(iban, 1, 2)
Set cd=$Extract(iban, 3, 4)
Set bban=$Extract(iban, 5, *)
// ensure IBAN is correct format
If $Match(iban, ..GetIBANPat... |
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... | #Go | Go | package main
import (
"fmt"
"math/big"
)
var (
one = new(big.Int).SetUint64(1)
two = new(big.Int).SetUint64(2)
three = new(big.Int).SetUint64(3)
five = new(big.Int).SetUint64(5)
seven = new(big.Int).SetUint64(7)
ten = new(big.Int).SetUint64(10)
)
func min(a, b *big.Int) *big... |
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
⋮
⋮
⋮
⋱
... | #BBC_BASIC | BBC BASIC | INPUT "Enter size of matrix: " size%
PROCidentitymatrix(size%, im())
FOR r% = 0 TO size%-1
FOR c% = 0 TO size%-1
PRINT im(r%, c%),;
NEXT
PRINT
NEXT r%
END
DEF PROCidentitymatrix(s%, RETURN m())
LOCAL i%
DIM m(s%-1, s%-1)
FOR 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 ... | #Racket | Racket |
#lang racket
; Hunt the Wumpus
(require racket/random)
(struct game-state (labyrinth
player-location
number-of-arrows
wumpus-location
bat-locations
pit-locations) #:mutable #:transparent)
; The labyrinth-data l... |
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 ... | #Raku | Raku |
Red [
Title: "Hunt the Wumpus"
Author: "Gregg Irwin"
Version: 1.0.2
Comment: {
2001 Notes:
I found an old version, in C (by Eric Raymond), which was adapted from
an even older version, in BASIC (by Magnus Olsson), that had been found
in a SIMTEL archive. It's got lineage.
As of 22-Oct-2001, it appea... |
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... | #Wren | Wren | import "/complex" for Complex
import "/fmt" for Fmt
class QuaterImaginary {
construct new(b2i) {
if (b2i.type != String || b2i == "" || !b2i.all { |d| "0123.".contains(d) } ||
b2i.count { |d| d == "." } > 1) Fiber.abort("Invalid Base 2i number.")
_b2i = b2i
}
// only works prop... |
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
| #Pascal | Pascal | Program ImageNoise;
uses
SDL;
var
surface: PSDL_Surface;
pixel: ^byte;
frameNumber, totalTime, lastTime, time, i: longint;
begin
frameNumber := 0;
totalTime := 0;
lastTime := 0;
randomize;
SDL_Init(SDL_INIT_TIMER or SDL_INIT_VIDEO);
surface := SDL_SetVideoMode(320, 240, 8, SDL_DOUBLEBUF o... |
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... | #Wren | Wren | import "graphics" for Canvas, Color, ImageData
import "dome" for Window
class ArrayData {
construct new(width, height) {
_width = width
_height = height
_dataArray = List.filled(width * height, 0)
}
width { _width }
height { _height }
[x, y] { _dataArray[y * _width + ... |
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... | #Icon_and_Unicon | Icon and Unicon | procedure main()
every write(seq(1)) # the most concise way
end |
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... | #IS-BASIC | IS-BASIC | 100 FOR I=1 TO INF
110 PRINT I;
120 NEXT |
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... | #Python | Python | >>> float('infinity')
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... | #QB64 | QB64 | #include<math.h>
//save as inf.h
double inf(void){
return HUGE_VAL;
} |
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... | #QBasic | QBasic | DECLARE FUNCTION f! ()
ON ERROR GOTO TratoError
PRINT 0!
PRINT 0 / -1.5
PRINT 1.5 / 0
PRINT 0 / 0
PRINT f
END
TratoError:
PRINT "Error "; ERR; " on line "; ERL; CHR$(9); " --> ";
SELECT CASE ERR
CASE 6
PRINT "Overflow"
RESUME NEXT
CASE 11
PRINT "Division by zero"
RESUME NEXT
CASE ELSE
PRINT "Une... |
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.
| #Nim | Nim | var line = ""
while stdin.readLine(line):
echo line |
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.
| #Oberon-2 | Oberon-2 |
MODULE InputLoop;
IMPORT
StdChannels,
Channel;
VAR
reader: Channel.Reader;
writer: Channel.Writer;
c: CHAR;
BEGIN
reader := StdChannels.stdin.NewReader();
writer := StdChannels.stdout.NewWriter();
reader.ReadByte(c);
WHILE reader.res = Channel.done DO
writer.WriteByte(c);
reader.ReadByte(c... |
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... | #Wren | Wren | import "os" for Platform, Process
import "io" for File
import "meta" for Meta
import "/pattern" for Pattern
import "/math" for Nums
var a = 4 /* 1st integer variable */
var b = 0xA /* 2nd integer variable */
var c = -8 /* 3rd integer variable */
var bloop = -17.3
var checkVersion = Fn.new {
var 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... | #REBOL | REBOL | rebol []
execute: func [death-list [block!] kill [integer!]] [
assert [not empty? death-list]
until [
loop kill - 1 [append death-list take death-list]
(1 == length? remove death-list)
]
]
prisoner: [] for n 0 40 1 [append prisoner n]
execute prisoner 3
print ["Prisoner" prisoner "surviv... |
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... | #CLU | CLU | report = cluster is new, classify, results
rep = record[cie, xie, cei, xei, words: int]
new = proc () returns (cvt)
return(rep${cie: 0, xie: 0, cei: 0, xei: 0, words: 0})
end new
classify = proc (r: cvt, word: string)
r.words := r.words + 1
if string$indexs("ie", word) ~= 0 t... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #DWScript | DWScript | var value : String = "1234";
value := IntToStr(StrToInt(value) + 1);
PrintLn(value); |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #D.C3.A9j.C3.A0_Vu | Déjà Vu | !. to-str ++ to-num "100" |
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 |... | #Common_Lisp | Common Lisp | (let ((a (read *standard-input*))
(b (read *standard-input*)))
(cond
((not (numberp a)) (format t "~A is not a number." a))
((not (numberp b)) (format t "~A is not a number." b))
((< a b) (format t "~A is less than ~A." a b))
((> a b) (format t "~A is greater than ~A." a 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
| #LabVIEW | LabVIEW | web_response -> include('my_file.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
| #Lasso | Lasso | include('myfile.lasso') |
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
| #Lingo | Lingo | -- load Lingo code from file
fp = xtra("fileIO").new()
fp.openFile(_movie.path&"someinclude.ls", 1)
code = fp.readFile()
fp.closeFile()
-- create new script member, assign loaded code
m = new(#script)
m.name = "someinclude"
m.scriptText = code
-- use it instantly in the current script (i.e. the script that containe... |
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... | #TXR | TXR | @(defex cat animal)
@(defex lab dog animal)
@(defex 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... | #Visual_Basic_.NET | Visual Basic .NET | Class Animal
' ...
End Class
Class Dog
Inherits Animal
' ...
End Class
Class Lab
Inherits Dog
' ...
End Class
Class Collie
Inherits Dog
' ...
End Class
Class Cat
Inherits Animal
' ...
End Class |
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... | #Vorpal | Vorpal | pet = new()
cat = new(pet)
dog = new(pet)
fido = new(dog)
felix = new(cat) |
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... | #Clojure | Clojure | (def explen
{"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 "LU" ... |
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... | #Haskell | Haskell | import Data.Set (deleteFindMin, fromList, union)
import Data.List.Split (chunksOf)
import Data.List (group)
import Data.Bool (bool)
--------------------- HUMBLE NUMBERS ----------------------
humbles :: [Integer]
humbles = go $ fromList [1]
where
go sofar = x : go (union pruned $ fromList ((x *) <$> [2, 3, 5, 7... |
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
⋮
⋮
⋮
⋱
... | #Beads | Beads | beads 1 program 'Identity matrix'
var
id : array^2 of num
n = 5
calc main_init
loop from:1 to:n index:i
loop from:1 to:n index:j
id[i,j] = 1 if i == j else 0 |
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 ... | #Red | Red |
Red [
Title: "Hunt the Wumpus"
Author: "Gregg Irwin"
Version: 1.0.2
Comment: {
2001 Notes:
I found an old version, in C (by Eric Raymond), which was adapted from
an even older version, in BASIC (by Magnus Olsson), that had been found
in a SIMTEL archive. It's got lineage.
As of 22-Oct-2001, it appea... |
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 ... | #Ruby | Ruby |
-- HUNT THE WUMPUS
-- BY GREGORY YOB
-- SenseTalk adaptation by Jonathan Gover
answer "INSTRUCTIONS (Y-N)" with "No" or "Yes"
if it is "Yes" then showInstructions
-- SET UP CAVE (DODECAHEDRAL NODE LIST)
set rooms to [
[2,5,8],[1,3,10],[2,4,12],[3,5,14],[1,4,6],
[5,7,15],[6,8,17],[1,7,9],[8,10,18],[2,9,11],
[1... |
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
| #Perl | Perl | use Gtk3 '-init';
use Glib qw/TRUE FALSE/;
use Time::HiRes qw/ tv_interval gettimeofday/;
my $time0 = [gettimeofday];
my $frames = -8; # account for set-up steps before drawing
my $window = Gtk3::Window->new();
$window->set_default_size(320, 240);
$window->set_border_width(0);
$window->set_title("Image_noise");
$wi... |
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... | #J | J | count=: (smoutput ] >:)^:_ |
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... | #Java | Java | public class Count{
public static void main(String[] args){
for(long i = 1; ;i++) System.out.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... | #R | R | Inf #positive infinity
-Inf #negative infinity
.Machine$double.xmax # largest finite floating-point number
is.finite # function to test to see if a number is finite
# function that returns the input if it is finite, otherwise returns (plus or minus) the largest... |
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... | #Racket | Racket | #lang racket
+inf.0 ; positive infinity
(define (finite? x) (< -inf.0 x +inf.0))
(define (infinite? x) (not (finite? x))) |
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... | #Raku | Raku | my $x = 1.5/0; # Failure: catchable error, if evaluated will return: "Attempt to divide by zero ...
my $y = (1.5/0).Num; # assigns '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... | #REXX | REXX | For the default setting of
NUMERIC DIGITS 9
the biggest number that can be used is (for the Regina REXX and R4 REXX interpreters):
.999999999e+999999999
|
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.
| #Objeck | Objeck |
use IO;
bundle Default {
class Test {
function : Main(args : System.String[]) ~ Nil {
f := FileReader->New("in.txt");
if(f->IsOpen()) {
string := f->ReadString();
while(string->Size() > 0) {
string->PrintLine();
string := f->ReadString();
};
f->C... |
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.
| #OCaml | OCaml | let rec read_lines ic =
try let line = input_line ic in
line :: read_lines ic
with End_of_file ->
[] |
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... | #Yabasic | Yabasic | if peek("version") < 2.63 error "Interpreter version is too old!" |
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... | #zkl | zkl | Language.version //-->L(1,12,8,"2014-04-01")
if (Language.version[1] < 10) System.exit("Too old");
var bloop=-123;
if ((1).resolve("abs",1) and resolve("bloop",8)) bloop.abs().println() |
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... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 LET totram=PEEK 23732 + 256 * PEEK 23733: REM Check that we have a 48k machine
20 IF totram < 65535 THEN PRINT "Your 16k Spectrum is too old": STOP
30 REM variables must exist before they are used, otherwise we get an error
40 REM we can poke a new error handler and check for variable not found.
50 REM I haven't imp... |
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... | #REXX | REXX | /* 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
* 09.05.2013 Walter Pachl accept arguments n w s and fix output
* ... |
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... | #Coco | Coco | ie-npc = ei-npc = ie-pc = ei-pc = 0
for word of dict.toLowerCase!.match /\S+/g
++ie-npc if /(^|[^c])ie/.test word
++ei-npc if /(^|[^c])ei/.test word
++ie-pc if word.indexOf('cie') > -1
++ei-pc if word.indexOf('cei') > -1
p1 = ie-npc > 2 * ei-npc
p2 = ei-pc > 2 * ie-pc
console.log '(1) is%s plausible... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #E | E | __makeInt("1234", 10).next().toString(10) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #EasyLang | EasyLang | a$ = "12"
a$ = number a$ + 1
print a$ |
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 |... | #Computer.2Fzero_Assembly | Computer/zero Assembly | start: STP ; get input
x: NOP
y: NOP
LDA x
SUB y
BRZ start ; x=y, A=0
loop: LDA x
SUB one
BRZ x<y
STA x
LDA y
SUB one
BRZ x>y
STA y
JMP loop
x>y: LDA one ; A := 1
JMP start
... |
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 |... | #D | D | void main() {
import std.stdio, std.conv, std.string;
int a = 10, b = 20;
try {
a = readln.strip.to!int;
b = readln.strip.to!int;
} catch (StdioException) {}
if (a < b)
writeln(a, " is less than ", b);
if (a == b)
writeln(a, " is equal to ", b);
if (a ... |
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
| #Logtalk | Logtalk |
:- object(foo).
:- include(bar).
:- end_object.
|
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
| #Lua | Lua | require "myheader" |
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
| #M2000_Interpreter | M2000 Interpreter |
Document A$={
Module Global Beta {
Print "This is Beta"
x=10
Print x
}
Print "This is statement to execute"
Beta ' this call not happen
}
Save.Doc A$, "TestThis.Gsb"
Module checkit {
\\ we can delete Global
\\ usinf New Modules we get latest TestThis, excluding stateme... |
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... | #Wren | Wren | class Animal {
// methods
}
class Dog is Animal {
// methods
}
class Cat is Animal {
// mwethods
}
class Labrador is Dog {
// methods
}
class Collie is Dog {
// methods
} |
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... | #XLISP | XLISP | (define-class animal)
(define-class dog
(super-class animal))
(define-class cat
(super-class animal))
(define-class collie
(super-class dog))
(define-class lab
(super-class 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... | #zkl | zkl | class Animal{}
class Dog(Animal){} class Cat(Animal){}
class Lab(Dog){} class Collie(Dog){}
Collie.linearizeParents |
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... | #COBOL | COBOL | IDENTIFICATION DIVISION.
PROGRAM-ID. iban-main.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 iban PIC X(50).
01 iban-flag PIC X.
88 is-valid VALUE "Y", FALSE "N".
PROCEDURE DIVISION.
main-line.
... |
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... | #J | J |
humble=: 4 : 0
NB. x humble y generates x humble numbers based on factors y
result=. , 1
while. x > # result do.
a=. , result */ y
result=. result , <./ a #~ a > {: result
end.
)
|
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... | #Java | Java |
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HumbleNumbers {
public static void main(String[] args) {
System.out.println("First 50 humble numbers:");
... |
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
⋮
⋮
⋮
⋱
... | #Burlesque | Burlesque |
blsq ) 6 -.^^0\/r@\/'0\/.*'1+]\/{\/{rt}\/E!XX}x/+]m[sp
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 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 ... | #Rust | Rust |
-- HUNT THE WUMPUS
-- BY GREGORY YOB
-- SenseTalk adaptation by Jonathan Gover
answer "INSTRUCTIONS (Y-N)" with "No" or "Yes"
if it is "Yes" then showInstructions
-- SET UP CAVE (DODECAHEDRAL NODE LIST)
set rooms to [
[2,5,8],[1,3,10],[2,4,12],[3,5,14],[1,4,6],
[5,7,15],[6,8,17],[1,7,9],[8,10,18],[2,9,11],
[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 ... | #SenseTalk | SenseTalk |
-- HUNT THE WUMPUS
-- BY GREGORY YOB
-- SenseTalk adaptation by Jonathan Gover
answer "INSTRUCTIONS (Y-N)" with "No" or "Yes"
if it is "Yes" then showInstructions
-- SET UP CAVE (DODECAHEDRAL NODE LIST)
set rooms to [
[2,5,8],[1,3,10],[2,4,12],[3,5,14],[1,4,6],
[5,7,15],[6,8,17],[1,7,9],[8,10,18],[2,9,11],
[1... |
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
| #Phix | Phix | -- demo\rosetta\ImageNoise.exw
include pGUI.e
Ihandle dlg, canvas, timer
cdCanvas cddbuffer, cdcanvas
constant TITLE = "Image noise"
integer fps = 129 -- (typical value)
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
integer {w, h} = IupGetIntInt(canvas, "DRAWSIZE")
cdCanvasAct... |
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
| #PicoLisp | PicoLisp | (javac "ImageNoise" "JPanel" NIL
"java.util.*"
"java.awt.*" "java.awt.image.*" "javax.swing.*" )
int DX, DY;
int[] Pixels;
MemoryImageSource Source;
Image Img;
Random Rnd;
public ImageNoise(int dx, int dy) {
DX = dx;
DY = dy;
Pixels = new int[DX * DY];
Source = ... |
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... | #JavaScript | JavaScript | var i = 0;
while (true)
document.write(++i + ' '); |
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... | #Joy | Joy |
1 [0 >] [dup put succ] while pop. |
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... | #RLaB | RLaB |
>> x = inf()
inf
>> isinf(x)
1
>> inf() > 10
1
>> -inf() > 10
0
|
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... | #Ruby | Ruby | a = 1.0/0 # => Infinity
a.finite? # => false
a.infinite? # => 1
a = -1/0.0 # => -Infinity
a.infinite? # => -1
a = Float::MAX # => 1.79769313486232e+308
a.finite? # => true
a.infinite? # => nil |
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... | #Rust | Rust | fn main() {
let inf = f32::INFINITY;
println!("{}", 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... | #Scala | Scala | val inf = Double.PositiveInfinity //defined as 1.0/0.0
inf.isInfinite; //true |
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.
| #Oforth | Oforth | : readFile(filename) File new(filename) apply(#println) ; |
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.
| #Oz | Oz | %% Returns a list of lines.
%% Text: an instance of Open.text (a mixin class)
fun {ReadAll Text}
case {Text getS($)} of false then nil
[] Line then Line|{ReadAll Text}
end
end |
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... | #Ring | Ring |
n = 41
k=3
see "n =" + n + " k = " + k + " final survivor = " + josephus(n, k, 0) + nl
func josephus (n, k, m)
lm = m
for a = m+1 to n
lm = (lm+k) % a
next
josephus = lm
return josephus
|
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... | #Common_Lisp | Common Lisp |
(defun test-rule (rule-name examples counter-examples)
(let ((plausible (if (> examples (* 2 counter-examples)) 'plausible 'not-plausible)))
(list rule-name plausible examples counter-examples)))
(defun plausibility (result-string file parser)
(let ((cei 0) (cie 0) (ie 0) (ei 0))
(macrolet ((search-coun... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #EchoLisp | EchoLisp |
(number->string (1+ (string->number "665")))
→ "666"
|
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Eero | Eero | #import <Foundation/Foundation.h>
int main()
i := (int)'123' + 1
s := @(i).description
Log( '%@', s )
return 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 |... | #Dc | Dc | [Use _ (underscore) as negative sign for numbers.]P []pP
[Enter two numbers to compare: ]P
? sbsa
[[greater than]]sp lb la >p
[ [less than]]sp lb la <p
[ [equal to]]sp lb la =p
la n [ is ]P P [ ]P lbn []pP
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.