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/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#SQL
SQL
  CREATE TEMPORARY TABLE factors(n INT); INSERT INTO factors VALUES(2); INSERT INTO factors VALUES(3); INSERT INTO factors VALUES(5);   CREATE TEMPORARY TABLE hamming AS WITH RECURSIVE ham AS ( SELECT 1 AS h UNION SELECT h*n x FROM ham JOIN factors ORDER BY x LIMIT 1700 ...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Racket
Racket
#lang racket   (define (guess-number min max) (define target (+ min (random (- max min -1)))) (printf "I'm thinking of a number between ~a and ~a\n" min max) (let loop ([prompt "Your guess"]) (printf "~a: " prompt) (flush-output) (define guess (read)) (define response (cond [(not (exact-inte...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Raku
Raku
my $maxnum = prompt("Hello, please give me an upper boundary: "); until 0 < $maxnum < Inf { say "Oops! The upper boundary should be > 0 and not Inf"; $maxnum = prompt("Please give me a valid upper boundary: "); }   my $count = 0; my $number = (1..$maxnum).pick;   say "I'm thinking of a number from 1 to $maxnum,...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#PureBasic
PureBasic
#ToFind=8 #MaxTests=100 #True = 1: #False = 0 Declare is_happy(n)   If OpenConsole() Define i=1,Happy Repeat If is_happy(i) Happy+1 PrintN("#"+Str(Happy)+RSet(Str(i),3)) EndIf i+1 Until Happy>=#ToFind ; Print(#CRLF$+#CRLF$+"Press ENTER to exit"): Input() CloseConsole() EndIf   Proced...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#Lang5
Lang5
"Hello world!\n" .
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#Go
Go
a, b = b, a
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Icon_and_Unicon
Icon and Unicon
procedure main() local l l := [7,8,6,9,4,5,2,3,1] write(max(l)) end   procedure max(l) local max max := l[1] every max <:= !l return max end
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#Free_Pascal
Free Pascal
' version 17-06-2015 ' compile with: fbc -s console   Function gcd(x As ULongInt, y As ULongInt) As ULongInt   Dim As ULongInt t   While y t = y y = x Mod y x = t Wend   Return x   End Function   ' ------=< MAIN >=------   Dim As ULongInt a = 111111111111111 Dim As ULongInt b = 1...
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#HicEst
HicEst
DIMENSION stones(1000)   H27 = hailstone(27) ALIAS(stones,1, first4,4) ALIAS(stones,H27-3, last4,4) WRITE(ClipBoard, Name) H27, first4, "...", last4   longest_sequence = 0 DO try = 1, 1E5 elements = hailstone(try) IF(elements >= longest_sequence) THEN number = try longest_sequence = elements WRIT...
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#Tcl
Tcl
package require Tcl 8.6   # Simple helper: Tcl-style list "map" proc map {varName list script} { set l {} upvar 1 $varName v foreach v $list {lappend l [uplevel 1 $script]} return $l }   # The core of a coroutine to compute the product of a hamming sequence. # # Tricky bit: we don't automatically advanc...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Retro
Retro
: high|low ( gn-g$ ) over > [ "high" ] [ "low" ] if ;   : checkGuess ( gn-gf || f ) 2over = [ "You guessed correctly!\n" puts 2drop 0 ] [ high|low "Sorry, your guess was too %s.\nTry again.\n" puts -1 ] if ;   : think ( -n ) random abs 100 mod 1+ ;   : guess ( - ) "I'm thinking of a number between 1 a...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#REXX
REXX
/*REXX program plays guess the number game with a human; the computer picks the number*/ low= 1 /*the lower range for the guessing game*/ high= 100 /* " upper " " " " " */ try= 0 ...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#Python
Python
>>> def happy(n): past = set() while n != 1: n = sum(int(i)**2 for i in str(n)) if n in past: return False past.add(n) return True   >>> [x for x in xrange(500) if happy(x)][:8] [1, 7, 10, 13, 19, 23, 28, 31]
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#langur
langur
writeln "yo, peeps"
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#Gri
Gri
`Swap Vars &.a. &.b.' { new .temp. .temp. = \.word2. \.word2. = \.word3. \.word3. = .temp. delete .temp. }   .foo. = 123 .bar. = 456 Swap Vars &.foo. &.bar.   show .foo. " " .bar. # prints "456 123"
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#IS-BASIC
IS-BASIC
1000 DEF FINDMAX(REF ARR) 1010 LET MX=ARR(LBOUND(ARR)) 1020 FOR I=LBOUND(ARR)+1 TO UBOUND(ARR) 1030 LET MX=MAX(MX,ARR(I)) 1040 NEXT 1050 LET FINDMAX=MX 1060 END DEF
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#J
J
>./
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#FreeBASIC
FreeBASIC
' version 17-06-2015 ' compile with: fbc -s console   Function gcd(x As ULongInt, y As ULongInt) As ULongInt   Dim As ULongInt t   While y t = y y = x Mod y x = t Wend   Return x   End Function   ' ------=< MAIN >=------   Dim As ULongInt a = 111111111111111 Dim As ULongInt b = 1...
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#Icon_and_Unicon
Icon and Unicon
procedure hailstone(n) while n > 1 do { suspend n n := if n%2 = 0 then n/2 else 3*n+1 } suspend 1 end
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#uBasic.2F4tH
uBasic/4tH
For H = 1 To 20 Print "H("; H; ") = "; Func (_FnHamming(H)) Next   End   _FnHamming Param (1) @(0) = 1   X = 2 : Y = 3 : Z = 5 I = 0 : J = 0 : K = 0   For N = 1 To a@ - 1 M = X If M > Y Then M = Y If M > Z Then M = Z @(N) = M   If M = X Then I = I + 1 : X = 2 * @(I) If M = Y Then J = J...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Ring
Ring
fr = 1 t0 = 10 while true see "Hey There, ======================== I'm thinking of a number between " + fr + " and " + t0 + ", Can you guess it?? Guess :> " give x n = nrandom(fr,t0) if x = n see "   Congratulations :D   ***************************************************** ** Your guess was rig...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Ruby
Ruby
number = rand(1..10)   puts "Guess the number between 1 and 10"   loop do begin user_number = Integer(gets) if user_number == number puts "You guessed it." break elsif user_number > number puts "Too high." else puts "Too low." end rescue ArgumentError puts "Please e...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#Quackery
Quackery
  [ 0 swap [ 10 /mod 2 ** rot + swap dup 0 = until ] drop ] is digitsquare ( n --> n )   [ [ digitsquare dup 1 != while dup 42 != while again ] 1 = ] is happy ( n --> b )   [ [] 1 [ dip [ 2dup size > ] ...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#Lasso
Lasso
'Hello world!'
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#Groovy
Groovy
(a, b) = [b, a]
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Janet
Janet
  (def elems @[3 1 3 2])   # Use extreme function from stdlib with > function. (extreme > elems)   # Unpack list as arguments to max function. (max ;elems)  
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Java
Java
public static float max(float[] values) throws NoSuchElementException { if (values.length == 0) throw new NoSuchElementException(); float themax = values[0]; for (int idx = 1; idx < values.length; ++idx) { if (values[idx] > themax) themax = values[idx]; } return themax; }
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#Frege
Frege
module gcd.GCD where   pure native parseInt java.lang.Integer.parseInt :: String -> Int   gcd' a 0 = a gcd' a b = gcd' b (a `mod` b)   main args = do (a:b:_) = args println $ gcd' (parseInt a) (parseInt b)  
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#Inform_7
Inform 7
Home is a room.   To decide which list of numbers is the hailstone sequence for (N - number): let result be a list of numbers; add N to result; while N is not 1: if N is even, let N be N / 2; otherwise let N be (3 * N) + 1; add N to result; decide on result.   Hailstone length cache relates various numbers to...
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#UNIX_Shell
UNIX Shell
typeset -a hamming=(1) function nextHamming { typeset -Sa q2 q3 q5 integer h=${hamming[${#hamming[@]}-1]} q2+=( $(( h*2 )) ) q3+=( $(( h*3 )) ) q5+=( $(( h*5 )) ) h=$( min3 ${q2[0]} ${q3[0]} ${q5[0]} ) (( ${q2[0]} == h )) && ashift q2 >/dev/null (( ${q3[0]} == h )) && ashift q3 >/dev/nul...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Rust
Rust
use rand::Rng; use std::cmp::Ordering; use std::io;   const LOWEST: u32 = 1; const HIGHEST: u32 = 100;   fn main() { let secret_number = rand::thread_rng().gen_range(1..101);   println!("I have chosen my number between {} and {}. Guess the number!", LOWEST, HIGHEST);   loop { println!("Please input ...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Scala
Scala
import java.util.Random import java.util.Scanner   val scan = new Scanner(System.in) val random = new Random val (from , to) = (1, 100) val randomNumber = random.nextInt(to - from + 1) + from var guessedNumber = 0 printf("The number is between %d and %d.\n", from, to)   do { print("Guess what the number is: ") gues...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#R
R
is.happy <- function(n) { stopifnot(is.numeric(n) && length(n)==1) getdigits <- function(n) { as.integer(unlist(strsplit(as.character(n), ""))) } digits <- getdigits(n) previous <- c() repeat { sumsq <- sum(digits^2, na.rm=TRUE) if(sumsq==1L) { happy <- TRUE ...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#LaTeX
LaTeX
\documentclass{minimal} \begin{document} Hello World! \end{document}
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#Harbour
Harbour
PROCEDURE Swap( /*@*/v1, /*@*/v2 ) LOCAL xTmp xTmp := v1 v1 := v2 v2 := xTmp RETURN  
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#JavaScript
JavaScript
Math.max.apply(null, [ 0, 1, 2, 5, 4 ]); // 5
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#Frink
Frink
  println[gcd[12345,98765]]  
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#FunL
FunL
def gcd( 0, 0 ) = error( 'integers.gcd: gcd( 0, 0 ) is undefined' ) gcd( a, b ) = def _gcd( a, 0 ) = a _gcd( a, b ) = _gcd( b, a%b )   _gcd( abs(a), abs(b) )
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#Io
Io
  makeItHail := method(n, stones := list(n) while (n != 1, if(n isEven, n = n / 2, n = 3 * n + 1 ) stones append(n) ) stones )   out := makeItHail(27) writeln("For the sequence beginning at 27, the number of elements generated is ", out size, ".") write("The first four elements generated...
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#Ursala
Ursala
#import std #import nat   smooth"p" "n" = ~&z take/"n" nleq-< (rep(length "n") ^Ts/~& product*K0/"p") <1>
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Scheme
Scheme
(define maximum 5) (define minimum -5) (define number (+ (random (- (+ maximum 1) minimum)) minimum))   (display "Pick a number from ") (display minimum) (display " through ") (display maximum) (display ".\n> ") (do ((guess (read) (read))) ((eq? guess number)) (if (or (>= guess maximum) (< guess minimum)) ...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#Racket
Racket
#lang racket (define (sum-of-squared-digits number (result 0)) (if (zero? number) result (sum-of-squared-digits (quotient number 10) (+ result (expt (remainder number 10) 2)))))   (define (happy-number? number (seen null)) (define next (sum-of-squared-digits number)) (cond...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#Latitude
Latitude
putln "Hello world!".
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#Haskell
Haskell
swap :: (a, b) -> (b, a) swap (x, y) = (y, x)
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#jq
jq
[1, 3, 1.0] | max # => 3   [ {"a": 1}, {"a":3}, {"a":1.0}] | max # => {"a": 3}
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Julia
Julia
julia> maximum([1,3,3,7]) 7   julia> maximum([pi,e+2/5,cos(6)/5,sqrt(91/10)]) 3.141592653589793   julia> maximum([1,6,Inf]) Inf   julia> maximum(Float64[]) maximum: argument is empty at In[138]:1 in maximum at abstractarray.jl:1591  
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#FutureBasic
FutureBasic
window 1, @"Greatest Common Divisor", (0,0,480,270)   local fn gcd( a as short, b as short ) as short short result   if ( b != 0 ) result = fn gcd( b, a mod b) else result = abs(a) end if end fn = result   print fn gcd( 6, 9 )   HandleEvents
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#GAP
GAP
# Built-in GcdInt(35, 42); # 7   # Euclidean algorithm GcdInteger := function(a, b) local c; a := AbsInt(a); b := AbsInt(b); while b > 0 do c := a; a := b; b := RemInt(c, b); od; return a; end;   GcdInteger(35, 42); # 7
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#Ioke
Ioke
collatz = method(n, n println unless(n <= 1, if(n even?, collatz(n / 2), collatz(n * 3 + 1))) )
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#VBA
VBA
'RosettaCode Hamming numbers 'This is a well known hard problem in number theory: 'counting the number of lattice points in a 'n-dimensional tetrahedron, here n=3. Public a As Double, b As Double, c As Double, d As Double Public p As Double, q As Double, r As Double Public cnt() As Integer 'stores the number of lattice...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Seed7
Seed7
$ include "seed7_05.s7i";   const integer: lower_limit is 0; const integer: upper_limit is 100;   const proc: main is func local var integer: number is 0; var integer: guess is 0; begin number := rand(lower_limit, upper_limit); write("Guess the number between " <& lower_limit <& " and " <& upper_lim...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Sidef
Sidef
var number = rand(1..10); say "Guess the number between 1 and 10";   loop { given(var n = Sys.scanln("> ").to_i) { when (number) { say "You guessed it."; break } case (n < number) { say "Too low" } default { say "Too high" } } }
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#Raku
Raku
sub happy (Int $n is copy --> Bool) { loop { state %seen; $n = [+] $n.comb.map: { $_ ** 2 } return True if $n == 1; return False if %seen{$n}++; } }   say join ' ', grep(&happy, 1 .. *)[^8];
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#LC3_Assembly
LC3 Assembly
.orig x3000 LEA R0, hello  ; R0 = &hello TRAP x22  ; PUTS (print char array at addr in R0) HALT hello .stringz "Hello World!" .end
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#Icon_and_Unicon
Icon and Unicon
procedure main() x := 1 y := 2 x :=: y write(x," ",y) # swap that will reverse if surrounding expression fails if x <-> y & x < y then write(x, " ", y) end  
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#K
K
|/ 6 1 7 4 7
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#Genyris
Genyris
def gcd (u v) u = (abs u) v = (abs v) cond (equal? v 0) u else (gcd v (% u v))
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#GFA_Basic
GFA Basic
  ' ' Greatest Common Divisor ' a%=24 b%=112 PRINT "GCD of ";a%;" and ";b%;" is ";@gcd(a%,b%) ' ' Function computes gcd ' FUNCTION gcd(a%,b%) LOCAL t% ' WHILE b%<>0 t%=a% a%=b% b%=t% MOD b% WEND ' RETURN ABS(a%) ENDFUNC  
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#J
J
hailseq=: -:`(1 3&p.)@.(2&|) ^:(1 ~: ]) ^:a:"0
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#VBScript
VBScript
  For h = 1 To 20 WScript.StdOut.Write "H(" & h & ") = " & Hamming(h) WScript.StdOut.WriteLine Next WScript.StdOut.Write "H(" & 1691 & ") = " & Hamming(1691) WScript.StdOut.WriteLine   Function Hamming(l) Dim h() : Redim h(l) : h(0) = 1 i = 0 : j = 0 : k = 0 x2 = 2 : x3 = 3 : x5 = 5 For n = 1 To l-1 m = x2 If...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Small_Basic
Small Basic
number=Math.GetRandomNumber(10) TextWindow.WriteLine("I just thought of a number between 1 and 10. What is it?") While guess<>number guess=TextWindow.ReadNumber() If guess>number Then TextWindow.WriteLine("Lower number!") EndIf If guess<number Then TextWindow.WriteLine("Higher number!") EndIf EndWhile...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Smalltalk
Smalltalk
  'From Pharo7.0.3 of 12 April 2019 [Build information: Pharo-7.0.3+build.158.sha.0903ade8a6c96633f07e0a7f1baa9a5d48cfdf55 (64 Bit)] on 30 October 2019 at 4:24:17.115807 pm'! Object subclass: #GuessingGame instanceVariableNames: 'min max uiManager tries' classVariableNames: '' poolDictionaries: '' category: 'Guessi...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#Relation
Relation
  function happy(x) set y = x set lasty = 0 set found = " " while y != 1 and not (found regex "\s".y."\s") set found = found . y . " " set m = 0 while y > 0 set digit = y mod 10 set m = m + digit * digit set y = (y - digit) / 10 end while set y = format(m,"%1d") end while set found = found . y . " " if y = 1 set re...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#LDPL
LDPL
  procedure: display "Hello World!" crlf  
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#IDL
IDL
pro swap, a, b c = temporary(a) a = temporary(b) b = temporary(c) end
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Klingphix
Klingphix
include ..\Utilitys.tlhy   ( "1" "1234" "62" "234" "12" "34" "6" )   dup "Alphabetic order: " print lmax ?   :f tonum ;   @f map   "Numeric order: " print lmax ?   " " input
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Klong
Klong
list::[ 1.0 2.3 1.1 5.0 3 2.8 2.01 3.14159 77 ] |/list |/ [ 1.0 2.3 1.1 5.0 3 2.8 2.01 3.14159 66 ] |/ 1.0,2.3,1.1,5.0,3,2.8,2.01,3.14159,55
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#GML
GML
  var n,m,r; n = max(argument0,argument1); m = min(argument0,argument1); while (m != 0) { r = n mod m; n = m; m = r; } return a;  
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#Java
Java
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;   class Hailstone {   public static List<Long> getHailstoneSequence(long n) { if (n <= 0) throw new IllegalArgumentException("Invalid starting sequence number"); List<Long> list = new ArrayList<Long>(); ...
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#Vlang
Vlang
import math.big   fn min(a big.Integer, b big.Integer) big.Integer { if a < b { return a } return b }   fn hamming(n int) []big.Integer { mut h := []big.Integer{len: n} h[0] = big.one_int two, three, five  := big.two_int, big.integer_from_int(3), big.integer_from_int(5) mut next2, ...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Sparkling
Sparkling
printf("Lower bound: "); let lowerBound = toint(getline());   printf("Upper bound: "); let upperBound = toint(getline());   assert(upperBound > lowerBound, "upper bound must be greater than lower bound");   seed(time()); let n = floor(random() * (upperBound - lowerBound) + lowerBound); var guess;   print();   while tru...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#REXX
REXX
/*REXX program computes and displays a specified amount of happy numbers. */ parse arg limit . /*obtain optional argument from the CL.*/ if limit=='' | limit=="," then limit=8 /*Not specified? Then use the default.*/ haps=0 ...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#Lean
Lean
  #eval "Hello world!"  
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#IS-BASIC
IS-BASIC
100 DEF SWAP(REF A,REF B) 110 LET T=A:LET A=B:LET B=T 120 END DEF 130 LET A=1:LET B=2 140 PRINT A,B 150 CALL SWAP(A,B) 160 PRINT A,B
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Kotlin
Kotlin
// version 1.0.5-2 fun main(args: Array<String>) { print("Number of values to be input = ") val n = readLine()!!.toInt() val array = DoubleArray(n) for (i in 0 until n) { print("Value ${i + 1} = ") array[i] = readLine()!!.toDouble() } println("\nThe greatest element is ${array....
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#gnuplot
gnuplot
gcd (a, b) = b == 0 ? a : gcd (b, a % b)
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#JavaScript
JavaScript
function hailstone (n) { var seq = [n]; while (n > 1) { n = n % 2 ? 3 * n + 1 : n / 2; seq.push(n); } return seq; }   // task 2: verify the sequence for n = 27 var h = hailstone(27), hLen = h.length; print("sequence 27 is (" + h.slice(0, 4).join(", ") + " ... " + h.slice(hLen - 4, hL...
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#Wren
Wren
import "/big" for BigInt, BigInts   var primes = [2, 3, 5].map { |p| BigInt.new(p) }.toList   var hamming = Fn.new { |size| if (size < 1) Fiber.abort("size must be at least 1") var ns = List.filled(size, null) ns[0] = BigInt.one var next = primes.toList var indices = List.filled(3, 0) for (m in ...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Swift
Swift
import Cocoa   var found = false   let randomNum = Int(arc4random_uniform(100) + 1)   println("Guess a number between 1 and 100\n")   while (!found) { var fh = NSFileHandle.fileHandleWithStandardInput()   println("Enter a number: ") let data = fh.availableData let str = NSString(data: data, encoding: NS...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#Ring
Ring
n = 1 found = 0   While found < 8 If IsHappy(n) found += 1 see string(found) + " : " + string(n) + nl ok n += 1 End   Func IsHappy n cache = [] While n != 1 Add(cache,n) t = 0 strn = string(n) for e in strn t += pow(number(e),2) ...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#LFE
LFE
  (: io format '"Hello world!~n")  
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#J
J
(<2 4) C. 2 3 5 7 11 13 17 19 2 3 11 7 5 13 17 19 (<0 3)&C.&.;:'Roses are red. Violets are blue.' Violets are red. Roses are blue.
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Lambdatalk
Lambdatalk
  1) using the builtin primitive   {max 556 1 7344 4 7 52 22 55 88 122 55 99 1222 578} -> 7344   2) buidling a function   {def my-max {def max-h {lambda {:l :greatest} {if {A.empty? :l} then :greatest else {max-h {A.rest :l} {if {> {A.first :l} :greatest} then {A.first :...
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#Go
Go
package main   import "fmt"   func gcd(a, b int) int { var bgcd func(a, b, res int) int   bgcd = func(a, b, res int) int { switch { case a == b: return res * a case a % 2 == 0 && b % 2 == 0: return bgcd(a/2, b/2, 2*res) case a % 2 == 0: return bgcd(a/2, b, res) case b % 2 == 0: return b...
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#jq
jq
# Generate the hailstone sequence as a stream to save space (and time) when counting def hailstone: recurse( if . > 1 then if . % 2 == 0 then ./2|floor else 3*. + 1 end else empty end );   def count(g): reduce g as $i (0; .+1);   # return [i, length] for the first maximal-length ha...
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#Yabasic
Yabasic
dim h(1000000) for i =1 to 20 print hamming(i)," "; next i   print print "Hamming List First(1691) = ",hamming(1691) end   sub hamming(limit) local x2,x3,x5,i,j,k,n   h(0) =1 x2 = 2: x3 = 3: x5 =5 i = 0: j = 0: k =0 for n =1 to limit h(n) = min(x2, min(x3, x5)) if x2 = h(n)...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#Tcl
Tcl
set from 1 set to 10 set target [expr {int(rand()*($to-$from+1) + $from)}] puts "I have thought of a number from $from to $to." puts "Try to guess it!" while 1 { puts -nonewline "Enter your guess: " flush stdout gets stdin guess if {![string is int -strict $guess] || $guess < $from || $guess > $to} { p...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#Ruby
Ruby
require 'set' # Set: Fast array lookup / Simple existence hash   @seen_numbers = Set.new @happy_numbers = Set.new   def happy?(n) return true if n == 1 # Base case return @happy_numbers.include?(n) if @seen_numbers.include?(n) # Use performance cache, and stop unhappy cycles   @seen_numbers << n digit_squared_s...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#Liberty_BASIC
Liberty BASIC
print "Hello world!"
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#Java
Java
class Pair<T> { T first; T second; } public static <T> void swap(Pair<T> p) { T temp = p.first; p.first = p.second; p.second = temp; }
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#Lasso
Lasso
define greatest(a::array) => { return (#a->sort&)->last }   local(x = array(556,1,7344,4,7,52,22,55,88,122,55,99,1222,578)) greatest(#x)
http://rosettacode.org/wiki/Greatest_common_divisor
Greatest common divisor
Greatest common divisor You are encouraged to solve this task according to the task description, using any language you may know. Task Find the greatest common divisor   (GCD)   of two integers. Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure. Related tas...
#Golfscript
Golfscript
;'2706 410' ~{.@\%.}do;
http://rosettacode.org/wiki/Hailstone_sequence
Hailstone sequence
The Hailstone sequence of numbers can be generated from a starting positive integer,   n   by:   If   n   is     1     then the sequence ends.   If   n   is   even then the next   n   of the sequence   = n/2   If   n   is   odd   then the next   n   of the sequence   = (3 * n) + 1 The (unproven) Collatz conje...
#Julia
Julia
function hailstonelength(n::Integer) len = 1 while n > 1 n = ifelse(iseven(n), n ÷ 2, 3n + 1) len += 1 end return len end   @show hailstonelength(27); nothing @show findmax([hailstonelength(i) for i in 1:100_000]); nothing
http://rosettacode.org/wiki/Hamming_numbers
Hamming numbers
Hamming numbers are numbers of the form   H = 2i × 3j × 5k where i, j, k ≥ 0 Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5). Task Generate the sequence of Hamming numbers, in increasing order.   In ...
#zkl
zkl
var BN=Import("zklBigNum"); // only needed for large N fcn hamming(N){ h:=List.createLong(N+1); (0).pump(N+1,h.write,Void); // fill list with stuff h[0]=1; #if 1 // regular (64 bit) ints x2:=2; x3:=3; x5:=5; i:=j:=k:=0; #else // big ints x2:=BN(2); x3:=BN(3); x5:=BN(5); i:=j:=k:=0; #endif foreach n in...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT PRINT "Find the luckynumber (7 tries)!" SET luckynumber=RANDOM NUMBERS (1,100,1) LOOP round=1,7 SET message=CONCAT ("[",round,"] Please insert a number") ASK $message: n="" IF (n!='digits') THEN PRINT "wrong insert: ",n," Please insert a digit" ELSEIF (n>100.or.n<1) THEN PRINT "wrong insert: ...
http://rosettacode.org/wiki/Guess_the_number/With_feedback
Guess the number/With feedback
Task Write a game (computer program) that follows the following rules: The computer chooses a number between given set limits. The player is asked for repeated guesses until the the target number is guessed correctly At each guess, the computer responds with whether the guess is: higher than the target, equal to...
#UNIX_Shell
UNIX Shell
function guess { [[ -n $BASH_VERSION ]] && shopt -s extglob [[ -n $ZSH_VERSION ]] && set -o KSH_GLOB local -i max=${1:-100} local -i number=RANDOM%max+1 local -i guesses=0   local guess while true; do echo -n "Guess my number! (range 1 - $max): " read guess if [[ "$guess" != +([0-9]) ]] || (( ...
http://rosettacode.org/wiki/Happy_numbers
Happy numbers
From Wikipedia, the free encyclopedia: A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not inclu...
#Run_BASIC
Run BASIC
for i = 1 to 100 if happy(i) = 1 then cnt = cnt + 1 PRINT cnt;". ";i;" is a happy number " if cnt = 8 then end end if next i   FUNCTION happy(num) while count < 50 and happy <> 1 num$ = str$(num) count = count + 1 happy = 0 for i = 1 to len(num$) happy = happy + val(mid$(num$,i,1)) ^ 2 next i n...
http://rosettacode.org/wiki/Hello_world/Text
Hello world/Text
Hello world/Text is part of Short Circuit's Console Program Basics selection. Task Display the string Hello world! on a text console. Related tasks   Hello world/Graphical   Hello world/Line Printer   Hello world/Newbie   Hello world/Newline omission   Hello world/Standard error   Hello world/Web server
#LIL
LIL
# # Hello world in lil #   print "Hello, world!"
http://rosettacode.org/wiki/Generic_swap
Generic swap
Task Write a generic swap function or operator which exchanges the values of two variables (or, more generally, any two storage places that can be assigned), regardless of their types. If your solution language is statically typed please describe the way your language provides genericity. If variables are typed in t...
#JavaScript
JavaScript
function swap(arr) { var tmp = arr[0]; arr[0] = arr[1]; arr[1] = tmp; }
http://rosettacode.org/wiki/Greatest_element_of_a_list
Greatest element of a list
Task Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
#LFE
LFE
>(: lists max '[9 4 3 8 5]) 9