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/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#XSLT
XSLT
<xsl:variable name="foo" select="XPath expression" /> <xsl:if test="$foo = 4">... </xsl:if> <!-- prepend '$' to reference a variable or parameter-->
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Fortran
Fortran
IsNaN(x)
http://rosettacode.org/wiki/Undefined_values
Undefined values
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Dim i As Integer '' initialized to 0 by default Dim j As Integer = 3 '' initialized to 3 Dim k As Integer = Any '' left uninitialized (compiler warning but can be ignored)   Print i, j, k Sleep
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 ...
#80386_Assembly
80386 Assembly
#!/usr/local/bin/a68g --script # # -*- coding: utf-8 -*- #   # UNICHAR/UNICODE must be printed using REPR to convert to UTF8 #   MODE UNICHAR = STRUCT(BITS #31# bits); # assuming bits width >=31 # MODE UNICODE = FLEX[0]UNICHAR;   OP INITUNICHAR = (BITS bits)UNICHAR: (UNICHAR out; bits OF out := #ABS# bits; out); OP INI...
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...
#11l
11l
V limit = 10'000'000 V is_prime = [0B] * 2 [+] [1B] * (limit - 1) L(n) 0 .< Int(limit ^ 0.5 + 1.5) I is_prime[n] L(i) (n * n .< limit + 1).step(n) is_prime[i] = 0B   F unprimeable(a) I :is_prime[a] R 0B V d = 1 L d <= a V base = (a I/ (d * 10)) * (d * 10) + (a % d) I any((ba...
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...
#AutoHotkey
AutoHotkey
Δ = 1 Δ++ MsgBox, % Δ
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...
#BaCon
BaCon
PRAGMA COMPILER clang   DECLARE Δ TYPE INT   Δ = 1   INCR Δ   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...
#11l
11l
F randN(n) ‘1,0 random generator factory with 1 appearing 1/n'th of the time’ R () -> random:(@=n) == 0   F unbiased(biased) ‘uses a biased() generator of 1 or 0, to create an unbiased one’ V (this, that) = (biased(), biased()) L this == that (this, that) = (biased(), biased()) R this   L(n) 3.....
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...
#ALGOL_68
ALGOL 68
BEGIN # find some untouchable numbers - numbers not equal to the sum of the # # proper divisors of any +ve integer # INT max untouchable = 1 000 000; # a table of the untouchable numbers # [ 1 : max untouchable ]BOOL untouchable...
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:...
#C.23
C#
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks;   namespace Unix_ls { public class UnixLS { public static void Main(string[] args) { UnixLS ls = new UnixLS(); ls.list(args.Length.Equals(0) ? "." : args[0]);...
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:...
#C.2B.2B
C++
  #include <iostream> #include <set> #include <boost/filesystem.hpp>   namespace fs = boost::filesystem;   int main(void) { fs::path p(fs::current_path()); std::set<std::string> tree;   for (auto it = fs::directory_iterator(p); it != fs::directory_iterator(); ++it) tree.insert(it->path().filename()....
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...
#PowerShell
PowerShell
  function dot-product($a,$b) { $a[0]*$b[0] + $a[1]*$b[1] + $a[2]*$b[2] }   function cross-product($a,$b) { $v1 = $a[1]*$b[2] - $a[2]*$b[1] $v2 = $a[2]*$b[0] - $a[0]*$b[2] $v3 = $a[0]*$b[1] - $a[1]*$b[0] @($v1,$v2,$v3) }   function scalar-triple-product($a,$b,$c) { dot-product $a (cross-produc...
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
#Scheme
Scheme
(define str (read)) (define num (read)) (display "String = ") (display str) (display "Integer = ") (display num)
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
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local var integer: integer_input is 0; var string: string_input is ""; begin write("Enter an integer: "); readln(integer_input); write("Enter a string: "); readln(string_input); end func;
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Z80_Assembly
Z80 Assembly
UserRam equ &C000   ld a,&50 ;load hexadecimal 50 into A ld (UserRam),a ;initialize UserRam with a value of &50   ld a,&40 ;load hexadecimal 40 into A ld (UserRam),a ;assign UserRam a new value of &40
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#zkl
zkl
var v; // global to the class that encloses this file class C{ var v } // global to class C, each instance gets a new v class C{fcn f{var v=123;}} // v can only be seen by f, initialized when C is class C{fcn init{var [const] v=5;}} // init is part of the constructor, so vars are promoted yo class scope. This allo...
http://rosettacode.org/wiki/Undefined_values
Undefined values
#GAP
GAP
IsBound(a); # true   Unbind(a);   IsBound(a); # false
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Go
Go
package main   import "fmt"   var ( s []int p *int f func() i interface{} m map[int]int c chan int )   func main() { fmt.Println("Exercise nil objects:") status()   // initialize objects s = make([]int, 1) p = &s[0] // yes, reference element of slice just created f = func...
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 ...
#8th
8th
#!/usr/local/bin/a68g --script # # -*- coding: utf-8 -*- #   # UNICHAR/UNICODE must be printed using REPR to convert to UTF8 #   MODE UNICHAR = STRUCT(BITS #31# bits); # assuming bits width >=31 # MODE UNICODE = FLEX[0]UNICHAR;   OP INITUNICHAR = (BITS bits)UNICHAR: (UNICHAR out; bits OF out := #ABS# bits; out); OP INI...
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...
#ALGOL_68
ALGOL 68
BEGIN # find unprimable numbers - numbers which can't be made into a prime by changing one digit # # construct a sieve of primes up to max prime # PR read "primes.incl.a68" PR INT max prime = 9 999 999; []BOOL prime = PRIMESIEVE max prime; # returns TRUE if n is unprimeable, FALSE otherwise # PR...
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...
#Bracmat
Bracmat
( (Δ=1) & 1+!Δ:?Δ & out$("Δ:" !Δ) );
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...
#C
C
// Works for clang and GCC 10+ #include<stdio.h>   int main() { int Δ = 1; // if unsupported, use \u0394 Δ++; printf("%d",Δ); return 0; }
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...
#Ada
Ada
with Ada.Text_IO; with Ada.Numerics.Discrete_Random;   procedure Bias_Unbias is   Modulus: constant Integer := 60; -- lcm of {3,4,5,6} type M is mod Modulus; package Rand is new Ada.Numerics.Discrete_Random(M); Gen: Rand.Generator;   subtype Bit is Integer range 0 .. 1;   function Biased_Bit(Bias_Base...
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...
#C.2B.2B
C++
  // Untouchable Numbers : Nigel Galloway - March 4th., 2021; #include <functional> #include <bitset> #include <iostream> #include <cmath> using namespace std; using Z0=long long; using Z1=optional<Z0>; using Z2=optional<array<int,3>>; using Z3=function<Z2()>; const int maxUT{3000000}, dL{(int)log2(maxUT)}; struct uT{...
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:...
#Clojure
Clojure
(def files (sort (filter #(= "." (.getParent %)) (file-seq (clojure.java.io/file ".")))))   (doseq [n files] (println (.getName n)))
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:...
#Common_Lisp
Common Lisp
(defun files-list (&optional (path ".")) (let* ((dir (concatenate 'string path "/")) (abs-path (car (directory dir))) (file-pattern (concatenate 'string dir "*")) (subdir-pattern (concatenate 'string file-pattern "/"))) (remove-duplicates (mapcar (lambda (p) (enough-namestring p ...
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...
#Prolog
Prolog
  dot_product([A1, A2, A3], [B1, B2, B3], Ans) :- Ans is A1 * B1 + A2 * B2 + A3 * B3.   cross_product([A1, A2, A3], [B1, B2, B3], Ans) :- T1 is A2 * B3 - A3 * B2, T2 is A3 * B1 - A1 * B3, T3 is A1 * B2 - A2 * B1, Ans = [T1, T2, T3].   scala_triple(A, B, C, Ans) :- cross_product(B, C, Temp), ...
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
#Sidef
Sidef
var s = read(String); var i = read(Number); # auto-conversion to a number
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
#Slate
Slate
print: (query: 'Enter a String: '). [| n | n: (Integer readFrom: (query: 'Enter an Integer: ')). (n is: Integer) ifTrue: [print: n] ifFalse: [inform: 'Not an integer: ' ; n printString] ] do.
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Zoea
Zoea
program: variables # The concept of variables is completely alien in zoea: # there is no support for variables and no way of defining or using them. # Instead programs are described by giving examples of input and output values.  
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Haskell
Haskell
main = print $ "Incoming error--" ++ undefined -- When run in GHC: -- "Incoming error--*** Exception: Prelude.undefined
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Icon_and_Unicon
Icon and Unicon
global G1   procedure main(arglist) local ML1 static MS1 undeftest() end   procedure undeftest(P1) static S1 local L1,L2 every #write all local, parameter, static, and global variable names write((localnames|paramnames|staticnames|globalnames)(&curre...
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 ...
#Ada
Ada
#!/usr/local/bin/a68g --script # # -*- coding: utf-8 -*- #   # UNICHAR/UNICODE must be printed using REPR to convert to UTF8 #   MODE UNICHAR = STRUCT(BITS #31# bits); # assuming bits width >=31 # MODE UNICODE = FLEX[0]UNICHAR;   OP INITUNICHAR = (BITS bits)UNICHAR: (UNICHAR out; bits OF out := #ABS# bits; out); OP INI...
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...
#Arturo
Arturo
unprimeable?: function [n][ if prime? n -> return false nd: to :string n loop.with:'i nd 'prevDigit [ loop `0`..`9` 'newDigit [ if newDigit <> prevDigit [ nd\[i]: newDigit if prime? to :integer nd -> return false ] ] nd\[i]: pre...
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...
#C.23
C#
class Program { static void Main() { var Δ = 1; Δ++; System.Console.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...
#Clojure
Clojure
(let [Δ 1] (inc Δ))
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...
#Common_Lisp
Common Lisp
(let ((Δ 1)) (incf Δ))
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...
#Aime
Aime
integer biased(integer bias) { 1 ^ min(drand(bias - 1), 1); }   integer unbiased(integer bias) { integer a;   while ((a = biased(bias)) == biased(bias)) { }   a; }   integer main(void) { integer b, n, cb, cu, i;   n = 10000; b = 3; while (b <= 6) { i = cb = cu = 0; wh...
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...
#AutoHotkey
AutoHotkey
Biased(){ Random, q, 0, 4 return q=4 } Unbiased(){ Loop If ((a := Biased()) != biased()) return a } Loop 1000 t .= biased(), t2 .= unbiased() StringReplace, junk, t2, 1, , UseErrorLevel MsgBox % "Unbiased probability of a 1 occurring: " Errorlevel/1000 StringReplace, junk, t, 1, , UseErrorLe...
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...
#Delphi
Delphi
  program Untouchable_numbers;   {$APPTYPE CONSOLE}   uses System.SysUtils;   function SumDivisors(n: Integer): Integer; begin Result := 1; var k := 2; if not odd(n) then k := 1; var i := 1 + k; while i * i <= n do begin if (n mod i) = 0 then begin inc(Result, i); var j := n div 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:...
#D
D
void main() { import std.stdio, std.file, std.path, std.array, std.algorithm;   foreach (const string path; dirEntries(getcwd, SpanMode.shallow).array.sort) path.baseName.writeln; }
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:...
#Delphi
Delphi
  program LsCommand;   {$APPTYPE CONSOLE}       uses System.SysUtils, System.IoUtils;   procedure Ls(folder: string = '.'); var offset: Integer; fileName: string;   // simulate unix results in windows   function ToUnix(path: string): string; begin Result := path.Replace('/', PathDelim, [rfReplaceAll])...
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...
#PureBasic
PureBasic
Structure vector x.f y.f z.f EndStructure   ;convert vector to a string for display Procedure.s toString(*v.vector) ProcedureReturn "[" + StrF(*v\x, 2) + ", " + StrF(*v\y, 2) + ", " + StrF(*v\z, 2) + "]" EndProcedure   Procedure.f dotProduct(*a.vector, *b.vector) ProcedureReturn *a\x * *b\x + *a\y * *b\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
#Smalltalk
Smalltalk
'Enter a number: ' display. a := stdin nextLine asInteger.   'Enter a string: ' display. b := stdin nextLine.
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
#smart_BASIC
smart BASIC
INPUT "Enter a string.":a$ INPUT "Enter the value 75000.":n
http://rosettacode.org/wiki/Undefined_values
Undefined values
#J
J
  foo=: 3 nc;:'foo bar' 0 _1
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Java
Java
String string = null; // the variable string is undefined System.out.println(string); //prints "null" to std out System.out.println(string.length()); // dereferencing null throws java.lang.NullPointerException
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 ...
#ALGOL_68
ALGOL 68
#!/usr/local/bin/a68g --script # # -*- coding: utf-8 -*- #   # UNICHAR/UNICODE must be printed using REPR to convert to UTF8 #   MODE UNICHAR = STRUCT(BITS #31# bits); # assuming bits width >=31 # MODE UNICODE = FLEX[0]UNICHAR;   OP INITUNICHAR = (BITS bits)UNICHAR: (UNICHAR out; bits OF out := #ABS# bits; out); OP INI...
http://rosettacode.org/wiki/Ultra_useful_primes
Ultra useful primes
An ultra-useful prime is a member of the sequence where each a(n) is the smallest positive integer k such that 2(2n) - k is prime. k must always be an odd number since 2 to any power is always even. Task Find and show here, on this page, the first 10 elements of the sequence. Stretch Find and show the next sev...
#ALGOL_68
ALGOL 68
BEGIN # find members of the sequence a(n) = smallest k such that 2^(2^n) - k is prime # PR precision 650 PR # set number of digits for LONG LOMG INT # # 2^(2^10) has 308 digits but we need more for # # Miller Rabin primality testing # PR read "...
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...
#C
C
#include <assert.h> #include <locale.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h>   typedef struct bit_array_tag { uint32_t size; uint32_t* array; } bit_array;   bool bit_array_create(bit_array* b, uint32_t size) { uint32_t* array = calloc((size + 31)/32, sizeof(uint32_...
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...
#Crystal
Crystal
Δ = 1 Δ += 1 puts Δ
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...
#D
D
import std.stdio;   void main() { auto Δ = 1; Δ++; writeln(Δ); }
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...
#Delphi
Delphi
(* Compiled with Delphi XE *) program UnicodeVariableName;   {$APPTYPE CONSOLE}   uses SysUtils;   var Δ: Integer;   begin Δ:= 1; Inc(Δ); Writeln(Δ); Readln; end.
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...
#BASIC
BASIC
  function randN (n) if int(rand * n) + 1 <> 1 then return 0 else return 1 end function   function unbiased (n) do a = randN (n) b = randN (n) until a <> b return a end function   numveces = 100000   print "Resultados de números aleatorios sesgados e imparciales" + chr(10) for n = 3 to 6 dim b_numveces(n) fill...
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...
#BBC_BASIC
BBC BASIC
FOR N% = 3 TO 6 biased% = 0 unbiased% = 0 FOR I% = 1 TO 10000 IF FNrandN(N%) biased% += 1 IF FNunbiased(N%) unbiased% += 1 NEXT PRINT "N = ";N% " : biased = "; biased%/100 "%, unbiased = "; unbiased%/100 "%" NEXT END   DEF FNunbiased(N%...
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...
#F.23
F#
  // Applied dendrology. Nigel Galloway: February 15., 2021 let uT a=let N,G=Array.create(a+1) true, [|yield! primes64()|>Seq.takeWhile((>)(int64 a))|] let fN n i e=let mutable p=e-1 in (fun()->p<-p+1; if p<G.Length && (n+i)*(1L+G.[p])-n*G.[p]<=(int64 a) then Some(n,i,p) else None) let fG n i e=let ...
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:...
#EchoLisp
EchoLisp
  ;; ls of stores (kind of folders) (for-each writeln (list-sort < (local-stores))) → AGES NEMESIS info objects.dat reader system user words   ;; ls of "NEMESIS" store (for-each writeln (local-keys "NEMESIS")) → Alan Glory Jonah  
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:...
#Elixir
Elixir
iex(1)> ls = fn dir -> File.ls!(dir) |> Enum.each(&IO.puts &1) end #Function<6.54118792/1 in :erl_eval.expr/5> iex(2)> ls.("foo") bar :ok iex(3)> ls.("foo/bar") 1 2 a b :ok
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...
#Python
Python
def crossp(a, b): '''Cross product of two 3D vectors''' assert len(a) == len(b) == 3, 'For 3D vectors only' a1, a2, a3 = a b1, b2, b3 = b return (a2*b3 - a3*b2, a3*b1 - a1*b3, a1*b2 - a2*b1)   def dotp(a,b): '''Dot product of two eqi-dimensioned vectors''' assert len(a) == len(b), 'Vector si...
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
#SNOBOL4
SNOBOL4
output = "Enter a string:" str = trim(input) output = "Enter an integer:" int = trim(input) output = "String: " str " Integer: " int end
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
#SPL
SPL
text = #.input("Input a string") number = #.val(#.input("Input a number"))
http://rosettacode.org/wiki/Undefined_values
Undefined values
#JavaScript
JavaScript
var a;   typeof(a) === "undefined"; typeof(b) === "undefined";   var obj = {}; // Empty object. typeof(obj.c) === "undefined";   obj.c = 42;   obj.c === 42; delete obj.c; typeof(obj.c) === "undefined";
http://rosettacode.org/wiki/Undefined_values
Undefined values
#jq
jq
{}["key"] #=> null
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 ...
#Arturo
Arturo
text: "你好"   print ["text:" text] print ["length:" size text] print ["contains string '好'?:" contains? text "好"] print ["contains character '平'?:" contains? text `平`] print ["text as ascii:" as.ascii text]
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 ...
#AutoHotkey
AutoHotkey
VDU 23,22,640;512;8,16,16,128+8 : REM Select UTF-8 mode *FONT Times New Roman, 20   PRINT "Arabic:"   arabic1$ = "هنا مثال يمكنك من الكتابة من اليمين" arabic2$ = "الى اليسار باللغة العربية"   VDU 23,16,2;0;0;0;13 : REM Select right-to-left printing PRINT FNarabic(arabic1$) ' FN...
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 ...
#AWK
AWK
VDU 23,22,640;512;8,16,16,128+8 : REM Select UTF-8 mode *FONT Times New Roman, 20   PRINT "Arabic:"   arabic1$ = "هنا مثال يمكنك من الكتابة من اليمين" arabic2$ = "الى اليسار باللغة العربية"   VDU 23,16,2;0;0;0;13 : REM Select right-to-left printing PRINT FNarabic(arabic1$) ' FN...
http://rosettacode.org/wiki/Ultra_useful_primes
Ultra useful primes
An ultra-useful prime is a member of the sequence where each a(n) is the smallest positive integer k such that 2(2n) - k is prime. k must always be an odd number since 2 to any power is always even. Task Find and show here, on this page, the first 10 elements of the sequence. Stretch Find and show the next sev...
#Arturo
Arturo
ultraUseful: function [n][ k: 1 p: (2^2^n) - k while ø [ if prime? p -> return k p: p-2 k: k+2 ] ]   print [pad "n" 3 "|" pad.right "k" 4] print repeat "-" 10 loop 1..10 'x -> print [(pad to :string x 3) "|" (pad.right to :string ultraUseful x 4)]
http://rosettacode.org/wiki/Ultra_useful_primes
Ultra useful primes
An ultra-useful prime is a member of the sequence where each a(n) is the smallest positive integer k such that 2(2n) - k is prime. k must always be an odd number since 2 to any power is always even. Task Find and show here, on this page, the first 10 elements of the sequence. Stretch Find and show the next sev...
#Factor
Factor
USING: io kernel lists lists.lazy math math.primes prettyprint ;   : useful ( -- list ) 1 lfrom [ 2^ 2^ 1 lfrom [ - prime? ] with lfilter car ] lmap-lazy ;   10 useful ltake [ pprint bl ] leach nl
http://rosettacode.org/wiki/Ultra_useful_primes
Ultra useful primes
An ultra-useful prime is a member of the sequence where each a(n) is the smallest positive integer k such that 2(2n) - k is prime. k must always be an odd number since 2 to any power is always even. Task Find and show here, on this page, the first 10 elements of the sequence. Stretch Find and show the next sev...
#Go
Go
package main   import ( "fmt" big "github.com/ncw/gmp" )   var two = big.NewInt(2)   func a(n uint) int { one := big.NewInt(1) p := new(big.Int).Lsh(one, 1 << n) p.Sub(p, one) for k := 1; ; k += 2 { if p.ProbablyPrime(15) { return k } p.Sub(p, two) } }   f...
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...
#C.2B.2B
C++
#include <iostream> #include <cstdint> #include "prime_sieve.hpp"   typedef uint32_t integer;   // return number of decimal digits int count_digits(integer n) { int digits = 0; for (; n > 0; ++digits) n /= 10; return digits; }   // return the number with one digit replaced integer change_digit(integ...
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...
#DWScript
DWScript
var Δ : Integer;   Δ := 1; Inc(Δ); PrintLn(Δ);
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...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
set :Δ 1 set :Δ ++ Δ !. Δ
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...
#EchoLisp
EchoLisp
  (define ∆-🍒 1) → ∆-🍒 (set! ∆-🍒 (1+ ∆-🍒)) → 2 (printf "🔦 Look at ∆-🍒 : %d" ∆-🍒) 🔦 Look at ∆-🍒 : 2  
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...
#C
C
#include <stdio.h> #include <stdlib.h>   int biased(int bias) { /* balance out the bins, being pedantic */ int r, rand_max = RAND_MAX - (RAND_MAX % bias); while ((r = rand()) > rand_max); return r < rand_max / bias; }   int unbiased(int bias) { int a; while ((a = biased(bias)) == biased(bias)); return a; }   int...
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...
#Go
Go
package main   import "fmt"   func sumDivisors(n int) int { sum := 1 k := 2 if n%2 == 0 { k = 1 } for i := 1 + k; i*i <= n; i += k { if n%i == 0 { sum += i j := n / i if j != i { sum += j } } } return sum...
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:...
#Erlang
Erlang
  1> Ls = fun(Dir) -> 1> {ok, DirContents} = file:list_dir(Dir), 1> [io:format("~s~n", [X]) || X <- lists:sort(DirContents)] 1> end. #Fun<erl_eval.6.36634728> 2> Ls("foo"). bar [ok] 3> Ls("foo/bar"). 1 2 a b [ok,ok,ok,ok]  
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:...
#F.23
F#
let ls = DirectoryInfo(".").EnumerateFileSystemInfos() |> Seq.map (fun i -> i.Name) |> Seq.sort |> Seq.iter (printfn "%s")
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...
#Quackery
Quackery
[ 0 unrot witheach [ over i^ peek * rot + swap ] drop ] is dotproduct ( [ [ --> n )   [ join dup 1 peek over 5 peek * swap dup 2 peek over 4 peek * swap dip - dup 2 peek over 3 peek * swap dup 0 peek over 5 peek * swap dip - dup 0 peek o...
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
#Standard_ML
Standard ML
print "Enter a string: "; let val str = valOf (TextIO.inputLine TextIO.stdIn) in (* note: this keeps the trailing newline *) print "Enter an integer: "; let val num = valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn) in print (str ^ Int.toString num ^ "\n") end end
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
#Swift
Swift
print("Enter a string: ", terminator: "") if let str = readLine() { print(str) }
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Julia
Julia
julia> x + 1 ERROR: UndefVarError: x not defined Stacktrace: [1] top-level scope at none:0
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Kotlin
Kotlin
// version 1.1.2   class SomeClass   class SomeOtherClass { lateinit var sc: SomeClass   fun initialize() { sc = SomeClass() // not initialized in place or in constructor }   fun printSomething() { println(sc) // 'sc' may not have been initialized at this point }   fun someFun...
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 ...
#BBC_BASIC
BBC BASIC
VDU 23,22,640;512;8,16,16,128+8 : REM Select UTF-8 mode *FONT Times New Roman, 20   PRINT "Arabic:"   arabic1$ = "هنا مثال يمكنك من الكتابة من اليمين" arabic2$ = "الى اليسار باللغة العربية"   VDU 23,16,2;0;0;0;13 : REM Select right-to-left printing PRINT FNarabic(arabic1$) ' FN...
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 ...
#Bracmat
Bracmat
#include <stdio.h> #include <stdlib.h> #include <locale.h>   /* wchar_t is the standard type for wide chars; what it is internally * depends on the compiler. */ wchar_t poker[] = L"♥♦♣♠"; wchar_t four_two[] = L"\x56db\x5341\x4e8c";   int main() { /* Set the locale to alert C's multibyte output routines */ if ...
http://rosettacode.org/wiki/Ultra_useful_primes
Ultra useful primes
An ultra-useful prime is a member of the sequence where each a(n) is the smallest positive integer k such that 2(2n) - k is prime. k must always be an odd number since 2 to any power is always even. Task Find and show here, on this page, the first 10 elements of the sequence. Stretch Find and show the next sev...
#Julia
Julia
using Primes   nearpow2pow2prime(n) = findfirst(k -> isprime(2^(big"2"^n) - k), 1:10000)   @time println([nearpow2pow2prime(n) for n in 1:12])  
http://rosettacode.org/wiki/Ultra_useful_primes
Ultra useful primes
An ultra-useful prime is a member of the sequence where each a(n) is the smallest positive integer k such that 2(2n) - k is prime. k must always be an odd number since 2 to any power is always even. Task Find and show here, on this page, the first 10 elements of the sequence. Stretch Find and show the next sev...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[FindUltraUsefulPrimeK] FindUltraUsefulPrimeK[n_] := Module[{num, tmp}, num = 2^(2^n); Do[ If[PrimeQ[num - k], tmp = k; Break[]; ] , {k, 1, \[Infinity], 2} ]; tmp ] res = FindUltraUsefulPrimeK /@ Range[13]; TableForm[res, TableHeadings -> Automatic]
http://rosettacode.org/wiki/Ultra_useful_primes
Ultra useful primes
An ultra-useful prime is a member of the sequence where each a(n) is the smallest positive integer k such that 2(2n) - k is prime. k must always be an odd number since 2 to any power is always even. Task Find and show here, on this page, the first 10 elements of the sequence. Stretch Find and show the next sev...
#Perl
Perl
use strict; use warnings; use feature 'say'; use bigint; use ntheory 'is_prime';   sub useful { my @n = @_; my @u; for my $n (@n) { my $p = 2**(2**$n); LOOP: for (my $k = 1; $k < $p; $k += 2) { is_prime($p-$k) and push @u, $k and last LOOP; } } @u }   say join ' ',...
http://rosettacode.org/wiki/Ultra_useful_primes
Ultra useful primes
An ultra-useful prime is a member of the sequence where each a(n) is the smallest positive integer k such that 2(2n) - k is prime. k must always be an odd number since 2 to any power is always even. Task Find and show here, on this page, the first 10 elements of the sequence. Stretch Find and show the next sev...
#Phix
Phix
with javascript_semantics atom t0 = time() include mpfr.e mpz p = mpz_init() function a(integer n) mpz_ui_pow_ui(p,2,power(2,n)) mpz_sub_si(p,p,1) integer k = 1 while not mpz_prime(p) do k += 2 mpz_sub_si(p,p,2) end while return k end function for i=1 to 10 do printf(1,"%...
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...
#D
D
import std.algorithm; import std.array; import std.conv; import std.range; import std.stdio;   immutable MAX = 10_000_000; bool[] primes;   bool[] sieve(int limit) { bool[] p = uninitializedArray!(bool[])(limit); p[0..2] = false; p[2..$] = true; foreach (i; 2..limit) { if (p[i]) { fo...
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...
#Elena
Elena
public program() { var Δ := 1; Δ := Δ + 1;   console.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...
#Emacs_Lisp
Emacs Lisp
(setq Δ 1) (setq Δ (1+ Δ)) (message "Δ is %d" Δ)
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...
#F.23
F#
let mutable Δ = 1 Δ <- Δ + 1 printfn "%d" Δ
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...
#C.2B.2B
C++
#include <iostream> #include <random>   std::default_random_engine generator; bool biased(int n) { std::uniform_int_distribution<int> distribution(1, n); return distribution(generator) == 1; }   bool unbiased(int n) { bool flip1, flip2;   /* Flip twice, and check if the values are the same. * If so...
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...
#J
J
  factor=: 3 : 0 NB. explicit 'primes powers'=. __&q: y input_to_cartesian_product=. primes ^&.> i.&.> >: powers cartesian_product=. , { input_to_cartesian_product , */&> cartesian_product )   factor=: [: , [: */&> [: { [: (^&.> i.&.>@>:)/ __&q: NB. tacit     proper_divisors=: [: }: factor ...
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...
#Julia
Julia
using Primes   function properfactorsum(n) f = [one(n)] for (p,e) in factor(n) f = reduce(vcat, [f*p^j for j in 1:e], init=f) end pop!(f) return sum(f) end   const maxtarget, sievelimit = 1_000_000, 512_000_000 const untouchables = ones(Bool, maxtarget)   for i in 2:sievelimit n = proper...
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:...
#Forth
Forth
256 buffer: filename-buf : each-filename { xt -- } \ xt-consuming variant s" ." open-dir throw { d } begin filename-buf 256 d read-dir throw while filename-buf swap xt execute repeat d close-dir throw ;   \ immediate variant : each-filename[ s" ." postpone sliteral ]] open-dir throw >r begin filename-buf 2...
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:...
#Fortran
Fortran
PROGRAM LS !Names the files in the current directory. USE DFLIB !Mysterious library. TYPE(FILE$INFO) INFO !With mysterious content. NAMELIST /HIC/INFO !This enables annotated output. INTEGER MARK,L !Assistants.   MARK = FILE$FIRST !Starting state. Call for the next file. 10 L...
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...
#R
R
#=============================================================== # Vector products # R implementation #===============================================================   a <- c(3, 4, 5) b <- c(4, 3, 5) c <- c(-5, -12, -13)   #--------------------------------------------------------------- # Dot product #----------------...
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
#Tcl
Tcl
set str [gets stdin] set num [gets stdin]
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
#TI-83_BASIC
TI-83 BASIC
   :Input "Enter a string:",Str1  :Prompt i  :If(i ≠ 75000): Then  :Disp "That isn't 75000"  :Else  :Stop