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/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #JavaScript | JavaScript |
//console
var answers = [ "It is certain", "It is decidedly so", "Without a doubt",
"Yes, definitely", "You may rely on it", "As I see it, yes",
"Most likely", "Outlook good", "Signs point to yes", "Yes",
"Reply hazy, try again", "Ask again later",
"Better not tell you now", "Cannot pr... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Julia | Julia | const responses = ["It is certain", "It is decidedly so", "Without a doubt",
"Yes, definitely", "You may rely on it", "As I see it, yes", "Most likely",
"Outlook good", "Signs point to yes", "Yes", "Reply hazy, try again",
"Ask again later", "Better not tell you now", "Cannot predict now",
"Concentrate... |
http://rosettacode.org/wiki/Machine_code | Machine code | The task requires poking machine code directly into memory and executing it. The machine code is the architecture-specific opcodes which have the simple task of adding two unsigned bytes together and making the result available to the high-level language.
For example, the following assembly language program is given f... | #XPL0 | XPL0 | func Sum(A, B); \Return sum of A+B
char A, B;
[asm { ldrb r0, A
ldrb r1, B
add r0, r1
strb r0, A
}
return A;
];
IntOut(0, Sum(7, 12)) |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #SequenceL | SequenceL | import <Utilities/Complex.sl>;
import <Utilities/Sequence.sl>;
import <Utilities/Math.sl>;
COLOR_STRUCT ::= (R: int(0), G: int(0), B: int(0));
rgb(r(0), g(0), b(0)) := (R: r, G: g, B: b);
RESULT_STRUCT ::= (FinalValue: Complex(0), Iterations: int(0));
makeResult(val(0), iters(0)) := (FinalValue: val, Iterations: it... |
http://rosettacode.org/wiki/Matrix_multiplication | Matrix multiplication | Task
Multiply two matrices together.
They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
| #XSLT_1.0 | XSLT 1.0 | <?xml-stylesheet href="matmul.templ.xsl" type="text/xsl"?>
<mult>
<A>
<r><c>1</c><c>2</c></r>
<r><c>3</c><c>4</c></r>
<r><c>5</c><c>6</c></r>
<r><c>7</c><c>8</c></r>
</A>
<B>
<r><c>1</c><c>2</c><c>3</c></r>
<r><c>4</c><c>5</c><c>6</c></r>
</B>
</mult> |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #Aime | Aime | file f;
data b;
list l;
record r;
f.stdin;
o_text("Enter the blank line terminated story:\n");
while (0 < f.b_line(b)) {
l.append(b);
}
for (, b in l) {
integer p, q;
text s, t;
while ((p = b.place('<')) ^ -1) {
q = b.probe(p, '>');
if (q ^ -1) {
s = bq_string(b, p ... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #AppleScript | AppleScript | -- Generate a list of the ludic numbers up to and including n.
on ludicsTo(n)
if (n < 1) then return {}
-- Start with an array of numbers from 2 to n and a ludic collection already containing 1.
script o
property array : {}
property ludics : {1}
end script
repeat with i from 2 to n
... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Kotlin | Kotlin | // Version 1.2.40
import java.util.Random
fun main(args: Array<String>) {
val answers = listOf(
"It is certain", "It is decidedly so", "Without a doubt",
"Yes, definitely", "You may rely on it", "As I see it, yes",
"Most likely", "Outlook good", "Signs point to yes", "Yes",
"Repl... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #Sidef | Sidef | func mandelbrot(z) {
var c = z
{ z = (z*z + c)
z.abs > 2 && return true
} * 20
return false
}
for y range(1, -1, -0.05) {
for x in range(-2, 0.5, 0.0315) {
print(mandelbrot(x + y.i) ? ' ' : '#')
}
print "\n"
} |
http://rosettacode.org/wiki/Matrix_multiplication | Matrix multiplication | Task
Multiply two matrices together.
They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
| #Yabasic | Yabasic | dim a(4, 2)
a(0, 0) = 1 : a(0, 1) = 2
a(1, 0) = 3 : a(1, 1) = 4
a(2, 0) = 5 : a(2, 1) = 6
a(3, 0) = 7 : a(3, 1) = 8
dim b(2, 3)
b(0, 0) = 1 : b(0, 1) = 2 : b(0, 2) = 3
b(1, 0) = 4 : b(1, 1) = 5 : b(1, 2) = 6
dim prod(arraysize(a(),1), arraysize(b(),2))
if (arraysize(a(),2) = arraysize(b(),1)) then
for i = 0 to array... |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #ALGOL_68 | ALGOL 68 | # Mad Libs style story generation #
# gets the story template from the file f. The template terminates with #
# a blank line #
# The user is then promoted for the replacements for the <word> markers #
# and the story is... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #Arturo | Arturo | ludicGen: function [nmax][
result: [1]
lst: new 2..nmax+1
i: 0
worked: false
while [and? [not? empty? lst] [i < size lst]][
item: lst\[i]
result: result ++ item
del: 0
worked: false
while [del < size lst][
worked: true
remove 'lst .inde... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Liberty_BASIC | Liberty BASIC | data "It is certain","It is decidedly so","Without a doubt","Yes - definitely",_
"You may rely on it","As I see it, yes","Most likely","Outlook good","Yes",_
"Signs point to yes","Reply hazy, try again","Ask again later","Better not tell you now",_
"Cannot predict now","Concentrate and ask again","Don't count on it","M... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #Simula | Simula | BEGIN
REAL XCENTRE, YCENTRE, WIDTH, RMAX, XOFFSET, YOFFSET, PIXELSIZE;
INTEGER N, IMAX, JMAX, COLOURMAX;
TEXT FILENAME;
CLASS COMPLEX(RE,IM); REAL RE,IM;;
REF(COMPLEX) PROCEDURE ADD(A,B); REF(COMPLEX) A,B;
ADD :- NEW COMPLEX(A.RE + B.RE, A.IM + B.IM);
REF(COMPLEX) PROCEDURE SUB(A,B... |
http://rosettacode.org/wiki/Matrix_multiplication | Matrix multiplication | Task
Multiply two matrices together.
They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
| #zkl | zkl | var [const] GSL=Import("zklGSL"); // libGSL (GNU Scientific Library)
A:=GSL.Matrix(4,2).set(1,2, 3,4, 5,6, 7,8);
B:=GSL.Matrix(2,3).set(1,2,3, 4,5,6);
(A*B).format().println(); // creates a new matrix |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #AppleScript | AppleScript |
set theNoun to the text returned of (display dialog "What is your noun?" default answer "")
set thePerson to the text returned of (display dialog "What is the person's name?" default answer "")
set theGender to the text returned of (display dialog "He or she? Please capitalize." default answer "")
display dia... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #AutoHotkey | AutoHotkey | #NoEnv
SetBatchLines, -1
Ludic := LudicSieve(22000)
Loop, 25 ; the first 25 ludic numbers
Task1 .= Ludic[A_Index] " "
for i, Val in Ludic ; the number of ludic numbers less than or equal to 1000
if (Val <= 1000)
Task2++
else
break
Loop, 6 ; the 2000..2005'th ludic numbers
Task3 .= Ludic[1999 + A_... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #11l | 11l | F rev(n)
R BigInt(reversed(String(n)))
[BigInt = (Bool, BigInt)] cache
F lychrel(BigInt =n)
I n C :cache
R :cache[n]
V r = rev(n)
V res = (1B, n)
[BigInt] seen
L(i) 1000
n += r
r = rev(n)
I n == r
res = (0B, BigInt(0))
L.break
I n C :cache
... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Locomotive_Basic | Locomotive Basic | 10 mode 2:defint a-z:randomize time
20 input "Your question (hit Return to quit)";i$
30 if i$="" then print "Goodbye!":end
40 q=1+19*rnd
50 on q gosub 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290
60 goto 20
100 print "It is certain":return
110 print "It is decidedly... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #Spin | Spin | con
_clkmode = xtal1+pll16x
_clkfreq = 80_000_000
xmin=-8601 ' int(-2.1*4096)
xmax=2867 ' int( 0.7*4096)
ymin=-4915 ' int(-1.2*4096)
ymax=4915 ' int( 1.2*4096)
maxiter=25
obj
ser : "FullDuplexSerial"
pub main | c,cx,cy,dx,dy,x,y,x2,y2,iter
ser.start(31, 30, 0, 115200)
dx:... |
http://rosettacode.org/wiki/Matrix_multiplication | Matrix multiplication | Task
Multiply two matrices together.
They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
| #zonnon | zonnon |
module MatrixOps;
type
Matrix = array {math} *,* of integer;
procedure WriteMatrix(x: array {math} *,* of integer);
var
i,j: integer;
begin
for i := 0 to len(x,0) - 1 do
for j := 0 to len(x,1) - 1 do
write(x[i,j]);
end;
writeln;
end
end WriteMatrix;
procedure Multiplication;
var
a,b... |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #Applesoft_BASIC | Applesoft BASIC | 100 DIM L$(100),W$(50),T$(50)
110 LET M$ = CHR$ (13)
120 FOR L = 1 TO 1E9
130 READ L$(L)
140 IF LEN (L$(L)) THEN NEXT L
150 FOR I = 1 TO L
160 LET M = 0
170 LET N$(0) = ""
180 FOR J = 1 TO LEN (L$(I))
190 LET C$ = MID$ (L$(I),J,1)
200 IF C$ = "<" AND NOT M... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #C | C | #include <stdio.h>
#include <stdlib.h>
typedef unsigned uint;
typedef struct { uint i, v; } filt_t;
// ludics with at least so many elements and reach at least such value
uint* ludic(uint min_len, uint min_val, uint *len)
{
uint cap, i, v, active = 1, nf = 0;
filt_t *f = calloc(cap = 2, sizeof(*f));
f[1].i = 4;
... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #ALGOL_68 | ALGOL 68 | PR read "aArray.a68" PR
# number of additions to attempt before deciding the number is Lychrel #
INT max additions = 500;
# buffer to hold number during testing #
# addition of two equal sized numbers can produce a number of at most #
# one additional digit, so for 500 additions of ... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Lua | Lua | math.randomseed(os.time())
answers = {
"It is certain.", "It is decidedly so.", "Without a doubt.", "Yes, definitely.", "You may rely on it.",
"As I see it, yes.", "Most likely.", "Outlook good.", "Signs point to yes.", "Yes.",
"Reply hazy, try again.", "Ask again later.", "Better not tell you now.", "Cannot pred... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #SPL | SPL | w,h = #.scrsize()
sfx = -2.5; sfy = -2*h/w; fs = 4/w
#.aaoff()
> y, 1...h
> x, 1...w
fx = sfx + x*fs; fy = sfy + y*fs
#.drawpoint(x,y,color(fx,fy):3)
<
<
color(x,y)=
zr = x; zi = y; n = 0; maxn = 150
> zr*zr+zi*zi<4 & n<maxn
zrn = zr*zr-zi*zi+x; zin = 2*zr*zi+y
zr = zrn; zi = zin; n += 1
<
?... |
http://rosettacode.org/wiki/Matrix_multiplication | Matrix multiplication | Task
Multiply two matrices together.
They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
| #ZPL | ZPL |
program matmultSUMMA;
prototype GetSingleDim(infile:file):integer;
prototype GetInnerDim(infile1:file; infile2:file):integer;
config var
Afilename: string = "";
Bfilename: string = "";
Afile: file = open(Afilename,file_read);
Bfile: file = open(Bfilename,file_read);
... |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #Arturo | Arturo | story: strip input "Enter a story: "
vars: unique map match story {/\|([^\|]+)\|/} 'v -> replace v "|" ""
i: 0
while [i < size vars].import [
let vars\[i] input ~"Enter value for <|vars\[i]|>: "
i: i + 1
]
print ~story |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #C.23 | C# | using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
Console.WriteLine("First 25 ludic numbers:");
Console.WriteLine(string.Join(", ", LudicNumbers(150).Take(25)));
Console.WriteLine();
Console.WriteLine($"There... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #AppleScript | AppleScript | on Lychrels(numberLimit, iterationLimit)
script o
property digits : missing value -- Digits of the current startNumber or a derived sum.
property stigid : missing value -- Reverse thereof.
property digitLists : missing value -- Copies of the digit lists in the current sequence.
-- Th... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #M2000_Interpreter | M2000 Interpreter |
Module Magic.8.Ball {
answers=("It is certain", "It is decidedly so", "Without a doubt", "Yes, definitely", "You may rely on it", "As I see it, yes", "Most likely", "Outlook good", "Signs point to yes", "Yes", "Reply hazy, try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concent... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | answers = {"It is certain.", "It is decidedly so.",
"Without a doubt.", "Yes - definitely.", "You may rely on it.",
"As I see it, yes.", "Most likely.", "Outlook good.", "Yes.",
"Signs point to yes.", "Reply hazy, try again.",
"Ask again later.", "Better not tell you now.",
"Cannot predict now.", "C... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #Swift | Swift | import Foundation
import Numerics
import QDBMP
public typealias Color = (red: UInt8, green: UInt8, blue: UInt8)
public class BitmapDrawer {
public let imageHeight: Int
public let imageWidth: Int
var grid: [[Color?]]
private let bmp: OpaquePointer
public init(height: Int, width: Int) {
self.image... |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #AutoHotkey | AutoHotkey | FileSelectFile, filename, , %A_ScriptDir%, Select a Mad Libs template, *.txt
If ErrorLevel
ExitApp ; the user canceled the file selection
FileRead, contents, %filename%
pos := match := 0
While pos := RegExMatch(contents, "<[^>]+>", match, pos+strLen(match))
{
InputBox, repl, Mad Libs, Enter a replacement for %match%:... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #C.2B.2B | C++ |
#include <vector>
#include <iostream>
using namespace std;
class ludic
{
public:
void ludicList()
{
_list.push_back( 1 );
vector<int> v;
for( int x = 2; x < 22000; x++ )
v.push_back( x );
while( true )
{
vector<int>::iterator i = v.begin();... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #BASIC | BASIC |
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
' Lychrel Numbers V1.0 '
' '
' Developed by A. David Garza Marín in QB64 for '
' RosettaCode. December 2, 2016. '
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #min | min | randomize ; Seed the RNG with current timestamp.
(
"It is certain" "It is decidedly so" "Without a doubt"
"Yes, definitely" "You may rely on it" "As I see it, yes"
"Most likely" "Outlook good" "Signs point to yes" "Yes"
"Reply hazy, try again" "Ask again later"
"Better not tell you now" "Cannot ... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #MiniScript | MiniScript | answers = ["It is certain", "It is decidedly so", "Without a doubt",
"Yes, definitely", "You may rely on it", "As I see it, yes",
"Most likely", "Outlook good", "Signs point to yes", "Yes",
"Reply hazy, try again", "Ask again later",
"Better not tell you now", "Cannot predict now",
... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #Tcl | Tcl | package require Tk
proc mandelIters {cx cy} {
set x [set y 0.0]
for {set count 0} {hypot($x,$y) < 2 && $count < 255} {incr count} {
set x1 [expr {$x*$x - $y*$y + $cx}]
set y1 [expr {2*$x*$y + $cy}]
set x $x1; set y $y1
}
return $count
}
proc mandelColor {iter} {
set r [expr... |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #AWK | AWK |
# syntax: GAWK -f MAD_LIBS.AWK
BEGIN {
print("enter story:")
}
{ story_arr[++nr] = $0
if ($0 ~ /^ *$/) {
exit
}
while ($0 ~ /[<>]/) {
L = index($0,"<")
R = index($0,">")
changes_arr[substr($0,L,R-L+1)] = ""
sub(/</,"",$0)
sub(/>/,"",$0)
}
}
END {
PROCINFO[... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #Clojure | Clojure | (defn ints-from [n]
(cons n (lazy-seq (ints-from (inc n)))))
(defn drop-nth [n seq]
(cond
(zero? n) seq
(empty? seq) []
:else (concat (take (dec n) seq) (lazy-seq (drop-nth n (drop n seq))))))
(def ludic ((fn ludic
([] (ludic 1))
([n] (ludic n (ints-from (inc n))))
([n [f & r]] ... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #C.2B.2B | C++ | #include <iostream>
#include <map>
#include <vector>
#include <gmpxx.h>
using integer = mpz_class;
integer reverse(integer n) {
integer rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n /= 10;
}
return rev;
}
void print_vector(const std::vector<integer>& vec) {
if (vec.empt... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Nim | Nim | import random, strutils
const Answers = ["It is certain", "It is decidedly so", "Without a doubt",
"Yes, definitely", "You may rely on it", "As I see it, yes",
"Most likely", "Outlook good", "Signs point to yes", "Yes",
"Reply hazy, try again", "Ask again later",
... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #ooRexx | ooRexx |
/* REXX */
a=.array~of("It is certain", "It is decidedly so", "Without a doubt",,
"Yes, definitely", "You may rely on it", "As I see it, yes",,
"Most likely", "Outlook good", "Signs point to yes", "Yes",,
"Reply hazy, try again", "Ask again later",,
"Better not tell you... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #Plain_TeX | Plain TeX | \input pst-fractal
\psfractal[type=Mandel,xWidth=14cm,yWidth=12cm,maxIter=30,dIter=20] (-2.5,-1.5)(1,1.5)
\end |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #BASIC256 | BASIC256 |
cadena = "<name> went for a walk in the park. <he or she> found a <noun>. <name> decided to take it home."
k = instr(cadena, "<")
print "La historia: " : print cadena : print
while k
reemplaza = mid(cadena, k, instr(cadena, ">") - k + 1)
print "What should replace "; reemplaza; : input " ", con
while k
cadena ... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #Common_Lisp | Common Lisp | (defun ludic-numbers (max &optional n)
(loop with numbers = (make-array (1+ max) :element-type 'boolean :initial-element t)
for i from 2 to max
until (and n (= num-results (1- n))) ; 1 will be added at the end
when (aref numbers i)
collect i into results
and count t into nu... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #Clojure | Clojure | (ns lychrel.core
(require [clojure.string :as s])
(require [clojure.set :as set-op])
(:gen-class))
(defn palindrome? "Returns true if given number is a palindrome (number on base 10)"
[number]
(let [number-str (str number)]
(= number-str (s/reverse number-str))))
(defn delete-leading-zeros
"Delete l... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Perl | Perl | @a = ('It is certain', 'It is decidedly so', 'Without a doubt', 'Yes, definitely',
'You may rely on it', 'As I see it, yes', 'Most likely', 'Outlook good',
'Signs point to yes', 'Yes', 'Reply hazy, try again', 'Ask again later',
'Better not tell you now', 'Cannot predict now', 'Concentrate and ask again',
"Don't be... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #LaTeX | LaTeX | \documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shadings}
\begin{document}
\begin{tikzpicture}
\shade[shading=Mandelbrot set] (0,0) rectangle (4,4);
\end{tikzpicture}
\end{document} |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #C | C |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define err(...) fprintf(stderr, ## __VA_ARGS__), exit(1)
/* We create a dynamic string with a few functions which make modifying
* the string and growing a bit easier */
typedef struct {
char *data;
size_t alloc;
size_t length;
} dstr;
inl... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #D | D | struct Ludics(T) {
int opApply(int delegate(in ref T) dg) {
int result;
T[] rotor, taken = [T(1)];
result = dg(taken[0]);
if (result) return result;
for (T i = 2; ; i++) { // Shoud be stopped if T has a max.
size_t j = 0;
for (; j < rotor.length; j++... |
http://rosettacode.org/wiki/Lucas-Lehmer_test | Lucas-Lehmer test | Lucas-Lehmer Test:
for
p
{\displaystyle p}
an odd prime, the Mersenne number
2
p
−
1
{\displaystyle 2^{p}-1}
is prime if and only if
2
p
−
1
{\displaystyle 2^{p}-1}
divides
S
(
p
−
1
)
{\displaystyle S(p-1)}
where
S
(
n
+
1
)
=
(
S
(
n
)
)
2
−
2
{\displaystyle S(n+1)=(... | #11l | 11l | F isPrime(p)
I p < 2 | p % 2 == 0
R p == 2
L(i) 3..Int(sqrt(p))
I p % i == 0
R 0B
R 1B
F isMersennePrime(p)
I !isPrime(p)
R 0B
I p == 2
R 1B
V mp = BigInt(2) ^ p - 1
V s = BigInt(4)
L 3..p
s = (s ^ 2 - 2) % mp
R s == 0
L(p) 2..2299
I isMersennePri... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #Common_Lisp | Common Lisp | (defun Lychrel (number &optional (max 500))
"Returns T if number is a candidate Lychrel (up to max iterations), and a second value with the sequence of sums"
(do* ((n number (+ n (parse-integer rev-str)))
(n-str (write-to-string n) (write-to-string n))
(rev-str (reverse n-str) (reverse n-str))
... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Phix | Phix | with javascript_semantics
constant answers = {"As I see it, yes", "Ask again later", "You may rely on it",
"Without a doubt", "Don't bet on it", "Outlook not so good",
"Signs point to yes", "It is decidedly so", "It is certain",
"Better not tell you now", "My... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #LuaTeX | LuaTeX | PROGRAM:MANDELBR
:Input "ITER. ",D
:For(A,Xmin,Xmax,ΔX)
:For(B,Ymin,Ymax,ΔY)
:0→X
:0→Y
:0→I
:D→M
:While X^2+Y^2≤4 and I<M
:X^2-Y^2+A→R
:2XY+B→Y
:R→X
:I+1→I
:End
:If I≠M
:Then
:I→C
:Else
:0→C
:End
:If C<1
:Pt-On(A,B)
:End
:End
:End
|
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #C.2B.2B | C++ | #include <iostream>
#include <string>
using namespace std;
int main()
{
string story, input;
//Loop
while(true)
{
//Get a line from the user
getline(cin, input);
//If it's blank, break this loop
if(input == "\r")
break;
//Add the line to the story
story += input;
}
//... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #Delphi | Delphi |
class
LUDIC_NUMBERS
create
make
feature
make (n: INTEGER)
-- Initialized arrays for find_ludic_numbers.
require
n_positive: n > 0
local
i: INTEGER
do
create initial.make_filled (0, 1, n - 1)
create ludic_numbers.make_filled (1, 1, 1)
from
i := 2
until
i > n
loop
init... |
http://rosettacode.org/wiki/Lucas-Lehmer_test | Lucas-Lehmer test | Lucas-Lehmer Test:
for
p
{\displaystyle p}
an odd prime, the Mersenne number
2
p
−
1
{\displaystyle 2^{p}-1}
is prime if and only if
2
p
−
1
{\displaystyle 2^{p}-1}
divides
S
(
p
−
1
)
{\displaystyle S(p-1)}
where
S
(
n
+
1
)
=
(
S
(
n
)
)
2
−
2
{\displaystyle S(n+1)=(... | #360_Assembly | 360 Assembly | * Lucas-Lehmer test
LUCASLEH CSECT
USING LUCASLEH,R12
SAVEARA B STM-SAVEARA(R15)
DC 17F'0'
DC CL8'LUCASLEH'
STM STM R14,R12,12(R13) save calling context
ST R13,4(R15)
ST R15,8(R13)
LR R12,R15 set addessabilit... |
http://rosettacode.org/wiki/Lucky_and_even_lucky_numbers | Lucky and even lucky numbers | Note that in the following explanation list indices are assumed to start at one.
Definition of lucky numbers
Lucky numbers are positive integers that are formed by:
Form a list of all the positive odd integers > 0
1
,
3
,
5
,
7
,
9
,
11
,
13
,
15
,
17
,
19
,
21
,
23
,
25
,
27
,
29
,
31
,
33
,
35
,
37
,
39...
{... | #11l | 11l | -V NoValue = 0
F initLuckyNumbers(nelems, evenlucky, limit = -1)
[Int] result
L(i) 0 .< nelems
V k = i
L(j) (result.len - 1 .< 0).step(-1)
k = k * result[j] I/ (result[j] - 1)
V n = 2 * k + 1 + evenlucky
I limit != -1 & n > limit
L.break
result.append(n)
R resu... |
http://rosettacode.org/wiki/LZW_compression | LZW compression | The Lempel-Ziv-Welch (LZW) algorithm provides loss-less data compression.
You can read a complete description of it in the Wikipedia article on the subject. It was patented, but it entered the public domain in 2004.
| #11l | 11l | F compress(uncompressed)
V dict_size = 256
V dictionary = Dict((0 .< dict_size).map(i -> (String(Char(code' i)), i)))
V w = ‘’
[Int] result
L(c) uncompressed
V wc = w‘’c
I wc C dictionary
w = wc
E
result.append(dictionary[w])
dictionary[wc] = dict_size
... |
http://rosettacode.org/wiki/LU_decomposition | LU decomposition | Every square matrix
A
{\displaystyle A}
can be decomposed into a product of a lower triangular matrix
L
{\displaystyle L}
and a upper triangular matrix
U
{\displaystyle U}
,
as described in LU decomposition.
A
=
L
U
{\displaystyle A=LU}
It is a modified form of Gaussian elimination.
Whil... | #11l | 11l | F pprint(m)
L(row) m
print(row)
F matrix_mul(a, b)
V result = [[0.0] * a.len] * a.len
L(j) 0 .< a.len
L(i) 0 .< a.len
V r = 0.0
L(k) 0 .< a.len
r += a[i][k] * b[k][j]
result[i][j] = r
R result
F pivotize(m)
‘Creates the pivoting matrix for m.’
V n... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #Crystal | Crystal | require "set"
require "big"
def add_reverse(num, max_iter=1000)
num = num.to_big_i
nums = [] of BigInt
(1..max_iter).each_with_object(Set.new([num])) do |_, nums|
num += reverse_int(num)
nums << num
return nums if palindrome?(num)
end
end
def palindrome?(num)
num == reverse_int(num)
end
def ... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #PHP | PHP | <?php
$fortunes = array(
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Signs point to yes",
"Yes",
"Reply hazy, try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Conce... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #TI-83_BASIC | TI-83 BASIC | PROGRAM:MANDELBR
:Input "ITER. ",D
:For(A,Xmin,Xmax,ΔX)
:For(B,Ymin,Ymax,ΔY)
:0→X
:0→Y
:0→I
:D→M
:While X^2+Y^2≤4 and I<M
:X^2-Y^2+A→R
:2XY+B→Y
:R→X
:I+1→I
:End
:If I≠M
:Then
:I→C
:Else
:0→C
:End
:If C<1
:Pt-On(A,B)
:End
:End
:End
|
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #C.23 | C# | using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace MadLibs_RosettaCode
{
class Program
{
static void Main(string[] args)
{
string madLibs =
@"Write a program to create a Mad Libs like story.
The program should read an arbitrary multiline story from input.
The... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #Eiffel | Eiffel |
class
LUDIC_NUMBERS
create
make
feature
make (n: INTEGER)
-- Initialized arrays for find_ludic_numbers.
require
n_positive: n > 0
local
i: INTEGER
do
create initial.make_filled (0, 1, n - 1)
create ludic_numbers.make_filled (1, 1, 1)
from
i := 2
until
i > n
loop
init... |
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers | Luhn test of credit card numbers | The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits.
Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
Reverse the order of the digits in the number.
Tak... | #11l | 11l | F luhn(n)
V ch = String(n)
V sum = 0
V chParity = ch.len % 2
L(i) (ch.len-1 .. 0).step(-1)
V j = Int(ch[i])
I (i + 1) % 2 != chParity
j *= 2
I j > 9
j -= 9
sum += j
R sum % 10 == 0
L(n) (49927398716,
49927398717,
1234567812345678,
123456... |
http://rosettacode.org/wiki/Lucas-Lehmer_test | Lucas-Lehmer test | Lucas-Lehmer Test:
for
p
{\displaystyle p}
an odd prime, the Mersenne number
2
p
−
1
{\displaystyle 2^{p}-1}
is prime if and only if
2
p
−
1
{\displaystyle 2^{p}-1}
divides
S
(
p
−
1
)
{\displaystyle S(p-1)}
where
S
(
n
+
1
)
=
(
S
(
n
)
)
2
−
2
{\displaystyle S(n+1)=(... | #Ada | Ada | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
procedure Lucas_Lehmer_Test is
type Ull is mod 2**64;
function Mersenne(Item : Integer) return Boolean is
S : Ull := 4;
MP : Ull := 2**Item - 1;
begin
if Item = 2 then
return True;
else
... |
http://rosettacode.org/wiki/Lucky_and_even_lucky_numbers | Lucky and even lucky numbers | Note that in the following explanation list indices are assumed to start at one.
Definition of lucky numbers
Lucky numbers are positive integers that are formed by:
Form a list of all the positive odd integers > 0
1
,
3
,
5
,
7
,
9
,
11
,
13
,
15
,
17
,
19
,
21
,
23
,
25
,
27
,
29
,
31
,
33
,
35
,
37
,
39...
{... | #C | C | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#define LUCKY_SIZE 60000
int luckyOdd[LUCKY_SIZE];
int luckyEven[LUCKY_SIZE];
void compactLucky(int luckyArray[]) {
int i, j, k;
for (i = 0; i < LUCKY_SIZE; i++) {
if (luckyArray[i] == 0) {
j = i;
break;
}
... |
http://rosettacode.org/wiki/LZW_compression | LZW compression | The Lempel-Ziv-Welch (LZW) algorithm provides loss-less data compression.
You can read a complete description of it in the Wikipedia article on the subject. It was patented, but it entered the public domain in 2004.
| #Ada | Ada | package LZW is
MAX_CODE : constant := 4095;
type Codes is new Natural range 0 .. MAX_CODE;
type Compressed_Data is array (Positive range <>) of Codes;
function Compress (Cleartext : in String) return Compressed_Data;
function Decompress (Data : in Compressed_Data) return String;
end LZW; |
http://rosettacode.org/wiki/LU_decomposition | LU decomposition | Every square matrix
A
{\displaystyle A}
can be decomposed into a product of a lower triangular matrix
L
{\displaystyle L}
and a upper triangular matrix
U
{\displaystyle U}
,
as described in LU decomposition.
A
=
L
U
{\displaystyle A=LU}
It is a modified form of Gaussian elimination.
Whil... | #Ada | Ada | with Ada.Numerics.Generic_Real_Arrays;
generic
with package Matrix is new Ada.Numerics.Generic_Real_Arrays (<>);
package Decomposition is
-- decompose a square matrix A by PA = LU
procedure Decompose (A : Matrix.Real_Matrix; P, L, U : out Matrix.Real_Matrix);
end Decomposition; |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #D | D | import std.stdio, std.conv, std.range, std.typecons, std.bigInt;
auto rev(in BigInt n) {
return n.text.retro.text.BigInt;
}
alias Res = Tuple!(bool, BigInt);
Res lychrel(BigInt n) {
static Res[BigInt] cache;
if (n in cache)
return cache[n];
auto r = n.rev;
auto res = Res(true, n);
... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #PureBasic | PureBasic | Define.s Magic8="● It is certain."+#LF$+
"● It is decidedly so."+#LF$+
"● Without a doubt."+#LF$+
"● Yes – definitely."+#LF$+
"● You may rely on it."+#LF$+
"● As I see it, yes."+#LF$+
"● Most likely."+#LF$+
"... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #TXR | TXR | (defvar x-centre -0.5)
(defvar y-centre 0.0)
(defvar width 4.0)
(defvar i-max 800)
(defvar j-max 600)
(defvar n 100)
(defvar r-max 2.0)
(defvar file "mandelbrot.pgm")
(defvar colour-max 255)
(defvar pixel-size (/ width i-max))
(defvar x-offset (- x-centre (* 0.5 pixel-size (+ i-max 1))))
(defvar y-offset (+ y-centre (*... |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #Clojure | Clojure | (ns magic.rosetta
(:require [clojure.string :as str]))
(defn mad-libs
"Write a program to create a Mad Libs like story.
The program should read an arbitrary multiline story from input.
The story will be terminated with a blank line.
Then, find each replacement to be made within the story,
... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #Elixir | Elixir | defmodule Ludic do
def numbers(n \\ 100000) do
[h|t] = Enum.to_list(1..n)
numbers(t, [h])
end
defp numbers(list, nums) when length(list) < hd(list), do: Enum.reverse(nums, list)
defp numbers([h|_]=list, nums) do
Enum.drop_every(list, h) |> numbers([h | nums])
end
def task do
IO.puts "Fir... |
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers | Luhn test of credit card numbers | The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits.
Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
Reverse the order of the digits in the number.
Tak... | #360_Assembly | 360 Assembly | * Luhn test of credit card numbers 22/05/2016
LUHNTEST CSECT
USING LUHNTEST,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
STM R14,R12,12(R13) prolog
ST R13,4(R15) "
ST R15,8(R1... |
http://rosettacode.org/wiki/Lucas-Lehmer_test | Lucas-Lehmer test | Lucas-Lehmer Test:
for
p
{\displaystyle p}
an odd prime, the Mersenne number
2
p
−
1
{\displaystyle 2^{p}-1}
is prime if and only if
2
p
−
1
{\displaystyle 2^{p}-1}
divides
S
(
p
−
1
)
{\displaystyle S(p-1)}
where
S
(
n
+
1
)
=
(
S
(
n
)
)
2
−
2
{\displaystyle S(n+1)=(... | #Agena | Agena | readlib 'mapm';
mapm.xdigits(100);
mersenne := proc(p::number) is
local s, m;
s := 4;
m := mapm.xnumber(2^p) - 1;
if p = 2 then
return true
else
for i from 3 to p do
s := (mapm.xnumber(s)^2 - 2) % m
od;
return mapm.xtoNumber(s) = 0
fi
end;
for i from 3 to 64 do
... |
http://rosettacode.org/wiki/Lucky_and_even_lucky_numbers | Lucky and even lucky numbers | Note that in the following explanation list indices are assumed to start at one.
Definition of lucky numbers
Lucky numbers are positive integers that are formed by:
Form a list of all the positive odd integers > 0
1
,
3
,
5
,
7
,
9
,
11
,
13
,
15
,
17
,
19
,
21
,
23
,
25
,
27
,
29
,
31
,
33
,
35
,
37
,
39...
{... | #C.2B.2B | C++ | #include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
const int luckySize = 60000;
std::vector<int> luckyEven(luckySize);
std::vector<int> luckyOdd(luckySize);
void init() {
for (int i = 0; i < luckySize; ++i) {
luckyEven[i] = i * 2 + 2;
luckyOdd[i] = i * 2 + 1;
}
}
... |
http://rosettacode.org/wiki/LZW_compression | LZW compression | The Lempel-Ziv-Welch (LZW) algorithm provides loss-less data compression.
You can read a complete description of it in the Wikipedia article on the subject. It was patented, but it entered the public domain in 2004.
| #Arturo | Arturo | compress: function [str][
dict: #[]
loop 0..255 'i -> dict\[to :char i]: i
w: ""
result: new []
loop str 'c [
wc: w ++ c
if? key? dict wc -> w: wc
else [
'result ++ dict\[w]
dict\[wc]: size dict
w: to :string c
]
]
if 0 ... |
http://rosettacode.org/wiki/LU_decomposition | LU decomposition | Every square matrix
A
{\displaystyle A}
can be decomposed into a product of a lower triangular matrix
L
{\displaystyle L}
and a upper triangular matrix
U
{\displaystyle U}
,
as described in LU decomposition.
A
=
L
U
{\displaystyle A=LU}
It is a modified form of Gaussian elimination.
Whil... | #AutoHotkey | AutoHotkey | ;--------------------------
LU_decomposition(A){
P := Pivot(A)
A_ := Multiply_Matrix(P, A)
U := [], L := [], n := A_.Count()
loop % n {
i := A_Index
loop % n {
j := A_Index
Sigma := 0, k := 1
while (k <= i-1)
Sigma += (U[k, j] * L[i... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #Fortran | Fortran |
SUBROUTINE CROAK(GASP) !A dying message.
CHARACTER*(*) GASP !The message.
WRITE (6,*) "Oh dear! ",GASP !The gasp.
STOP "Alas." !The death.
END !Goodbye, cruel world.
MODULE LYCHREL SEARCH !Assistants for the pursuit of Lychrel numbers.
INTEGER LOTSADIGITS,BASE !Par... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Python | Python | import random
s = ('It is certain', 'It is decidedly so', 'Without a doubt', 'Yes, definitely',
'You may rely on it', 'As I see it, yes', 'Most likely', 'Outlook good',
'Signs point to yes', 'Yes', 'Reply hazy, try again', 'Ask again later',
'Better not tell you now', 'Cannot predict now', 'Concentrate and ask aga... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Quackery | Quackery | [ 20 random
[ table
$ "Concentrate and ask again." $ "Yes."
$ "Better not tell you now." $ "Most likely."
$ "Reply hazy, try again." $ "Outlook good."
$ "Outlook not so good." $ "It is certain."
$ "Cannot predict now." $ "Very doubtful."
$ "Signs point to yes." $ "My reply is no... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #uBasic.2F4tH | uBasic/4tH | A =-21000 ' Left Edge = -2.1
B = 15000 ' Right Edge = 1.5
C = 15000 ' Top Edge = 1.5
D =-15000 ' Bottom Edge = -1.5
E = 200 ' Max Iteration Depth
F = 350 ... |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #Commodore_BASIC | Commodore BASIC | 10 rem mad lib for rosetta code
15 dim bf$(100),wd$(50),tg$(50):tb=49152
20 print chr$(147);chr$(14);"Mad Lib Processor":print
25 gosub 1000
30 gosub 100:gosub 250:gosub 300:gosub 400
40 print:print:print "Again? ";:gosub 500:print k$
45 if k$<>"y" then end
50 goto 20
100 tg=1:for i=1 to bp:n$="":mo=0
105 t$=bf$(i)
110... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #Factor | Factor | USING: formatting fry kernel make math math.ranges namespaces
prettyprint.config sequences sequences.extras ;
IN: rosetta-code.ludic-numbers
: next-ludic ( seq -- seq' )
dup first '[ nip _ mod zero? not ] filter-index ;
: ludics-upto-2005 ( -- a )
22,000 2 swap [a,b] [ ! 22k suffices to produce 2005 ludics
... |
http://rosettacode.org/wiki/Loops/Wrong_ranges | Loops/Wrong ranges | Loops/Wrong ranges
You are encouraged to solve this task according to the task description, using any language you may know.
Some languages have syntax or function(s) to generate a range of numeric values from a start value, a stop value, and an increment.
The purpose of this task is to select the range syntax/functi... | #11l | 11l | F displayRange(first, last, step)
print(‘(#2, #2, #2): ’.format(first, last, step), end' ‘’)
I step == 0
print(‘not allowed.’)
E
print(Array((first..last).step(step)))
L(f, l, s) [(-2, 2, 1), (-2, 2, 0), (-2, 2, -1),
(-2, 2, 10), (2, -2, 1), ( 2, 2, 1),
( 2, 2, -1), (2... |
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers | Luhn test of credit card numbers | The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits.
Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
Reverse the order of the digits in the number.
Tak... | #8080_Assembly | 8080 Assembly | org 100h
jmp demo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Check if the 0-terminated string at HL passes the Luhn test.
;;; Returns with carry clear if the string passes, carry set
;;; if the string fails.
luhn: mvi b,0 ; Counter
mov d,b ; D = S1+S2 (we don't need to keep the... |
http://rosettacode.org/wiki/Lucas-Lehmer_test | Lucas-Lehmer test | Lucas-Lehmer Test:
for
p
{\displaystyle p}
an odd prime, the Mersenne number
2
p
−
1
{\displaystyle 2^{p}-1}
is prime if and only if
2
p
−
1
{\displaystyle 2^{p}-1}
divides
S
(
p
−
1
)
{\displaystyle S(p-1)}
where
S
(
n
+
1
)
=
(
S
(
n
)
)
2
−
2
{\displaystyle S(n+1)=(... | #ALGOL_68 | ALGOL 68 | PRAGMAT stack=1M precision=20000 PRAGMAT
PROC is prime = ( INT p )BOOL:
IF p = 2 THEN TRUE
ELIF p <= 1 OR p MOD 2 = 0 THEN FALSE
ELSE
BOOL prime := TRUE;
FOR i FROM 3 BY 2 TO ENTIER sqrt(p)
WHILE prime := p MOD i /= 0 DO SKIP OD;
prime
FI;
PROC is mersenne prime = ( INT p )BOOL:
IF p = 2... |
http://rosettacode.org/wiki/Lucky_and_even_lucky_numbers | Lucky and even lucky numbers | Note that in the following explanation list indices are assumed to start at one.
Definition of lucky numbers
Lucky numbers are positive integers that are formed by:
Form a list of all the positive odd integers > 0
1
,
3
,
5
,
7
,
9
,
11
,
13
,
15
,
17
,
19
,
21
,
23
,
25
,
27
,
29
,
31
,
33
,
35
,
37
,
39...
{... | #D | D | import std.algorithm;
import std.concurrency;
import std.conv;
import std.getopt;
import std.range;
import std.stdio;
auto lucky(bool even, int nmax=200_000) {
import std.container.array;
int start = even ? 2 : 1;
return new Generator!int({
auto ln = make!(Array!int)(iota(start,nmax,2));
... |
http://rosettacode.org/wiki/LZW_compression | LZW compression | The Lempel-Ziv-Welch (LZW) algorithm provides loss-less data compression.
You can read a complete description of it in the Wikipedia article on the subject. It was patented, but it entered the public domain in 2004.
| #BaCon | BaCon | CONST lzw_data$ = "TOBEORNOTTOBEORTOBEORNOT"
PRINT "LZWData: ", lzw_data$
encoded$ = Encode_LZW$(lzw_data$)
PRINT "Encoded: ", encoded$
PRINT "Decoded: ", Decode_LZW$(encoded$)
'----------------------------------------------------------
FUNCTION Encode_LZW$(sample$)
LOCAL dict ASSOC int
LOCAL ch$, buf$,... |
http://rosettacode.org/wiki/LU_decomposition | LU decomposition | Every square matrix
A
{\displaystyle A}
can be decomposed into a product of a lower triangular matrix
L
{\displaystyle L}
and a upper triangular matrix
U
{\displaystyle U}
,
as described in LU decomposition.
A
=
L
U
{\displaystyle A=LU}
It is a modified form of Gaussian elimination.
Whil... | #BBC_BASIC | BBC BASIC | DIM A1(2,2)
A1() = 1, 3, 5, 2, 4, 7, 1, 1, 0
PROCLUdecomposition(A1(), L1(), U1(), P1())
PRINT "L1:" ' FNshowmatrix(L1())
PRINT "U1:" ' FNshowmatrix(U1())
PRINT "P1:" ' FNshowmatrix(P1())
DIM A2(3,3)
A2() = 11, 9, 24, 2, 1, 5, 2, 6, 3, 17, 18, 1, 2, 5, 7, 1
PROCLU... |
http://rosettacode.org/wiki/Lychrel_numbers | Lychrel numbers | Take an integer n, greater than zero.
Form the next n of its series by reversing the digits of the current n and adding the result to the current n.
Stop when n becomes palindromic - i.e. the digits of n in reverse order == n.
The above recurrence relation when applied to most starting numbers n = 1, 2, ... ... | #FreeBASIC | FreeBASIC | ' version 13-09-2015
' compile with: fbc -s console
' iteration limit
#Define max_it 500
' the highest number to be tested
#Define max_number_to_test 10000
Dim As String num, rev
Dim As String temp(), store()
Dim As Integer x, x1, palindrome
Dim As UInteger it, s, carry, sum, match, seed, related
Dim As UInteger ... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #R | R | eight_ball <- function()
{
responses <- c("It is certain", "It is decidedly so", "Without a doubt",
"Yes, definitely", "You may rely on it", "As I see it, yes",
"Most likely", "Outlook good", "Signs point to yes", "Yes",
"Reply hazy, try again", "Ask again la... |
http://rosettacode.org/wiki/Magic_8-ball | Magic 8-ball | Task
Create Magic 8-Ball.
See details at: Magic 8-Ball.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioinformatics/base count
Count occurren... | #Racket | Racket | (define eight-ball-responses
(list "It is certain" "It is decidedly so" "Without a doubt" "Yes definitely" "You may rely on it"
"As I see it, yes" "Most likely" "Outlook good" "Yes" "Signs point to yes"
"Reply hazy try again" "Ask again later" "Better not tell you now" "Cannot predict now"
... |
http://rosettacode.org/wiki/Mandelbrot_set | Mandelbrot set | Mandelbrot set
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
| #UNIX_Shell | UNIX Shell | ((xmin=-8601)) # int(-2.1*4096)
((xmax=2867)) # int( 0.7*4096)
((ymin=-4915)) # int(-1.2*4096)
((ymax=4915)) # int( 1.2*4096)
((maxiter=30))
((dx=(xmax-xmin)/72))
((dy=(ymax-ymin)/24))
C='0123456789'
((lC=${#C}))
for((cy=ymax;cy>=ymin;cy-=dy)) ; do
for((cx=xmin;cx<=xmax;cx+=dx)) ; do
((x=0,y=0,x2=0,y... |
http://rosettacode.org/wiki/Mad_Libs | Mad Libs |
This page uses content from Wikipedia. The original article was at Mad Libs. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Mad Libs is a phrasal template word game where one player prompts another... | #D | D | import std.stdio, std.regex, std.algorithm, std.string, std.array;
void main() {
writeln("Enter a story template, terminated by an empty line:");
string story;
while (true) {
auto line = stdin.readln().strip();
if (line.empty) break;
story ~= line ~ "\n";
}
auto re = rege... |
http://rosettacode.org/wiki/Ludic_numbers | Ludic numbers | Ludic numbers are related to prime numbers as they are generated by a sieve quite like the Sieve of Eratosthenes is used to generate prime numbers.
The first ludic number is 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1... | #Fortran | Fortran | program ludic_numbers
implicit none
integer, parameter :: nmax = 25000
logical :: ludic(nmax) = .true.
integer :: i, j, n
do i = 2, nmax / 2
if (ludic(i)) then
n = 0
do j = i+1, nmax
if(ludic(j)) n = n + 1
if(n == i) then
ludic(j) = .false.
n = 0
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.