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/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...
#Frink
Frink
  a = "Monkey" b = a  
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...
#FutureBasic
FutureBasic
  include "NSLog.incl"   CFStringRef original, copy   original = @"Hello!" copy = fn StringWithString( original )   NSLog( @"%@", copy )   HandleEvents  
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#Ada
Ada
with Ada.Text_IO; with Ada.Numerics.Discrete_Random; procedure Circle is -- extreme coordinate values are -15:0, 15:0, 0:-15, 0:15 subtype Coordinate is Integer range -15 .. 15; type Point is record X, Y : Coordinate; end record; type Point_List is array (Positive range <>) of Point;   function ...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#ATS
ATS
// // Convex hulls by Andrew's monotone chain algorithm. // // For a description of the algorithm, see // https://en.wikibooks.org/w/index.php?title=Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain&stableid=40169 // // // The implementation is designed for use with a garbage collector. // In other words, so...
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...
#EasyLang
EasyLang
func split sec . s$ . divs[] = [ 60 60 24 7 ] n$[] = [ "sec" "min" "hr" "d" "wk" ] len r[] 5 for i range 4 r[i] = sec mod divs[i] sec = sec div divs[i] . r[4] = sec s$ = "" for i = 4 downto 0 if r[i] <> 0 if s$ <> "" s$ &= ", " . s$ &= r[i] & " " & n$[i] . . ....
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 ...
#Ruby
Ruby
class Foodbox def initialize (*food) raise ArgumentError, "food must be eadible" unless food.all?{|f| f.respond_to?(:eat)} @box = food end end   class Fruit def eat; end end   class Apple < Fruit; end   p Foodbox.new(Fruit.new, Apple.new) # => #<Foodbox:0x00000001420c88 @box=[#<Fruit:0x00000001420cd8>, #...
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 ...
#Rust
Rust
  // This declares the "Eatable" constraint. It could contain no function. trait Eatable { fn eat(); }   // This declares the generic "FoodBox" type, // whose parameter must satisfy the "Eatable" constraint. // The objects of this type contain a vector of eatable objects. struct FoodBox<T: Eatable> { _data: Vec...
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 ...
#Sather
Sather
abstract class $EDIBLE is eat; end;   class FOOD < $EDIBLE is readonly attr name:STR; eat is #OUT + "eating " + self.name + "\n"; end; create(name:STR):SAME is res ::= new; res.name := name; return res; end; end;   class CAR is readonly attr name:STR; create(name:STR):SAME is res ::=...
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 ...
#Scala
Scala
type Eatable = { def eat: Unit }   class FoodBox(coll: List[Eatable])   case class Fish(name: String) { def eat { println("Eating "+name) } }   val foodBox = new FoodBox(List(new Fish("salmon")))
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...
#Phix
Phix
integer pn = 1, -- prime numb lp = 2, -- last prime lg = 0, -- last gap pd = 0 -- prev d sequence cr = {0,0}, -- curr run [a,d] mr = {{0},{0}} -- max runs "" while true do pn += 1 integer p = get_prime(pn), gap = p-lp, d = compare(gap,lg) if p>1e6 then exit ...
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...
#CoffeeScript
CoffeeScript
# Compute a continuous fraction of the form # a0 + b1 / (a1 + b2 / (a2 + b3 / ... continuous_fraction = (f) -> a = f.a b = f.b c = 1 for n in [100000..1] c = b(n) / (a(n) + c) a(0) + c   # A little helper. p = (a, b) -> console.log a console.log b console.log "---"   do -> fsqrt2 = a: (n) -> i...
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...
#Gambas
Gambas
Public Sub main() Dim src As String Dim dst As String   src = "Hello" dst = src   Print src Print dst 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...
#GAP
GAP
#In GAP strings are lists of characters. An affectation simply copy references a := "more"; b := a; b{[1..4]} := "less"; a; # "less"   # Here is a true copy a := "more"; b := ShallowCopy(a); b{[1..4]} := "less"; a; # "more"
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#ALGOL_68
ALGOL 68
PROC clrscr = VOID: printf(($g"[2J"$,REPR 27)); # ansi.sys #   PROC gotoxy = (INT x,y)VOID: printf(($g"["g(0)";"g(0)"H"$,REPR 27, y,x)); # ansi.sys #   MODE POINT = STRUCT( INT x,y );   INT radius = 15; INT inside radius = 10;   POINT center = (radius+1, radius+1);   FLEX[0]POINT set;   PROC swap ...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#C
C
#include <assert.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h>   typedef struct tPoint { int x, y; } Point;   bool ccw(const Point *a, const Point *b, const Point *c) { return (b->x - a->x) * (c->y - a->y) > (b->y - a->y) * (c->x - a->x); }   int comparePoints(const void *lhs, const vo...
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...
#Elixir
Elixir
defmodule Convert do @minute 60 @hour @minute*60 @day @hour*24 @week @day*7 @divisor [@week, @day, @hour, @minute, 1]   def sec_to_str(sec) do {_, [s, m, h, d, w]} = Enum.reduce(@divisor, {sec,[]}, fn divisor,{n,acc} -> {rem(n,divisor), [div(n,divisor) | acc]} end) [...
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 ...
#Sidef
Sidef
class FoodBox(*food { .all { .respond_to(:eat) } }) { }   class Fruit { method eat { ... } } class Apple < Fruit { }   say FoodBox(Fruit(), Apple()).dump #=> FoodBox(food: [Fruit(), Apple()]) say FoodBox(Apple(), "foo") #!> ERROR: class `FoodBox` !~ (Apple, String)
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 ...
#Swift
Swift
protocol Eatable { func eat() }
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 ...
#Wren
Wren
// abstract class class Eatable { eat() { /* override in child class */ } }   class FoodBox { construct new(contents) { if (contents.any { |e| !(e is Eatable) }) { Fiber.abort("All FoodBox elements must be eatable.") } _contents = contents }   contents { _...
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...
#Python
Python
  from sympy import sieve   primelist = list(sieve.primerange(2,1000000))   listlen = len(primelist)   # ascending   pindex = 1 old_diff = -1 curr_list=[primelist[0]] longest_list=[]   while pindex < listlen:   diff = primelist[pindex] - primelist[pindex-1] if diff > old_diff: curr_list.append(primelist...
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...
#Raku
Raku
use Math::Primesieve; use Lingua::EN::Numbers;   my $sieve = Math::Primesieve.new;   my $limit = 1000000;   my @primes = $sieve.primes($limit);   sub runs (&op) { my $diff = 1; my $run = 1;   my @diff = flat 1, (1..^@primes).map: { my $next = @primes[$_] - @primes[$_ - 1]; if &op($next, $dif...
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...
#Common_Lisp
Common Lisp
(defun estimate-continued-fraction (generator n) (let ((temp 0)) (loop for n1 from n downto 1 do (multiple-value-bind (a b) (funcall generator n1) (setf temp (/ b (+ a temp))))) (+ (funcall generator 0) temp)))   (format t "sqrt(2) = ~a~%" (coerce (estimate-continued-fraction (lamb...
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...
#GML
GML
src = "string"; 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...
#Go
Go
src := "Hello" dst := src
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#AutoHotkey
AutoHotkey
z=100 ; x = x-coord; y = y-coord; z = count; pBitmap = a pointer to the image; f = filename   pToken := Gdip_Startup() pBitmap := Gdip_CreateBitmap(31, 32)   While z { Random, x, -20, 20 Random, y, -20,20 If ( t := sqrt(x**2 + y**2) ) >= 10 && t <= 15 Gdip_SetPixel(pBitmap, x+15, y+16, 255<<24), z-- }   Gdip_SaveB...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#C.23
C#
using System; using System.Collections.Generic;   namespace ConvexHull { class Point : IComparable<Point> { private int x, y;   public Point(int x, int y) { this.x = x; this.y = y; }   public int X { get => x; set => x = value; } public int Y { get => ...
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...
#Erlang
Erlang
  -module(convert_seconds).   -export([test/0]).   test() -> lists:map(fun convert/1, [7259, 86400, 6000000]), ok.   convert(Seconds) -> io:format( "~7s seconds = ~s\n", [integer_to_list(Seconds), compoundDuration(Seconds)] ).   % Compound duration of t seconds. The argument is assumed to be positive. compound...
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 ...
#zkl
zkl
class Eatable{ var v; fcn eat{ println("munching ",self.topdog.name); } } class FoodBox{ fcn init(food1,food2,etc){ editable,garbage:=vm.arglist.filter22("isChildOf",Eatable); var contents=editable; if(garbage) println("Rejecting: ",garbage); } }
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...
#REXX
REXX
/*REXX program finds the longest sequence of consecutive primes where the differences */ /*──────────── between the primes are strictly ascending; also for strictly descending.*/ parse arg hi cols . /*obtain optional argument from the CL.*/ if hi=='' | hi=="," then hi= 1000000 ...
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...
#D
D
import std.stdio, std.functional, std.traits;   FP calc(FP, F)(in F fun, in int n) pure nothrow if (isCallable!F) { FP temp = 0;   foreach_reverse (immutable ni; 1 .. n + 1) { immutable p = fun(ni); temp = p[1] / (FP(p[0]) + temp); } return fun(0)[0] + temp; }   int[2] fSqrt2(in int n) p...
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...
#Groovy
Groovy
def string = 'Scooby-doo-bee-doo' // assigns string object to a variable reference def stringRef = string // assigns another variable reference to the same object def stringCopy = new String(string) // copies string value into a new object, and assigns to a third variable reference
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...
#GUISS
GUISS
Start.Programs,Accessories,Notepad, Type:Hello world[pling],Highlight:Hello world[pling], Menu,Edit,Copy,Menu,Edit,Paste
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#BASIC
BASIC
graphsize 31, 31   for i = 1 to 100 do x = int(rand * 30) - 15 y = int(rand * 30) - 15 r = sqr(x*x + y*y) until 10 <= r and r <= 15 color rgb(255, 0, 0) plot(x+15, y+15) next i end
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#C.2B.2B
C++
#include <algorithm> #include <iostream> #include <ostream> #include <vector> #include <tuple>   typedef std::tuple<int, int> point;   std::ostream& print(std::ostream& os, const point& p) { return os << "(" << std::get<0>(p) << ", " << std::get<1>(p) << ")"; }   std::ostream& print(std::ostream& os, const std::vec...
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...
#F.23
F#
open System   let convert seconds = let span = TimeSpan.FromSeconds(seconds |> float) let (wk, day) = Math.DivRem(span.Days, 7) let parts = [(wk, "wk"); (day, "day"); (span.Hours, "hr"); (span.Minutes, "min"); (span.Seconds, "sec")] let result = List.foldBack (fun (n, u) acc -> ...
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...
#Ruby
Ruby
require "prime" limit = 1_000_000   puts "First found longest run of ascending prime gaps up to #{limit}:" p Prime.each(limit).each_cons(2).chunk_while{|(i1,i2), (j1,j2)| j1-i1 < j2-i2 }.max_by(&:size).flatten.uniq puts "\nFirst found longest run of descending prime gaps up to #{limit}:" p Prime.each(limit).each_con...
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...
#Rust
Rust
// [dependencies] // primal = "0.3"   fn print_diffs(vec: &[usize]) { for i in 0..vec.len() { if i > 0 { print!(" ({}) ", vec[i] - vec[i - 1]); } print!("{}", vec[i]); } println!(); }   fn main() { let limit = 1000000; let mut asc = Vec::new(); let mut desc = ...
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...
#Sidef
Sidef
func runs(f, arr) {   var run = 0 var diff = 0 var diffs = []   arr.each_cons(2, {|p1,p2| var curr_diff = (p2 - p1) f(curr_diff, diff) ? ++run : (run = 1) diff = curr_diff diffs << run })   var max = diffs.max var runs = []   diffs.indices_by { _ == max }...
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...
#Erlang
Erlang
  -module(continued). -compile([export_all]).   pi_a (0) -> 3; pi_a (_N) -> 6.   pi_b (N) -> (2*N-1)*(2*N-1).   sqrt2_a (0) -> 1; sqrt2_a (_N) -> 2.   sqrt2_b (_N) -> 1.   nappier_a (0) -> 2; nappier_a (N) -> N.   nappier_b (1) -> 1; nappier_b (N) -> N-1.   continued_fraction(FA,_FB,0) -...
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...
#Harbour
Harbour
cSource := "Hello World" cDestination := cSource
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...
#Haskell
Haskell
src = "Hello World" dst = src
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#C
C
#include <stdio.h> #include <stdlib.h>   inline int randn(int m) { int rand_max = RAND_MAX - (RAND_MAX % m); int r; while ((r = rand()) > rand_max); return r / (rand_max / m); }   int main() { int i, x, y, r2; unsigned long buf[31] = {0}; /* could just use 2d array */   for (i = 0; i < 100; ) { x = randn(31) -...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#Common_Lisp
Common Lisp
#!/bin/sh #|-*- mode:lisp -*-|# #| exec ros -Q -- $0 "$@" |# (progn ;;init forms (ros:ensure-asdf) #+quicklisp(ql:quickload '() :silent t) )   (defpackage :ros.script.convex-hull-task.3861520611 (:use :cl)) (in-package :ros.script.convex-hull-task.3861520611)   ;;; ;;; Convex hulls by Andrew's monotone chain al...
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...
#Factor
Factor
USING: assocs io kernel math math.parser qw sequences sequences.generalizations ;   : mod/ ( x y -- w z ) /mod swap ;   : convert ( n -- seq ) 60 mod/ 60 mod/ 24 mod/ 7 mod/ 5 narray reverse ;   : .time ( n -- ) convert [ number>string ] map qw{ wk d hr min sec } zip [ first "0" = ] reject [ " " join ] map ...
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...
#Wren
Wren
import "/math" for Int   var LIMIT = 999999 var primes = Int.primeSieve(LIMIT)   var longestSeq = Fn.new { |dir| var pd = 0 var longSeqs = [[2]] var currSeq = [2] for (i in 1...primes.count) { var d = primes[i] - primes[i-1] if ((dir == "ascending" && d <= pd) || (dir == "descending" && ...
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...
#F.23
F#
  // I provide four functions:- // cf2S general purpose continued fraction to sequence of float approximations // cN2S Normal continued fractions (a-series always 1) // cfSqRt uses cf2S to calculate sqrt of float // π takes a sequence of b values returning the next until the list is exhausted after which it injects in...
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...
#HicEst
HicEst
src = "Hello World" 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...
#i
i
//Strings are immutable in 'i'. software { a = "Hello World" b = a //This copies the string.   a += "s"   print(a) print(b) }  
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#C.23
C#
using System; using System.Diagnostics; using System.Drawing;   namespace RosettaConstrainedRandomCircle { class Program { static void Main(string[] args) { var points = new Point[404]; int i = 0; for (int y = -15; y <= 15; y++) for (int x = -1...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#D
D
import std.algorithm.sorting; import std.stdio;   struct Point { int x; int y;   int opCmp(Point rhs) { if (x < rhs.x) return -1; if (rhs.x < x) return 1; return 0; }   void toString(scope void delegate(const(char)[]) sink) const { import std.format; sink("(")...
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...
#Forth
Forth
CREATE C 0 , : ., C @ IF ." , " THEN 1 C ! ; : .TIME ( n --) [ 60 60 24 7 * * * ]L /MOD ?DUP-IF ., . ." wk" THEN [ 60 60 24 * * ]L /MOD ?DUP-IF ., . ." d" THEN [ 60 60 * ]L /MOD ?DUP-IF ., . ." hr" THEN [ 60 ]L /MOD ?DUP-IF ., . ." min" THEN  ?D...
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...
#XPL0
XPL0
func IsPrime(N); \Return 'true' if N > 2 is a prime number int N, I; [if (N&1) = 0 \even number\ then return false; for I:= 3 to sqrt(N) do [if rem(N/I) = 0 then return false; I:= I+1; ]; return true; ];   proc ShowSeq(Dir, Str); \Show longest sequence of distances between primes int Dir, Str; int ...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#ALGOL_68
ALGOL 68
BEGIN # find composite k with no single digit factors whose factors are all substrings of k # # returns TRUE if the string representation of f is a substring of k str, FALSE otherwise # PROC is substring = ( STRING k str, INT f )BOOL: BEGIN STRING f str = whole( f, 0 ); INT ...
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...
#Factor
Factor
USING: arrays combinators io kernel locals math math.functions math.ranges prettyprint sequences ; IN: rosetta.cfrac   ! Every continued fraction must implement these two words. GENERIC: cfrac-a ( n cfrac -- a ) GENERIC: cfrac-b ( n cfrac -- b )   ! square root of 2 SINGLETON: sqrt2 M: sqrt2 cfrac-a  ! If n is 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...
#Icon_and_Unicon
Icon and Unicon
procedure main() a := "qwerty" b := a b[2+:4] := "uarterl" write(a," -> ",b) 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...
#J
J
src =: 'hello' dest =: src
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#C.2B.2B
C++
  #include <windows.h> #include <list> #include <iostream>   //-------------------------------------------------------------------------------------------------- using namespace std;   //-------------------------------------------------------------------------------------------------- class point { public: int x, y...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#Delphi
Delphi
  program ConvexHulls;   {$APPTYPE CONSOLE}   {$R *.res}   uses System.Types, System.SysUtils, System.Generics.Defaults, System.Generics.Collections;   function Ccw(const a, b, c: TPoint): Boolean; begin Result := ((b.X - a.X) * (c.Y - a.Y)) > ((b.Y - a.Y) * (c.X - a.X)); end;   function ConvexHull(...
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...
#Fortran
Fortran
  SUBROUTINE PROUST(T) !Remembrance of time passed. INTEGER T !The time, in seconds. Positive only, please. INTEGER NTYPES !How many types of time? PARAMETER (NTYPES = 5) !This should do. INTEGER USIZE(NTYPES) !Size of the time unit. CHARACTER*3 UNAME(NTYPES)!Name of the time ...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Arturo
Arturo
valid?: function [n][ pf: factors.prime n every? pf 'f -> and? [contains? to :string n to :string f] [1 <> size digits f] ]   cnt: 0 i: new 3   while [cnt < 10][ if and? [not? prime? i][valid? i][ print i cnt: cnt + 1 ] 'i + 2 ]
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#F.23
F#
  // Composite numbers k with no single digit factors whose factors are all substrings of k. Nigel Galloway: January 28th., 2022 let fG n g=let rec fN i g e l=match i<g,g=0L,i%10L=g%10L with (true,_,_)->false |(_,true,_)->true |(_,_,true)->fN(i/10L)(g/10L) e l |_->fN l e e (l/10L) in fN n g g (n/10L) let fN(g:int64)=O...
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...
#Felix
Felix
fun pi (n:int) : (double*double) => let a = match n with | 0 => 3.0 | _ => 6.0 endmatch in let b = pow(2.0 * n.double - 1.0, 2.0) in (a,b);   fun sqrt_2 (n:int) : (double*double) => let a = match n with | 0 => 1.0 | _ => 2.0 endmatch in let b = 1.0 in (a,b);   fun napier (n:int) : (double*doubl...
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...
#Forth
Forth
: fsqrt2 1 s>f 0> if 2 s>f else fdup then ; : fnapier dup dup 1 > if 1- else drop 1 then s>f dup 1 < if drop 2 then s>f ; : fpi dup 2* 1- dup * s>f 0> if 6 else 3 then s>f ; ( n -- f1 f2) : cont.fraction ( xt n -- f) 1 swap 1+ 0 s>f \ ...
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...
#Java
Java
String src = "Hello"; String newAlias = src; String strCopy = new String(src);   //"newAlias == src" is true //"strCopy == src" is false //"strCopy.equals(src)" is true
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...
#JavaScript
JavaScript
var container = {myString: "Hello"}; var containerCopy = container; // Now both identifiers refer to the same object   containerCopy.myString = "Goodbye"; // container.myString will also return "Goodbye"
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#Clojure
Clojure
(ns rosettacode.circle-random-points (:import [java.awt Color Graphics Dimension] [javax.swing JFrame JPanel]))   (let [points (->> (for [x (range -15 16), y (range -15 16) :when (<= 10 (Math/hypot x y) 15)] [(+ x 15) (+ y 15)]) shuffle (take 100))] (doto (JFrame.) (.add (doto (proxy...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#F.23
F#
open System   type Point = struct val X : int val Y : int new (x : int, y : int ) = {X = x; Y = y} end   let (poly : Point list) = [ Point(16, 3); Point(12, 17); Point( 0, 6); Point(-4, -6); Point(16, 6); Point(16, -7); Point(16, -3); Point(17, -4); Point( ...
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...
#FreeBASIC
FreeBASIC
'FreeBASIC version 1.05 32/64 bit   Sub Show(m As Long) Dim As Long c(1 To 5)={604800,86400,3600,60,1} Dim As String g(1 To 5)={" Wk"," d"," hr"," min"," sec"},comma Dim As Long b(1 To 5),flag,m2=m Redim As Long s(0) For n As Long=1 To 5 If m>=c(n) Then Do Redim P...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Go
Go
package main   import ( "fmt" "rcu" "strconv" "strings" )   func main() { count := 0 k := 11 * 11 var res []int for count < 20 { if k%3 == 0 || k%5 == 0 || k%7 == 0 { k += 2 continue } factors := rcu.PrimeFactors(k) if len(factors) ...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#J
J
*/2 3 5 7 210 #1+I.0=+/|:4 q:1+i.210 48
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...
#Fortran
Fortran
module continued_fractions implicit none   integer, parameter :: long = selected_real_kind(7,99)   type continued_fraction integer :: a0, b1 procedure(series), pointer, nopass :: a, b end type   interface pure function series (n) integer, intent(in) :: n inte...
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...
#Joy
Joy
"hello" dup
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...
#jq
jq
def demo: "abc" as $s # assignment of a string to a variable | $s as $t # $t points to the same string as $s | "def" as $s # This $s shadows the previous $s | $t # $t still points to "abc" ;   demo  
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#COBOL
COBOL
  identification division. program-id. circle. environment division. input-output section. file-control. select plot-file assign "circle.txt". data division. file section. fd plot-file report plot. working-storage section. 1 binary. ...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#Fortran
Fortran
module convex_hulls ! ! Convex hulls by Andrew's monotone chain algorithm. ! ! For a description of the algorithm, see ! https://en.wikibooks.org/w/index.php?title=Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain&stableid=40169 ! ! For brevity in the task, I shall use the built-in "complex" ty...
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...
#Frink
Frink
  wk := week n = eval[input["Enter duration in seconds: "]] res = n s -> [0, "wk", "d", "hr", "min", "sec", 0] res =~ %s/, 0[^,]+//g println[res]  
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Julia
Julia
using Lazy using Primes   function containsitsonlytwodigfactors(n) s = string(n) return !isprime(n) && all(t -> length(t) > 1 && contains(s, t), map(string, collect(keys(factor(n))))) end   seq = @>> Lazy.range(2) filter(containsitsonlytwodigfactors)   foreach(p -> print(lpad(last(p), 9), first(p) == 10 ? "\n" ...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[CompositeAndContainsPrimeFactor] CompositeAndContainsPrimeFactor[k_Integer] := Module[{id, pf}, If[CompositeQ[k], pf = FactorInteger[k][[All, 1]]; If[AllTrue[pf, GreaterThan[10]], id = IntegerDigits[k]; AllTrue[pf, SequenceCount[id, IntegerDigits[#]] > 0 &] , False ] , False ...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Pascal
Pascal
program FacOfInt; // gets factors of consecutive integers fast // limited to 1.2e11 {$IFDEF FPC} {$MODE DELPHI} {$OPTIMIZATION ON,ALL} {$COPERATORS ON} {$ELSE} {$APPTYPE CONSOLE} {$ENDIF} uses sysutils, strutils //Numb2USA {$IFDEF WINDOWS},Windows{$ENDIF} ; //################################################...
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...
#FreeBASIC
FreeBASIC
#define MAX 70000   function sqrt2_a( n as uinteger ) as uinteger return iif(n,2,1) end function   function sqrt2_b( n as uinteger ) as uinteger return 1 end function   function napi_a( n as uinteger ) as uinteger return iif(n,n,2) end function   function napi_b( n as uinteger ) as uinteger return iif(n>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...
#Julia
Julia
  s = "Rosetta Code" t = s   println("s = \"", s, "\" and, after \"t = s\", t = \"", t, "\"")   s = "Julia at "*s   println("s = \"", s, "\" and, after this change, t = \"", t, "\"")  
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...
#KonsolScript
KonsolScript
Var:String str1 = "Hello"; Var:String str2 = str1;
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#CoffeeScript
CoffeeScript
  NUM_POINTS = 100 MIN_R = 10 MAX_R = 15   random_circle_points = -> rand_point = -> Math.floor (Math.random() * (MAX_R * 2 + 1) - MAX_R)   points = {} cnt = 0 while cnt < 100 x = rand_point() y = rand_point() continue unless MIN_R * MIN_R <= x*x + y*y <= MAX_R * MAX_R points["#{x},#{y}"] = ...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#FreeBASIC
FreeBASIC
  #include "crt.bi" Screen 20 Window (-20,-20)-(30,30)   Type Point As Single x,y As Long done End Type   #macro rotate(pivot,p,a,scale) Type<Point>(scale*(Cos(a*.0174533)*(p.x-pivot.x)-Sin(a*.0174533)*(p.y-pivot.y))+pivot.x, _ scale*(Sin(a*.0174533)*(p.x-pivot.x)+Cos(a*.0174533)*(p.y-pivot.y))+pivot.y) #endmac...
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...
#Gambas
Gambas
Public Sub Main() Dim iInput As Integer[] = [7259, 86400, 6000000] 'Input details Dim iChecks As Integer[] = [604800, 86400, 3600, 60] 'Weeks, days, hours, mins in seconds Dim iTime As New Integer[5] 'To ...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Perl
Perl
use strict; use warnings; use ntheory qw<is_prime factor gcd>;   my($values,$cnt); LOOP: for (my $k = 11; $k < 1E10; $k += 2) { next if 1 < gcd($k,2*3*5*7) or is_prime $k; map { next if index($k, $_) < 0 } factor $k; $values .= sprintf "%10d", $k; last LOOP if ++$cnt == 20; } print $values =~ s/.{1,100...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Phix
Phix
with javascript_semantics integer count = 0, n = 11*11, limit = iff(platform()=JS?10:20) atom t0 = time(), t1 = time() while count<limit do if gcd(n,3*5*7)=1 then sequence f = prime_factors(n,true,-1) if length(f)>1 then string s = sprintf("%d",n) bool valid = true ...
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...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import "fmt"   type cfTerm struct { a, b int }   // follows subscript convention of mathworld and WP where there is no b(0). // cf[0].b is unused in this representation. type cf []cfTerm   func cfSqrt2(nTerms int) cf { f := make(cf, nTerms) for n := range f { f[n] = cfTerm{2, 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...
#Kotlin
Kotlin
val s = "Hello" val alias = s // alias === s val copy = "" + s // copy !== s
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...
#LabVIEW
LabVIEW
'hello dup
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#Common_Lisp
Common Lisp
(flet ((good-p (x y) (<= 100 (+ (* x x) (* y y)) 255))) (loop with x with y with cnt = 0 with scr = (loop repeat 31 collect (loop repeat 31 collect " ")) while (< cnt 100) do (when (good-p (- (setf x (random 31)) 15) (- (setf y (random 31)) 15)) (setf (elt (elt scr y) x) "@ ") (incf cnt)) finally...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#Go
Go
package main   import ( "fmt" "image" "sort" )     // ConvexHull returns the set of points that define the // convex hull of p in CCW order starting from the left most. func (p points) ConvexHull() points { // From https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain // with o...
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...
#Go
Go
package main   import "fmt"   func main(){ fmt.Println(TimeStr(7259)) fmt.Println(TimeStr(86400)) fmt.Println(TimeStr(6000000)) }   func TimeStr(sec int)(res string){ wks, sec := sec / 604800,sec % 604800 ds, sec := sec / 86400, sec % 86400 hrs, sec := sec / 3600, sec % 3600 mins, sec := sec / 60, sec % 60 Comm...
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Raku
Raku
use Prime::Factor; use Lingua::EN::Numbers;   put (2..∞).hyper(:5000batch).map( { next if (1 < $_ gcd 210) || .is-prime || any .&prime-factors.map: -> $n { !.contains: $n }; $_ } )[^20].batch(10)».&comma».fmt("%10s").join: "\n";
http://rosettacode.org/wiki/Composite_numbers_k_with_no_single_digit_factors_whose_factors_are_all_substrings_of_k
Composite numbers k with no single digit factors whose factors are all substrings of k
Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k. Task Find and show here, on this page, the first ten elements of the sequence. Stretch Find and show the next ten elements.
#Sidef
Sidef
var e = Enumerator({|f|   var c = (9.primorial) var a = (1..c -> grep { .is_coprime(c) })   loop { var n = a.shift   a.push(n + c) n.is_composite || next   f(n) if n.factor.all {|p| Str(n).contains(p) } } })   var count = 10   e.each {|n| say n break if (--count <...
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...
#Go
Go
package main   import "fmt"   type cfTerm struct { a, b int }   // follows subscript convention of mathworld and WP where there is no b(0). // cf[0].b is unused in this representation. type cf []cfTerm   func cfSqrt2(nTerms int) cf { f := make(cf, nTerms) for n := range f { f[n] = cfTerm{2, 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...
#Lang5
Lang5
'hello dup
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...
#Lasso
Lasso
local(x = 'I saw a rhino!') local(y = #x)   #x //I saw a rhino! '\r' #y //I saw a rhino!   '\r\r' #x = 'I saw one too' #x //I saw one too '\r' #y //I saw a rhino!   '\r\r' #y = 'it was grey.' #x //I saw one too '\r' #y //it was grey.
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#D
D
import std.stdio, std.random, std.math, std.complex;   void main() { char[31][31] table = ' ';   foreach (immutable _; 0 .. 100) { int x, y; do { x = uniform(-15, 16); y = uniform(-15, 16); } while(abs(12.5 - complex(x, y).abs) > 2.5); table[x + 15][y + 15...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#Groovy
Groovy
class ConvexHull { private static class Point implements Comparable<Point> { private int x, y   Point(int x, int y) { this.x = x this.y = y }   @Override int compareTo(Point o) { return Integer.compare(x, o.x) }   @Override ...