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_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.... | #C.23 | C# | using System;
using System.Diagnostics;
class Program
{
static void Inner()
{
Console.WriteLine(new StackTrace());
}
static void Middle()
{
Inner();
}
static void Outer()
{
Middle();
}
static void Main()
{
Outer();
}
} |
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.... | #Clojure | Clojure |
(doall
(map println (.dumpAllThreads (java.lang.management.ManagementFactory/getThreadMXBean) false false)))
|
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... | #Aime | Aime | void step_up(void)
{
while (!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... | #ALGOL_68 | ALGOL 68 | PROC step up = VOID:
BEGIN
WHILE NOT step DO
step up
OD
END # step 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... | #Haskell | Haskell | {-# LANGUAGE TupleSections #-}
import Data.Char (isLetter, toLower)
import Data.Function (on)
import Data.List (groupBy, nub, sort, sortBy)
-------------------- STATE NAME PUZZLE -------------------
puzzle :: [String] -> [((String, String), (String, String))]
puzzle states =
concatMap
((filter isValid . pai... |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Processing | Processing | println("hello world");
line(0, 0, width, height); |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #PureBasic | PureBasic | [ say "Please use the shell to calculate a value" cr
say "and leave it on the stack. Type 'leave' when" cr
say "you have done this." cr
shell ] constant is my-value |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Quackery | Quackery | [ say "Please use the shell to calculate a value" cr
say "and leave it on the stack. Type 'leave' when" cr
say "you have done this." cr
shell ] constant is my-value |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Racket | Racket |
#/usr/bin/env racket -tm
#lang racket
(provide main)
(define (main . args) (displayln "Hello World!"))
|
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Raku | Raku | BEGIN {...} # as soon as parsed
CHECK {...} # end of compile time
INIT {...} # beginning of run time
END {...} # end of run time |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #REXX | REXX | /*REXX*/
address 'XEDIT'
.
.
.
[XEDIT commands here.]
.
.
. |
http://rosettacode.org/wiki/Straddling_checkerboard | Straddling checkerboard | Task
Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits.
Num... | #Scala | Scala | object StraddlingCheckerboard extends App {
private val dictonary = Map("H" -> "0", "O" -> "1",
"L" -> "2", "M" -> "4", "E" -> "5", "S" -> "6", "R" -> "8", "T" -> "9",
"A" -> "30", "B" -> "31", "C" -> "32", "D" -> "33", "F" -> "34", "G" -> "35",
"I" -> "36", "J" -> "37", "K" -> "38", "N" -> "39", "P" ->... |
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 |... | #NetRexx | NetRexx | s_ = 'Hello'
s_ = s_', 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 |... | #NewLISP | NewLISP | (setq str "foo")
(push "bar" str -1)
; or as an alternative introduced in v.10.1
(extend str "bar")
(println 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 ... | #Lasso | Lasso | define stat1(a) => {
if(#a->size) => {
local(mean = (with n in #a sum #n) / #a->size)
local(sdev = math_pow(((with n in #a sum Math_Pow((#n - #mean),2)) / #a->size),0.5))
return (:#sdev, #mean)
else
return (:0,0)
}
}
define stat2(a) => {
if(#a->size) => {
local(sx = 0, sxx = 0)
with x in #a do => {
#... |
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 ... | #Liberty_BASIC | Liberty BASIC | call sample 100000
end
sub sample n
dim dat( n)
for i =1 to n
dat( i) =normalDist( 1, 0.2)
next i
'// show mean, standard deviation. Find max, min.
mx =-1000
mn = 1000
sum =0
sSq =0
for i =1 to n
d =dat( i)
mx =max( mx, d)
mn =min( mn, d)
... |
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... | #Euphoria | Euphoria | include sort.e
procedure leaf_plot(sequence s)
sequence stem
s = sort(s)
stem = repeat({},floor(s[$]/10)+1)
for i = 1 to length(s) do
stem[floor(s[i]/10)+1] &= remainder(s[i],10)
end for
for i = 1 to length(stem) do
printf(1, "%3d | ", i-1)
for j = 1 to length(stem[i]) ... |
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... | #C.2B.2B | C++ |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
unsigned gcd( unsigned i, unsigned j ) {
return i ? i < j ? gcd( j % i, i ) : gcd( i % j, j ) : j;
}
void createSequence( std::vector<unsigned>& seq, int c ) {
if( 1500 == seq.size() ) return;
unsigned t = seq.at( c ) + seq.at... |
http://rosettacode.org/wiki/Stream_merge | Stream merge | 2-stream merge
Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink.
Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was.
N-strea... | #zkl | zkl | fcn mergeStreams(s1,s2,etc){ //-->Walker
streams:=vm.arglist.pump(List(),fcn(s){ // prime and prune
if( (w:=s.walker())._next() ) return(w);
Void.Skip // stream is dry
});
Walker().tweak(fcn(streams){
if(not streams) return(Void.Stop); // all streams are dry
values:=streams.apply("va... |
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.... | #Common_Lisp | Common Lisp | (swank-backend:call-with-debugging-environment
(lambda ()
(swank:backtrace 0 nil))) |
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.... | #D | D | import std.stdio, core.runtime;
void inner() { defaultTraceHandler.writeln; }
void middle() { inner; }
void outer() { middle; }
void main() {
outer;
"After the stack trace.".writeln;
} |
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... | #Arturo | Arturo | Position: 0
stepUp: function [].export:[Position][
startPos: Position
until -> step [
Position = startPos + 1
]
]
step: function [].export:[Position][
(0.5 > random 0 1.0)? [
Position: Position - 1
print ~"fall (|Position|)"
false
][
Position: Position + 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... | #AutoHotkey | AutoHotkey | step_up()
{
While !step()
step_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... | #Icon_and_Unicon | Icon and Unicon | link strings # for csort and deletec
procedure main(arglist)
ECsolve(S1 := getStates()) # original state names puzzle
ECsolve(S2 := getStates2()) # modified fictious names puzzle
GNsolve(S1)
GNsolve(S2)
end
procedure ECsolve(S) # Solve challenge using equivalence clas... |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Ring | Ring |
func Main
see "Hello World!" + nl
|
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Ruby | Ruby | BEGIN {
# begin code
}
END {
# end code
} |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Scala | Scala | object PrimaryMain extends App {
Console.println("Hello World: " + (args mkString ", "))
}
object MainTheSecond extends App {
Console.println("Goodbye, World: " + (args mkString ", "))
} |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #sed | sed | # This code runs only for line 1.
1 {
i\
Explain-a-lot processed this file and
i\
replaced every period with three exclamation points!!!
i\
}
# This code runs for each line of input.
s/\./!!!/g |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: main is func
begin
writeln("hello world");
end func; |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Tcl | Tcl | SUB Main()
' This is the start of the program
END |
http://rosettacode.org/wiki/Straddling_checkerboard | Straddling checkerboard | Task
Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits.
Num... | #Tcl | Tcl | package require Tcl 8.6
oo::class create StraddlingCheckerboardCypher {
variable encmap decmap
constructor table {
# Sanity check the table
foreach ch [lindex $table 0] i {"" 0 1 2 3 4 5 6 7 8 9} {
if {$ch eq "" && $i ne "" && [lsearch -index 0 $table $i] < 1} {
error "bad checkerboard table"
}
... |
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 |... | #Nim | Nim | var str = "123456"
str.add("78") # Using procedure "add".
str &= "9!" # Using operator "&=".
echo str
|
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 |... | #NS-HUBASIC | NS-HUBASIC | 10 S$ = "HELLO"
20 S$ = S$ + " WORLD!"
30 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 |... | #Objeck | Objeck |
class Append {
function : Main(args : String[]) ~ Nil {
x := "foo";
x->Append("bar");
x->PrintLine();
}
}
|
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 ... | #Lua | Lua | function gaussian (mean, variance)
return math.sqrt(-2 * variance * math.log(math.random())) *
math.cos(2 * math.pi * math.random()) + mean
end
function mean (t)
local sum = 0
for k, v in pairs(t) do
sum = sum + v
end
return sum / #t
end
function std (t)
local squares, a... |
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... | #F.23 | F# | open System
let 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; 121; 116;
125; 32; 61; 37; 127; 29; 113; 121; 58; 114; 126; 53; 114... |
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... | #Clojure | Clojure | ;; each step adds two items
(defn sb-step [v]
(let [i (quot (count v) 2)]
(conj v (+ (v (dec i)) (v i)) (v i))))
;; A lazy, infinite sequence -- `take` what you want.
(def all-sbs (sequence (map peek) (iterate sb-step [1 1])))
;; zero-based
(defn first-appearance [n]
(first (keep-indexed (fn [i x] (when (= ... |
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.... | #DWScript | DWScript | procedure Inner;
begin
try
raise Exception.Create('');
except
on E: Exception do
PrintLn(E.StackTrace);
end;
end;
procedure Middle;
begin
Inner;
end;
procedure Outer;
begin
Middle;
end;
Outer; |
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.... | #Elena | Elena | import extensions;
public singleton program
{
inner()
{
console.printLine(new CallStack())
}
middle()
{
self.inner()
}
outer()
{
self.middle()
}
// program entry point
function()
{
program.outer()
}
} |
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... | #AWK | AWK |
function step_up() {
while (!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... | #BASIC | BASIC | SUB stepup
IF NOT step1 THEN stepup: stepup
END SUB |
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... | #J | J | require'strings stats'
states=:<;._2]0 :0-.LF
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 Jers... |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Visual_Basic | Visual Basic | SUB Main()
' This is the start of the program
END |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Visual_Basic_.NET | Visual Basic .NET | Imports System.Collections.ObjectModel
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
' The following events are available for MyApplication:
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This ... |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Wren | Wren | var main = Fn.new {
System.print("Hello from the main function.")
}
main.call() |
http://rosettacode.org/wiki/Straddling_checkerboard | Straddling checkerboard | Task
Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits.
Num... | #VBScript | VBScript | ' Straddling checkerboard - VBScript - 19/04/2019
Function encrypt(ByVal originalText, ByVal alphabet, blank1, blank2)
Const notEscape = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ."
Dim i, j, curChar, escChar, outText
Dim cipher 'Hash table
Set cipher = CreateObject("Scripting.Dictionary")
'build cipher referenc... |
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 |... | #OCaml | OCaml | let () =
let s = Buffer.create 17 in
Buffer.add_string s "Bonjour";
Buffer.add_string s " tout le monde!";
print_endline (Buffer.contents 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 |... | #Oforth | Oforth | StringBuffer new "Hello, " << "World!" << println |
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 ... | #Maple | Maple | with(Statistics):
n := 100000:
X := Sample( Normal(0,1), n );
Mean( X );
StandardDeviation( X );
Histogram( 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 ... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | x:= RandomReal[1]
SampleNormal[n_] := (Print[#//Length, " numbers, Mean : ", #//Mean, ", StandardDeviation : ", #//StandardDeviation];
Histogram[#, BarOrigin -> Left,Axes -> False])& [(Table[(-2*Log[x])^0.5*Cos[2*Pi*x], {n} ]]
Invocation:
SampleNormal[ 10000 ]
->10000 numbers, Mean : -0.0122308, StandardDeviation :... |
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... | #Factor | Factor | USING: assocs formatting grouping.extras io kernel math
prettyprint sequences sorting ;
: leaf-plot ( seq -- )
natural-sort [ 10 /i ] group-by dup keys last 1 +
[ dup "%2d | " printf of [ 10 mod pprint bl ] each nl ] with
each-integer ;
{
12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36
... |
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... | #CLU | CLU | stern = proc (n: int) returns (array[int])
s: array[int] := array[int]$fill(1, n, 1)
for i: int in int$from_to(2, n/2) do
s[i*2-1] := s[i] + s[i-1]
s[i*2] := s[i]
end
return (s)
end stern
gcd = proc (a,b: int) returns (int)
while b ~= 0 do
a, b := b, a//b
end
return... |
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.... | #Elixir | Elixir | defmodule Stack_traces do
def main do
{:ok, a} = outer
IO.inspect a
end
defp outer do
{:ok, a} = middle
{:ok, a}
end
defp middle do
{:ok, a} = inner
{:ok, a}
end
defp inner do
try do
throw(42)
catch 42 -> {:ok, :erlang.get_stacktrace}
end
end
end
Stack... |
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.... | #Erlang | Erlang | -module(stack_traces).
-export([main/0]).
main() ->
{ok,A} = outer(),
io:format("~p\n", [A]).
outer() ->
{ok,A} = middle(),
{ok,A}.
middle() ->
{ok,A} = inner(),
{ok,A}.
inner() ->
try throw(42) catch 42 -> {ok,erlang:get_stacktrace()} 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... | #BBC_BASIC | BBC BASIC | DEF PROCstepup
IF NOT FNstep PROCstepup : PROCstepup
ENDPROC |
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... | #C | C | void step_up(void)
{
while (!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... | #C.23 | C# | void step_up() {
while (!step()) step_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... | #Java | Java | import java.util.*;
import java.util.stream.*;
public class StateNamePuzzle {
static String[] states = {"Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "hawaii", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
"Kans... |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #XBasic | XBasic | FUNCTION main ()
'This is the beginning of the program
END FUNCTION |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #Z80_Assembly | Z80 Assembly | org &8000 |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #zkl | zkl | "Hello".println() |
http://rosettacode.org/wiki/Start_from_a_main_routine | Start from a main routine |
Some languages (like Gambas and Visual Basic) support two startup modes. Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead. Data driven or event driven languages may also require similar tricker... | #ZX_Spectrum_Basic | ZX Spectrum Basic | SAVE "MYPROG" LINE 500: REM For a program with main code starting at line 500 |
http://rosettacode.org/wiki/Straddling_checkerboard | Straddling checkerboard | Task
Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits.
Num... | #Wren | Wren | import "/str" for Str
var board = "ET AON RISBCDFGHJKLMPQ/UVWXYZ."
var digits = "0123456789"
var rows = " 26"
var escape = "62"
var key = "0452"
var encrypt = Fn.new { |message|
var msg = Str.upper(message).
where { |c| (board.contains(c) || digits.contains(c)) && !" /".contains(c) }.join()
... |
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 |... | #PARI.2FGP | PARI/GP | s = "Hello";
s = Str(s, ", world!") |
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 |... | #Pascal | Pascal | program StringAppend;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
var
s: String = 'Hello';
begin
s += ' World !';
WriteLn(S);
ReadLn;
end. |
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 ... | #MATLAB_.2F_Octave | MATLAB / Octave | N = 100000;
x = randn(N,1);
mean(x)
std(x)
[nn,xx] = hist(x,100);
bar(xx,nn); |
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 ... | #Nim | Nim | import math, random, sequtils, stats, strformat, strutils
proc drawHistogram(ns: seq[float]) =
# Distribute values in bins.
const NBins = 50
var minval = min(ns)
var maxval = max(ns)
var h = newSeq[int](NBins + 1)
for n in ns:
let pos = ((n - minval) * NBins / (maxval - minval)).toInt
inc h[pos]... |
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... | #Forth | Forth | create 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 , 121 , 116 , 125 , 32 , 61 ... |
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... | #Common_Lisp | Common Lisp | (defun stern-brocot (numbers)
(declare ((or null (vector integer)) numbers))
(cond ((null numbers)
(setf numbers (make-array 2 :element-type 'integer :adjustable t :fill-pointer t
:initial-element 1)))
((zerop (length numbers))
(vector-push-extend 1 num... |
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.... | #F.23 | F# | open System.Diagnostics
type myClass() =
member this.inner() = printfn "%A" (new StackTrace())
member this.middle() = this.inner()
member this.outer() = this.middle()
[<EntryPoint>]
let main args =
let that = new myClass()
that.outer()
0 |
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.... | #Factor | Factor | USE: prettyprint
get-callstack callstack. |
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... | #C.2B.2B | C++ | void step_up()
{
while (!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... | #Clojure | Clojure | ;; the initial level
(def level (atom 41))
;; the probability of success
(def prob 0.5001)
(defn step
[]
(let [success (< (rand) prob)]
(swap! level (if success inc dec))
success) ) |
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... | #jq | jq | # Input: a string
# Output: an array, being the exploded form of the normalized input
def normalize:
explode
| map(if . >= 97 then (. - 97) elif . >= 65 then (. - 65) else empty end);
# Input: an array of strings
# Output: a dictionary with key:value pairs: normalizedString:string
def dictionary:
reduce .[] as ... |
http://rosettacode.org/wiki/Straddling_checkerboard | Straddling checkerboard | Task
Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits.
Num... | #zkl | zkl | var [const]
val2key=Dictionary(
"A","30", "B","31", "C","32", "D","33", "E","5", "F","34", "G","35",
"H","0", "I","36", "J","37", "K","38", "L","2", "M","4", ".","78",
"N","39", "/","79", "O","1", "0","790", "P","70", "1","791", "Q","71",
"2","792", "R","8", "3","793", "S","6... |
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 |... | #Perl | Perl | my $str = 'Foo';
$str .= 'bar';
print $str; |
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 |... | #Phix | Phix | string s = "this string" ?s
s &= " is now longer" ?s
|
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 ... | #PARI.2FGP | PARI/GP | rnormal()={
my(u1=random(1.),u2=random(1.);
sqrt(-2*log(u1))*cos(2*Pi*u1)
\\ Could easily be extended with a second normal at very little cost.
};
mean(v)={
sum(i=1,#v,v[i])/#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)... |
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... | #Fortran | Fortran |
SUBROUTINE COMBSORT(A,N)
INTEGER A(*) !The array.
INTEGER N !The count.
INTEGER H,T !Assistants.
LOGICAL CURSE
H = N - 1 !Last - First, and not +1.
1 H = MAX(1,H*10/13) !The special feature.
IF (H.EQ.9 .OR. H.EQ.10) H = 11 !A twiddle.
CURSE = .FALSE. !... |
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... | #Cowgol | Cowgol | include "cowgol.coh";
# Redefining these is enough to change the type and length everywhere,
# but arrays are 0-based so you need one extra element.
typedef Stern is uint8; # 8-bit math is enough for the numbers we need
var stern: Stern[1201]; # Array containing Stern-Brocot sequence
# Fill up the Stern-Brocot ar... |
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.... | #Forth | Forth | [UNDEFINED] R.S [IF]
\ Return stack counterpart of DEPTH
\ Note the STACK-CELLS correction is there to hide RDEPTH itself
( -- n)
: RDEPTH STACK-CELLS -2 [+] CELLS RP@ - ;
\ Return stack counterpart of .S
\ Note the : R.S R> .. >R ; sequence is there to hide R.S itself
... |
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.... | #Fortran | Fortran | Gnash: croak Life is troubled
Goodbye, cruel world!
Routine XeqACard croaks: Life is troubled
...from XeqACard Confronting croak Life is troubled
...from Attack some input
...from Gnash Gnash gnashing
Omitted exit from level 3:XeqACard
Omitted exit from level 2:Attack
|
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.... | #Go | Go | package main
import (
"fmt"
"runtime"
)
func main() {
stackTrace := make([]byte, 1024)
n := runtime.Stack(stackTrace, true)
stackTrace = stackTrace[:n]
fmt.Printf("%s\n", stackTrace)
fmt.Printf("(%d bytes)\n", len(stackTrace))
} |
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... | #Common_Lisp | Common Lisp | (defun step-up ()
(unless (step) (step-up) (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... | #D | D | void step_up()
{
while(!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... | #E | E | var level := 41
var prob := 0.5001
def step() {
def success := entropy.nextDouble() < prob
level += success.pick(1, -1)
return success
} |
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... | #Julia | Julia | module StateNamePuzzle
const realnames = ["Alabama", "Alaska", "Arizona", "Arkansas", "California",
"Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississi... |
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... | #Kotlin | Kotlin | // version 1.2.10
fun solve(states: List<String>) {
val dict = mutableMapOf<String, String>()
for (state in states) {
val key = state.toLowerCase().replace(" ", "")
if (dict[key] == null) dict.put(key, state)
}
val keys = dict.keys.toList()
val solutions = mutableListOf<String>()
... |
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 |... | #Picat | Picat | main =>
S = "a string",
S := S + " that is longer",
println(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 |... | #PicoLisp | PicoLisp | (setq Str1 "12345678")
(setq Str1 (pack Str1 "9!"))
(println Str1) |
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 ... | #Pascal | Pascal | Program Example40;
{$IFDEF FPC}
{$MOde objFPC}
{$ENDIF}
{ Program to demonstrate the randg function. }
Uses Math;
type
tTestData = extended;//because of math.randg
ttstfunc = function (mean, sd: tTestData): tTestData;
tExArray = Array of tTestData;
tSolution = record
SolExArr : tExArray;
... |
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... | #FreeBASIC | FreeBASIC | ' version 22-06-2015
' compile with: fbc -s console
' for boundry checks on array's compile with: fbc -s console -exx
' from the rosetta code FreeBASIC entry
#Define out_of_data 99999999 ' any number that is not in the set will do
Sub shellsort(s() As Integer)
' from the FreeBASIC entry at rosetta code
' sort... |
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... | #D | D | import std.stdio, std.numeric, std.range, std.algorithm;
/// Generates members of the stern-brocot series, in order,
/// returning them when the predicate becomes false.
uint[] sternBrocot(bool delegate(in uint[]) pure nothrow @safe @nogc pred=seq => seq.length < 20)
pure nothrow @safe {
typeof(return) sb = [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.... | #Groovy | Groovy | def rawTrace = { Thread.currentThread().stackTrace } |
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.... | #Icon_and_Unicon | Icon and Unicon |
import Utils # for buildStackTrace
procedure main()
g()
write()
f()
end
procedure f()
g()
end
procedure g()
# Using 1 as argument omits the trace of buildStackTrace itself
every write("\t",!buildStackTrace(1))
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.... | #J | J | 13!:0]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... | #EchoLisp | EchoLisp |
(define (step-up) (while (not (step)) (step-up)))
;; checking this is tail-recusive :
step-up
→ (#λ null (#while (#not (step)) (#lambda-tail-call)))
;; Experimentation (not part of the task)
;; How much step calls to climb 1000 stairs ?
;; success is the robot success probability
(define (step)
(set! STEPS (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... | #Elixir | Elixir | defmodule Stair_climbing do
defp step, do: 1 == :rand.uniform(2)
defp step_up(true), do: :ok
defp step_up(false) do
step_up(step)
step_up(step)
end
def step_up, do: step_up(step)
end
IO.inspect Stair_climbing.step_up |
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... | #11l | 11l | F SquareFree(_number)
V max = Int(sqrt(_number))
L(root) 2 .. max
I 0 == _number % (Int64(root) ^ 2)
R 0B
R 1B
F ListSquareFrees(Int64 _start, Int64 _end)
V count = 0
L(i) _start .. _end
I SquareFree(i)
print(i"\t", end' ‘’)
I count % 5 == 4
print(... |
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... | #LiveCode | LiveCode | function pairwiseAnagrams X
if the optionkey is down then breakpoint
put the long seconds into T
put empty into itemsSoFar
repeat for each item W in X
put word 1 to -1 of W into W
if D[W] = 1 then next repeat
put 1 into D[W]
repeat for each item W2 in itemsSoFar
put W,W2 & c... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.