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/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...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;   procedure Main is procedure print_range(start : integer; stop : integer; step : integer) is Num : Integer := start; begin Put("Range(" & start'Image ...
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...
#8086_Assembly
8086 Assembly
bits 16 cpu 8086 org 100h section .text jmp demo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Check whether the 0-terminated string at DS:SI passes the Luhn ;;; test. Returns with carry clear if the string passes, carry ;;; set if the string fails. luhn: push es ; Keep original...
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)=(...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program lucaslehmer.s */ /* use library gmp */ /* link with gcc option -lgmp */   /* Constantes */ .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ WRITE, 4 @ Linux sys...
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... {...
#F.23
F#
  // Odd and Even Lucky Numbers. Nigel Galloway: October 3rd., 2020 let rec fN i g e l=seq{yield! i|>Seq.skip g|>Seq.take(e-g-1) let n=Seq.chunkBySize e i|>Seq.collect(Seq.take(e-1)) in yield! fN n (e-1) (Seq.item l n) (l+1)} let oLuck,eLuck=let rec fG g=seq{yield g; yield! fG(g+2)} in (fN(fG 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.
#BBC_BASIC
BBC BASIC
plaintext$ = "TOBEORNOTTOBEORTOBEORNOT" encodeLZW$ = FNencodeLZW(plaintext$) FOR i% = 1 TO LEN(encodeLZW$) STEP 2 PRINT ; ASCMID$(encodeLZW$,i%) + 256*ASCMID$(encodeLZW$,i%+1) " " ; NEXT PRINT ' FNdecodeLZW(encodeLZW$) END   DEF FNencodeLZW(i$) LOCAL c%, d%, i%, l...
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...
#C
C
#include <stdio.h> #include <stdlib.h> #include <math.h>   #define foreach(a, b, c) for (int a = b; a < c; a++) #define for_i foreach(i, 0, n) #define for_j foreach(j, 0, n) #define for_k foreach(k, 0, n) #define for_ij for_i for_j #define for_ijk for_ij for_k #define _dim int n #define _swap(x, y) { typeof(x) tmp = x;...
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, ... ...
#Go
Go
package main   import ( "flag" "fmt" "math" "math/big" "os" )   var maxRev = big.NewInt(math.MaxUint64 / 10) // approximate var ten = big.NewInt(10)   // Reverse sets `result` to the value of the base ten digits of `v` in // reverse order and returns `result`. // Only handles positive integers. func reverseInt(v *...
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...
#Raku
Raku
put 'Please enter your question or a blank line to quit.';   ["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", "Cann...
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 .
#Vedit_macro_language
Vedit macro language
#1 =-21000 // left edge = -2.1 #2 = 15000 // right edge = 1.5 #3 = 15000 // top edge = 1.5 #4 =-15000 // bottom edge = -1.5 #5 = 200 // max iteration depth #6 = 350 // x step size #7 = 750 // y step size   Buf_Switch(Buf_Fr...
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...
#Erlang
Erlang
-module(madlib). -compile(export_all).   main() -> main([]).   main([]) -> madlib(standard_io); main([File]) -> {ok, F} = file:open(File,read), madlib(F).   madlib(Device) -> {Dict, Lines} = parse(Device), Substitutions = prompt(Dict), print(Substitutions, Lines).   prompt(Dict) -> Keys ...
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#11l
11l
V prod = 1 V s = 0   -V x = +5 y = -5 z = -2 one = 1 three = 3 seven = 7   F body(j)  :s += abs(j) I abs(:prod) < 2 ^ 27 & j != 0  :prod *= j   L(j) (-three .. 3 ^ 3).step(three) {body(j)} L(j) (-seven .. seven).step(x) {body(j)} L(j) 555 .. 550 - y {body(j)} L(j) (22 .. -...
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...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   ' As it would be too expensive to actually remove elements from the array ' we instead set an element to 0 if it has been removed.   Sub ludic(n As Integer, lu() As Integer) If n < 1 Then Return Redim lu(1 To n) lu(1) = 1 If n = 1 Then Return Dim As Integer count = 1, count2 Dim As Integ...
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...
#ALGOL_W
ALGOL W
begin  % sets the first n elements of s to the sequences of values specified by start, stop and increment  %  % s( 0 ) is set to the number of elements of s that have been set, in case the sequence ends before n % procedure sequence ( integer array s ( * )  ; integer value n, start, st...
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...
#Applesoft_BASIC
Applesoft BASIC
0 LIMIT = 10 :MAX=1E37 10 DATA-2,2,1,NORMAL 20 DATA-2,2,0,ZERO INCREMENT 30 DATA-2,2,-1,INCREMENTS AWAY FROM STOP VALUE 40 DATA-2,2,10,FIRST INCREMENT IS BEYOND STOP VALUE 50 DATA2,-2,1,"START MORE THAN STOP: POSITIVE INCREMENT 60 DATA2,2,1,"START EQUAL STOP: POSITIVE INCREMENT 70 DATA2,2,-1,"START EQUAL STOP: NEGATIVE...
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...
#AWK
AWK
  # syntax: GAWK -f LOOPS_WRONG_RANGES.AWK BEGIN { arr[++n] = "-2, 2, 1,Normal" arr[++n] = "-2, 2, 0,Zero increment" arr[++n] = "-2, 2,-1,Increments away from stop value" arr[++n] = "-2, 2,10,First increment is beyond stop value" arr[++n] = " 2,-2, 1,Start more than stop: positive increment" arr...
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...
#8th
8th
  \ Adapted from the C version: : remap \ n1 -- n2 [0,2,4,6,8,1,3,5,7,9] swap caseof ;   : luhn \ s -- f 0 swap s:rev ( '0 n:- swap 2 n:mod if remap then n:+ ) s:each 10 n:mod not ;   : test-luhn \ s -- dup . space luhn if "OK" else "FAIL" then . cr ;   "49927398716" test-luhn "4992739871...
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)=(...
#Arturo
Arturo
mersenne?: function [p][ if p=2 -> return true mp: dec shl 1 p s: 4 loop 3..p 'i -> s: (sub s*s 2) % mp return s=0 ]   print "Mersenne primes:" mersennes: select 2..32 'x -> and? prime? x mersenne? x print join.with:", " map mersennes 'm -> ~"M|m|"
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... {...
#Go
Go
package main   import ( "fmt" "log" "os" "strconv" "strings" )   const luckySize = 60000   var luckyOdd = make([]int, luckySize) var luckyEven = make([]int, luckySize)   func init() { for i := 0; i < luckySize; i++ { luckyOdd[i] = i*2 + 1 luckyEven[i] = i*2 + 2 } }   func fil...
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.
#C
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h>   /* -------- aux stuff ---------- */ void* mem_alloc(size_t item_size, size_t n_item) { size_t *x = calloc(1, sizeof(size_t)*2 + n_item * item_size); x[...
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...
#C.2B.2B
C++
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <numeric> #include <sstream> #include <vector>   template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {}   ...
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, ... ...
#Haskell
Haskell
module Main where   import Data.List   procLychrel :: Integer -> [Integer] procLychrel a = a : pl a where pl n = let s = n + reverseInteger n in if isPalindrome s then [s] else s : pl s   isPalindrome :: Integer -> Bool isPalindrome n = let s = show n i...
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...
#REXX
REXX
  /* REXX */ Call mk_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", "Ca...
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...
#Ring
Ring
  # Project : 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", ...
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 .
#Wren
Wren
import "graphics" for Canvas, Color import "dome" for Window   var MaxIters = 570 var Zoom = 150   class MandelbrotSet { construct new(width, height) { Window.title = "Mandelbrot Set" Window.resize(width, height) Canvas.resize(width, height) _w = width _h = height }   ...
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...
#Factor
Factor
USING: formatting io kernel make regexp sequences sets splitting ; IN: rosetta-code.mad-libs   : get-mad-lib ( -- str ) "Enter a mad lib. A blank line signals end of input." print [ [ "> " write flush readln dup , empty? f t ? ] loop ] { } make harvest "\n" join ;   : find-replacements ( str -- seq ...
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program loopnrange64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesA...
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#Ada
Ada
  with Ada.Text_IO; use Ada.Text_IO; with Ada.Containers.Vectors;   procedure Main is package int_vector is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Integer); use int_vector;   summing_values : Vector := Empty_Vector;   prod : Integer := 1; sum  : Integer := 0; x  : In...
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...
#Go
Go
package main   import "fmt"   // Ludic returns a slice of Ludic numbers stopping after // either n entries or when max is exceeded. // Either argument may be <=0 to disable that limit. func Ludic(n int, max int) []uint32 { const maxInt32 = 1<<31 - 1 // i.e. math.MaxInt32 if max > 0 && n < 0 { n = maxInt32 } if n ...
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...
#BASIC256
BASIC256
arraybase 1 dim start(9) : dim fin(9) : dim inc(9) : dim cmt$(9) start[1] = -2 : fin[1] = 2 : inc[1] = 1 : cmt$[1] = "Normal" start[2] = -2 : fin[2] = 2 : inc[2] = 0 : cmt$[2] = "Zero increment" start[3] = -2 : fin[3] = 2 : inc[3] = -1 : cmt$[3] = "Increments away from stop value" start[4] = -2 : fin[4] = 2 : inc...
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...
#ABAP
ABAP
METHOD luhn_check.   DATA: sum(1) TYPE n VALUE 0. " Sum of checksum. DATA: current TYPE i. " Current digit. DATA: odd TYPE i VALUE 1. " Multiplier. DATA: len TYPE i. " String crowler.     " Luhn algorithm. len = NUMOFCHAR( pi_string ) - 1. WHILE ( len >= 0 ). current = pi_string+len(1) * odd. IF (...
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)=(...
#AWK
AWK
  # syntax: GAWK -f LUCAS-LEHMER_TEST.AWK # converted from Pascal BEGIN { printf("Mersenne primes:") n = 1 for (exponent=2; exponent<=32; exponent++) { s = (exponent == 2) ? 0 : 4 n = (n+1)*2-1 for (i=1; i<=exponent-2; i++) { s = (s*s-2)%n } if (s == 0) { printf...
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... {...
#Haskell
Haskell
  import System.Environment import Text.Regex.Posix   data Lucky = Lucky | EvenLucky   helpMessage :: IO () helpMessage = do putStrLn " what is displayed (on a single line)" putStrLn " argument(s) (optional verbiage is encouraged)" putStrLn "======================|====...
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.
#C.23
C#
using System; using System.Collections.Generic; using System.Text;   namespace LZW { public class Program { public static void Main(string[] args) { List<int> compressed = Compress("TOBEORNOTTOBEORTOBEORNOT"); Console.WriteLine(string.Join(", ", compressed)); ...
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...
#Common_Lisp
Common Lisp
;; Creates a nxn identity matrix. (defun eye (n) (let ((I (make-array `(,n ,n) :initial-element 0))) (loop for j from 0 to (- n 1) do (setf (aref I j j) 1)) I))   ;; Swap two rows l and k of a mxn matrix A, which is a 2D array. (defun swap-rows (A l k) (let* ((n (cadr (array-dimensions 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, ... ...
#J
J
revdig=:('x',~|.)&.":"0
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...
#Ruby
Ruby
#!/usr/bin/ruby   class EightBall def initialize print "Welcome to 8 ball! Ask your question below. " puts "Type 'quit' to exit the program.\n\n" @responses = ["It is certain", "It is decidedly so", "Without a doubt", "Yes, definitely", "You may rely on ...
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...
#Rust
Rust
extern crate rand;   use rand::prelude::*; use std::io;   fn main() { let 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 p...
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 .
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations int X, Y, \screen coordinates of current point Cnt; \iteration counter real Cx, Cy, \coordinates scaled to +/-2 range Zx, Zy, \complex accumulator Temp; ...
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...
#Fortran
Fortran
Reads a story in template form, containing special entries such as <dog's name> amongst the text. You will be invited to supply a replacement text for each such entry, as encountered, after which the story will be presented with your substitutions made.
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#ALGOL_60
ALGOL 60
begin integer prod, sum, x, y, z, one, three, seven; integer j; prod := 1; sum := 0; x := 5; y := -5; z := -2; one := 1; three := 3; seven := 7;   for j := -three step three until 3^3 , -seven step x until seven , 555 step 1 until 550 - y, 2...
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#ALGOL_68
ALGOL 68
BEGIN # translation of task PL/1 code, with minimal changes, semicolons required by # # PL/1 but not allowed in Algol 68 removed, unecessary rounding removed # # Note that in Algol 68, the loop counter is a local variable to the loop and # # the value of j is not available outside t...
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...
#Haskell
Haskell
import Data.List (unfoldr, genericSplitAt)   ludic :: [Integer] ludic = 1 : unfoldr (\xs@(x:_) -> Just (x, dropEvery x xs)) [2 ..] where dropEvery n = concatMap tail . unfoldr (Just . genericSplitAt n)   main :: IO () main = do print $ take 25 ludic (print . length) $ takeWhile (<= 1000) ludic print $ take ...
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...
#C
C
#include <stdio.h>   #define TRUE 1 #define FALSE 0   typedef int bool;   typedef struct { int start, stop, incr; const char *comment; } S;   S examples[9] = { {-2, 2, 1, "Normal"}, {-2, 2, 0, "Zero increment"}, {-2, 2, -1, "Increments away from stop value"}, {-2, 2, 10, "First increment is beyo...
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...
#ACL2
ACL2
(include-book "arithmetic-3/top" :dir :system)   (defun digits (n) (if (zp n) nil (cons (mod n 10) (digits (floor n 10)))))   (defun sum (xs) (if (endp xs) 0 (+ (first xs) (sum (rest xs)))))   (defun double-and-sum-digits (xs) (if (endp xs) nil (...
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)=(...
#BBC_BASIC
BBC BASIC
*FLOAT 64 PRINT "Mersenne Primes:" FOR p% = 2 TO 23 IF FNlucas_lehmer(p%) PRINT "M" ; p% NEXT END   DEF FNlucas_lehmer(p%) LOCAL i%, mp, sn IF p% = 2 THEN = TRUE IF (p% AND 1) = 0 THEN = FALSE mp = 2^p% - 1 sn = 4 FOR i% = 3 TO p% s...
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... {...
#J
J
luckySeq=:3 :0 1 luckySeq y : len=.0 nth=.0 seq=.x+2*i.4*y while. len~:#seq do. len=. #seq nth=. nth+1 seq=. nth exclude seq end. )   exclude=: ] #~ 1 - #@] $ -@{ {. 1:   lucky=:'' evenLucky=:0 program=:3 :0 range=: |y-.0 seq=. (1+0 e.y) luckySeq >./range if. 0><./y do. (#~ e.&(thru/r...
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.
#C.2B.2B
C++
#include <string> #include <map>   // Compress a string to a list of output symbols. // The result will be written to the output iterator // starting at "result"; the final iterator is returned. template <typename Iterator> Iterator compress(const std::string &uncompressed, Iterator result) { // Build the dictionary....
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...
#D
D
import std.stdio, std.algorithm, std.typecons, std.numeric, std.array, std.conv, std.string, std.range;   bool isRectangular(T)(in T[][] m) pure nothrow @nogc { return m.all!(r => r.length == m[0].length); }   bool isSquare(T)(in T[][] m) pure nothrow @nogc { return m.isRectangular && m[0].length == m.le...
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, ... ...
#Java
Java
import java.math.BigInteger; import java.util.*;   public class Lychrel {   static Map<BigInteger, Tuple> cache = new HashMap<>();   static class Tuple { final Boolean flag; final BigInteger bi;   Tuple(boolean f, BigInteger b) { flag = f; bi = b; } } ...
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...
#Sather
Sather
class MAIN is const answers: ARRAY{STR} := | "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 ...
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...
#Scala
Scala
import scala.util.Random   object Magic8Ball extends App { val shake: () => String = { val answers = 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.",...
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 .
#XSLT
XSLT
  <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   <!-- XSLT Mandelbrot - written by Joel Yliluoma 2007, http://iki.fi/bisqwit/ -->   <xsl:output method="html" indent="no" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system="http://www.w3...
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...
#FreeBASIC
FreeBASIC
  Dim As String con, cadena cadena = "<name> went for a walk in the park. <he or she> found a <noun>. <name> decided to take it home." Dim As Integer k = Instr(cadena, "<")   Print "La historia: " Print cadena & Chr(10) While k Dim As String reemplaza = Mid(cadena, k, Instr(cadena, ">") - k + 1) Print "What sho...
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#ALGOL_W
ALGOL W
begin  % translation of task PL/1 code, with minimal changes, semicolons required by  %  % PL/1 but redundant in Algol W retained ( technically they introduce empty  %  % statements after the "if" in the loop body and before the final "end" )  %  % Note that in Algol W, the loop counter 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...
#Icon_and_Unicon
Icon and Unicon
global num, cascade, sieve, nfilter   procedure main(A) lds := ludic(2005) # All we need for the four tasks. every writes("First 25:" | (" "||!lds)\25 | "\n") every (n := 0) +:= (!lds < 1000, 1) write("There are ",n," Ludic numbers < 1000.") every writes("2000th through 2005th: " | (lds[2000 to 200...
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...
#C.23
C#
using System; using System.Collections.Generic;   static class Program { static void Main() { Example(-2, 2, 1, "Normal"); Example(-2, 2, 0, "Zero increment"); Example(-2, 2, -1, "Increments away from stop value"); Example(-2, 2, 10, "First increment is beyond stop value"); ...
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...
#Action.21
Action!
PROC ReverseDigits(CHAR ARRAY n,rev) BYTE i,j   i=n(0) WHILE i>0 AND n(i)='0 DO i==-1 OD   j=1 WHILE i>0 DO rev(j)=n(i) j==+1 i==-1 OD rev(0)=j-1 RETURN   BYTE FUNC SumOddDigits(CHAR ARRAY n) BYTE sum,i   sum=0 FOR i=1 TO n(0) STEP 2 DO sum==+ValB(n(i)) OD RETURN(sum)   BYT...
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)=(...
#BCPL
BCPL
  GET "libhdr"   LET M(n) = (1 << n) - 1   LET isMersennePrime(p) = p < 3 -> p = 2, VALOF { LET n = M(p) LET s = 4 FOR i = 1 TO p-2 DO { muldiv(s, s, n) // ignore quotient; remainder is in result2 s := result2 - 2 s := s + (n & s < 0) } ...
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... {...
#Java
Java
  import java.util.ArrayList; import java.util.Collections; import java.util.List;   public class LuckyNumbers {   private static int MAX = 200000; private static List<Integer> luckyEven = luckyNumbers(MAX, true); private static List<Integer> luckyOdd = luckyNumbers(MAX, false);   public static void mai...
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.
#Clojure
Clojure
(defn make-dict [] (let [vals (range 0 256)] (zipmap (map (comp #'list #'char) vals) vals)))   (defn compress [#^String text] (loop [t (seq text) r '() w '() dict (make-dict) s 256] (let [c (first t)] (if c (let [wc (cons c w)] (if (get dict wc) ...
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...
#EchoLisp
EchoLisp
  (lib 'matrix) ;; the matrix library provides LU-decomposition (decimals 5)   (define A (list->array' (1 3 5 2 4 7 1 1 0 ) 3 3)) (define PLU (matrix-lu-decompose A)) ;; -> list of three matrices, P, Lower, Upper   (array-print (first PLU)) 0 1 0 1 0 0 0 0 1 (array-print (second PLU)) 1 0 0 0.5 1 0 0...
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, ... ...
#jq
jq
# This workhorse function assumes its arguments are # non-negative integers represented as decimal strings: def add(num1;num2): if (num1|length) < (num2|length) then add(num2;num1) else (num1 | explode | map(.-48) | reverse) as $a1 | (num2 | explode | map(.-48) | reverse) as $a2 | reduce range(0; num1|length) ...
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...
#Tcl
Tcl
namespace path {::tcl::mathop ::tcl::mathfunc}   set answers { "As I see it, yes" "Ask again later" "Better not tell you now" "Cannot predict now" "Concentrate and ask again" "Don't bet on it" "It is certain" "It is decidedly so" "Most likely" "My reply is no" "My sources say maybe" "My sources say no" "Ou...
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 .
#Z80_Assembly
Z80 Assembly
  ; ; Compute a Mandelbrot set on a simple Z80 computer. ; ; Porting this program to another Z80 platform should be easy and straight- ; forward: The only dependencies on my homebrew machine are the system-calls ; used to print strings and characters. These calls are performed by loading ; IX with the number of the s...
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...
#Go
Go
package main   import ( "bufio" "fmt" "io/ioutil" "log" "os" "regexp" "strings" )   func main() { pat := regexp.MustCompile("<.+?>") if len(os.Args) != 2 { fmt.Println("usage: madlib <story template file>") return } b, err := ioutil.ReadFile(os.Args[1]) if...
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#Applesoft_BASIC
Applesoft BASIC
100  ::::::::: REMALL VARIABLES ARE DECLARED AS INTEGERS. 110 PROD= 1 : REMSTART WITH A PRODUCT OF UNITY. 120 SUM= 0:: REM " " " SUM " ZERO. 130 X= +5 140 Y= -5 150 Z= -2 160 UNO= 1 170 THREE= 3 180 SEVEN= 7 190 REM(BELOW) ^ IS EXPONENTIATION: 4^3=64 200 DO(0) = -THREE : T0...
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...
#J
J
ludic =: _1 |.!.1 [: {."1 [: (#~ 0 ~: {. | i.@#)^:a: 2 + i.
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...
#Common_Lisp
Common Lisp
  (dolist (lst '((-2 2 1 "Normal") ; Iterate the parameters list `start' `stop' `increment' and `comment' (-2 2 0 "Zero increment") (-2 2 -1 "Increments away from stop value") (-2 2 10 "First increment is beyond stop value") ( 2 -2 1 "Start more than stop: positive increment") ...
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...
#ActionScript
ActionScript
function isValid(numString:String):Boolean { var isOdd:Boolean = true; var oddSum:uint = 0; var evenSum:uint = 0; for(var i:int = numString.length - 1; i >= 0; i--) { var digit:uint = uint(numString.charAt(i)) if(isOdd) oddSum += digit; else evenSum += digit/5 + (2*digit) % 10; isOdd = !isOdd; } if((oddS...
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)=(...
#Bracmat
Bracmat
( clk$:?t0:?now & ( time = ( print = . put $ ( str $ ( div$(!arg,1) "," ( div$(mod$(!arg*100,100),1):?arg & !arg:<10 & 0 | )  !ar...
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... {...
#JavaScript
JavaScript
  function luckyNumbers(opts={}) { /**************************************************************************\ | OPTIONS | |**************************************************************************| | even ...... boolean ............. return e...
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.
#CoffeeScript
CoffeeScript
  lzw = (s) -> dct = {} # map substrings to codes between 256 and 4096 stream = [] # array of compression results   # initialize basic ASCII characters for code_num in [0..255] c = String.fromCharCode(code_num) dct[c] = code_num code_num = 256   i = 0 while i < s.length # Find word and new_wor...
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...
#Fortran
Fortran
program lu1 implicit none call check( reshape([real(8)::1,2,1,3,4,1,5,7,0 ],[3,3]) ) call check( reshape([real(8)::11,1,3,2,9,5,17,5,24,2,18,7,2,6,1,1],[4,4]) )   contains   subroutine check(a) real(8), intent(in) :: a(:,:) integer :: i,j,n real(8), allocatable :: 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, ... ...
#Julia
Julia
const cache = Dict{BigInt, Tuple{Bool, BigInt}}()   Base.reverse(n::Integer) = parse(BigInt, string(n) |> reverse) function lychrel(n::BigInt)::Tuple{Bool, BigInt} if haskey(cache, n) return cache[n] end   r = reverse(n) rst = (true, n) seen = Set{BigInt}() for i in 0:500 n += r ...
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...
#Tiny_BASIC
Tiny BASIC
10 PRINT "Concentrate hard on your question, then tell me your favorite number." 20 INPUT N 30 REM in lieu of a random number generator 40 IF N<0 THEN LET N=-N 50 IF N<20 THEN GOTO 1000+N*10 60 LET N=N-20 70 GOTO 50 1000 PRINT "It is certain." 1005 END 1010 PRINT "It is decidedly so." 1015 END 1020 PRINT "Without a dou...
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 .
#zkl
zkl
fcn mandelbrot{ // lord this is slooooow bitmap:=PPM(640,480); foreach y,x in ([0..479],[0..639]){ cx:=(x.toFloat()/640 - 0.5)*4.0; //range: -2.0 to +2.0 cy:=((y-240).toFloat()/240.0)*1.5; //range: -1.5 to +1.5 cnt:=0; zx:=0.0; zy:=0.0; do(1000){ if(zx*zx + zy*zy > 2.0){ //z...
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...
#Haskell
Haskell
import System.IO (stdout, hFlush)   import System.Environment (getArgs)   import qualified Data.Map as M (Map, lookup, insert, empty)   getLines :: IO [String] getLines = reverse <$> getLines_ [] where getLines_ xs = do line <- getLine case line of [] -> return xs _ -> getLines_ $ line...
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program loopnrange.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /*********************************/ /* C...
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#0815
0815
<:400:~}:_:%<:a:~$=<:2:=/^:_:
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...
#Java
Java
import java.util.ArrayList; import java.util.List;   public class Ludic{ public static List<Integer> ludicUpTo(int n){ List<Integer> ludics = new ArrayList<Integer>(n); for(int i = 1; i <= n; i++){ //fill the initial list ludics.add(i); }   //start at index 1 because the first ludic number is 1 and we don...
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...
#Delphi
Delphi
  program Wrong_ranges;   {$APPTYPE CONSOLE}   uses System.SysUtils;   procedure Example(start, stop, Increment: Integer; comment: string); var MAX_ITER, iteration, i: Integer; begin Write((comment + ' ').PadRight(50, '-') + ' '); MAX_ITER := 9; iteration := 0;   if Increment = 1 then begin for i := s...
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...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO;   procedure Luhn is   function Luhn_Test (Number: String) return Boolean is Sum  : Natural := 0; Odd  : Boolean := True; Digit: Natural range 0 .. 9; begin for p in reverse Number'Range loop Digit := Integer'Value (Number (p..p)); if Odd then S...
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)=(...
#Burlesque
Burlesque
607rz2en{J4{J.*2.-2{th}c!**-..%}#R2.-E!n!it}f[2+]{2\/**-.}m[p^
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... {...
#Julia
Julia
using Base, StringDistances   struct Lucky start::Int nmax::Int Lucky(iseven, nmax) = new(iseven ? 2 : 1, nmax) end   struct LuckyState nextindex::Int sequence::Vector{Int} end   Base.eltype(iter::Lucky) = Int   function Base.iterate(iter::Lucky, state = LuckyState(1, collect(iter.start:2:iter.nmax)...
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... {...
#Kotlin
Kotlin
// version 1.1.51   typealias IAE = IllegalArgumentException   val luckyOdd = MutableList(100000) { it * 2 + 1 } val luckyEven = MutableList(100000) { it * 2 + 2 }   fun filterLuckyOdd() { var n = 2 while (n < luckyOdd.size) { val m = luckyOdd[n - 1] val end = (luckyOdd.size / m) * m - 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.
#Common_Lisp
Common Lisp
(declaim (ftype (function (vector vector &optional fixnum fixnum) vector) vector-append)) (defun vector-append (old new &optional (start2 0) end2) (declare (optimize (speed 3) (safety 0) (debug 0))) (prog1 old (let* ((old-fill (fill-pointer old)) (new-fill (+ old-...
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...
#Go
Go
package main   import "fmt"   type matrix [][]float64   func zero(n int) matrix { r := make([][]float64, n) a := make([]float64, n*n) for i := range r { r[i] = a[n*i : n*(i+1)] } return r }   func eye(n int) matrix { r := zero(n) for i := range r { r[i][i] = 1 } ret...
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, ... ...
#Kotlin
Kotlin
// version 1.0.6   import java.math.BigInteger   const val ITERATIONS = 500 const val LIMIT = 10000   val bigLimit = BigInteger.valueOf(LIMIT.toLong())   // In the sieve, 0 = not Lychrel, 1 = Seed Lychrel, 2 = Related Lychrel val lychrelSieve = IntArray(LIMIT + 1) // all zero by default val seedLychrels = mutab...
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...
#uBasic.2F4tH
uBasic/4tH
Push Dup("It is certain"), Dup("It is decidedly so"), Dup("Without a doubt") Push Dup("Yes, definitely"), Dup("You may rely on it") Push Dup("As I see it, yes"), Dup("Most likely"), Dup("Outlook good") Push Dup("Signs point to yes"), Dup("Yes"), Dup("Reply hazy, try again") Push Dup("Ask again later"), Dup("Better not ...
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...
#UNIX_Shell
UNIX Shell
#!/bin/bash   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 n...
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() ml := "<name> went for a walk in the park. There <he or she> _ found a <noun>. <name> decided to take it home." # sample MadLib(ml) # run it end   link strings   procedure MadLib(story) write("Please provide words for the following:") ...
http://rosettacode.org/wiki/Loops/With_multiple_ranges
Loops/With multiple ranges
Loops/With multiple ranges You are encouraged to solve this task according to the task description, using any language you may know. Some languages allow multiple loop ranges, such as the PL/I example (snippet) below. /* all variables are DECLARED as integers. */ prod=...
#AutoHotkey
AutoHotkey
for_J(doFunction, start, stop, step:=1){ j := start while (j<=stop) && (start<=stop) && (step>0) %doFunction%(j), j+=step while (j>=stop) && (start>stop) && (step<0) %doFunction%(j), j+=step }
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#11l
11l
V n = 1024 L n > 0 print(n) n I/= 2
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#360_Assembly
360 Assembly
* While 27/06/2016 WHILELOO CSECT program's control section USING WHILELOO,12 set base register LR 12,15 load base register LA 6,1024 v=1024 LOOP LTR 6,6 while v>0 BNP EN...
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...
#JavaScript
JavaScript
/** * Boilerplate to simply get an array filled between 2 numbers * @param {!number} s Start here (inclusive) * @param {!number} e End here (inclusive) */ const makeArr = (s, e) => new Array(e + 1 - s).fill(s).map((e, i) => e + i);   /** * Remove every n-th element from the given array * @param {!Array} arr * @p...
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...
#Eiffel
Eiffel
  example -- Loops/Wrong ranges do ⟳ ic:(-2 |..| 2) ¦ do_nothing ⟲ -- 2 2 1 Normal ⟳ ic:(-2 |..| 2).new_cursor + 0 ¦ do_nothing ⟲ -- -2 2 0 Zero increment ⟳ ic:(-2 |..| 2).new_cursor - 1 ¦ do_nothing ⟲ -- -2 2 -1 Increments away from stop value ⟳ ic:(-2 |..| 2).new_cursor + 10 ¦ do_noth...
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...
#Factor
Factor
USING: continuations formatting io kernel math.ranges prettyprint sequences ;   : try-range ( from length step -- ) [ <range> { } like . ] [ 4drop "Exception: divide by zero." print ] recover ;   { { -2 2 1 } { 2 2 0 } { -2 2 -1 } { -2 2 10 } { 2 -2 1 } { 2 2 1 } { 2 2 -1 } { 2 2 0 } { 0 0 0 } } [ f...
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...
#ALGOL_68
ALGOL 68
PROC to int = (CHAR c)INT: ABS c - ABS "0";   PROC confirm = (STRING id)BOOL: ( BOOL is odd digit := TRUE; INT s := 0; STRING cp;   FOR cp key FROM UPB id BY -1 TO LWB id DO INT k := to int(id[cp key]); s +:= IF is odd digit THEN k ELIF k /= 9 THEN 2*k MOD 9 ...
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)=(...
#C
C
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <gmp.h>   int lucas_lehmer(unsigned long p) { mpz_t V, mp, t; unsigned long k, tlim; int res;   if (p == 2) return 1; if (!(p&1)) return 0;   mpz_init_set_ui(t, p); if (!mpz_probab_prime_p(t, 25)) /* if p is composite, 2^p-1 is not prime ...
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... {...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[GetLuckies, GetEvenLuckies] GetLuckies[max_] := Module[{luckies, f, i}, luckies = Range[1, max, 2]; f[n_] := Block[{k = luckies[[n]]}, luckies = Delete[luckies, Table[{k}, {k, k, Length@luckies, k}]]]; i = 2; While[i < Length[luckies], f[i]; i++ ]; luckies ] GetEvenLuckies[max_] := Module[...