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/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
letters[words_,n_] := Sort[Flatten[Characters /@ Take[words,n]]]; groupSameQ[g1_, g2_] := Sort /@ Partition[g1, 2] === Sort /@ Partition[g2, 2]; permutations[{a_, b_, c_, d_}] = Union[Permutations[{a, b, c, d}], SameTest -> groupSameQ]; Select[Flatten[permutations /@ Subsets[Union[ToLowerCase/@{"Alabama", "Alaska",...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Pike
Pike
  string msg = "hello"; msg += " world"; write(msg +"\n");  
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#PL.2FI
PL/I
Cat: procedure options (main); declare s character (100) varying; s = 'dust '; s ||= 'bowl'; put (s); end Cat;
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Plain_English
Plain English
To run: Start up. Put "abc" into a string. Append "123" to the string. Write the string to the console. Wait for the escape key. Shut down.
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#Perl
Perl
use constant pi => 3.14159265; use List::Util qw(sum reduce min max);   sub normdist { my($m, $sigma) = @_; my $r = sqrt -2 * log rand; my $theta = 2 * pi * rand; $r * cos($theta) * $sigma + $m; }   $size = 100000; $mean = 50; $stddev = 4;   push @dataset, normdist($mean,$stddev) for 1..$size;   my $m =...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#Go
Go
package main   import ( "fmt" "sort" "strconv" "strings" )   var data = `12 127 28 42` //...omitted...127 31 116 146`   func main() { // load data into map m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) ...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#EchoLisp
EchoLisp
  ;; stern (2n ) = stern (n) ;; stern(2n+1) = stern(n) + stern(n+1)   (define (stern n) (cond (( < n 3) 1) ((even? n) (stern (/ n 2))) (else (let ((m (/ (1- n) 2))) (+ (stern m) (stern (1+ m))))))) (remember 'stern)  
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Java
Java
public class StackTracer { public static void printStackTrace() { StackTraceElement[] elems = Thread.currentThread().getStackTrace();   System.out.println("Stack trace:"); for (int i = elems.length-1, j = 2 ; i >= 3 ; i--, j+=2) { System.out.printf("%" + j + "s%s.%s%n", "", elems[i].getClassName(), el...
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#JavaScript
JavaScript
try { throw new Error; } catch(e) { alert(e.stack); }
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Erlang
Erlang
  -module(stair). -compile(export_all).   step() -> 1 == random:uniform(2).   step_up(true) -> ok; step_up(false) -> step_up(step()), step_up(step()).   step_up() -> step_up(step()).  
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Euphoria
Euphoria
procedure step_up() if not step() then step_up() step_up() end if end procedure
http://rosettacode.org/wiki/Square-free_integers
Square-free integers
Task Write a function to test if a number is   square-free. A   square-free   is an integer which is divisible by no perfect square other than   1   (unity). For this task, only positive square-free numbers will be used. Show here (on this page) all square-free integers (in a horizontal format) that are between...
#ALGOL_68
ALGOL 68
BEGIN # count/show some square free numbers # # a number is square free if not divisible by any square and so not divisible # # by any squared prime # # to satisfy the task we need to know the primes up ...
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#Nim
Nim
import algorithm, sequtils, strformat, strutils, tables     const States = @["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky"...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Plain_TeX
Plain TeX
\def\addtomacro#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}} \def\foo{Hello} Initial: \foo   \addtomacro\foo{ world!} Appended: \foo \bye
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#PowerShell
PowerShell
  $str = "Hello, " $str += "World!" $str  
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#Phix
Phix
with javascript_semantics procedure sample(integer n) -- show mean, standard deviation. Find max, min. sequence dat = repeat(0,n) for i=1 to n do dat[i] = sqrt(-2*log(rnd()))*cos(2*PI*rnd()) end for printf(1,"%d data terms used.\n",{n}) atom mean = sum(dat)/n, mx = max(dat), ...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#Haskell
Haskell
import Data.List import Control.Arrow import Control.Monad   nlsRaw = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31" ++ " 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63" ++ " 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53" ++ " 114 96 25 109 7 31...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#Elixir
Elixir
defmodule SternBrocot do def sequence do Stream.unfold({0,{1,1}}, fn {i,acc} -> a = elem(acc, i) b = elem(acc, i+1) {a, {i+1, Tuple.append(acc, a+b) |> Tuple.append(b)}} end) end   def task do IO.write "First fifteen members of the sequence:\n " IO.inspect Enum.take(sequence, 15...
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Julia
Julia
f() = g() g() = println.(stacktrace())   f()
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Kotlin
Kotlin
// version 1.1.2 (stacktrace.kt which compiles to StacktraceKt.class)   fun myFunc() { println(Throwable().stackTrace.joinToString("\n")) }   fun main(args:Array<String>) { myFunc() println("\nContinuing ... ") }
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Lasso
Lasso
// Define our own trace method define trace => { local(gb) = givenblock   // Set a depth counter var(::_tracedepth)->isnota(::integer) ? $_tracedepth = 0 handle => {$_tracedepth--}   // Only output when supplied a capture #gb ? stdoutnl( // Indent ('\t' * $_tracedepth++) + ...
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Factor
Factor
: step-up ( -- ) step [ step-up step-up ] unless ;
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Forth
Forth
: step-up begin step 0= while recurse repeat ;
http://rosettacode.org/wiki/Square-free_integers
Square-free integers
Task Write a function to test if a number is   square-free. A   square-free   is an integer which is divisible by no perfect square other than   1   (unity). For this task, only positive square-free numbers will be used. Show here (on this page) all square-free integers (in a horizontal format) that are between...
#AWK
AWK
  # syntax: GAWK -f SQUARE-FREE_INTEGERS.AWK # converted from LUA BEGIN { main(1,145,1) main(1000000000000,1000000000145,1) main(1,100,0) main(1,1000,0) main(1,10000,0) main(1,100000,0) main(1,1000000,0) exit(0) } function main(lo,hi,show_values, count,i,leng) { printf("%d-%d: ",lo,...
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#Perl
Perl
#!/usr/bin/perl use warnings; use strict; use feature qw{ say };     sub uniq { my %uniq; undef @uniq{ @_ }; return keys %uniq }     sub puzzle { my @states = uniq(@_);   my %pairs; for my $state1 (@states) { for my $state2 (@states) { next if $state1 le $state2; ...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#PureBasic
PureBasic
S$ = "Hello" S$ = S$ + " Wo" ;by referencing the string twice S$ + "rld!" ;by referencing the string once If OpenConsole() PrintN(S$)   Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input() CloseConsole() EndIf
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Python
Python
#!/usr/bin/env python # -*- coding: utf-8 -*- #   str = "12345678"; str += "9!"; print(str)
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#PureBasic
PureBasic
Procedure.f randomf(resolution = 2147483647) ProcedureReturn Random(resolution) / resolution EndProcedure   Procedure.f normalDist() ;Box Muller method ProcedureReturn Sqr(-2 * Log(randomf())) * Cos(2 * #PI * randomf()) EndProcedure   Procedure sample(n, nBins = 50) Protected i, maxBinValue, binNumber Protecte...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#HicEst
HicEst
REAL :: workspace(1000), base=16   DLG(CHeckbox=bitmap, NameEdit=base, DNum, MIn=1, MAx=16) ! 1 <= stem base <= 16 READ(ClipBoard, ItemS=nData) workspace ! get raw data   ALIAS(workspace,1, dataset,nData, stems,nData) SORT(Vector=dataset, Sorted=dataset) stems = (dataset - MOD(dataset,base)) / base dataset = datas...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#F.23
F#
  // Generate Stern-Brocot Sequence. Nigel Galloway: October 11th., 2018 let sb=Seq.unfold(fun (n::g::t)->Some(n,[g]@t@[n+g;g]))[1;1]  
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Lua
Lua
function Inner( k ) print( debug.traceback() ) print "Program continues..." end   function Middle( x, y ) Inner( x+y ) end   function Outer( a, b, c ) Middle( a*b, c ) end   Outer( 2, 3, 5 )
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
f[g[1, Print[Stack[]]; 2]]
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Fortran
Fortran
module StairRobot implicit none   contains   logical function step() ! try to climb up and return true or false step = .true. ! to avoid compiler warning end function step   recursive subroutine step_up_rec do while ( .not. step() ) call step_up_rec end do end subroutine step_up_rec...
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#FreeBASIC
FreeBASIC
Sub step_up() Dim As Integer i Do If step_() Then i += 1 Else i -= 1 End If Loop Until i = 1 End Sub
http://rosettacode.org/wiki/Square_form_factorization
Square form factorization
Task. Daniel Shanks's Square Form Factorization (SquFoF). Invented around 1975, ‘On a 32-bit computer, SquFoF is the clear champion factoring algorithm for numbers between 1010 and 1018, and will likely remain so.’ An integral binary quadratic form is a polynomial f(x,y) = ax2 + bxy + cy2 with integer coefficients ...
#C
C
#include <math.h> #include <stdio.h>   #define nelems(x) (sizeof(x) / sizeof((x)[0]))   const unsigned long multiplier[] = {1, 3, 5, 7, 11, 3*5, 3*7, 3*11, 5*7, 5*11, 7*11, 3*5*7, 3*5*11, 3*7*11, 5*7*11, 3*5*7*11};   unsigned long long gcd(unsigned long long a, unsigned long long b) { while (b != 0) { a...
http://rosettacode.org/wiki/Square-free_integers
Square-free integers
Task Write a function to test if a number is   square-free. A   square-free   is an integer which is divisible by no perfect square other than   1   (unity). For this task, only positive square-free numbers will be used. Show here (on this page) all square-free integers (in a horizontal format) that are between...
#C
C
#include <stdio.h> #include <stdlib.h> #include <math.h>   #define TRUE 1 #define FALSE 0 #define TRILLION 1000000000000   typedef unsigned char bool; typedef unsigned long long uint64;   void sieve(uint64 limit, uint64 *primes, uint64 *length) { uint64 i, count, p, p2; bool *c = calloc(limit + 1, sizeof(bool))...
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#Phix
Phix
with javascript_semantics constant states = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", ...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#QB64
QB64
s$ = "String" s$ = s$ + " append" PRINT s$
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Quackery
Quackery
[ tuck take swap join swap put ] is append ( [ s --> )   $ "L'homme qui attend de voir un canard roti voler " temp put $ "dans sa bouche doit attendre tres, tres longtemps." temp append temp take echo$
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#Python
Python
from __future__ import division import matplotlib.pyplot as plt import random   mean, stddev, size = 50, 4, 100000 data = [random.gauss(mean, stddev) for c in range(size)]   mn = sum(data) / size sd = (sum(x*x for x in data) / size - (sum(data) / size) ** 2) ** 0.5   print("Sample mean = %g; Stddev = %g; max = ...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#Icon_and_Unicon
Icon and Unicon
procedure main(A) prune := integer(\A[1]) | 10 # Boundary between leaf and stem every put(data := [], integer(!&input)) writes(right(oldStem := 0,5)," |") every item := !sort(data) do { leaf := item % prune stem := item / prune while (oldStem < stem) do writes("\n",right(oldSte...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#Factor
Factor
USING: formatting io kernel lists lists.lazy locals math math.ranges prettyprint sequences ; IN: rosetta-code.stern-brocot   : fn ( n -- m ) [ 1 0 ] dip [ dup zero? ] [ dup 1 bitand zero? [ dupd [ + ] 2dip ] [ [ dup ] [ + ] [ ] tri* ] if -1 shift ] until drop nip ;   :...
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Nanoquery
Nanoquery
def print_stack() global __calls__   println "stack trace:" for i in range(len(__calls__) - 2, 0) println "\t" + __calls__[i] end end   print_stack() println   for i in range(1, 1) print_stack() end   println println "The program would continue."
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   class RStackTraces method inner() static StackTracer.printStackTrace() method middle() static inner() method outer() static middle() method main(args = String[]) public static outer()   class RStackTraces.StackTracer ...
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Go
Go
func step_up(){for !step(){step_up()}}
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Groovy
Groovy
  class Stair_climbing{ static void main(String[] args){ } static def step_up(){ while not step(){ step_up(); } }   }  
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Haskell
Haskell
stepUp :: Robot () stepUp = untilM step stepUp   untilM :: Monad m => m Bool -> m () -> m () untilM test action = do result <- test if result then return () else action >> untilM test action
http://rosettacode.org/wiki/Square_form_factorization
Square form factorization
Task. Daniel Shanks's Square Form Factorization (SquFoF). Invented around 1975, ‘On a 32-bit computer, SquFoF is the clear champion factoring algorithm for numbers between 1010 and 1018, and will likely remain so.’ An integral binary quadratic form is a polynomial f(x,y) = ax2 + bxy + cy2 with integer coefficients ...
#FreeBASIC
FreeBASIC
' *********************************************** 'subject: Shanks's square form factorization: ' ambiguous forms of discriminant 4N ' give factors of N. 'tested : FreeBasic 1.08.1     '------------------------------------------------ const MxN = culngint(1) shl 62 'input maximum   const qx = (1 shl 5) ...
http://rosettacode.org/wiki/Statistics/Basic
Statistics/Basic
Statistics is all about large groups of numbers. When talking about a set of sampled data, most frequently used is their mean value and standard deviation (stddev). If you have set of data x i {\displaystyle x_{i}} where i = 1 , 2 , … , n {\displaystyle i=1,2,\ldots ,n\,\!} , the mean is x ¯...
#11l
11l
F sd_mean(numbers) V mean = sum(numbers) / numbers.len V sd = (sum(numbers.map(n -> (n - @mean) ^ 2)) / numbers.len) ^ 0.5 R (sd, mean)   F histogram(numbers) V h = [0] * 10 V maxwidth = 50 L(n) numbers h[Int(n * 10)]++ V mx = max(h) print() L(i) h print(‘#.1: #.’.format(L.index /...
http://rosettacode.org/wiki/Square-free_integers
Square-free integers
Task Write a function to test if a number is   square-free. A   square-free   is an integer which is divisible by no perfect square other than   1   (unity). For this task, only positive square-free numbers will be used. Show here (on this page) all square-free integers (in a horizontal format) that are between...
#C.2B.2B
C++
#include <cstdint> #include <iostream> #include <string>   using integer = uint64_t;   bool square_free(integer n) { if (n % 4 == 0) return false; for (integer p = 3; p * p <= n; p += 2) { integer count = 0; for (; n % p == 0; n /= p) { if (++count > 1) return...
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#PicoLisp
PicoLisp
(setq *States (group (mapcar '((Name) (cons (clip (sort (chop (lowc Name)))) Name)) (quote "Alabama" "Alaska" "Arizona" "Arkansas" "California" "Colorado" "Connecticut" "Delaware" "Florida" "Georgia" "Hawaii" "Idaho" "Illinois" "Indiana" "Iow...
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#Prolog
Prolog
state_name_puzzle :- L = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", ...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Racket
Racket
;there is no built-in way to set! append in racket (define mystr "foo") (set! mystr (string-append mystr " bar")) (displayln mystr)   ;but you can create a quick macro to solve that problem (define-syntax-rule (set-append! str value) (set! str (string-append str value)))   (define mymacrostr "foo") (set-append! mymac...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Raku
Raku
my $str = "foo"; $str ~= "bar"; say $str;
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#R
R
n <- 100000 u <- sqrt(-2*log(runif(n))) v <- 2*pi*runif(n) x <- u*cos(v) y <- v*sin(v) hist(x)
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#Racket
Racket
  #lang racket (require math (planet williams/science/histogram-with-graphics))   (define data (sample (normal-dist 50 4) 100000))   (displayln (~a "Mean:\t" (mean data))) (displayln (~a "Stddev:\t" (stddev data))) (displayln (~a "Max:\t" (apply max data))) (displayln (~a "Min:\t" (apply min data)))   (define h...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#J
J
stem =: <.@(%&10) leaf =: 10&| stemleaf =: (stem@{. ; leaf)/.~ stem expandStems =: <./ ([ + i.@>:@-~) >./ expandLeaves=: (expandStems e. ])@[ #inv ]   showStemLeaf=: (":@,.@expandStems@[ ; ":&>@expandLeaves)&>/@(>@{. ; <@{:)@|:@stemleaf@/:~
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#Forth
Forth
: stern ( n -- x : return N'th item of Stern-Brocot sequence) dup 2 >= if 2 /mod swap if dup 1+ recurse swap recurse + else recurse then then ;   : first ( n -- x : return X such that stern X = n ) 1 begin over over stern <> while 1+ repeat swap drop ; ...
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Nim
Nim
proc g() = # Writes the current stack trace to stderr. writeStackTrace() # Or fetch the stack trace entries for the current stack trace: echo "----" for e in getStackTraceEntries(): echo e.filename, "@", e.line, " in ", e.procname   proc f() = g()   f()
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Objective-C
Objective-C
#include <execinfo.h>   void *frames[128]; int len = backtrace(frames, 128); char **symbols = backtrace_symbols(frames, len); for (int i = 0; i < len; ++i) { NSLog(@"%s", symbols[i]); } free(symbols);
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Icon_and_Unicon
Icon and Unicon
procedure step_up() return step() | (step_up(),step_up()) end
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#J
J
step =: 0.6 > ?@0: attemptClimb =: [: <:`>:@.step 0: isNotUpOne =: -.@(+/@])   step_up=: (] , attemptClimb)^:isNotUpOne^:_
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Java
Java
public void stepUp() { while (!step()) stepUp(); }
http://rosettacode.org/wiki/Square_form_factorization
Square form factorization
Task. Daniel Shanks's Square Form Factorization (SquFoF). Invented around 1975, ‘On a 32-bit computer, SquFoF is the clear champion factoring algorithm for numbers between 1010 and 1018, and will likely remain so.’ An integral binary quadratic form is a polynomial f(x,y) = ax2 + bxy + cy2 with integer coefficients ...
#Go
Go
package main   import ( "fmt" "math" )   func isqrt(x uint64) uint64 { x0 := x >> 1 x1 := (x0 + x/x0) >> 1 for x1 < x0 { x0 = x1 x1 = (x0 + x/x0) >> 1 } return x0 }   func gcd(x, y uint64) uint64 { for y != 0 { x, y = y, x%y } return x }   var multiplier =...
http://rosettacode.org/wiki/Statistics/Basic
Statistics/Basic
Statistics is all about large groups of numbers. When talking about a set of sampled data, most frequently used is their mean value and standard deviation (stddev). If you have set of data x i {\displaystyle x_{i}} where i = 1 , 2 , … , n {\displaystyle i=1,2,\ldots ,n\,\!} , the mean is x ¯...
#Action.21
Action!
INCLUDE "H6:REALMATH.ACT"   DEFINE SIZE="10000" DEFINE HIST_SIZE="10" BYTE ARRAY data(SIZE) CARD ARRAY hist(HIST_SIZE)   PROC Generate() INT i   FOR i=0 TO SIZE-1 DO data(i)=Rand(0) OD RETURN   PROC CalcMean(INT count REAL POINTER mean) REAL tmp1,tmp2,r255 INT i   IntToReal(0,mean) IntToReal(255,r25...
http://rosettacode.org/wiki/Statistics/Basic
Statistics/Basic
Statistics is all about large groups of numbers. When talking about a set of sampled data, most frequently used is their mean value and standard deviation (stddev). If you have set of data x i {\displaystyle x_{i}} where i = 1 , 2 , … , n {\displaystyle i=1,2,\ldots ,n\,\!} , the mean is x ¯...
#Ada
Ada
with Ada.Text_IO, Ada.Command_Line, Ada.Numerics.Float_Random, Ada.Numerics.Generic_Elementary_Functions;   procedure Basic_Stat is   package FRG renames Ada.Numerics.Float_Random; package TIO renames Ada.Text_IO;   type Counter is range 0 .. 2**31-1; type Result_Array is array(Natural range <>) of Counte...
http://rosettacode.org/wiki/Square-free_integers
Square-free integers
Task Write a function to test if a number is   square-free. A   square-free   is an integer which is divisible by no perfect square other than   1   (unity). For this task, only positive square-free numbers will be used. Show here (on this page) all square-free integers (in a horizontal format) that are between...
#D
D
import std.array; import std.math; import std.stdio;   long[] sieve(long limit) { long[] primes = [2]; bool[] c = uninitializedArray!(bool[])(cast(size_t)(limit + 1)); long p = 3; while (true) { long p2 = p * p; if (p2 > limit) { break; } for (long i = p2; i <...
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#Python
Python
from collections import defaultdict   states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Miss...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Relation
Relation
  set a = "Hello" set b = " World" set c = a.b echo c  
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#REXX
REXX
s='he' s=s'llo world!' Say s
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Ring
Ring
  aString1 = "Welcome to the " aString2 = "Ring Programming Language" aString3 = aString1 + aString2 see aString3  
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#Raku
Raku
sub normdist ($m, $σ) { my $r = sqrt -2 * log rand; my $Θ = τ * rand; $r * cos($Θ) * $σ + $m; }   sub MAIN ($size = 100000, $mean = 50, $stddev = 4) { my @dataset = normdist($mean,$stddev) xx $size;   my $m = [+](@dataset) / $size; say (:$m);   my $σ = sqrt [+](@dataset X** 2) / $size - $m**...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#Java
Java
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap;   public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#Fortran
Fortran
* STERN-BROCOT SEQUENCE - FORTRAN IV DIMENSION ISB(2400) NN=2400 ISB(1)=1 ISB(2)=1 I=1 J=2 K=2 1 IF(K.GE.NN) GOTO 2 K=K+1 ISB(K)=ISB(K-I)+ISB(K-J) K=K+1 ISB(K)=ISB(K-J) I=I+1 J=J+1 GOTO 1 2 N=15 WRITE(*,101) ...
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#OCaml
OCaml
let div a b = a / b   let () = try let _ = div 3 0 in () with e -> prerr_endline(Printexc.to_string e); Printexc.print_backtrace stderr; ;;
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Oforth
Oforth
: f1 Exception throw("An exception") ; Integer method: f2 self f1 ; : f3 f2 ; : f4 f3 ;   10 f4
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#OxygenBasic
OxygenBasic
  '32bit x86   static string Report     macro ReportStack(n) '===================   ' scope ' static sys stack[0X100],stackptr,e ' 'CAPTURE IMAGE OF UP TO 256 ENTRIES ' ' mov eax,n cmp eax,0x100 ( jle exit mov eax,0x100 'UPPER LIMIT ) mov e,eax mov stackptr,esp lea edx,stack mov ...
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#jq
jq
def tick: .+1;
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Julia
Julia
  step_up() = while !step() step_up() end  
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Kotlin
Kotlin
// version 1.2.0   import java.util.Random   val rand = Random(6321L) // generates short repeatable sequence var position = 0   fun step(): Boolean { val r = rand.nextBoolean() if (r) println("Climbed up to ${++position}") else println("Fell down to ${--position}") return r }   fun stepU...
http://rosettacode.org/wiki/Square_but_not_cube
Square but not cube
Task Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.
#11l
11l
V n = 1 V count = 0   L count < 30 V sq = n * n V cr = Int(sq ^ (1/3) + 1e-6) I cr * cr * cr != sq count++ print(sq) E print(sq‘ is square and cube’) n++
http://rosettacode.org/wiki/Square_form_factorization
Square form factorization
Task. Daniel Shanks's Square Form Factorization (SquFoF). Invented around 1975, ‘On a 32-bit computer, SquFoF is the clear champion factoring algorithm for numbers between 1010 and 1018, and will likely remain so.’ An integral binary quadratic form is a polynomial f(x,y) = ax2 + bxy + cy2 with integer coefficients ...
#jq
jq
def gcd(a; b): # subfunction expects [a,b] as input # i.e. a ~ .[0] and b ~ .[1] def rgcd: if .[1] == 0 then .[0] else [.[1], .[0] % .[1]] | rgcd end; [a,b] | rgcd;   # for infinite precision integer-arithmetic def idivide($p; $q): ($p - ($p % $q)) / $q ; def idivide($q): (. - (. % $q)) / $q ;...
http://rosettacode.org/wiki/Square_form_factorization
Square form factorization
Task. Daniel Shanks's Square Form Factorization (SquFoF). Invented around 1975, ‘On a 32-bit computer, SquFoF is the clear champion factoring algorithm for numbers between 1010 and 1018, and will likely remain so.’ An integral binary quadratic form is a polynomial f(x,y) = ax2 + bxy + cy2 with integer coefficients ...
#Julia
Julia
function square_form_factor(n::T)::T where T <: Integer multiplier = T.([1, 3, 5, 7, 11, 3*5, 3*7, 3*11, 5*7, 5*11, 7*11, 3*5*7, 3*5*11, 3*7*11, 5*7*11, 3*5*7*11]) s = T(round(sqrt(n))) s * s == n && return s for k in multiplier T != BigInt && n > typemax(T) ÷ k && break d = k * n ...
http://rosettacode.org/wiki/Square_form_factorization
Square form factorization
Task. Daniel Shanks's Square Form Factorization (SquFoF). Invented around 1975, ‘On a 32-bit computer, SquFoF is the clear champion factoring algorithm for numbers between 1010 and 1018, and will likely remain so.’ An integral binary quadratic form is a polynomial f(x,y) = ax2 + bxy + cy2 with integer coefficients ...
#Nim
Nim
import math, strformat   const M = [uint64 1, 3, 5, 7, 11]   template isqrt(n: uint64): uint64 = uint64(sqrt(float(n))) template isEven(n: uint64): bool = (n and 1) == 0   proc squfof(n: uint64): uint64 =   if n.isEven: return 2 var h = uint64(sqrt(float(n)) + 0.5) if h * h == n: return h   for m in M: if m...
http://rosettacode.org/wiki/Statistics/Basic
Statistics/Basic
Statistics is all about large groups of numbers. When talking about a set of sampled data, most frequently used is their mean value and standard deviation (stddev). If you have set of data x i {\displaystyle x_{i}} where i = 1 , 2 , … , n {\displaystyle i=1,2,\ldots ,n\,\!} , the mean is x ¯...
#C
C
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <stdint.h>   #define n_bins 10   double rand01() { return rand() / (RAND_MAX + 1.0); }   double avg(int count, double *stddev, int *hist) { double x[count]; double m = 0, s = 0;   for (int i = 0; i < n_bins; i++) hist[i] = 0; for (int i = 0; i < coun...
http://rosettacode.org/wiki/Square-free_integers
Square-free integers
Task Write a function to test if a number is   square-free. A   square-free   is an integer which is divisible by no perfect square other than   1   (unity). For this task, only positive square-free numbers will be used. Show here (on this page) all square-free integers (in a horizontal format) that are between...
#Factor
Factor
USING: formatting grouping io kernel math math.functions math.primes.factors math.ranges sequences sets ; IN: rosetta-code.square-free   : sq-free? ( n -- ? ) factors all-unique? ;   ! Word wrap for numbers. : numbers-per-line ( m -- n ) log10 >integer 2 + 80 swap /i ;   : sq-free-show ( from to -- ) 2dup "Square-f...
http://rosettacode.org/wiki/Square-free_integers
Square-free integers
Task Write a function to test if a number is   square-free. A   square-free   is an integer which is divisible by no perfect square other than   1   (unity). For this task, only positive square-free numbers will be used. Show here (on this page) all square-free integers (in a horizontal format) that are between...
#Forth
Forth
: square_free? ( n -- ? ) dup 4 mod 0= if drop false exit then 3 begin 2dup dup * >= while 0 >r begin 2dup mod 0= while r> 1+ dup 1 > if 2drop drop false exit then >r tuck / swap repeat rdrop 2 + repeat 2drop true ;   \ print square-free numb...
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#Racket
Racket
  #lang racket (define states (list->set (map string-downcase '("Alabama" "Alaska" "Arizona" "Arkansas" "California" "Colorado" "Connecticut" "Delaware" "Florida" "Georgia" "Hawaii" "Idaho" "Illinois" "Indiana" "Iowa" "Kansas" "Kentucky" "Loui...
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#Raku
Raku
my @states = < Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New_Hampshire New_Jersey New_Mexico New_Yo...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Robotic
Robotic
  set "$str1" to "Hello " inc "$str1" by "world!" * "&$str1&" end  
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Ruby
Ruby
s = "Hello wo" s += "rld" # new string object s << "!" # mutates in place, same object puts s
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Rust
Rust
  use std::ops::Add;   fn main(){ let hello = String::from("Hello world"); println!("{}", hello.add("!!!!")); }
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#REXX
REXX
/*REXX program generates 10,000 normally distributed numbers (Gaussian distribution).*/ numeric digits 20 /*use twenty decimal digs for accuracy.*/ parse arg n seed . /*obtain optional arguments from the CL*/ if n=='' | n=="," then n= 10000 ...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#JavaScript
JavaScript
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <title>stem and leaf plot</title> <script type='text/javascript'>   function has_property(obj, propname) { return typeof(obj[propname]) === "u...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#FreeBASIC
FreeBASIC
' version 02-03-2019 ' compile with: fbc -s console   #Define max 2000   Dim Shared As UInteger stern(max +2)   Sub stern_brocot   stern(1) = 1 stern(2) = 1   Dim As UInteger i = 2 , n = 2, ub = UBound(stern)   Do While i < ub i += 1 stern(i) = stern(n) + stern(n -1) i += 1 ...
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Oz
Oz
declare proc {Test} _ = 1 div 0 end in try {Test} catch E then {Inspect E} end
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Perl
Perl
use Carp 'cluck';   sub g {cluck 'Hello from &g';} sub f {g;}   f;
http://rosettacode.org/wiki/Stack_traces
Stack traces
Many programming languages allow for introspection of the current call stack environment. This can be for a variety of purposes such as enforcing security checks, debugging, or for getting access to the stack frame of callers. Task Print out (in a manner considered suitable for the platform) the current call stack....
#Phix
Phix
constant W = machine_word(), {RTN,PREVEBP} = iff(W=4?{8,20}:{16,40}) procedure show_stack() sequence symtab, symtabN integer rtn atom prev_ebp #ilASM{ [32] lea edi,[symtab] call :%opGetST -- [edi]=symtab (ie our local:=the real symtab) mov edi,[ebp+20] ...
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Liberty_BASIC
Liberty BASIC
'This demo will try to get the robot to step up 'Run it several times to see the differences; sometimes the robot falls 'quite a ways before making it to the next step up, but sometimes he makes it 'on the first try   result = Stepp.Up()   Function Stepp.Up() While Not(Stepp()) result = Stepp.Up() Wend ...
http://rosettacode.org/wiki/Stair-climbing_puzzle
Stair-climbing puzzle
From Chung-Chieh Shan (LtU): Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a...
#Logo
Logo
to step.up if not step [step.up step.up] end