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/Stack | Stack |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A stack is a container of elements with last in, first out access policy. Sometimes it also called LIFO.
The stack is accessed through its top.
The ba... | #Batch_File | Batch File | @echo off
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: LIFO stack usage
:: Define the stack
call :newStack myStack
:: Push some values onto the stack
for %%A in (value1 value2 value3) do call :pushStack myStack %%A
:: Test if stack is empty by examining th... |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Perl | Perl | use Speech::Synthesis;
($engine) = Speech::Synthesis->InstalledEngines();
($voice) = Speech::Synthesis->InstalledVoices(engine => $engine);
Speech::Synthesis
->new(engine => $engine, voice => $voice->{id})
->speak("This is an example of speech synthesis."); |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Phix | Phix | --
-- demo\rosetta\Speak.exw
-- ======================
--
with javascript_semantics
requires(6) -- WINDOWS or JS, not LINUX
requires(32) -- Windows 32 bit only, for now...
-- (^ runs fine on a 64-bit OS, but needs a 32-bit p.exe)
requires("1.0.2")
include builtins\speak.e -- (new in 1.0.2)
constant text = "This is an ... |
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.
| #F.23 | F# |
let rec fN n g φ=if φ<31 then match compare(n*n)(g*g*g) with | -1->printfn "%d"(n*n);fN(n+1) g (φ+1)
| 0->printfn "%d cube and square"(n*n);fN(n+1)(g+1)φ
| 1->fN n (g+1) φ
fN 1 1 1
|
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
¯... | #Nim | Nim | import random, sequtils, stats, strutils, strformat
proc drawHistogram(ns: seq[float]) =
var h = newSeq[int](11)
for n in ns:
let pos = (n * 10).toInt
inc h[pos]
const maxWidth = 50
let mx = max(h)
echo ""
for n, count in h:
echo n.toFloat / 10, ": ", repeat('+', int(count / mx * maxWidth))
... |
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
¯... | #Oforth | Oforth | : main(n)
| l m std i nb |
// Create list and calculate avg and stddev
ListBuffer init(n, #[ Float rand ]) dup ->l avg ->m
0 l apply(#[ sq +]) n / m sq - sqrt ->std
System.Out "n = " << n << ", avg = " << m << ", std = " << std << cr
// Histo
0.0 0.9 0.1 step: i [
l count(#[ between(i, i 0.... |
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... | #Sidef | Sidef | func is_square_free(n) {
n.abs! if (n < 0)
return false if (n == 0)
n.factor_exp + [[1,1]] -> all { .[1] == 1 }
}
func square_free_count(n) {
1 .. n.isqrt -> sum {|k|
moebius(k) * idiv(n, k*k)
}
}
func display_results(a, c, f = { _ }) {
a.each_slice(c, {|*s|
say s.... |
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... | #Ring | Ring |
# Project : Stem-and-leaf plot
data = list(120)
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,
35, 113, 122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105,
99, 41, 128, ... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #C.2B.2B | C++ |
// Solution for http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
#include<string>
#include<iostream>
auto split(const std::string& input, const std::string& delim){
std::string res;
for(auto ch : input){
if(!res.empty() && ch != res.back())
res += delim;
res += ch;
}
retu... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #Clojure | Clojure | (defn print-cchanges [s]
(println (clojure.string/join ", " (map first (re-seq #"(.)\1*" s)))))
(print-cchanges "gHHH5YY++///\\")
|
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... | #PL.2FI | PL/I | sternBrocot: procedure options(main);
%replace MAX by 1200;
declare S(1:MAX) fixed;
/* find the first occurrence of N in S */
findFirst: procedure(n) returns(fixed);
declare (n, i) fixed;
do i=1 to MAX;
if S(i)=n then return(i);
end;
end findFirst;
/* find... |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Emacs_Lisp | Emacs Lisp | (while t
(dolist (char (string-to-list "\\|/-"))
(message "%c" char)
(sit-for 0.25))) |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Factor | Factor | USING: calendar combinators.extras formatting io sequences
threads ;
[
"\\|/-" [ "%c\r" printf flush 1/4 seconds sleep ] each
] forever |
http://rosettacode.org/wiki/Stack | Stack |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A stack is a container of elements with last in, first out access policy. Sometimes it also called LIFO.
The stack is accessed through its top.
The ba... | #BBC_BASIC | BBC BASIC | STACKSIZE = 1000
FOR n = 3 TO 5
PRINT "Push ";n : PROCpush(n)
NEXT
PRINT "Pop " ; FNpop
PRINT "Push 6" : PROCpush(6)
REPEAT
PRINT "Pop " ; FNpop
UNTIL FNisempty
PRINT "Pop " ; FNpop
END
DEF PROCpush(n) : LOCAL f%
DEF FNpop : LOCAL f% ... |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #PHP | PHP |
<?php
<?php
/*
_ _____ _ _ _ ___ __
| | |_ _| \ | | | | \ \ / /
| | | | | \| | | | |\ V /
| | | | | . ` | | | | > <
| |____ _| |_| |\ | |__| |/ . \
|______|_____|_| \_|\____//_/ \_\
*/
// Install eSpeak - Run this command in a terminal
/... |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #PicoLisp | PicoLisp | (call 'espeak "This is an example of speech synthesis.") |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #PowerShell | PowerShell |
Add-Type -AssemblyName System.Speech
$anna = New-Object System.Speech.Synthesis.SpeechSynthesizer
$anna.Speak("I'm sorry Dave, I'm afraid I can't do that.")
$anna.Dispose()
|
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.
| #Factor | Factor | USING: combinators interpolate io kernel prettyprint math
math.functions math.order pair-rocket ;
IN: rosetta-code.square-but-not-cube
: fn ( s c n -- s' c' n' )
dup 31 < [
2over [ sq ] [ 3 ^ ] bi* <=> {
+lt+ => [ [ dup sq . 1 + ] 2dip 1 + fn ]
+eq+ => [ [ dup sq [I ${} cube and sq... |
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.
| #FALSE | FALSE | 1 1 1
[2O30>~][
[$$*2O$$**>][\1+\]#
1O$$**1O$*>[$$*.@1+@@" "]?
1+
]#
%%%
10, |
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
¯... | #PARI.2FGP | PARI/GP | mean(v)={
vecsum(v)/#v
};
stdev(v,mu="")={
if(mu=="",mu=mean(v));
sqrt(sum(i=1,#v,(v[i]-mu)^2))/#v
};
histogram(v,bins=16,low=0,high=1)={
my(u=vector(bins),width=(high-low)/bins);
for(i=1,#v,u[(v[i]-low)\width+1]++);
u
};
show(n)={
my(v=vector(n,i,random(1.)),mu=mean(v),s=stdev(v,mu),h=histogram(v),sz=cei... |
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... | #Swift | Swift | import BigInt
import Foundation
extension BinaryInteger {
@inlinable
public var isSquare: Bool {
var x = self / 2
var seen = Set([x])
while x * x != self {
x = (x + (self / x)) / 2
if seen.contains(x) {
return false
}
seen.insert(x)
}
return true
}
... |
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... | #Ruby | Ruby | class StemLeafPlot
def initialize(data, options = {})
opts = {:leaf_digits => 1}.merge(options)
@leaf_digits = opts[:leaf_digits]
@multiplier = 10 ** @leaf_digits
@plot = generate_structure(data)
end
private
def generate_structure(data)
plot = Hash.new {|h,k| h[k] = []}
data.sort.eac... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #CLU | CLU | % Split a string based on a change of character
split_on_change = iter (s: string) yields (string)
part: string := ""
for c: char in string$chars(s) do
if ~string$empty(part)
cand part[string$size(part)] ~= c then
yield(part)
part := ""
end
part := part ... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #COBOL | COBOL |
identification division.
program-id. split-ch.
data division.
1 split-str pic x(30) value space.
88 str-1 value "gHHH5YY++///\".
88 str-2 value "gHHH5 ))YY++,,,///\".
1 binary.
2 ptr pic 9(4) value 1.
2 str-start pic 9(4) value 1.
2 delim-len p... |
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... | #PL.2FM | PL/M | 100H:
/* FIND LOCATION OF FIRST ELEMENT IN ARRAY */
FIND$FIRST: PROCEDURE (ARR, EL) ADDRESS;
DECLARE (ARR, N) ADDRESS, (EL, A BASED ARR) BYTE;
N = 0;
LOOP:
IF A(N) = EL THEN RETURN N;
ELSE N = N + 1;
GO TO LOOP;
END FIND$FIRST;
/* CP/M CALL */
BDOS: PROCEDURE (FN, ARG);
DECLARE FN BYTE, ARG AD... |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Forth | Forth |
: rod
cr
begin
[char] \ emit 250 ms
13 emit [char] | emit 250 ms
13 emit [char] - emit 250 ms
13 emit [char] / emit 250 ms
13 emit
key?
until
;
rod
|
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #FreeBASIC | FreeBASIC | ' version 13-07-2018
' compile with: fbc -s console
Dim As String spinning_rod = "|/-" + Chr(92)
Dim As UInteger c
While InKey <> "" : Wend
While InKey = ""
Cls
Print
Print " hit any key to end program "; Chr(spinning_rod[c And 3])
c += 1
Sleep(250) ' in milliseconds
Wend
End |
http://rosettacode.org/wiki/Stack | Stack |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A stack is a container of elements with last in, first out access policy. Sometimes it also called LIFO.
The stack is accessed through its top.
The ba... | #beeswax | beeswax | instruction: _f
gstack: UInt64[0]• (at the beginning of a program lstack is initialized to [0 0 0] |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Python | Python |
import pyttsx
engine = pyttsx.init()
engine.say("It was all a dream.")
engine.runAndWait()
|
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Racket | Racket |
#lang racket
(require racket/lazy-require)
(lazy-require [ffi/com (com-create-instance com-release com-invoke)])
(define (speak text)
(cond [(eq? 'windows (system-type))
(define c (com-create-instance "SAPI.SpVoice"))
(com-invoke c "Speak" text)
(com-release c)]
[(ormap find-execu... |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Raku | Raku | run 'espeak', 'This is an example of speech synthesis.'; |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #REXX | REXX | /*REXX program uses a command line interface to invoke Windows SAM for speech synthesis.*/
parse arg t /*get the (optional) text from the C.L.*/
if t='' then exit /*Nothing to say? Then exit program.*/
dquote= '"'
rate= 1 ... |
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.
| #FOCAL | FOCAL | 01.10 S C=1;S S=1;S Q=1;S R=1;S N=1
01.20 I (N-30)1.3,1.3,1.8
01.30 S S=Q*Q
01.40 I (S-C)1.6,1.7,1.5
01.50 S R=R+1;S C=R*R*R;G 1.4
01.60 S N=N+1;T %4,S,!
01.70 S Q=Q+1;G 1.2
01.80 Q |
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.
| #Forth | Forth | : square dup * ;
: cube dup dup * * ;
: 30-non-cube-squares
0 1 1
begin 2 pick 30 < while
begin over over square swap cube > while
swap 1+ swap
repeat
over over square swap cube <> if
dup square . rot 1+ -rot
then
1+
repeat
2drop drop
;
3... |
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
¯... | #Perl | Perl | my @histogram = (0) x 10;
my $sum = 0;
my $sum_squares = 0;
my $n = $ARGV[0];
for (1..$n) {
my $current = rand();
$sum+= $current;
$sum_squares+= $current ** 2;
$histogram[$current * @histogram]+= 1;
}
my $mean = $sum / $n;
print "$n numbers\n",
"Mean: $mean\n",
"Stddev: ", sqrt(($sum_squa... |
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... | #Tcl | Tcl | proc isSquarefree {n} {
for {set d 2} {($d * $d) <= $n} {set d [expr {($d+1)|1}]} {
if {0 == ($n % $d)} {
set n [expr {$n / $d}]
if {0 == ($n % $d)} {
return 0 ;# no, just found dup divisor
}
}
} ... |
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... | #Scala | Scala | def stemAndLeaf(numbers: List[Int]) = {
val lineFormat = "%" + (numbers map (_.toString.length) max) + "d | %s"
val map = numbers groupBy (_ / 10)
for (stem <- numbers.min / 10 to numbers.max / 10) {
println(lineFormat format (stem, map.getOrElse(stem, Nil) map (_ % 10) sortBy identity mkString " "))
}
} |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #Common_Lisp | Common Lisp | (defun split (string)
(loop :for prev := nil :then c
:for c :across string
:do (format t "~:[~;, ~]~c" (and prev (char/= c prev)) c)))
(split "gHHH5YY++///\\")
|
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #Cowgol | Cowgol | include "cowgol.coh";
sub split(in: [uint8], buf: [uint8]): (out: [uint8]) is
out := buf;
loop
[buf] := [in];
if [in] == 0 then break; end if;
if [in] != [@next in] and [@next in] != 0 then
[buf+1] := ',';
[buf+2] := ' ';
buf := buf+2;
end if... |
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... | #PowerShell | PowerShell |
# An iterative approach
function iter_sb($count = 2000)
{
# Taken from RosettaCode GCD challenge
function Get-GCD ($x, $y)
{
if ($y -eq 0) { $x } else { Get-GCD $y ($x%$y) }
}
$answer = @(1,1)
$index = 1
while ($answer.Length -le $count)
{
$answer += $answer[$index] ... |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #GlovePIE | GlovePIE | debug="|"
wait 250 ms
debug="/"
wait 250 ms
debug="-"
wait 250 ms
debug="\"
wait 250 ms |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Go | Go | package main
import (
"fmt"
"time"
)
func main() {
a := `|/-\`
fmt.Printf("\033[?25l") // hide the cursor
start := time.Now()
for {
for i := 0; i < 4; i++ {
fmt.Print("\033[2J") // clear terminal
fmt.Printf("\033[0;0H") // place cursor at top left co... |
http://rosettacode.org/wiki/Stack | Stack |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A stack is a container of elements with last in, first out access policy. Sometimes it also called LIFO.
The stack is accessed through its top.
The ba... | #BQN | BQN | Push ← ∾
∾
Pop ← ¯1⊸↓
¯1⊸↓
Empty ← 0=≠
0=≠
1‿2‿3 Push 4
⟨ 1 2 3 4 ⟩
Pop 1‿2‿3
⟨ 1 2 ⟩
Empty 1‿2‿3
0
Empty ⟨⟩
1 |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Ring | Ring |
load "guilib.ring"
myApp = New qApp
{
Text = "Hello. This is an example of speech synthesis"
voice = new QTextToSpeech(null)
voice.Say(Text)
exec()
}
|
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Ring_2 | Ring |
load "guilib.ring"
load "stdlib.ring"
MyApp = New qApp {
win1 = new qWidget() {
setwindowtitle("Hello World")
setGeometry(100,100,370,250)
Text = "This is an example of speech synthesis"
Text = split(Text," ")
label1 = n... |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Ruby | Ruby | module OperatingSystem
require 'rbconfig'
module_function
def operating_system
case RbConfig::CONFIG["host_os"]
when /linux/i
:linux
when /cygwin|mswin|mingw|windows/i
:windows
when /darwin/i
:mac
when /solaris/i
:solaris
else
nil
end
end
def linux?; ... |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Scala | Scala | import javax.speech.Central
import javax.speech.synthesis.{Synthesizer, SynthesizerModeDesc}
object ScalaSpeaker extends App {
def speech(text: String) = {
if (!text.trim.isEmpty) {
val VOICENAME = "kevin16"
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoice... |
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.
| #FreeBASIC | FreeBASIC | function is_pow(n as integer, q as integer) as boolean
'tests if the number n is the q'th power of some other integer
dim as integer r = int( n^(1.0/q) )
for i as integer = r-1 to r+1 'there might be a bit of floating point nonsense, so test adjacent numbers also
if i^q = n then return true
nex... |
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
¯... | #Phix | Phix | function generate_statistics(integer n)
sequence hist = repeat(0,10)
atom sum_r = 0,
sum_squares = 0.0
for i=1 to n do
atom r = rnd()
sum_r += r
sum_squares += r*r
hist[floor(10*r)+1] += 1
end for
atom mean = sum_r / n
atom stddev = sqrt((sum_squares / n) - mean*me... |
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... | #Visual_Basic_.NET | Visual Basic .NET | Module Module1
Function Sieve(limit As Long) As List(Of Long)
Dim primes As New List(Of Long) From {2}
Dim c(limit + 1) As Boolean
Dim p = 3L
While True
Dim p2 = p * p
If p2 > limit Then
Exit While
End If
For i = p2 To... |
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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: leafPlot (in var array integer: x) is func
local
var integer: i is 0;
var integer: j is 0;
var integer: d is 0;
begin
x := sort(x);
i := x[1] div 10 - 1;
for key j range x do
d := x[j] div 10;
while d > i do
if j <> 1 then
... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #D | D | import std.stdio;
void main() {
auto source = "gHHH5YY++///\\";
char prev = source[0];
foreach(ch; source) {
if (prev != ch) {
prev = ch;
write(", ");
}
write(ch);
}
writeln();
} |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #Dyalect | Dyalect | func String.SmartSplit() {
var c
var str = ""
var last = this.Length() - 1
for n in 0..last {
if c && this[n] != c {
str += ", "
}
c = this[n]
str += c
}
str
}
print("gHHH5YY++///\\".SmartSplit()) |
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... | #PureBasic | PureBasic | EnableExplicit
Define.i i
If OpenConsole("")
PrintN("Stern-Brocot_sequence")
Else
End 1
EndIf
Procedure.i f(n.i)
If n<2
ProcedureReturn n
ElseIf n&1
ProcedureReturn f(n/2)+f(n/2+1)
Else
ProcedureReturn f(n/2)
EndIf
EndProcedure
Procedure.i gcd(a.i,b.i)
If b : ProcedureReturn gcd(b,a%... |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Haskell | Haskell | import Control.Concurrent (threadDelay)
import Control.Exception (bracket_)
import Control.Monad (forM_)
import System.Console.Terminfo
import System.IO (hFlush, stdout)
-- Use the terminfo database to write the terminal-specific characters
-- for the given capability.
runCapability :: Terminal -> String -> IO ()
run... |
http://rosettacode.org/wiki/Stack | Stack |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A stack is a container of elements with last in, first out access policy. Sometimes it also called LIFO.
The stack is accessed through its top.
The ba... | #Bracmat | Bracmat | ( ( stack
= (S=)
(push=.(!arg.!(its.S)):?(its.S))
( pop
= top.!(its.S):(%?top.?(its.S))&!top
)
(top=top.!(its.S):(%?top.?)&!top)
(empty=.!(its.S):)
)
& new$stack:?Stack
& (Stack..push)$(2*a)
& (Stack..push)$pi
& (Stack..push)$
& (Stack..push)$"to be or"
& (Stack..push)$"not to ... |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Sidef | Sidef | func text2speech(text, lang='en') {
Sys.run("espeak -v #{lang} -w /dev/stdout #{text.escape} | aplay");
}
text2speech("This is an example of speech synthesis."); |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Swift | Swift | import Foundation
let task = NSTask()
task.launchPath = "/usr/bin/say"
task.arguments = ["This is an example of speech synthesis."]
task.launch() |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Tcl | Tcl | exec festival --tts << "This is an example of speech synthesis." |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #UNIX_Shell | UNIX Shell | #!/bin/sh
espeak "This is an example of speech synthesis." |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #VBScript | VBScript |
Dim message, sapi
message = "This is an example of speech synthesis."
Set sapi = CreateObject("sapi.spvoice")
sapi.Speak message
|
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.
| #Go | Go | package main
import (
"fmt"
"math"
)
func main() {
for n, count := 1, 0; count < 30; n++ {
sq := n * n
cr := int(math.Cbrt(float64(sq)))
if cr*cr*cr != sq {
count++
fmt.Println(sq)
} else {
fmt.Println(sq, "is square and cube")
... |
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.
| #Haskell | Haskell | {-# LANGUAGE TupleSections #-}
import Control.Monad (join)
import Data.List (partition, sortOn)
import Data.Ord (comparing)
------------------- SQUARE BUT NOT CUBE ------------------
isCube :: Int -> Bool
isCube n = n == round (fromIntegral n ** (1 / 3)) ^ 3
both, only :: [Int]
(both, only) = partition isCube... |
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
¯... | #PicoLisp | PicoLisp |
(seed (time))
(scl 8)
(de statistics (Cnt . Prg)
(prinl Cnt " numbers")
(let (Sum 0 Sqr 0 Hist (need 10 NIL 0))
(do Cnt
(let N (run Prg 1) # Get next number
(inc 'Sum N)
(inc 'Sqr (*/ N N 1.0))
(inc (nth Hist (inc (/ N 0.1)))) ) )
(let M (*/ Sum Cn... |
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
¯... | #PL.2FI | PL/I | stat: procedure options (main); /* 21 May 2014 */
stats: procedure (values, mean, standard_deviation);
declare (values(*), mean, standard_deviation) float;
declare n fixed binary (31) initial ( (hbound(values,1)) );
mean = sum(values)/n;
standard_deviation = sqrt( sum(values - mean)**2 / n);
end st... |
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... | #Wren | Wren | import "/fmt" for Fmt
var isSquareFree = Fn.new { |n|
var i = 2
while (i * i <= n) {
if (n%(i*i) == 0) return false
i = (i > 2) ? i + 2 : i + 1
}
return true
}
var ranges = [ [1..145, 3, 20], [1e12..1e12+145, 12, 5] ]
for (r in ranges) {
System.print("The square-free integers bet... |
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... | #Sidef | Sidef | var data = %i(
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 141
46 13 27 ... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #EasyLang | EasyLang | a$ = "gHHH5YY++///\\"
a$[] = strchars a$
cp$ = a$[0]
for c$ in a$[]
if c$ <> cp$
s$ &= ", "
cp$ = c$
.
s$ &= c$
.
print s$ |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #Elixir | Elixir | split = fn str ->
IO.puts " input string: #{str}"
String.graphemes(str)
|> Enum.chunk_by(&(&1))
|> Enum.map_join(", ", &Enum.join &1)
|> fn s -> IO.puts "output string: #{s}" end.()
end
split.("gHHH5YY++///\\") |
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... | #Python | Python | def stern_brocot(predicate=lambda series: len(series) < 20):
"""\
Generates members of the stern-brocot series, in order, returning them when the predicate becomes false
>>> print('The first 10 values:',
stern_brocot(lambda series: len(series) < 10)[:10])
The first 10 values: [1, 1, 2, 1... |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Java | Java | public class SpinningRod
{
public static void main(String[] args) throws InterruptedException {
String a = "|/-\\";
System.out.print("\033[2J"); // hide the cursor
long start = System.currentTimeMillis();
while (true) {
for (int i = 0; i < 4; i++) {
Syst... |
http://rosettacode.org/wiki/Stack | Stack |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A stack is a container of elements with last in, first out access policy. Sometimes it also called LIFO.
The stack is accessed through its top.
The ba... | #Brat | Brat | stack = []
stack.push 1
stack.push 2
stack.push 3
until { stack.empty? } { p stack.pop } |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Wren | Wren | /* speech_synthesis.wren */
class C {
foreign static getInput(maxSize)
foreign static espeak(s)
}
System.write("Enter something to say (up to 100 characters) : ")
var s = C.getInput(100)
C.espeak(s) |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #Zoomscript | Zoomscript | speak "This is an example of speech synthesis." |
http://rosettacode.org/wiki/Speech_synthesis | Speech synthesis | Render the text This is an example of speech synthesis as speech.
Related task
using a speech engine to highlight words
| #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 LET s$="(th)is is an exampul of sp(ee)(ch) sin(th)esis":PAUSE 1 |
http://rosettacode.org/wiki/Spelling_of_ordinal_numbers | Spelling of ordinal numbers | Ordinal numbers (as used in this Rosetta Code task), are numbers that describe the position of something in a list.
It is this context that ordinal numbers will be used, using an English-spelled name of an ordinal number.
The ordinal numbers are (at least, one form of them):
1st 2nd 3rd 4th 5th 6t... | #AutoHotkey | AutoHotkey | OrdinalNumber(n){
OrdinalNumber := {"one":"first", "two":"second", "three":"third", "five":"fifth", "eight":"eighth", "nine":"ninth", "twelve": "twelfth"}
RegExMatch(n, "\w+$", m)
return (OrdinalNumber[m] ? RegExReplace(n, "\w+$", OrdinalNumber[m]) : n "th")
}
Spell(n) { ; recursive function to spell out the name ... |
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.
| #IS-BASIC | IS-BASIC | 100 PROGRAM "Square.bas"
110 LET SQNOTCB,SQANDCB,SQNUM,CBNUM,CBN,SQN,D1=0:LET SQD,D2=1
120 DO
130 LET SQN=SQN+1:LET SQNUM=SQNUM+SQD:LET SQD=SQD+2
140 IF SQNUM>CBNUM THEN
150 LET CBN=CBN+1:LET CBNUM=CBNUM+D2
160 LET D1=D1+6:LET D2=D2+D1
170 END IF
180 IF SQNUM<>CBNUM THEN
190 PRINT SQNUM:LET SQNOTC... |
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.
| #J | J | isSqrNotCubeofInt=: (*. -.)/@(= <.)@(2 3 %:/ ])
getN_Indicies=: adverb def '[ ({. I.) [ (] , [: u (i.200) + #@])^:(> +/)^:_ u@]' |
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
¯... | #PureBasic | PureBasic | Procedure.f randomf()
#RNG_max_resolution = 2147483647
ProcedureReturn Random(#RNG_max_resolution) / #RNG_max_resolution
EndProcedure
Procedure sample(n)
Protected i, nBins, binNumber, tickMarks, maxBinValue
Protected.f sum, sumSq, mean
Dim dat.f(n)
For i = 1 To n
dat(i) = randomf()
Next
;show... |
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... | #zkl | zkl | const Limit=1 + (1e12 + 145).sqrt(); // 1000001 because it fits this task
var [const]
BI=Import.lib("zklBigNum"), // GNU Multiple Precision Arithmetic Library
primes=List.createLong(Limit); // one big allocate (vs lots of allocs)
// GMP provide nice way to generate primes, nextPrime is in-place
p:=BI(0); wh... |
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... | #Stata | Stata | . clear all
. input x
12
127
28
...
31
116
146
end
. stem x
Stem-and-leaf plot for x
0* | 77
1* | 2388
2* | 357777778899
3* | 011112345677789
4* | 001222233344456788
5* | 23788
6* | 138
7* | 1
8* |
9* | 69
10* | 4555567999
11* | 13333444555666677778899
12* | 001122344455567777... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #F.23 | F# | open System.Text.RegularExpressions
let splitRuns s = Regex("""(.)\1*""").Matches(s) |> Seq.cast<Match> |> Seq.map (fun m -> m.Value) |> Seq.toList
printfn "%A" (splitRuns """gHHH5YY++///\""") |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #Factor | Factor | USE: splitting.monotonic
"gHHH5YY++///\\"
"aaabbccccdeeff" [ [ = ] monotonic-split ", " join print ] bi@ |
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... | #Quackery | Quackery | [ [ dup while
tuck mod again ]
drop abs ] is gcd ( n n --> n )
[ 2dup peek
dip [ 1+ 2dup peek ]
over + swap join
swap dip join ] is two-terms ( [ n --> [ n )
' [ 1 1 ] 0
8 times two-terms
over 15 split drop
witheach [ echo sp ] cr
[ two-terms
over -2 pe... |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #JavaScript | JavaScript |
const rod = (function rod() {
const chars = "|/-\\";
let i=0;
return function() {
i= (i+1) % 4;
// We need to use process.stdout.write since console.log automatically adds a \n to the end of lines
process.stdout.write(` ${chars[i]}\r`);
}
})();
setInterval(rod, 250);
|
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Julia | Julia | while true
for rod in "\|/-" # this needs to be a string, a char literal cannot be iterated over
print(rod,'\r')
sleep(0.25)
end
end
|
http://rosettacode.org/wiki/Stack | Stack |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A stack is a container of elements with last in, first out access policy. Sometimes it also called LIFO.
The stack is accessed through its top.
The ba... | #C | C | #include <stdio.h>
#include <stdlib.h>
/* to read expanded code, run through cpp | indent -st */
#define DECL_STACK_TYPE(type, name) \
typedef struct stk_##name##_t{type *buf; size_t alloc,len;}*stk_##name; \
stk_##name stk_##name##_create(size_t init_size) { \
stk_##name s; if (!init_size) init_size = 4; \
... |
http://rosettacode.org/wiki/Spelling_of_ordinal_numbers | Spelling of ordinal numbers | Ordinal numbers (as used in this Rosetta Code task), are numbers that describe the position of something in a list.
It is this context that ordinal numbers will be used, using an English-spelled name of an ordinal number.
The ordinal numbers are (at least, one form of them):
1st 2nd 3rd 4th 5th 6t... | #C | C | #include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <glib.h>
typedef uint64_t integer;
typedef struct number_names_tag {
const char* cardinal;
const char* ordinal;
} number_names;
const number_names small[] = {
{ "zero", "zeroth" }, { "one", "first" }, { "two", "second" },
{ "thre... |
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.
| #Java | Java | public class SquaresCubes {
public static boolean isPerfectCube(long n) {
long c = (long)Math.cbrt((double)n);
return ((c * c * c) == n);
}
public static void main(String... args) {
long n = 1;
int squareOnlyCount = 0;
int squareCubeCount = 0;
while ((square... |
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
¯... | #Python | Python | def sd1(numbers):
if numbers:
mean = sum(numbers) / len(numbers)
sd = (sum((n - mean)**2 for n in numbers) / len(numbers))**0.5
return sd, mean
else:
return 0, 0
def sd2(numbers):
if numbers:
sx = sxx = n = 0
for x in numbers:
sx += x
... |
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... | #Tcl | Tcl | package require Tcl 8.5
# How to process a single value, adding it to the table mapping stems to
# leaves.
proc addSLValue {tblName value {splitFactor 10}} {
upvar 1 $tblName tbl
# Extract the stem and leaf
if {$value < 0} {
set value [expr {round(-$value)}]
set stem -[expr {$value / $splitFactor}]
... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #Forth | Forth | CREATE A 0 ,
: C@A+ A @ C@ [ 1 CHARS ]L A +! ;
: SPLIT. ( c-addr u --) SWAP A ! A @ C@
BEGIN OVER WHILE
C@A+ TUCK <> IF ." , " THEN
DUP EMIT SWAP 1- SWAP
REPEAT DROP ;
: TEST OVER OVER
." input: " TYPE CR
." split: " SPLIT. CR ;
s" gHHH5YY++///\" TEST
s" gHHH5 )... |
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character | Split a character string based on change of character |
Task
Split a (character) string into comma (plus a blank) delimited
strings based on a change of character (left to right).
Show the output here (use the 1st example below).
Blanks should be treated as any other character (except
they are problematic to display clearly). The same applies
to commas.
Fo... | #Fortran | Fortran | SUBROUTINE SPLATTER(TEXT) !Print a comma-separated list. Repeated characters constitute one item.
Can't display the inserted commas in a different colour so as not to look like any commas in TEXT.
CHARACTER*(*) TEXT !The text.
INTEGER L !A finger.
CHARACTER*1 C !A state follower.
IF (... |
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... | #R | R |
## Stern-Brocot sequence
## 12/19/16 aev
SternBrocot <- function(n){
V <- 1; k <- n/2;
for (i in 1:k)
{ V[2*i] = V[i]; V[2*i+1] = V[i] + V[i+1];}
return(V);
}
## Required tests:
require(pracma);
{
cat(" *** The first 15:",SternBrocot(15),"\n");
cat(" *** The first i@n:","\n");
V=SternBrocot(40);
for (i in... |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Kotlin | Kotlin | // Version 1.2.50
const val ESC = "\u001b"
fun main(args: Array<String>) {
val a = "|/-\\"
print("$ESC[?25l") // hide the cursor
val start = System.currentTimeMillis()
while (true) {
for (i in 0..3) {
print("$ESC[2J") // clear terminal
print("$ESC[0;0H") // ... |
http://rosettacode.org/wiki/Spinning_rod_animation/Text | Spinning rod animation/Text | Task
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared be... | #Lua | Lua |
--
-- Simple String Animation - semi-hard-coded variant - you can alter the chars table - update the count and run it...
--
-- The basic animation runtime controller. This is where you assign the active animation ( you could create a simple function to replace the animation table and nil count, index and expiry to ... |
http://rosettacode.org/wiki/Stack | Stack |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A stack is a container of elements with last in, first out access policy. Sometimes it also called LIFO.
The stack is accessed through its top.
The ba... | #C.23 | C# | // Non-Generic Stack
System.Collections.Stack stack = new System.Collections.Stack();
stack.Push( obj );
bool isEmpty = stack.Count == 0;
object top = stack.Peek(); // Peek without Popping.
top = stack.Pop();
// Generic Stack
System.Collections.Generic.Stack<Foo> stack = new System.Collections.Generic.Stack<Foo>();
s... |
http://rosettacode.org/wiki/Special_variables | Special variables | Special variables have a predefined meaning within a computer programming language.
Task
List the special variables used within the language.
| #11l | 11l | ;DEFINING INTERRUPT VECTORS ON THE NES
org $FFFA
dw #### ;address of your NMI handler goes here (you can use labels for each of these for your convenience)
dw #### ;address of your Reset handler goes here
dw #### ;address of your IRQ handler goes here. |
http://rosettacode.org/wiki/Spelling_of_ordinal_numbers | Spelling of ordinal numbers | Ordinal numbers (as used in this Rosetta Code task), are numbers that describe the position of something in a list.
It is this context that ordinal numbers will be used, using an English-spelled name of an ordinal number.
The ordinal numbers are (at least, one form of them):
1st 2nd 3rd 4th 5th 6t... | #C.2B.2B | C++ | #include <iostream>
#include <string>
#include <cstdint>
typedef std::uint64_t integer;
struct number_names {
const char* cardinal;
const char* ordinal;
};
const number_names small[] = {
{ "zero", "zeroth" }, { "one", "first" }, { "two", "second" },
{ "three", "third" }, { "four", "fourth" }, { "f... |
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.
| #JavaScript | JavaScript | (() => {
'use strict';
const main = () =>
unlines(map(
x => x.toString() + (
isCube(x) ? (
` (cube of ${cubeRootInt(x)} and square of ${
Math.pow(x, 1/2)
})`
) : ''
),
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.