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/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would repr...
#Rust
Rust
#[derive(Debug)] struct Vector { x: f64, y: f64, z: f64, }   impl Vector { fn new(x: f64, y: f64, z: f64) -> Self { Vector { x: x, y: y, z: z, } }   fn dot_product(&self, other: &Vector) -> f64 { (self.x * other.x) + (self.y * other.y) ...
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Wee_Basic
Wee Basic
print 1 "Enter a string." input string$ print 1 "Enter an integer." input integer
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Wren
Wren
import "io" for Stdin, Stdout   var string while (true) { System.write("Enter a string : ") Stdout.flush() string = Stdin.readLine() if (string.count == 0) { System.print("String cannot be empty, try again.") } else { break } }   var number while (true) { System.write("Enter ...
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Pascal
Pascal
#!/usr/bin/perl -w use strict;   # Declare the variable. It is initialized to the value "undef" our $var;   # Check to see whether it is defined print "var contains an undefined value at first check\n" unless defined $var;   # Give it a value $var = "Chocolate";   # Check to see whether it is defined after we gave it t...
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Perl
Perl
#!/usr/bin/perl -w use strict;   # Declare the variable. It is initialized to the value "undef" our $var;   # Check to see whether it is defined print "var contains an undefined value at first check\n" unless defined $var;   # Give it a value $var = "Chocolate";   # Check to see whether it is defined after we gave it t...
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#jq
jq
--raw-input | -R :: each line of input is converted to a JSON string; --ascii-output | -a :: every non-ASCII character that would otherwise be sent to output is translated to an equivalent ASCII escape sequence; --raw-output | -r :: output strings as raw strings, ...
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Julia
Julia
julia> 四十二 = "voilà"; julia> println(四十二) voilà
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Kotlin
Kotlin
// version 1.1.2   fun main(args: Array<String>) { val åäö = "as⃝df̅ ♥♦♣♠ 頰" println(åäö) }
http://rosettacode.org/wiki/Twin_primes
Twin primes
Twin primes are pairs of natural numbers   (P1  and  P2)   that satisfy the following:     P1   and   P2   are primes     P1  +  2   =   P2 Task Write a program that displays the number of pairs of twin primes that can be found under a user-specified number (P1 < user-specified number & P2 < user-specified numbe...
#ALGOL_68
ALGOL 68
BEGIN # count twin primes (where p and p - 2 are prime) # PR heap=128M PR # set heap memory size for Algol 68G # # sieve of Eratosthenes: sets s[i] to TRUE if i is a prime, FALSE otherwise # PROC sieve = ( REF[]BOOL s )VOID: BEGIN ...
http://rosettacode.org/wiki/Unprimeable_numbers
Unprimeable numbers
Definitions As used here, all unprimeable numbers   (positive integers)   are always expressed in base ten. ───── Definition from OEIS ─────: Unprimeable numbers are composite numbers that always remain composite when a single decimal digit of the number is changed. ───── Definition from Wiktionary   (reference...
#J
J
  NB. replace concatenates at various ranks and in boxes to avoid fill NB. the curtailed prefixes (}:\) with all of 0..9 (i.10) with the beheaded suffixes (}.\.) NB. under the antibase 10 representation (10&#.inv) replace=: ([: ; <@}:\ ,"1 L:_1 ([: < (i.10) ,"0 1 }.)\.)&.(10&#.inv)   NB. primable tests if one of the re...
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#M2000_Interpreter
M2000 Interpreter
  Δ=1 Δ++ Print Δ ᾩ=3 Print ᾩ**2=ᾩ^2, ᾩ^2-1=8 Τύπωσε ᾩ**2=ᾩ^2, ᾩ^2-1=8 ' this is Print statement too Print ᾡ=3 जावास्क्रिप्ट=100 जावास्क्रिप्ट++ Print "जावास्क्रिप्ट=";जावास्क्रिप्ट ĦĔĽĻŎ$="hello" Print ĦĔĽĻŎ$+ħĕľļŏ$="hellohello" 〱〱〱〱$="too less" Print Left$(〱〱〱〱$, 3)="too"   c͓͈̃͂̋̈̆̽h̥̪͕ͣ͛̊aͨͣ̍͞ơ̱͔̖͖̑̽ș̻̥ͬ̃̈ͩ =10...
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Δ = 1; Δ++; Print[Δ]
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Nemerle
Nemerle
using System.Console;   module UnicodeVar { Main() : void { mutable Δ = 1; Δ++; WriteLine($"Δ = $Δ"); } }
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   upperΔ = 1 Δupper = upperΔ lowerδ = 2 δlower = lowerδ   say upperΔ '+' Δupper '= \-' upperΔ = upperΔ + Δupper say upperΔ   say lowerδ '+' δlower '= \-' lowerδ = lowerδ + δlower say lowerδ say   -- Unicode works with the NetRexx built-in func...
http://rosettacode.org/wiki/Unbias_a_random_generator
Unbias a random generator
P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} Task details Use your language's random number generator to create a function/method/sub...
#F.23
F#
open System   let random = Random()   let randN = random.Next >> (=)0 >> Convert.ToInt32   let rec unbiased n = let a = randN n if a <> randN n then a else unbiased n   [<EntryPoint>] let main argv = let n = if argv.Length > 0 then UInt32.Parse(argv.[0]) |> int else 100000 for b = 3 to 6 do let ...
http://rosettacode.org/wiki/Untouchable_numbers
Untouchable numbers
Definitions   Untouchable numbers   are also known as   nonaliquot numbers.   An   untouchable number   is a positive integer that cannot be expressed as the sum of all the proper divisors of any positive integer.   (From Wikipedia)   The   sum of all the proper divisors   is also known as   the   aliquot sum.   A...
#Wren
Wren
import "/math" for Int, Nums import "/seq" for Lst import "/fmt" for Fmt   var sieve = Fn.new { |n| n = n + 1 var s = List.filled(n+1, false) for (i in 0..n) { var sum = Nums.sum(Int.properDivisors(i)) if (sum <= n) s[sum] = true } return s }   var limit = 1e5 var c = Int.primeSieve...
http://rosettacode.org/wiki/Two_bullet_roulette
Two bullet roulette
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street: A revolver handgun has a revolving cylinder with six chambers for bullets. It is loaded with the following procedure: 1. Check the first chamber to the right of the trigger for a bullet. If a bullet is seen, the cyli...
#C
C
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h>   static int nextInt(int size) { return rand() % size; }   static bool cylinder[6];   static void rshift() { bool t = cylinder[5]; int i; for (i = 4; i >= 0; i--) { cylinder[i + 1] = cylinder[i]; ...
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Kotlin
Kotlin
// Version 1.2.41   import java.io.File   fun ls(directory: String) { val d = File(directory) if (!d.isDirectory) { println("$directory is not a directory") return } d.listFiles().map { it.name } .sortedBy { it.toLowerCase() } // case insensitive .forEa...
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Ksh
Ksh
  #!/bin/ksh   # List everything in the current folder (sorted), similar to `ls`   # # Variables: # targetDir=${1:-/tmp/foo}   ###### # main # ######   cd ${targetDir} for obj in *; do print ${obj} done  
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would repr...
#Scala
Scala
case class Vector3D(x:Double, y:Double, z:Double) { def dot(v:Vector3D):Double=x*v.x + y*v.y + z*v.z; def cross(v:Vector3D)=Vector3D(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x) def scalarTriple(v1:Vector3D, v2:Vector3D)=this dot (v1 cross v2) def vectorTriple(v1:Vector3D, v2:Vector3D)=this cross (v1 cross v2) ...
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#XLISP
XLISP
(display "Enter a string: ") (define s (read-line)) (display "Yes, ") (write s) (display " is a string.") ;; no need to verify, because READ-LINE has to return a string (newline) (display "Now enter the integer 75000: ") (define n (read)) (display (cond ((not (integerp n)) "That's not even an in...
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#XPL0
XPL0
string 0; \use zero-terminated strings, instead of MSb terminated include c:\cxpl\codes; int I; char Name(128); \the keyboard buffer limits input to 128 characters   [Text(0, "What's your name? "); I:= 0; loop [Name(I):= ChIn(0); \buffered keyboard input if Name(...
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Phix
Phix
object x procedure test() if object(x) then puts(1,"x is an object\n") else puts(1,"x is unassigned\n") end if end procedure test() x = 1 test()
http://rosettacode.org/wiki/Undefined_values
Undefined values
#PHP
PHP
<?php // Check to see whether it is defined if (!isset($var)) echo "var is undefined at first check\n";   // Give it a value $var = "Chocolate";   // Check to see whether it is defined after we gave it the // value "Chocolate" if (!isset($var)) echo "var is undefined at second check\n";   // Give the variable a...
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#langur
langur
q:any"any code points here"
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Lasso
Lasso
local(unicode = '♥♦♣♠') #unicode -> append('\u9830') #unicode '<br />' #unicode -> get (2) '<br />' #unicode -> get (4) -> integer
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#LFE
LFE
  > (set encoded (binary ("åäö ð" utf8))) #B(195 165 195 164 195 182 32 195 176)  
http://rosettacode.org/wiki/Twin_primes
Twin primes
Twin primes are pairs of natural numbers   (P1  and  P2)   that satisfy the following:     P1   and   P2   are primes     P1  +  2   =   P2 Task Write a program that displays the number of pairs of twin primes that can be found under a user-specified number (P1 < user-specified number & P2 < user-specified numbe...
#Arturo
Arturo
pairsOfPrimes: function [upperLim][ count: 0 j: 0 k: 1 i: 0 while [i=<upperLim][ i: (6 * k) - 1 j: i + 2 if and? [prime? i] [prime? j] [ count: count + 1 ] k: k + 1 ] return count + 1 ]   ToNum: 10 while [ToNum =< 1000000][ x: pairsOfPr...
http://rosettacode.org/wiki/Twin_primes
Twin primes
Twin primes are pairs of natural numbers   (P1  and  P2)   that satisfy the following:     P1   and   P2   are primes     P1  +  2   =   P2 Task Write a program that displays the number of pairs of twin primes that can be found under a user-specified number (P1 < user-specified number & P2 < user-specified numbe...
#AWK
AWK
  # syntax: GAWK -f TWIN_PRIMES.AWK BEGIN { n = 1 for (i=1; i<=6; i++) { n *= 10 printf("twin prime pairs < %8s : %d\n",n,count_twin_primes(n)) } exit(0) } function count_twin_primes(limit, count,i,p1,p2,p3) { p1 = 0 p2 = p3 = 1 for (i=5; i<=limit; i++) { p3 = p2 p2 ...
http://rosettacode.org/wiki/Unprimeable_numbers
Unprimeable numbers
Definitions As used here, all unprimeable numbers   (positive integers)   are always expressed in base ten. ───── Definition from OEIS ─────: Unprimeable numbers are composite numbers that always remain composite when a single decimal digit of the number is changed. ───── Definition from Wiktionary   (reference...
#Java
Java
  public class UnprimeableNumbers {   private static int MAX = 10_000_000; private static boolean[] primes = new boolean[MAX];   public static void main(String[] args) { sieve(); System.out.println("First 35 unprimeable numbers:"); displayUnprimeableNumbers(35); int n = 600; ...
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Nim
Nim
var Δ = 1 inc Δ echo Δ
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Objeck
Objeck
  class Test { function : Main(args : String[]) ~ Nil { Δ := 1; π := 3.141592; 你好 := "hello"; Δ += 1; Δ->PrintLine(); } }  
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Ol
Ol
  (define Δ 1) (define Δ (+ Δ 1)) (print Δ)  
http://rosettacode.org/wiki/Unbias_a_random_generator
Unbias a random generator
P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} Task details Use your language's random number generator to create a function/method/sub...
#Factor
Factor
USING: formatting kernel math math.ranges random sequences ; IN: rosetta-code.unbias   : randN ( n -- m ) random zero? 1 0 ? ;   : unbiased ( n -- m ) dup [ randN ] dup bi 2dup = not [ drop nip ] [ 2drop unbiased ] if ;   : test-generator ( quot -- x ) [ 1,000,000 dup ] dip replicate sum 100 * swap / ; inli...
http://rosettacode.org/wiki/Unbias_a_random_generator
Unbias a random generator
P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} Task details Use your language's random number generator to create a function/method/sub...
#Fortran
Fortran
program Bias_Unbias implicit none   integer, parameter :: samples = 1000000 integer :: i, j integer :: c1, c2, rand   do i = 3, 6 c1 = 0 c2 = 0 do j = 1, samples rand = bias(i) if (rand == 1) c1 = c1 + 1 rand = unbias(i) if (rand == 1) c2 = c2 + 1 end do write(*, "(...
http://rosettacode.org/wiki/Two_bullet_roulette
Two bullet roulette
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street: A revolver handgun has a revolving cylinder with six chambers for bullets. It is loaded with the following procedure: 1. Check the first chamber to the right of the trigger for a bullet. If a bullet is seen, the cyli...
#C.2B.2B
C++
#include <array> #include <iomanip> #include <iostream> #include <random> #include <sstream>   class Roulette { private: std::array<bool, 6> cylinder;   std::mt19937 gen; std::uniform_int_distribution<> distrib;   int next_int() { return distrib(gen); }   void rshift() { std::rot...
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#LiveCode
LiveCode
set the defaultFolder to "/foo" put the folders & the files set the defaultFolder to "/foo/bar" put the folders & the files
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Lua
Lua
require("lfs") for file in lfs.dir(".") do print(file) end
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Column[FileNames[]]
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would repr...
#Scheme
Scheme
(define (dot-product A B) (apply + (map * (vector->list A) (vector->list B))))   (define (cross-product A B) (define len (vector-length A)) (define xp (make-vector (vector-length A) #f)) (let loop ((n 0)) (vector-set! xp n (- (* (vector-ref A (modulo (+ n 1) len)) (vector-ref B (modulo (+ n 2) len))) ...
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#zkl
zkl
str:=ask("Gimmie a string: "); n:=ask("Type 75000: ").toInt();
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 INPUT "Enter a string:"; s$ 20 INPUT "Enter a number: "; n
http://rosettacode.org/wiki/Undefined_values
Undefined values
#PicoLisp
PicoLisp
: (myfoo 3 4) !? (myfoo 3 4) myfoo -- Undefined ?
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Pike
Pike
  > zero_type(UNDEFINED); Result: 1 > mapping bar = ([ "foo":"hello" ]); > zero_type(bar->foo); Result: 0 > zero_type(bar->baz); Result: 1 > bar->baz=UNDEFINED; Result: 0 > zero_type(bar->baz); Result: 0  
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Lingo
Lingo
put _system.getInstalledCharSets() -- ["big5", "cp1026", "cp866", "ebcdic-cp-us", "gb2312", "ibm437", "ibm737", "ibm775", "ibm850", "ibm852", "ibm857", "ibm861", "ibm869", "iso-8859-1", "iso-8859-15", "iso-8859-2", "iso-8859-4", "iso-8859-5", "iso-8859-7", "iso-8859-9", "johab", "koi8-r", "koi8-u", "ks_c_5601-1987", "m...
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Locomotive_Basic
Locomotive Basic
10 CLS:DEFINT a-z 20 ' define German umlauts as in Latin-1 30 SYMBOL AFTER 196 40 SYMBOL 196,&66,&18,&3C,&66,&7E,&66,&66,&0 50 SYMBOL 214,&C6,&0,&7C,&C6,&C6,&C6,&7C,&0 60 SYMBOL 220,&66,&0,&66,&66,&66,&66,&3C,&0 70 SYMBOL 228,&6C,&0,&78,&C,&7C,&CC,&76,&0 80 SYMBOL 246,&66,&0,&0,&3C,&66,&66,&3C,&0 90 SYMBOL 252,&66,&0,&...
http://rosettacode.org/wiki/Twin_primes
Twin primes
Twin primes are pairs of natural numbers   (P1  and  P2)   that satisfy the following:     P1   and   P2   are primes     P1  +  2   =   P2 Task Write a program that displays the number of pairs of twin primes that can be found under a user-specified number (P1 < user-specified number & P2 < user-specified numbe...
#BASIC256
BASIC256
  function isPrime(v) if v < 2 then return False if v mod 2 = 0 then return v = 2 if v mod 3 = 0 then return v = 3 d = 5 while d * d <= v if v mod d = 0 then return False else d += 2 end while return True end function   function paresDePrimos(limite) p1 = 0 p2 = 1 p3 = 1 cont = 0 for i = 5 t...
http://rosettacode.org/wiki/Twin_primes
Twin primes
Twin primes are pairs of natural numbers   (P1  and  P2)   that satisfy the following:     P1   and   P2   are primes     P1  +  2   =   P2 Task Write a program that displays the number of pairs of twin primes that can be found under a user-specified number (P1 < user-specified number & P2 < user-specified numbe...
#C
C
#include <stdbool.h> #include <stdint.h> #include <stdio.h>   bool isPrime(int64_t n) { int64_t i;   if (n < 2) return false; if (n % 2 == 0) return n == 2; if (n % 3 == 0) return n == 3; if (n % 5 == 0) return n == 5; if (n % 7 == 0) return n == 7; if (n % 11 == 0) return n == 11;...
http://rosettacode.org/wiki/Unprimeable_numbers
Unprimeable numbers
Definitions As used here, all unprimeable numbers   (positive integers)   are always expressed in base ten. ───── Definition from OEIS ─────: Unprimeable numbers are composite numbers that always remain composite when a single decimal digit of the number is changed. ───── Definition from Wiktionary   (reference...
#JavaScript
JavaScript
  Number.prototype.isPrime = function() { let i = 2, num = this; if (num == 0 || num == 1) return false; if (num == 2) return true; while (i <= Math.ceil(Math.sqrt(num))) { if (num % i == 0) return false; i++; } return true; }  
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#PARI.2FGP
PARI/GP
<@ LETVARLIT>Δ|1</@> <@ ACTICRVAR>Δ</@> <@ SAYVAR>Δ</@>
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Peloton
Peloton
<@ LETVARLIT>Δ|1</@> <@ ACTICRVAR>Δ</@> <@ SAYVAR>Δ</@>
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Perl
Perl
use utf8;   my $Δ = 1; $Δ++; print $Δ, "\n";
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Phix
Phix
with javascript_semantics integer Δ = 1 Δ += 1 ?Δ
http://rosettacode.org/wiki/Unbias_a_random_generator
Unbias a random generator
P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} Task details Use your language's random number generator to create a function/method/sub...
#FreeBASIC
FreeBASIC
  Function randN (n As Ubyte) As Ubyte If Int(Rnd * n) + 1 <> 1 Then Return 0 Else Return 1 End Function   Function unbiased (n As Ubyte) As Ubyte Dim As Ubyte a, b Do a = randN (n) b = randN (n) Loop Until a <> b Return a End Function   Const count = 100000   Dim x As Ubyte   Random...
http://rosettacode.org/wiki/Two_bullet_roulette
Two bullet roulette
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street: A revolver handgun has a revolving cylinder with six chambers for bullets. It is loaded with the following procedure: 1. Check the first chamber to the right of the trigger for a bullet. If a bullet is seen, the cyli...
#EasyLang
EasyLang
len cyl[] 6 func rshift . . h = cyl[5] for i = 5 downto 1 cyl[i] = cyl[i - 1] . cyl[0] = h . func unload . . for i range 6 cyl[i] = 0 . . func load . . while cyl[0] = 1 call rshift . cyl[0] = 1 call rshift . func spin . . lim = random 6 + 1 for i = 1 to lim - 1 call rshift . . ...
http://rosettacode.org/wiki/Two_bullet_roulette
Two bullet roulette
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street: A revolver handgun has a revolving cylinder with six chambers for bullets. It is loaded with the following procedure: 1. Check the first chamber to the right of the trigger for a bullet. If a bullet is seen, the cyli...
#Factor
Factor
USING: accessors assocs circular formatting fry kernel literals math random sequences ; IN: rosetta-code.roulette   CONSTANT: cyl $[ { f f f f f f } <circular> ]   : cylinder ( -- seq ) cyl [ drop f ] map! ;   : load ( seq -- seq' ) 0 over nth [ dup rotate-circular ] when t 0 rot [ set-nth ] [ rotate-circular ]...
http://rosettacode.org/wiki/Two_bullet_roulette
Two bullet roulette
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street: A revolver handgun has a revolving cylinder with six chambers for bullets. It is loaded with the following procedure: 1. Check the first chamber to the right of the trigger for a bullet. If a bullet is seen, the cyli...
#Go
Go
package main   import ( "fmt" "math/rand" "strings" "time" )   var cylinder = [6]bool{}   func rshift() { t := cylinder[5] for i := 4; i >= 0; i-- { cylinder[i+1] = cylinder[i] } cylinder[0] = t }   func unload() { for i := 0; i < 6; i++ { cylinder[i] = false } } ...
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Nanoquery
Nanoquery
import Nanoquery.IO import sort   fnames = sort(new(File).listDir("."))   for i in range(0, len(fnames) - 1) println fnames[i] end
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Nim
Nim
from algorithm import sorted from os import walkPattern from sequtils import toSeq   for path in toSeq(walkPattern("*")).sorted: echo path
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Objeck
Objeck
  class Test { function : Main(args : String[]) ~ Nil { file_names := System.IO.File.Directory->List("."); each(i : file_names) { file_name := file_names[i]; if(System.IO.File.Directory->Exists(file_name)) { file_name += '/'; }; file_name->PrintLine(); }; } }  
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would repr...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "float.s7i";   const type: vec3 is new struct var float: x is 0.0; var float: y is 0.0; var float: z is 0.0; end struct;   const func vec3: vec3 (in float: x, in float: y, in float: z) is func result var vec3: aVector is vec3.value; begin aVector.x := x; ...
http://rosettacode.org/wiki/Undefined_values
Undefined values
#PowerShell
PowerShell
  if (Get-Variable -Name noSuchVariable -ErrorAction SilentlyContinue) { $true } else { $false }  
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Prolog
Prolog
?- var(Y). true. ?- X = 4, var(X). false. ?- nonvar(Y). false. ?- X = 4, nonvar(X). X = 4.
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#M2000_Interpreter
M2000 Interpreter
  Font "Arial" Mode 32 ' M2000 internal editor can display left to rigtht languages if text is in same line, and same color. a$="لم أجد هذا الكتاب القديم" ' We can use console to display text, using proportional spacing Print Part $(4), a$ Print ' We can display right to left using ' the legend statement which render ...
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
{"AdobeStandard", "ASCII", "CP936", "CP949", "CP950", "Custom", "EUC-JP", "EUC", "IBM-850", "ISO10646-1", "ISO8859-15", "ISO8859-1", "ISO8859-2", "ISO8859-3", "ISO8859-4", "ISO8859-5", "ISO8859-6", "ISO8859-7", "ISO8859-8", "ISO8859-9", "ISOLatin1", "ISOLatin2", "ISOLatin3", "ISOLatin4", "ISOLatinCyrillic", "Klingo...
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Nemerle
Nemerle
use utf8;
http://rosettacode.org/wiki/Twin_primes
Twin primes
Twin primes are pairs of natural numbers   (P1  and  P2)   that satisfy the following:     P1   and   P2   are primes     P1  +  2   =   P2 Task Write a program that displays the number of pairs of twin primes that can be found under a user-specified number (P1 < user-specified number & P2 < user-specified numbe...
#C.2B.2B
C++
#include <cstdint> #include <iostream> #include <string> #include <primesieve.hpp>   void print_twin_prime_count(long long limit) { std::cout << "Number of twin prime pairs less than " << limit << " is " << (limit > 0 ? primesieve::count_twins(0, limit - 1) : 0) << '\n'; }   int main(int argc, char** argv) ...
http://rosettacode.org/wiki/Unprimeable_numbers
Unprimeable numbers
Definitions As used here, all unprimeable numbers   (positive integers)   are always expressed in base ten. ───── Definition from OEIS ─────: Unprimeable numbers are composite numbers that always remain composite when a single decimal digit of the number is changed. ───── Definition from Wiktionary   (reference...
#jq
jq
def digits: tostring | explode | map([.] | implode | tonumber);   def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;  
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#PHP
PHP
<?php $Δ = 1; ++$Δ; echo $Δ;
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#PicoLisp
PicoLisp
: (setq Δ 1) -> 1 : Δ -> 1 : (inc 'Δ) -> 2 : Δ -> 2
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Pike
Pike
  #charset utf8 void main() { int Δ = 1; Δ++; write( Δ +"\n"); }  
http://rosettacode.org/wiki/Unbias_a_random_generator
Unbias a random generator
P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} Task details Use your language's random number generator to create a function/method/sub...
#F.C5.8Drmul.C3.A6
Fōrmulæ
RandNGen := function(n) local v, rand; v := [1 .. n - 1]*0; Add(v, 1); rand := function() return Random(v); end; return rand; end;   UnbiasedGen := function(rand) local unbiased; unbiased := function() local a, b; while true do a := rand(); b := rand(); if a <> b then break; fi; od; re...
http://rosettacode.org/wiki/Unbias_a_random_generator
Unbias a random generator
P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} Task details Use your language's random number generator to create a function/method/sub...
#GAP
GAP
RandNGen := function(n) local v, rand; v := [1 .. n - 1]*0; Add(v, 1); rand := function() return Random(v); end; return rand; end;   UnbiasedGen := function(rand) local unbiased; unbiased := function() local a, b; while true do a := rand(); b := rand(); if a <> b then break; fi; od; re...
http://rosettacode.org/wiki/Two_bullet_roulette
Two bullet roulette
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street: A revolver handgun has a revolving cylinder with six chambers for bullets. It is loaded with the following procedure: 1. Check the first chamber to the right of the trigger for a bullet. If a bullet is seen, the cyli...
#JavaScript
JavaScript
  let Pistol = function(method) { this.fired = false; this.cylinder = new Array(6).fill(false); this.trigger = 0; this.rshift = function() { this.trigger = this.trigger == 0 ? 5 : this.trigger-1; } this.load = function() { while (this.cylinder[this.trigger]) this.rshift(); this.cylinder[this.tri...
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#OCaml
OCaml
let () = Array.iter print_endline ( Sys.readdir Sys.argv.(1) )
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#PARI.2FGP
PARI/GP
system("dir/b/on")
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would repr...
#Sidef
Sidef
class MyVector(x, y, z) { method ∙(vec) { [self{:x,:y,:z}] »*« [vec{:x,:y,:z}] «+» }   method ⨉(vec) { MyVector(self.y*vec.z - self.z*vec.y, self.z*vec.x - self.x*vec.z, self.x*vec.y - self.y*vec.x) }   method to_s { "(#{x}, #{y}, #{z})" } } ...
http://rosettacode.org/wiki/Undefined_values
Undefined values
#PureBasic
PureBasic
If OpenConsole()   CompilerIf Defined(var, #PB_Variable) PrintN("var is defined at first check") CompilerElse PrintN("var is undefined at first check") Define var CompilerEndIf   CompilerIf Defined(var, #PB_Variable) PrintN("var is defined at second check") CompilerElse PrintN("var is unde...
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Python
Python
# Check to see whether a name is defined try: name except NameError: print "name is undefined at first check"   # Create a name, giving it a string value name = "Chocolate"   # Check to see whether the name is defined now. try: name except NameError: print "name is undefined at second check"   # Remove the definition o...
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Nim
Nim
use utf8;
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Oforth
Oforth
use utf8;
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Ol
Ol
use utf8;
http://rosettacode.org/wiki/Twin_primes
Twin primes
Twin primes are pairs of natural numbers   (P1  and  P2)   that satisfy the following:     P1   and   P2   are primes     P1  +  2   =   P2 Task Write a program that displays the number of pairs of twin primes that can be found under a user-specified number (P1 < user-specified number & P2 < user-specified numbe...
#C.23
C#
using System;   class Program {   static uint[] res = new uint[10]; static uint ri = 1, p = 10, count = 0;   static void TabulateTwinPrimes(uint bound) { if (bound < 5) return; count++; uint cl = (bound - 1) >> 1, i = 1, j, limit = (uint)(Math.Sqrt(bound) - 1) >> 1; var ...
http://rosettacode.org/wiki/Unprimeable_numbers
Unprimeable numbers
Definitions As used here, all unprimeable numbers   (positive integers)   are always expressed in base ten. ───── Definition from OEIS ─────: Unprimeable numbers are composite numbers that always remain composite when a single decimal digit of the number is changed. ───── Definition from Wiktionary   (reference...
#Julia
Julia
using Primes, Lazy, Formatting   function isunprimeable(n) dvec = digits(n) for pos in 1:length(dvec), newdigit in 0:9 olddigit, dvec[pos] = dvec[pos], newdigit isprime(foldr((i, j) -> i + 10j, dvec)) && return false dvec[pos] = olddigit end return true end   println("First 35 un...
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#PowerShell
PowerShell
  $Δ = 2 $π = 3.14 $π*$Δ  
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Prolog
Prolog
% Unicode in predicate names: 是. % be: means, approximately, "True". 不是 :- \+ 是. % not be: means, approximately, "False". Defined as not 是.   % Unicode in variable names: test(Garçon, Δ) :- Garçon = boy, Δ = delta.   % Call test2(1, Result) to have 2 assigned to Result. test2(Δ, R) :- R is Δ + 1.
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#Python
Python
>>> Δx = 1 >>> Δx += 1 >>> print(Δx) 2 >>>
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identif...
#R
R
f <- function(`∆`=1) `∆`+1   f(1)
http://rosettacode.org/wiki/Unbias_a_random_generator
Unbias a random generator
P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} P 0 {\displaystyle P_{0}} P 0 {\displaystyle P_{0}} P 1 {\displaystyle P_{1}} Task details Use your language's random number generator to create a function/method/sub...
#Go
Go
package main   import ( "fmt" "math/rand" )   const samples = 1e6   func main() { fmt.Println("Generator 1 count 0 count  % 1 count") for n := 3; n <= 6; n++ { // function randN, per task description randN := func() int { if rand.Intn(n) == 0 { return 1 ...
http://rosettacode.org/wiki/Truncate_a_file
Truncate a file
Task Truncate a file to a specific length.   This should be implemented as a routine that takes two parameters: the filename and the required file length (in bytes). Truncation can be achieved using system or library calls intended for such a task, if such methods exist, or by creating a temporary file of a reduced...
#11l
11l
F truncate_file(name, length) I !fs:is_file(name) R 0B I length >= fs:file_size(name) R 0B fs:resize_file(name, length) R 1B
http://rosettacode.org/wiki/Two_bullet_roulette
Two bullet roulette
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street: A revolver handgun has a revolving cylinder with six chambers for bullets. It is loaded with the following procedure: 1. Check the first chamber to the right of the trigger for a bullet. If a bullet is seen, the cyli...
#Julia
Julia
const cyl = zeros(Bool, 6)   function load() while cyl[1] cyl .= circshift(cyl, 1) end cyl[1] = true cyl .= circshift(cyl, 1) end   spin() = (cyl .= circshift(cyl, rand(1:6)))   fire() = (shot = cyl[1]; cyl .= circshift(cyl, 1); shot)   function LSLSFSF() cyl .= 0 load(); spin(); load();...
http://rosettacode.org/wiki/Two_bullet_roulette
Two bullet roulette
The following is supposedly a question given to mathematics graduates seeking jobs on Wall Street: A revolver handgun has a revolving cylinder with six chambers for bullets. It is loaded with the following procedure: 1. Check the first chamber to the right of the trigger for a bullet. If a bullet is seen, the cyli...
#Kotlin
Kotlin
import kotlin.random.Random   val cylinder = Array(6) { false }   fun rShift() { val t = cylinder[cylinder.size - 1] for (i in (0 until cylinder.size - 1).reversed()) { cylinder[i + 1] = cylinder[i] } cylinder[0] = t }   fun unload() { for (i in cylinder.indices) { cylinder[i] = fals...
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Pascal
Pascal
  Program ls; {To list the names of all files/directories in the current directory.} Uses DOS; var DirInfo: SearchRec; {Predefined. See page 403 of the Turbo Pascal 4 manual.} BEGIN FindFirst('*.*',AnyFile,DirInfo); {AnyFile means any file name OR directory name.} While DOSerror = 0 do {Result of FindFirst/Nex...
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths:...
#Perl
Perl
opendir my $handle, '.' or die "Couldnt open current directory: $!"; while (readdir $handle) { print "$_\n"; } closedir $handle;
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would repr...
#Simula
Simula
BEGIN   CLASS VECTOR(I,J,K); REAL I,J,K;;   REAL PROCEDURE DOTPRODUCT(A,B); REF(VECTOR) A,B; DOTPRODUCT := A.I*B.I+A.J*B.J+A.K*B.K;   REF(VECTOR) PROCEDURE CROSSPRODUCT(A,B); REF(VECTOR) A,B; CROSSPRODUCT :- NEW VECTOR(A.J*B.K - A.K*B.J, A.K*B.I - A.I*B.K, ...
http://rosettacode.org/wiki/Undefined_values
Undefined values
#R
R
  exists("x")  
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Racket
Racket
  -> (letrec ([x x]) x) #<undefined>  
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Perl
Perl
use utf8;
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#Phix
Phix
(in '(iconv "-f" "ISO-8859-15" "file.txt") (line))
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for ...
#PicoLisp
PicoLisp
(in '(iconv "-f" "ISO-8859-15" "file.txt") (line))