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/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Julia
Julia
# It'st most appropriate to define a Julia iterable object for this task # Julia doesn't have Python'st yield, the closest to it is produce/consume calls with Julia tasks # but for various reasons they don't work out for this task # This solution works with two integers, a Julia rational or a real   mutable struct Cont...
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Kotlin
Kotlin
// version 1.1.2 // compile with -Xcoroutines=enable flag from command line   import kotlin.coroutines.experimental.buildSequence   fun r2cf(frac: Pair<Int, Int>) = buildSequence { var num = frac.first var den = frac.second while (Math.abs(den) != 0) { val div = num / den ...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Groovy
Groovy
Number.metaClass.mixin RationalCategory   [ 0.9054054, 0.518518, 0.75, Math.E, -0.423310825, Math.PI, 0.111111111111111111111111 ].each{ printf "%30.27f %s\n", it, it as Rational }
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Haskell
Haskell
Prelude> map (\d -> Ratio.approxRational d 0.0001) [0.9054054, 0.518518, 0.75] [67 % 74,14 % 27,3 % 4] Prelude> [0.9054054, 0.518518, 0.75] :: [Rational] [4527027 % 5000000,259259 % 500000,3 % 4] Prelude> map (fst . head . Numeric.readFloat) ["0.9054054", "0.518518", "0.75"] :: [Rational] [4527027 % 5000000,259259 % 50...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Action.21
Action!
PROC Main() CHAR ARRAY str1,str2,str3(10)   str1="Atari" str2=str1 SCopy(str3,str1)   PrintF(" base=%S%E",str1) PrintF("alias=%S%E",str2) PrintF(" copy=%S%E",str3) PutE()   SCopy(str1,"Action!")   PrintF(" base=%S%E",str1) PrintF("alias=%S%E",str2) PrintF(" copy=%S%E",str3) RETURN
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#ActionScript
ActionScript
var str1:String = "Hello"; var str2:String = str1;
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
ContinuedFraction[1/2] ContinuedFraction[3] ContinuedFraction[23/8] ContinuedFraction[13/11] ContinuedFraction[22/7] ContinuedFraction[-151/77] ContinuedFraction[14142/10000] ContinuedFraction[141421/100000] ContinuedFraction[1414214/1000000] ContinuedFraction[14142136/10000000]
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Modula-2
Modula-2
MODULE ConstructFromrationalNumber; FROM FormatString IMPORT FormatString; FROM Terminal IMPORT WriteString,WriteLn,ReadChar;   TYPE R2cf = RECORD num,den : INTEGER; END;   PROCEDURE HasNext(self : R2cf) : BOOLEAN; BEGIN RETURN self.den # 0; END HasNext;   PROCEDURE Next(VAR self : R2cf) : INTEGER; VAR div,rem ...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#J
J
x: 0.9054054 0.518518 0.75 NB. find "exact" rational representation 127424481939351r140737488355328 866492568306r1671094481399 3r4
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Java
Java
import org.apache.commons.math3.fraction.BigFraction;   public class Test {   public static void main(String[] args) { double[] n = {0.750000000, 0.518518000, 0.905405400, 0.142857143, 3.141592654, 2.718281828, -0.423310825, 31.415926536};   for (double d : n) System.out.prin...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Ada
Ada
Src : String := "Hello"; Dest : String := Src;
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Aime
Aime
text s, t; t = "Rosetta"; s = t;
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Nim
Nim
iterator r2cf*(n1, n2: int): int = var (n1, n2) = (n1, n2) while n2 != 0: yield n1 div n2 n1 = n1 mod n2 swap n1, n2   #———————————————————————————————————————————————————————————————————————————————————————————————————   when isMainModule:   from sequtils import toSeq   for pair in [(1, 2), (3, 1),...
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#PARI.2FGP
PARI/GP
apply(contfrac,[1/2,3,23/8,13/11,22/7,-151/77])
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#JavaScript
JavaScript
(() => { 'use strict';   const main = () => showJSON( map( // Using a tolerance epsilon of 1/10000 n => showRatio(approxRatio(0.0001)(n)), [0.9054054, 0.518518, 0.75] ) );   // Epsilon -> Real -> Ratio   // approxRatio :: Real -> Re...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#ALGOL_68
ALGOL 68
( STRING src:="Hello", dest; dest:=src )
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#ALGOL_W
ALGOL W
begin  % strings are (fixed length) values in algol W. Assignment makes a copy  % string(10) a, copyOfA; a := "some text"; copyOfA := a;  % assignment to a will not change copyOfA  % a := "new value"; write( a, copyOfA ) end.
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Perl
Perl
$|=1;   sub rc2f { my($num, $den) = @_; return sub { return unless $den; my $q = int($num/$den); ($num, $den) = ($den, $num - $q*$den); $q; }; }   sub rcshow { my $sub = shift; print "["; my $n = $sub->(); print "$n" if defined $n; print "; $n" while defined($n...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#jq
jq
# include "rational"; # a reminder that r/2 and power/1 are required   # Input: any JSON number, not only a decimal # Output: a rational, constructed using r/2 # Requires power/1 (to take advantage of gojq's support for integer arithmetic) # and r/2 (for rational number constructor) def number_to_r:   # input: a deci...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Julia
Julia
rationalize(0.9054054) rationalize(0.518518) rationalize(0.75)
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Apex
Apex
String original = 'Test'; String cloned = original; //"original == cloned" is true   cloned += ' more'; //"original == cloned" is false
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#AppleScript
AppleScript
set src to "Hello" set dst to src
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Phix
Phix
with javascript_semantics function r2cf(atom num, denom) atom quot = 0 if denom!=0 then quot = trunc(num/denom) {num,denom} = {denom,num-quot*denom} end if return {quot,{num,denom}} end function procedure test(string txt, sequence tests) printf(1,"Running %s :\n",{txt}) for i=1...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Kotlin
Kotlin
// version 1.1.2   class Rational(val num: Long, val den: Long) { override fun toString() = "$num/$den" }   fun decimalToRational(d: Double): Rational { val ds = d.toString().trimEnd('0').trimEnd('.') val index = ds.indexOf('.') if (index == -1) return Rational(ds.toLong(), 1L) var num = ds.replace(...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program copystr.s */   /* Constantes */ .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ WRITE, 4 @ Linux syscall /* Initialized data */ .data szString: .asciz "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"   /* UnInitialized data */ .bss .align 4 iPtSt...
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Python
Python
def r2cf(n1,n2): while n2: n1, (t1, n2) = n2, divmod(n1, n2) yield t1   print(list(r2cf(1,2))) # => [0, 2] print(list(r2cf(3,1))) # => [3] print(list(r2cf(23,8))) # => [2, 1, 7] print(list(r2cf(13,11))) # => [1, 5, 2] print(list(r2cf(22,7))) # => [3, 7] print(list(r2cf(14142,10000))) # => [1...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Liberty_BASIC
Liberty BASIC
  ' Uses convention that one repeating sequence implies infinitely repeating sequence.. ' Non-recurring fractions are limited to nd number of digits in nuerator & denominator   nd =3 ' suggest 3. 4 is slow. >4 is ....... do read x$ data "0.5", "0.1", "0.333", "1 /3", "0.33", "0.14159265", "2^-0.5", "0.1...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Arturo
Arturo
a: new "Hello" b: a ; reference the same string   ; changing one string in-place ; will change both strings   'b ++ "World" print b print a   c: "Hello" d: new c ; make a copy of the older string   ; changing one string in-place ; will change only the string in question   'd ++ "World" print d print c
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Asymptote
Asymptote
string src, dst; src = "Hello"; dst = src; src = " world..."; write(dst, src);
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Quackery
Quackery
  [ $ "bigrat.qky" loadfile ] now!   [ [] unrot [ proper 2swap join unrot over 0 != while 1/v again ] 2drop ] is cf ( n/d --> [ )   ' [ [ 1 2 ] [ 3 1 ] [ 23 8 ] [ 13 11 ] [ 22 7 ] [ -151 77 ] [ 14142 10000 ] [ 141421 100000 ] [ 1...
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Racket
Racket
  #lang racket   (define ((r2cf n d)) (or (zero? d) (let-values ([(q r) (quotient/remainder n d)]) (set! n d) (set! d r) q)))   (define (r->cf n d) (for/list ([i (in-producer (r2cf n d) #t)]) i))   (define (real->cf x places) (define d (expt 10 places)) (define n (exact-floor (* x ...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Lua
Lua
for _,v in ipairs({ 0.9054054, 0.518518, 0.75, math.pi }) do local n, d, dmax, eps = 1, 1, 1e7, 1e-15 while math.abs(n/d-v)>eps and d<dmax do d=d+1 n=math.floor(v*d) end print(string.format("%15.13f --> %d / %d", v, n, d)) end
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#AutoHotkey
AutoHotkey
src := "Hello" dst := src
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#AutoIt
AutoIt
$Src= "Hello" $dest = $Src
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Raku
Raku
sub r2cf(Rat $x is copy) { gather loop { $x -= take $x.floor; last unless $x > 0; $x = 1 / $x; } }   say r2cf(.Rat) for <1/2 3 23/8 13/11 22/7 1.41 1.4142136>;
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Maple
Maple
  > map( convert, [ 0.9054054, 0.518518, 0.75 ], 'rational', 'exact' ); 4527027 259259 [-------, ------, 3/4] 5000000 500000  
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
Map[Rationalize[#,0]&,{0.9054054,0.518518, 0.75} ] -> {4527027/5000000,259259/500000,3/4}
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#AWK
AWK
BEGIN { a = "a string" b = a sub(/a/, "X", a) # modify a print b # b is a copy, not a reference to... }
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#REXX
REXX
/*REXX program converts a decimal or rational fraction to a continued fraction. */ numeric digits 230 /*determines how many terms to be gened*/ say ' 1/2 ──► CF: ' r2cf( '1/2' ) say ' 3 ──► CF: ' r2cf( 3 ) say ' 23/8 ──► ...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#11l
11l
F duration(=sec) [Int] t L(dm) [60, 60, 24, 7] Int m (sec, m) = (sec I/ dm, sec % dm) t.insert(0, m) t.insert(0, sec) R zip(t, [‘wk’, ‘d’, ‘hr’, ‘min’, ‘sec’]).filter(num_unit -> num_unit[0] > 0).map(num_unit -> num_unit[0]‘ ’num_unit[1]).join(‘, ’)   print(duration(7259)) print(duration(8...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#MATLAB_.2F_Octave
MATLAB / Octave
  [a,b]=rat(.75) [a,b]=rat(.518518) [a,b]=rat(.9054054)  
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#.D0.9C.D0.9A-61.2F52
МК-61/52
П0 П1 ИП1 {x} x#0 14 КИП4 ИП1 1 0 * П1 БП 02 ИП4 10^x П0 ПA ИП1 ПB ИПA ИПB / П9 КИП9 ИПA ИПB ПA ИП9 * - ПB x=0 20 ИПA ИП0 ИПA / П0 ИП1 ИПA / П1 ИП0 ИП1 С/П
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Axe
Axe
Lbl STRCPY r₁→S While {r₂} {r₂}→{r₁} r₁++ r₂++ End 0→{r₁} S Return
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Babel
Babel
babel> "Hello, world\n" dup cp dup 0 "Y" 0 1 move8 babel> << << Yello, world Hello, world  
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Ruby
Ruby
# Generate a continued fraction from a rational number   def r2cf(n1,n2) while n2 > 0 n1, (t1, n2) = n2, n1.divmod(n2) yield t1 end end
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Rust
Rust
  struct R2cf { n1: i64, n2: i64 }   // This iterator generates the continued fraction representation from the // specified rational number. impl Iterator for R2cf { type Item = i64;   fn next(&mut self) -> Option<i64> { if self.n2 == 0 { None } else { let...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#Action.21
Action!
INCLUDE "H6:REALMATH.ACT" DEFINE PTR="CARD"   TYPE Time=[BYTE s,m,h,d,w] CARD ARRAY units(5)   PROC Convert(REAL POINTER seconds Time POINTER t) BYTE ARRAY b,duration=[60 60 24 7] BYTE i REAL r,n   b=t FOR i=0 TO 3 DO IntToReal(duration(i),n) RealMod(seconds,n,r) b(i)=RealToInt(r) RealDivInt...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#Ada
Ada
with Ada.Text_IO;   procedure Convert is   type Time is range 0 .. 10_000*356*20*60*60; -- at most 10_000 years subtype Valid_Duration is Time range 1 .. 10_000*356*20*60*60; type Units is (WK, D, HR, MIN, SEC);   package IO renames Ada.Text_IO;   Divide_By: constant array(Units) of Time := (1_000*53, 7...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#NetRexx
NetRexx
  /*NetRexx program to convert decimal numbers to fractions ************* * 16.08.2012 Walter Pachl derived from Rexx Version 2 **********************************************************************/ options replace format comments java crossref savelog symbols Numeric Digits 10 /* use "only" 10 digs of...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#BASIC
BASIC
src$ = "Hello" dst$ = src$
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Batch_File
Batch File
set src=Hello set dst=%src%
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Scheme
Scheme
; Create a terminating Continued Fraction generator for the given rational number. ; Returns one term per call; returns #f when no more terms remaining. (define make-continued-fraction-gen (lambda (rat) (let ((num (numerator rat)) (den (denominator rat))) (lambda () (if (= den 0) #f ...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#ALGOL_68
ALGOL 68
# MODE to hold the compound duration # MODE DURATION = STRUCT( INT weeks, days, hours, minutes, seconds );   # returns seconds converted to a DURATION # OP TODURATION = ( LONG INT seconds )DURATION: BEGIN LONG INT time := seconds; DURATION result := DURATION( 0, 0, 0, 0, 0 ); seconds OF re...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Nim
Nim
import math import fenv   type Rational = object numerator: int denominator: int   proc `$`(self: Rational): string = if self.denominator == 1: $self.numerator else: $self.numerator & "//" & $self.denominator   func rationalize(x: float, tol: float = epsilon(float)): Rational = var xx = x let ...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#PARI.2FGP
PARI/GP
convert(x)={ my(n=0); while(x-floor(x*10^n)/10^n!=0.,n++); floor(x*10^n)/10^n };
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#BBC_BASIC
BBC BASIC
source$ = "Hello, world!"   REM Copy the contents of a string: copy$ = source$ PRINT copy$   REM Make an additional reference to a string:  !^same$ = !^source$  ?(^same$+4) = ?(^source$+4)  ?(^same$+5) = ?(^source$+5) PRINT same$
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#BQN
BQN
a ← "Hello" b ← a •Show a‿b a ↩ "hi" •Show a‿b
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Sidef
Sidef
func r2cf(num, den) { func() { den || return nil var q = num//den (num, den) = (den, num - q*den) return q } }   func showcf(f) { print "[" var n = f() print "#{n}" if defined(n) print "; #{n}" while defined(n = f()) print "]\n" }   [ [1/2, 3/1, 23/8, 13/1...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#ALGOL_W
ALGOL W
begin  % record structure to hold a compound duration % record Duration ( integer weeks, days, hours, minutes, seconds );    % returns seconds converted to a Duration % reference(Duration) procedure toDuration( integer value secs ) ; begin integer time; reference(Duration) d; ...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Perl
Perl
sub gcd { my ($m, $n) = @_; ($m, $n) = ($n, $m % $n) while $n; return $m }   sub rat_machine { my $n = shift; my $denom = 1; while ($n != int $n) { # assuming the machine format is base 2, and multiplying # by 2 doesn't change the mantissa ...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Bracmat
Bracmat
abcdef:?a; !a:?b;   c=abcdef; !c:?d;   !a:!b { variables a and b are the same and probably referencing the same string } !a:!d { variables a and d are also the same but not referencing the same string }  
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#C
C
#include <stdlib.h> /* exit(), free() */ #include <stdio.h> /* fputs(), perror(), printf() */ #include <string.h>   int main() { size_t len; char src[] = "Hello"; char dst1[80], dst2[80]; char *dst3, *ref;   /* * Option 1. Use strcpy() from <string.h>. * * DANGER! strcpy() can overflow the destination buffer...
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Tcl
Tcl
package require Tcl 8.6   proc r2cf {n1 {n2 1}} { # Convert a decimal fraction (e.g., 1.23) into a form we can handle if {$n1 != int($n1) && [regexp {\.(\d+)} $n1 -> suffix]} { set pow [string length $suffix] set n1 [expr {int($n1 * 10**$pow)}] set n2 [expr {$n2 * 10**$pow}] } # Construct the continu...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#APL
APL
duration←{ names←'wk' 'd' 'hr' 'min' 'sec' parts←0 7 24 60 60⊤⍵ fmt←⍕¨(parts≠0)/parts,¨names ¯2↓∊fmt,¨⊂', ' }
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Phix
Phix
with javascript_semantics function decrat(string s) integer nom = 0, denom = 1 assert(s[1..2]="0.") for i=3 to length(s) do integer ch = s[i] assert(ch>='0' and ch<='9') nom = nom*10 + ch-'0' denom *= 10 end for return sq_div({nom,denom},gcd(nom,denom)) en...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#C.23
C#
string src = "Hello"; string dst = src;
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#C.2B.2B
C++
#include <iostream> #include <string>   int main( ) { std::string original ("This is the original"); std::string my_copy = original; std::cout << "This is the copy: " << my_copy << std::endl; original = "Now we change the original! "; std::cout << "my_copy still is " << my_copy << std::endl; }
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#Wren
Wren
import "/rat" for Rat import "/fmt" for Fmt   var toContFrac = Fn.new { |r| var a = r.num var b = r.den while (true) { Fiber.yield((a/b).truncate) var t = a % b a = b b = t if (a == 1) return } }   var groups = [ [ [1, 2], [3, 1], [23, 8], [13, 11], [22, 7], [...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#AppleScript
AppleScript
  -------------------- COMPOUND DURATIONS ------------------   -- weekParts Int -> [Int] on weekParts(intSeconds) unitParts(intSeconds, [missing value, 7, 24, 60, 60]) end weekParts     -- localCompoundDuration :: Int -> String on localCompoundDuration(localNames, intSeconds)   -- [String] -> (Int, String) -> [...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#PHP
PHP
function asRational($val, $tolerance = 1.e-6) { if ($val == (int) $val) { // integer return $val; }   $h1=1; $h2=0; $k1=0; $k2=1; $b = 1 / $val;   do { $b = 1 / $b; $a = floor($b); $aux = $h1; $h1 = $a * $h1 + $h2; $h2 = $aux; ...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Clojure
Clojure
(let [s "hello" s1 s] (println s s1))
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#COBOL
COBOL
MOVE "Hello" TO src MOVE src TO dst
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#XPL0
XPL0
include c:\cxpl\codes; real Val;   proc R2CF(N1, N2, Lev); \Output continued fraction for N1/N2 int N1, N2, Lev; int Quot, Rem; [if Lev=0 then Val:= 0.0; Quot:= N1/N2; Rem:= rem(0); IntOut(0, Quot); if Rem then [ChOut(0, if Lev then ^, else ^;); R2CF(N2, Rem, Lev+1)]; Val:= Val + float(Quot); \generat...
http://rosettacode.org/wiki/Continued_fraction/Arithmetic/Construct_from_rational_number
Continued fraction/Arithmetic/Construct from rational number
Continued fraction arithmetic The purpose of this task is to write a function r 2 c f ( i n t {\displaystyle {\mathit {r2cf}}(\mathrm {int} } N 1 , i n t {\displaystyle N_{1},\mathrm {int} } N 2 ) {\displaystyle N_{2})} , or r 2 c f ( F r a c t i o n {\displaystyle {\m...
#zkl
zkl
fcn r2cf(nom,dnom){ // -->Walker (iterator) Walker.tweak(fcn(state){ nom,dnom:=state; if(dnom==0) return(Void.Stop); n,d:=nom.divr(dnom); state.clear(dnom,d); n }.fp(List(nom,dnom))) // partial application (light weight closure) }
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#Applesoft_BASIC
Applesoft BASIC
100 DATA604800,WK,86400,D,3600,HR,60,MIN,1,SEC 110 FOR I = 0 TO 4 120 READ M(I), U$(I) 130 NEXT 140 DATA7259,86400,6000000 150 ON ERR GOTO 270 160 READ S 170 GOSUB 200 180 PRINT S " = " S$ 190 GOTO 160   200 N = S 210 S$ = "" 220 FOR I = 0 TO 4 230 IF INT(N / M(I)) THEN S$ = S$ + MID$(", ", 1, (LEN(...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#Arturo
Arturo
Units: [" wk", " d", " hr", " min", " sec"] Quantities: @[7 * 24 * 60 * 60, 24 * 60 * 60, 60 * 60, 60, 1]   durationString: function [d][ dur: d idx: 0 result: new [] while [not? zero? dur][ q: dur / Quantities\[idx] if not? zero? q [ dur: dur % Quantities\[idx] '...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#PL.2FI
PL/I
(size, fofl): Convert_Decimal_To_Rational: procedure options (main); /* 14 January 2014, from Ada */   Real_To_Rational: procedure (R, Bound, Numerator, Denominator) recursive options (reorder); declare R float (18), Bound float, (Numerator, Denominator) fixed binary (31); declare Error float; ...
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#PureBasic
PureBasic
Procedure.i ggT(a.i, b.i) Define t.i : If a < b : Swap a, b : EndIf While a%b : t=a : a=b : b=t%a : Wend : ProcedureReturn b EndProcedure   Procedure.s Dec2Rat(dn.d) Define nk$, gt.i, res$ nk$=Trim(StringField(StrD(dn),2,"."),"0") gt=ggT(Val(nk$),Int(Pow(10.0,Len(nk$)))) res$=Str(Val(nk$)/gt)+"/...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#ColdFusion
ColdFusion
<cfset stringOrig = "I am a string." /> <cfset stringCopy = stringOrig />
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Common_Lisp
Common Lisp
(let* ((s1 "Hello") ; s1 is a variable containing a string (s1-ref s1) ; another variable with the same value (s2 (copy-seq s1))) ; s2 has a distinct string object with the same contents (assert (eq s1 s1-ref)) ; same object (assert (not (eq s1 s2))) ; different obje...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#AutoHotkey
AutoHotkey
duration(n){ sec:=1, min:=60*sec, hr:=60*min, day:=24*hr, wk:=7*day w :=n//wk , n:=Mod(n,wk) d :=n//day , n:=Mod(n,day) h :=n//hr , n:=Mod(n,hr) m :=n//min , n:=Mod(n,min) s :=n return trim((w?w " wk, ":"") (d?d " d, ":"") (h?h " hr, ":"") (m?m " min, ":"") (s?s " sec":""),", ") }
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Python
Python
>>> from fractions import Fraction >>> for d in (0.9054054, 0.518518, 0.75): print(d, Fraction.from_float(d).limit_denominator(100))   0.9054054 67/74 0.518518 14/27 0.75 3/4 >>> for d in '0.9054054 0.518518 0.75'.split(): print(d, Fraction(d))   0.9054054 4527027/5000000 0.518518 259259/500000 0.75 3/4 >>>
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Component_Pascal
Component Pascal
  VAR str1: ARRAY 128 OF CHAR; str2: ARRAY 32 OF CHAR; str3: ARRAY 25 OF CHAR;  
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Computer.2Fzero_Assembly
Computer/zero Assembly
ldsrc: LDA src stdest: STA dest BRZ done  ; 0-terminated   LDA ldsrc ADD one STA ldsrc   LDA stdest ADD one STA stdest   JMP ldsrc   done: STP   one: 1   src: 82  ; ASCII 111 115 101 ...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#AWK
AWK
  # syntax: GAWK -f CONVERT_SECONDS_TO_COMPOUND_DURATION.AWK BEGIN { n = split("7259 86400 6000000 0 1 60 3600 604799 604800 694861",arr," ") for (i=1; i<=n; i++) { printf("%9s %s\n",arr[i],howlong(arr[i])) } exit(0) } function howlong(seconds, n_day,n_hour,n_min,n_sec,n_week,str,x) { if (sec...
http://rosettacode.org/wiki/Continued_fraction
Continued fraction
continued fraction Mathworld a 0 + b 1 a 1 + b 2 a 2 + b 3 a 3 + ⋱ {\displaystyle a_{0}+{\cfrac {b_{1}}{a_{1}+{\cfrac {b_{2}}{a_{2}+{\cfrac {b_{3}}{a_{3}+\ddots }}}}}}} The task is to write a program which generates su...
#11l
11l
F calc(f_a, f_b, =n = 1000) V r = 0.0 L n > 0 r = f_b(n) / (f_a(n) + r) n-- R f_a(0) + r   print(calc(n -> I n > 0 {2} E 1, n -> 1)) print(calc(n -> I n > 0 {n} E 2, n -> I n > 1 {n - 1} E 1)) print(calc(n -> I n > 0 {6} E 3, n -> (2 * n - 1) ^ 2))
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#R
R
  ratio<-function(decimal){ denominator=1 while(nchar(decimal*denominator)!=nchar(round(decimal*denominator))){ denominator=denominator+1 } str=paste(decimal*denominator,"/",sep="") str=paste(str,denominator,sep="") return(str) }  
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Quackery
Quackery
[ $ "bigrat.qky" loadfile ] now!   [ dup echo$ say " is " $->v drop dup 100 > if [ say "approximately " proper 100 round improper ] vulgar$ echo$ say "." cr ] is task ( $ --> )   $ "0.9054054 0.518518 0.75" nest$ witheach task
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Crystal
Crystal
s1 = "Hello" s2 = s1
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#D
D
void main() { string src = "This is a string";   // copy contents: auto dest1 = src.idup;   // copy contents to mutable char array auto dest2 = src.dup;   // copy just the fat reference of the string auto dest3 = src; }
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#BASIC
BASIC
10 REM CONVERT SECONDS TO COMPOUND DURATION 20 REM ADAPTED FROM RUN BASIC VERSION 30 REM =============================================================== 40 PRINT CHR$(14) 50 SEC = 7259 60 GOSUB 1000 70 SEC = 85400 80 GOSUB 1000 90 SEC = 6000000 100 GOSUB 1000 110 END 120 REM ============================================...
http://rosettacode.org/wiki/Continued_fraction
Continued fraction
continued fraction Mathworld a 0 + b 1 a 1 + b 2 a 2 + b 3 a 3 + ⋱ {\displaystyle a_{0}+{\cfrac {b_{1}}{a_{1}+{\cfrac {b_{2}}{a_{2}+{\cfrac {b_{3}}{a_{3}+\ddots }}}}}}} The task is to write a program which generates su...
#Action.21
Action!
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit   DEFINE PTR="CARD" DEFINE JSR="$20" DEFINE RTS="$60"   PROC CoeffA=*(INT n REAL POINTER res) [JSR $00 $00 ;JSR to address set by SetCoeffA RTS]   PROC CoeffB=*(INT n REAL POINTER res) [JSR $00 $00 ;JSR to address set by SetCoeffB RTS]   PROC SetCoeffA(PTR p) ...
http://rosettacode.org/wiki/Continued_fraction
Continued fraction
continued fraction Mathworld a 0 + b 1 a 1 + b 2 a 2 + b 3 a 3 + ⋱ {\displaystyle a_{0}+{\cfrac {b_{1}}{a_{1}+{\cfrac {b_{2}}{a_{2}+{\cfrac {b_{3}}{a_{3}+\ddots }}}}}}} The task is to write a program which generates su...
#Ada
Ada
generic type Scalar is digits <>;   with function A (N : in Natural) return Natural; with function B (N : in Positive) return Natural; function Continued_Fraction (Steps : in Natural) return Scalar;
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Racket
Racket
#lang racket   (inexact->exact 0.75)  ; -> 3/4 (exact->inexact 3/4)  ; -> 0.75   (exact->inexact 67/74) ; -> 0.9054054054054054 (inexact->exact 0.9054054054054054) ;-> 8155166892806033/9007199254740992
http://rosettacode.org/wiki/Convert_decimal_number_to_rational
Convert decimal number to rational
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. The task is to write a program to transform a decimal number into a fraction in lowest terms. It is not always possible to do this...
#Raku
Raku
say .nude.join('/') for 0.9054054, 0.518518, 0.75;
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#dc
dc
[a string] # push "a string" on the main stack d # duplicate the top value f # show the current contents of the main stack
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Delphi
Delphi
program CopyString;   {$APPTYPE CONSOLE}   var s1: string; s2: string; begin s1 := 'Goodbye'; s2 := s1; // S2 points at the same string as S1 s2 := s2 + ', World!'; // A new string is created for S2   Writeln(s1); Writeln(s2); end.
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#Batch_File
Batch File
@echo off ::The Main Thing... for %%d in (7259 86400 6000000) do call :duration %%d exit/b 0 ::/The Main Thing. ::The Function... :duration set output= set /a "wk=%1/604800,rem=%1%%604800" if %wk% neq 0 set "output= %wk% wk,"   set /a "d=%rem%/86400,rem=%rem%%%86400" if %d% neq 0 set "output=%output% %d% d,"   s...
http://rosettacode.org/wiki/Constrained_genericity
Constrained genericity
Constrained genericity or bounded quantification means that a parametrized type or function (see parametric polymorphism) can only be instantiated on types fulfilling some conditions, even if those conditions are not used in that function. Say a type is called "eatable" if you can call the function eat on it. Write a ...
#Ada
Ada
with Ada.Containers.Indefinite_Vectors;   package Nutrition is type Food is interface; procedure Eat (Object : in out Food) is abstract;   end Nutrition;   with Ada.Containers; with Nutrition;   generic type New_Food is new Nutrition.Food; package Food_Boxes is   package Food_Vectors is new Ada.Contain...
http://rosettacode.org/wiki/Consecutive_primes_with_ascending_or_descending_differences
Consecutive primes with ascending or descending differences
Task Find and display here on this page, the longest sequence of consecutive prime numbers where the differences between the primes are strictly ascending. Do the same for sequences of primes where the differences are strictly descending. In both cases, show the sequence for primes   <   1,000,000. If there...
#11l
11l
F primes_upto(limit) V is_prime = [0B] * 2 [+] [1B] * (limit - 1) L(n) 0 .< Int(limit ^ 0.5 + 1.5) I is_prime[n] L(i) (n * n .. limit).step(n) is_prime[i] = 0B R enumerate(is_prime).filter((i, prime) -> prime).map((i, prime) -> i)   V primelist = primes_upto(1'000'000)   V listlen = ...