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/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#Vlang
Vlang
import ui   fn main() { ui.message_box('Hello World') }
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#Web_68
Web 68
@1Introduction. Define the structure of the program.   @aPROGRAM goodbye world CONTEXT VOID USE standard BEGIN @<Included declarations@> @<Logic at the top level@> END FINISH   @ Include the graphical header file.   @iforms.w@>   @ Program code.   @<Logic...@>= open(LOC FILE,"",arg channel); fl initialize(argc,argv,NIL...
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...
#Fish
Fish
$
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.
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Function MaxElement(a() As Double) As Double Dim max As Double = a(LBound(a)) For i As Integer = LBound(a) + 1 To UBound(a) If a(i) > max Then max = a(i) Next Return max End Function   Dim As Integer i, n Input "How many values are to be input "; n If n < 1 Then End Dim a(1 To n) As Dou...
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...
#Euler_Math_Toolbox
Euler Math Toolbox
  >ggt(123456795,1234567851) 33 >function myggt (n:index, m:index) ... $ if n<m then {n,m}={m,n}; endif; $ repeat $ k=mod(n,m); $ if k==0 then return m; endif; $ if k==1 then return 1; endif; $ {n,m}={m,k}; $ end; $ endfunction >myggt(123456795,1234567851) 33  
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...
#Fortran
Fortran
program Hailstone implicit none   integer :: i, maxn integer :: maxseqlen = 0, seqlen integer, allocatable :: seq(:)   call hs(27, seqlen) allocate(seq(seqlen)) call hs(27, seqlen, seq) write(*,"(a,i0,a)") "Hailstone sequence for 27 has ", seqlen, " elements" write(*,"(a,4(i0,a),3(i0,a),i0)") "Sequenc...
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 ...
#Ring
Ring
  see "h(1) = 1" + nl for nr = 1 to 19 see "h(" + (nr+1) + ") = " + hamming(nr) + nl next see "h(1691) = " + hamming(1690) + nl see nl   func hamming limit h = list(1690) h[1] =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 ...
http://rosettacode.org/wiki/Guess_the_number
Guess the number
Task Write a program where the program chooses a number between   1   and   10. A player is then prompted to enter a guess.   If the player guesses wrong,   then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a   "Well guessed!"   message,   a...
#X86_Assembly
X86 Assembly
    segment .data   random dd 0 ; Where the random number will be stored guess dd 0 ; Where the user input will be stored   instructions db 10, "Welcome user! The game is simple: Guess a random number (1-10)!", 10, 10 len1 equ $ - instructions ; 1 \n before and 2 \n after instructi...
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...
#Perl
Perl
sub prompt { my $prompt = shift; while (1) { print "\n", $prompt, ": "; # type ^D, q, quit, quagmire, etc to quit defined($_ = <STDIN>) and !/^\s*q/ or exit;   return $_ if /^\s*\d+\s*$/s; $prompt = "Please give a non-negative integer"; } }   my $tgt = int(rand prompt("Hola! Please tell me the upper bound"...
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...
#PHP
PHP
function isHappy($n) { while (1) { $total = 0; while ($n > 0) { $total += pow(($n % 10), 2); $n /= 10; } if ($total == 1) return true; if (array_key_exists($total, $past)) return false; $n = $total; $past[$total]...
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
#Keg
Keg
Hello world\!
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#Wee_Basic
Wee Basic
print 1 at 10,12 "Hello world!" end
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#Wren
Wren
import "graphics" for Canvas, Color   class Game { static init() { Canvas.print("Goodbye, World!", 10, 10, Color.white) }   static update() {}   static draw(alpha) {} }
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...
#Forth
Forth
swap
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.
#Frink
Frink
  println[max[[1,2,3,5,10,20]]]  
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.
#FunL
FunL
println( max([1,2,3,-1,0]) )
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...
#Euphoria
Euphoria
function gcd_iter(integer u, integer v) integer t while v do t = u u = v v = remainder(t, v) end while if u < 0 then return -u else return u end if end function
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...
#Frege
Frege
module Hailstone where   import Data.List (maximumBy)   hailstone :: Int -> [Int] hailstone 1 = [1] hailstone n | even n = n : hailstone (n `div` 2) | otherwise = n : hailstone (n * 3 + 1)   withResult :: (t -> t1) -> t -> (t1, t) withResult f x = (f x, x)   main :: IO () main = do let h27 =...
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 ...
#Ruby
Ruby
hamming = Enumerator.new do |yielder| next_ham = 1 queues = [[ 2, []], [3, []], [5, []] ]   loop do yielder << next_ham # or: yielder.yield(next_ham)   queues.each {|m,queue| queue << next_ham * m} next_ham = queues.collect{|m,queue| queue.first}.min queues.each {|m,queue| queue.shift if queue.f...
http://rosettacode.org/wiki/Guess_the_number
Guess the number
Task Write a program where the program chooses a number between   1   and   10. A player is then prompted to enter a guess.   If the player guesses wrong,   then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a   "Well guessed!"   message,   a...
#XBS
XBS
const Range:{Min:number,Max:number} = { Min:number=1, Max:number=10, };   while(true){ set RandomNumber:number = math.random(Range.Min,Range.Max); set Response:string = window->prompt("Enter a number from "+tostring(Range.Min)+" to "+tostring(Range.Max)); if (toint(Response)==RandomNumber){ log("Well guessed!");...
http://rosettacode.org/wiki/Guess_the_number
Guess the number
Task Write a program where the program chooses a number between   1   and   10. A player is then prompted to enter a guess.   If the player guesses wrong,   then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a   "Well guessed!"   message,   a...
#XLISP
XLISP
(defun guessing-game () (defun prompt () (display "What is your guess? ") (define guess (read)) (if (= guess n) (display "Well guessed!") (begin (display "No...") (newline) (prompt)))) (define n (+ (random 10) 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...
#Phix
Phix
-- -- demo\rosetta\Guess_the_number3.exw -- with javascript_semantics requires("1.0.1") -- (VALUECHANGED_CB fix) include pGUI.e constant lower_limit = 0, upper_limit = 100, secret = rand_range(lower_limit,upper_limit), fmt = "Enter your guess, a number between %d and %d", prompt = sprintf(fm...
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...
#Picat
Picat
go => println(happy_len(8)).   happy(N) => S = [N], Happy = 1, while (Happy == 1, N > 1) N := sum([to_integer(I)**2 : I in N.to_string()]), if member(N,S) then Happy := 0 else S := S ++ [N] end end, Happy == 1.   happy_len(Limit) = S => S = [], N = 1, whil...
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
#Kite
Kite
"#!/usr/local/bin/kite   "Hello world!"|print;
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#X86_Assembly
X86 Assembly
;;; hellowin.asm ;;; ;;; nasm -fwin32 hellowin.asm ;;; link -subsystem:console -out:hellowin.exe -nodefaultlib -entry:main \ ;;; hellowin.obj user32.lib kernel32.lib   global _main extern _MessageBoxA@16 extern _ExitProcess@4   MessageBox equ _MessageBoxA@16 ExitProcess equ _E...
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#X86-64_Assembly
X86-64 Assembly
  option casemap:none   printf proto :qword, :vararg exit proto :dword ;; curses.h stuff initscr proto ;; WINDOW *initsrc(void); endwin proto ;; int endwin(void); start_color proto ;; int start_color(void); wrefresh proto :qword ...
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...
#Fortran
Fortran
MODULE Genericswap IMPLICIT NONE   INTERFACE Swap MODULE PROCEDURE Swapint, Swapreal, Swapstring END INTERFACE   CONTAINS   SUBROUTINE Swapint(a, b) INTEGER, INTENT(IN OUT) :: a, b INTEGER :: temp temp = a ; a = b ; b = temp END SUBROUTINE Swapint   SUBROUTINE Swapreal(a, b) REAL, INTENT...
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.
#Futhark
Futhark
let main (xs: []f64) = reduce f64.max (-f64.inf) xs
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...
#Excel
Excel
=GCD(A1:E1)
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...
#Frink
Frink
  hailstone[n] := { results = new array   while n != 1 { results.push[n] if n mod 2 == 0 // n is even? n = n / 2 else n = (3n + 1) }   results.push[1] return results }   longestLen = 0 longestN = 0 for n = 1 to 100000 { seq = hailstone[n] if length[seq] > l...
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 ...
#Run_BASIC
Run BASIC
  dim h(1000000) for i =1 to 20 print hamming(i);" "; next i   print print "Hamming List First(1691) =";chr$(9);hamming(1691) print "Hamming List Last(1000000) =";chr$(9);hamming(1000000)   end   function hamming(limit) h(0) =1 x2 = 2: x3 = 3: x5 =5 i = 0: j = 0: k =0 for n =1 to limit ...
http://rosettacode.org/wiki/Guess_the_number
Guess the number
Task Write a program where the program chooses a number between   1   and   10. A player is then prompted to enter a guess.   If the player guesses wrong,   then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a   "Well guessed!"   message,   a...
#XPL0
XPL0
code Ran=1, IntIn=10, Text=12; int N, G; [N:= Ran(10)+1; Text(0, "I'm thinking of a number between 1 and 10.^M^J"); loop [Text(0, "Can you guess it? "); G:= IntIn(0); if G=N then quit; Text(0, "Nope, that's not it.^M^J"); ]; Text(0, "Well guessed!^M^J"); ]
http://rosettacode.org/wiki/Guess_the_number
Guess the number
Task Write a program where the program chooses a number between   1   and   10. A player is then prompted to enter a guess.   If the player guesses wrong,   then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a   "Well guessed!"   message,   a...
#zkl
zkl
r:=((0).random(10)+1).toString(); while(1){ n:=ask("Num between 1 & 10: "); if(n==r){ println("Well guessed!"); break; } println("Nope") }
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...
#PHP
PHP
  <?php   session_start();   if(isset($_SESSION['number'])) { $number = $_SESSION['number']; } else { $_SESSION['number'] = rand(1,10); }     if($_POST["guess"]){ $guess = htmlspecialchars($_POST['guess']);   echo $guess . "<br />"; if ($guess < $number) { echo "Your guess is too low"; } ...
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...
#PicoLisp
PicoLisp
(de happy? (N) (let Seen NIL (loop (T (= N 1) T) (T (member N Seen)) (setq N (sum '((C) (** (format C) 2)) (chop (push 'Seen N)) ) ) ) ) )   (let H 0 (do 8 (until (happy? (inc 'H))) (printsp H) ) )
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
#Kitten
Kitten
"Hello world!" say
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#XPL0
XPL0
[SetVid($13); Text(6, "Goodbye, World!")]
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#XSLT
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml"/> <xsl:template match="/*"> <!-- Use a template to insert some text into a simple SVG graphic with hideous colors. --> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 200"> <rect x="0" y="0...
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...
#Free_Pascal
Free Pascal
{$ifdef fpc}{$mode delphi}{$H+}{$endif} { note this is compiled with delphi mode but will only compile in Free Pascal } { Delphi doesn't support this syntax } procedure swap<T>(var left,right:T); var temp:T; begin temp:=left; left:=right; right:=temp; end; var a:string...
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.
#F.C5.8Drmul.C3.A6
Fōrmulæ
10 INPUT "How many items? ", N% 20 DIM ARR(N%) 30 FOR I% = 0 TO N%-1 40 PRINT "Value of item #";I% 50 INPUT ARR(I%) 60 NEXT I% 70 CHAMP = ARR(0) : INDEX = 0 80 FOR I% = 1 TO N%-1 90 IF ARR(I%)>CHAMP THEN CHAMP=ARR(I%):INDEX=I% 100 NEXT I% 110 PRINT "The maximum value was ";CHAMP;" at index ";INDEX;"." 120 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...
#Ezhil
Ezhil
  ## இந்த நிரல் இரு எண்களுக்கு இடையிலான மீச்சிறு பொது மடங்கு (LCM), மீப்பெரு பொது வகுத்தி (GCD) என்ன என்று கணக்கிடும்   நிரல்பாகம் மீபொவ(எண்1, எண்2)   @(எண்1 == எண்2) ஆனால்   ## இரு எண்களும் சமம் என்பதால், அந்த எண்ணேதான் அதன் மீபொவ   பின்கொடு எண்1   @(எண்1 > எண்2) இல்லைஆனால்   சிறியது = எண்2 பெரியது = எண்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...
#FunL
FunL
def hailstone( 1 ) = [1] hailstone( n ) = n # hailstone( if 2|n then n/2 else n*3 + 1 )   if _name_ == '-main-' h27 = hailstone( 27 ) assert( h27.length() == 112 and h27.startsWith([27, 82, 41, 124]) and h27.endsWith([8, 4, 2, 1]) )   val (n, len) = maxBy( snd, [(i, hailstone( i ).length()) | i <- 1:100000] )...
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 ...
#Rust
Rust
extern crate num; num::bigint::BigUint;   use std::time::Instant;   fn basic_hamming(n: usize) -> BigUint { let two = BigUint::from(2u8); let three = BigUint::from(3u8); let five = BigUint::from(5u8); let mut h = vec![BigUint::from(0u8); n]; h[0] = BigUint::from(1u8); let mut x2 = BigUint::from(...
http://rosettacode.org/wiki/Guess_the_number
Guess the number
Task Write a program where the program chooses a number between   1   and   10. A player is then prompted to enter a guess.   If the player guesses wrong,   then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a   "Well guessed!"   message,   a...
#Zoomscript
Zoomscript
var randnum var guess randnum & random 1 10 guess = 0 while ne randnum guess print "I'm thinking of a number between 1 and 10. What is it? " guess & get if ne guess randnum print "Incorrect. Try again!" println endif endwhile print "Correct number. You win!"
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...
#PicoLisp
PicoLisp
(de guessTheNumber () (use (Low High Guess) (until (and (prin "Enter low limit : ") (setq Low (read)) (prin "Enter high limit: ") (setq High (read)) (> High Low) ) ) (seed (time)) (let Number (rand Low High) (loop ...
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...
#Plain_English
Plain English
The low number is 1.   The high number is 100.   To run: Start up. Play the guessing game. Wait for the escape key. Shut down.   To play the guessing game: Pick a secret number between the low number and the high number. Write "I chose a secret number between " then the low number then " and " then the high number then...
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...
#PILOT
PILOT
C :max=8  :n=0  :i=0 *test U :*happy T (a=1):#n C (a=1):i=i+1 C :n=n+1 J (i<max):*test E :   *happy C :a=n  :x=n U :*sumsq C :b=s *loop C :x=a U :*sumsq C :a=s C :x=b U :*sumsq C :x=s U :*sumsq C :b=s J (a<>b):*loop E :   *sumsq C :s=0 *digit C :y=x/10  :z=x-y*10  :s=s+z*#z  :x=y J (x):*digit E :
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
#Koka
Koka
fun main() { println("Hello world!") }
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#Yabasic
Yabasic
open window 200, 100 text 10, 20, "Hello world" color 255, 0, 0 : text 10, 40, "Good bye world", "roman14"
http://rosettacode.org/wiki/Hello_world/Graphical
Hello world/Graphical
Task Display the string       Goodbye, World!       on a GUI object   (alert box, plain window, text area, etc.). Related task   Hello world/Text
#zkl
zkl
System.cmd(0'|zenity --info --text="Goodbye, World!"|); // GTK+ pop up System.cmd(0'|notify-send "Goodbye, World!"|); // desktop notification System.cmd(0'|xmessage -buttons Ok:0,"Not sure":1,Cancel:2 -default Ok -nearmouse "Goodbye, World!" -timeout 10|); // X Windows dialog
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...
#FreeBASIC
FreeBASIC
' FB 1.05.0 #Macro Declare_Swap(T) Sub Swap_##T(ByRef t1 As T, ByRef t2 As T) Dim temp As T = t2 t2 = t1 t1 = temp End Sub #EndMacro   Dim As Integer i, j i = 1 : j = 2   Declare_Swap(Integer) ' expands the macro Swap_Integer(i, j) Print i, j   Dim As String s, t s = "Hello" : t = "World"   Declare_Swap(String) S...
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.
#GW-BASIC
GW-BASIC
10 INPUT "How many items? ", N% 20 DIM ARR(N%) 30 FOR I% = 0 TO N%-1 40 PRINT "Value of item #";I% 50 INPUT ARR(I%) 60 NEXT I% 70 CHAMP = ARR(0) : INDEX = 0 80 FOR I% = 1 TO N%-1 90 IF ARR(I%)>CHAMP THEN CHAMP=ARR(I%):INDEX=I% 100 NEXT I% 110 PRINT "The maximum value was ";CHAMP;" at index ";INDEX;"." 120 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...
#F.23
F#
  let rec gcd a b = if b = 0 then abs a else gcd b (a % b)   >gcd 400 600 val it : int = 200
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...
#Futhark
Futhark
  fun hailstone_step(x: int): int = if (x % 2) == 0 then x/2 else (3*x) + 1   fun hailstone_seq(x: int): []int = let capacity = 100 let i = 1 let steps = replicate capacity (-1) let steps[0] = x loop ((capacity,i,steps,x)) = while x != 1 do let (steps, capacity) = if i == capacity then ...
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 ...
#Scala
Scala
class Hamming extends Iterator[BigInt] { import scala.collection.mutable.Queue val qs = Seq.fill(3)(new Queue[BigInt]) def enqueue(n: BigInt) = qs zip Seq(2, 3, 5) foreach { case (q, m) => q enqueue n * m } def next = { val n = qs map (_.head) min; qs foreach { q => if (q.head == n) q.dequeue } enqu...
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...
#PowerShell
PowerShell
  function Get-Guess { [int]$number = 1..100 | Get-Random [int]$guess = 0 [int[]]$guesses = @()   Write-Host "Guess a number between 1 and 100" -ForegroundColor Cyan   while ($guess -ne $number) { try { [int]$guess = Read-Host -Prompt "Guess"   if ($guess ...
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...
#PL.2FI
PL/I
test: proc options (main); /* 19 November 2011 */ declare (i, j, n, m, nh initial (0) ) fixed binary (31);   main_loop: do j = 1 to 100; n = j; do i = 1 to 100; m = 0; /* Form the sum of squares of the digits. */ do until (n = 0); m = m + mod(n, 10)**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
#KonsolScript
KonsolScript
function main() { Konsol:Log("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...
#Frink
Frink
  [b,a] = [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.
#GAP
GAP
# Built-in   L := List([1 .. 100], n -> Random(1, 10));   MaximumList(L); # 10
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.
#Go
Go
package main   import ( "fmt" "math/rand" "time" )   // function, per task description func largest(a []int) (lg int, ok bool) { if len(a) == 0 { return } lg = a[0] for _, e := range a[1:] { if e > lg { lg = e } } return lg, true }   func main() { ...
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...
#Factor
Factor
: gcd ( a b -- c ) [ abs ] [ [ nip ] [ mod ] 2bi gcd ] if-zero ;
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...
#F.C5.8Drmul.C3.A6
Fōrmulæ
CollatzSequence := function(n) local v; v := [ n ]; while n > 1 do if IsEvenInt(n) then n := QuoInt(n, 2); else n := 3*n + 1; fi; Add(v, n); od; return v; end;   CollatzLength := function(n) local m; m := 1; while n > 1 do if IsEvenInt(n) then n := QuoInt(n, 2); ...
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 ...
#Scheme
Scheme
(define-syntax lons (syntax-rules () ((_ lar ldr) (delay (cons lar (delay ldr))))))   (define (lar lons) (car (force lons)))   (define (ldr lons) (force (cdr (force lons))))   (define (lap proc . llists) (lons (apply proc (map lar llists)) (apply lap proc (map ldr llists))))   (define (take n llist) (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...
#Prolog
Prolog
main :- play_guess_number.     /* Parameteres */   low(1). high(10).     /* Basic Game Logic */   play_guess_number :- low(Low), high(High), random(Low, High, N), tell_range(Low, High), repeat, % roughly, "repeat ... (until) Guess == N " ask_for_guess(Guess), ...
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...
#PL.2FM
PL/M
100H:   /* FIND SUM OF SQUARE OF DIGITS OF NUMBER */ DIGIT$SQUARE: PROCEDURE (N) BYTE; DECLARE (N, T, D) BYTE; T = 0; DO WHILE N > 0; D = N MOD 10; T = T + D * D; N = N / 10; END; RETURN T; END DIGIT$SQUARE;   /* CHECK IF NUMBER IS HAPPY */ HAPPY: PROCEDURE (N) BYTE; DECL...
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
#Kotlin
Kotlin
fun main() { println("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...
#FutureBasic
FutureBasic
window 1, @"Generic Swap", (0,0,480,270)   text ,,,,, 60   long i, j double x, y CFStringRef a, b   i = 1059 : j = 62 print i, j swap i, j print i, j   print   x = 1.23 : y = 4.56 print x, y swap x, y print x, y   print   a = @"Hello" : b = @"World!" print a, b swap a, b print a, b   HandleEvents  
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.
#Golfscript
Golfscript
{$-1=}:max; [1 4 8 42 6 3]max # Example usage
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.
#Groovy
Groovy
println ([2,4,0,3,1,2,-12].max())
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...
#FALSE
FALSE
10 15$ [0=~][$@$@$@\/*-$]#%. { gcd(10,15)=5 }
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...
#GAP
GAP
CollatzSequence := function(n) local v; v := [ n ]; while n > 1 do if IsEvenInt(n) then n := QuoInt(n, 2); else n := 3*n + 1; fi; Add(v, n); od; return v; end;   CollatzLength := function(n) local m; m := 1; while n > 1 do if IsEvenInt(n) then n := QuoInt(n, 2); ...
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 ...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "bigint.s7i";   const func bigInteger: min (in bigInteger: a, in bigInteger: b, in bigInteger: c) is func result var bigInteger: min is 0_; begin if a < b then min := a; else min := b; end if; if c < min then min := c; end if; end func;...
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...
#PureBasic
PureBasic
OpenConsole()   Repeat ; Ask for limits, with sanity check Print("Enter low limit : "): low =Val(Input()) Print("Enter high limit: "): High =Val(Input()) Until High>low   TheNumber=Random(High-low)+low Debug TheNumber Repeat Print("Guess what number I have: "): Guess=Val(Input()) If Guess=TheNumber Pri...
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...
#Potion
Potion
sqr = (n): n * n.   isHappy = (n) : loop : if (n == 1): return true. if (n == 4): return false. sum = 0 n = n string n length times (i): sum = sum + sqr(n(i) number integer). n = sum . .   firstEight = () i = 0 while (firstEight length < 8) : i++ if (isHappy(i)): firstEig...
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
#KQL
KQL
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...
#F.C5.8Drmul.C3.A6
Fōrmulæ
Public Sub Main() Dim vA As Variant = " World" Dim vB As Variant = 1   Swap vA, vB   Print vA; vB   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.
#Haskell
Haskell
my_max = maximum
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.
#hexiscript
hexiscript
fun greatest a let l len a let max a[0] for let i 1; i < l; i++ if max < a[i] let max a[i] endif endfor return max endfun
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...
#Fantom
Fantom
  class Main { static Int gcd (Int a, Int b) { a = a.abs b = b.abs while (b > 0) { t := a a = b b = t % b } return a }   public static Void main() { echo ("GCD of 51, 34 is: " + gcd(51, 34)) } }  
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...
#Fermat
Fermat
GCD(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...
#Go
Go
package main   import "fmt"   // 1st arg is the number to generate the sequence for. // 2nd arg is a slice to recycle, to reduce garbage. func hs(n int, recycle []int) []int { s := append(recycle[:0], n) for n > 1 { if n&1 == 0 { n = n / 2 } else { n = 3*n + 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 ...
#Sidef
Sidef
func ham_gen { var s = [[1], [1], [1]] var m = [2, 3, 5]   func { var n = [s[0][0], s[1][0], s[2][0]].min { |i| s[i].shift if (s[i][0] == n) s[i].append(n * m[i]) } << ^3 return n } }   var h = ham_gen()   var i = 20; say i.of { h() }.join(' ')   {...
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...
#Python
Python
import random   inclusive_range = (1, 100)   print("Guess my target number that is between %i and %i (inclusive).\n"  % inclusive_range) target = random.randint(*inclusive_range) answer, i = None, 0 while answer != target: i += 1 txt = input("Your guess(%i): " % i) try: answer = int(txt) ex...
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...
#PowerShell
PowerShell
function happy([int] $n) { $a=@() for($i=2;$a.count -lt $n;$i++) { $sum=$i $hist=@{} while( $hist[$sum] -eq $null ) { if($sum -eq 1) { $a+=$i } $hist[$sum]=$sum $sum2=0 foreach($j in $sum.ToString().ToCharArray()...
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
#KSI
KSI
  `plain 'Hello world!' #echo #  
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...
#Gambas
Gambas
Public Sub Main() Dim vA As Variant = " World" Dim vB As Variant = 1   Swap vA, vB   Print vA; vB   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.
#HicEst
HicEst
  max_value = MAX( -123, 234.56, 345.678, -456E3, -455) ! built-in function MAX(...)   ! or for an array: max_value = MAX( array_of_values )   ! or to find a maximum value in a file named filename: CHARACTER List, filename='Greatest element of a list.hic' ! filename contains this script REAL values(1) ! un...
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...
#Forth
Forth
: gcd ( a b -- n ) begin dup while tuck mod repeat drop ;
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...
#Groovy
Groovy
def hailstone = { long start -> def sequence = [] while (start != 1) { sequence << start start = (start % 2l == 0l) ? start / 2l : 3l * start + 1l } sequence << start }
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 ...
#Smalltalk
Smalltalk
Object subclass: Hammer [ Hammer class >> hammingNumbers: howMany [ |h i j k x2 x3 x5| h := OrderedCollection new. i := 0. j := 0. k := 0. h add: 1. x2 := 2. x3 := 2. x5 := 5. [ ( h size) < howMany ] whileTrue: [ |m| m := { x2. x3. x5 } sort first. (( h index...
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...
#Quackery
Quackery
[ say "Guess the number (1-100 inclusive.)" cr cr 100 random 1+ [ $ "Your guess... " input trim reverse trim reverse $->n not iff [ drop say "That is not a number." cr ] again 2dup != while over < iff [ say "Too small." cr ] again ...
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...
#R
R
guessANumber <- function(low, high) { boundryErrorCheck(low, high) goal <- sample(low:high, size = 1) guess <- getValidInput(paste0("I have a whole number between ", low, " and ", high, ". What's your guess? ")) while(guess != goal) { if(guess < low || guess > high){guess <- getValidInput("Out of range! T...
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...
#Prolog
Prolog
happy_numbers(L, Nb) :- % creation of the list length(L, Nb), % Process of this list get_happy_number(L, 1).     % the game is over get_happy_number([], _).   % querying the newt happy_number get_happy_number([H | T], N) :- N1 is N+1, (is_happy_number(N) -> H = N, get_happy_nu...
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
#Lambdatalk
Lambdatalk
  Hello world! {h1 Hello world!} _h1 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...
#Gecho
Gecho
  1 !0 2 !1  
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.
#Hoon
Hoon
:-  %say |= [^ [a=(list ,@) ~] ~] :-  %noun (snag 0 (sort a gte))
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.
#i
i
concept largest(l) { large = l[0] for element in l if element > large large = element end end return large }   software { print(largest([23, 1313, 21, 35757, 4, 434, 232, 2, 2342])) }
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...
#Fortran
Fortran
recursive function gcd_rec(u, v) result(gcd) integer :: gcd integer, intent(in) :: u, v   if (mod(u, v) /= 0) then gcd = gcd_rec(v, mod(u, v)) else gcd = v end if end function gcd_rec
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...
#Haskell
Haskell
import Data.List (maximumBy) import Data.Ord (comparing)   -------------------- HAILSTONE SEQUENCE ------------------   collatz :: Int -> Int collatz n | even n = n `div` 2 | otherwise = 1 + 3 * n   hailstone :: Int -> [Int] hailstone = takeWhile (1 /=) . iterate collatz   longestChain :: Int longestChain = fst $...