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/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#J
J
require 'plot' plot }:+/\ 0,*/\(^~ 0j_1 0j1 $~ #)'0'=_1{::F_Words 20
http://rosettacode.org/wiki/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#Java
Java
import java.awt.*; import javax.swing.*;   public class FibonacciWordFractal extends JPanel { String wordFractal;   FibonacciWordFractal(int n) { setPreferredSize(new Dimension(450, 620)); setBackground(Color.white); wordFractal = wordFractal(n); }   public String wordFractal(int...
http://rosettacode.org/wiki/Find_common_directory_path
Find common directory path
Create a routine that, given a set of strings representing directory paths and a single character directory separator, will return a string representing that part of the directory tree that is common to all the directories. Test your routine using the forward slash '/' character as the directory separator and the foll...
#Icon_and_Unicon
Icon and Unicon
procedure main() write(lcdsubstr(["/home/user1/tmp/coverage/test","/home/user1/tmp/covert/operator","/home/user1/tmp/coven/members"])) end   procedure lcdsubstr(sL,d) #: return the longest common sub-string of strings in the list sL delimited by d local ss   /d := "/" reverse(sL[1]) ? { if tab(find(d)+*d) || allma...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Bracmat
Bracmat
( :?odds & ( 1 2 3 4 5 6 7 8 9 10 16 25 36 49 64 81 100:? (=.!sjt*1/2:/&!odds !sjt:?odds)$() () | !odds ) )  
http://rosettacode.org/wiki/Find_limit_of_recursion
Find limit of recursion
Find limit of recursion is part of Short Circuit's Console Program Basics selection. Task Find the limit of recursion.
#M2000_Interpreter
M2000 Interpreter
  Module checkit { Global z Function a { z++ =a() } try { m=a() } Print z   z<=0 Function a { z++ call a() } try { call a() } Print z   z<=0 Module m { ...
http://rosettacode.org/wiki/Find_limit_of_recursion
Find limit of recursion
Find limit of recursion is part of Short Circuit's Console Program Basics selection. Task Find the limit of recursion.
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
$RecursionLimit=10^6
http://rosettacode.org/wiki/Find_palindromic_numbers_in_both_binary_and_ternary_bases
Find palindromic numbers in both binary and ternary bases
Find palindromic numbers in both binary and ternary bases You are encouraged to solve this task according to the task description, using any language you may know. Task   Find and show (in decimal) the first six numbers (non-negative integers) that are   palindromes   in   both:   base 2   base 3   Display   0   ...
#Wren
Wren
import "/fmt" for Fmt   var isPalindrome2 = Fn.new { |n| var x = 0 if (n % 2 == 0) return n == 0 while (x < n) { x = x*2 + (n%2) n = (n/2).floor } return n == x || n == (x/2).floor }   var reverse3 = Fn.new { |n| var x = 0 while (n != 0) { x = x*3 + (n%3) n = ...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#FreeBASIC
FreeBASIC
gen n word = cycle (take (n - 1) (repeat "") ++ [word]) pattern = zipWith (++) (gen 3 "fizz") (gen 5 "buzz") fizzbuzz = zipWith combine pattern [1..] where combine word number = if null word then show number else word show $ take 100 fizzbuzz
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#Fortran
Fortran
    use :: iso_fortran_env, only : FILE_STORAGE_SIZE implicit none character(len=*),parameter :: filename(*)=[character(len=256) :: 'input.txt', '/input.txt'] integer :: file_size, i do i=1,size(filename) INQUIRE(FILE=filename(i), SIZE=file_size) ! return -1 if cannot dete...
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   #include "file.bi"   Print FileLen("input.txt"), FileLen(Environ("SystemRoot") + "\input.txt") Sleep
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#C.23
C#
using System.IO;   using (var reader = new StreamReader("input.txt")) using (var writer = new StreamWriter("output.txt")) { var text = reader.ReadToEnd(); writer.Write(text); }
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#C.2B.2B
C++
#include <iostream> #include <fstream> #include <string>   using namespace std;   int main() { string line; ifstream input ( "input.txt" ); ofstream output ("output.txt");   if (output.is_open()) { if (input.is_open()){ while (getline (input,line)) { output << line <<...
http://rosettacode.org/wiki/Fibonacci_word
Fibonacci word
The   Fibonacci Word   may be created in a manner analogous to the   Fibonacci Sequence   as described here: Define   F_Word1   as   1 Define   F_Word2   as   0 Form     F_Word3   as   F_Word2     concatenated with   F_Word1   i.e.:   01 Form     F_Wordn   as   F_Wordn-1   concatenated with   F_wordn-...
#C.23
C#
using SYS = System; using SCG = System.Collections.Generic;   // // Basically a port of the C++ solution as posted // 2017-11-12. // namespace FibonacciWord { class Program { static void Main( string[] args ) { PrintHeading(); string firstString = "1"; int n = 1; PrintLine( n, firstS...
http://rosettacode.org/wiki/FASTA_format
FASTA format
In bioinformatics, long character strings are often encoded in a format called FASTA. A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line. Task Write a program that reads a FASTA file such as: >Rosetta_Example_1 THERECANBENOSPACE ...
#Action.21
Action!
PROC ReadFastaFile(CHAR ARRAY fname) CHAR ARRAY line(256) CHAR ARRAY tmp(256) BYTE newLine,dev=[1]   newLine=0 Close(dev) Open(dev,fname,4) WHILE Eof(dev)=0 DO InputSD(dev,line) IF line(0)>0 AND line(1)='> THEN IF newLine THEN PutE() FI newLine=1 SCopyS(tmp,line,2...
http://rosettacode.org/wiki/FASTA_format
FASTA format
In bioinformatics, long character strings are often encoded in a format called FASTA. A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line. Task Write a program that reads a FASTA file such as: >Rosetta_Example_1 THERECANBENOSPACE ...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO;   procedure Simple_FASTA is   Current: Character;   begin Get(Current); if Current /= '>' then raise Constraint_Error with "'>' expected"; end if; while not End_Of_File loop -- read name and string Put(Get_Line & ": "); -- read name and write directly to o...
http://rosettacode.org/wiki/Fermat_numbers
Fermat numbers
In mathematics, a Fermat number, named after Pierre de Fermat who first studied them, is a positive integer of the form Fn = 22n + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-...
#Factor
Factor
USING: formatting io kernel lists lists.lazy math math.functions math.primes.factors sequences ;   : lfermats ( -- list ) 0 lfrom [ [ 1 2 2 ] dip ^ ^ + ] lmap-lazy ;   CHAR: ₀ 10 lfermats ltake list>array [ "First 10 Fermat numbers:" print [ dupd "F%c = %d\n" printf 1 + ] each drop nl ] [ "Factors of f...
http://rosettacode.org/wiki/Fermat_numbers
Fermat numbers
In mathematics, a Fermat number, named after Pierre de Fermat who first studied them, is a positive integer of the form Fn = 22n + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-...
#Go
Go
package main   import ( "fmt" "github.com/jbarham/primegen" "math" "math/big" "math/rand" "sort" "time" )   const ( maxCurves = 10000 maxRnd = 1 << 31 maxB1 = uint64(43 * 1e7) maxB2 = uint64(2 * 1e10) )   var ( zero = big.NewInt(0) one = big.NewInt(1) ...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#ACL2
ACL2
(defun sum (xs) (if (endp xs) 0 (+ (first xs) (sum (rest xs)))))   (defun n-bonacci (prevs limit) (if (zp limit) nil (let ((next (append (rest prevs) (list (sum prevs))))) (cons (first next) (n-bonacci next (1- limit)))...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#Fortran
Fortran
program feigenbaum implicit none   integer i, j, k real ( KIND = 16 ) x, y, a, b, a1, a2, d1   print '(a4,a13)', 'i', 'd'   a1 = 1.0; a2 = 0.0; d1 = 3.2;   do i=2,20 a = a1 + (a1 - a2) / d1; do j=1,10 x = 0 y = 0 ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#FreeBASIC
FreeBASIC
' version 25-0-2019 ' compile with: fbc -s console   Dim As UInteger i, j, k, maxit = 13, maxitj = 13 Dim As Double x, y, a, a1 = 1, a2, d, d1 = 3.2   Print "Feigenbaum constant calculation:" Print Print " i d" Print "==================="   For i = 2 To maxIt a = a1 + (a1 - a2) / d1 For j = 1 To maxItJ ...
http://rosettacode.org/wiki/File_extension_is_in_extensions_list
File extension is in extensions list
File extension is in extensions list You are encouraged to solve this task according to the task description, using any language you may know. Filename extensions are a rudimentary but commonly used way of identifying files types. Task Given an arbitrary filename and a list of extensions, tell whether the filename...
#Kotlin
Kotlin
// version 1.1   /* implicitly allows for extensions containing dots */ fun String.isFileExtensionListed(extensions: List<String>): Boolean { return extensions.any { toLowerCase().endsWith("." + it.toLowerCase()) } }   fun main(args: Array<String>) { val extensions = listOf("zip", "rar", "7z", "gz", "archive", ...
http://rosettacode.org/wiki/File_extension_is_in_extensions_list
File extension is in extensions list
File extension is in extensions list You are encouraged to solve this task according to the task description, using any language you may know. Filename extensions are a rudimentary but commonly used way of identifying files types. Task Given an arbitrary filename and a list of extensions, tell whether the filename...
#Lua
Lua
-- Data declarations local extentions = {"zip", "rar", "7z", "gz", "archive", "A##", "tar.bz2"} local testCases = { "MyData.a##", "MyData.tar.Gz", "MyData.gzip", "MyData.7z.backup", "MyData...", "MyData", "MyData_v1.0.tar.bz2", "MyData_v1.0.bz2" }   -- Return boolean of whether example has a file extens...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#M2000_Interpreter
M2000 Interpreter
  Module CheckIt { \\ without *for wide output* we open for ANSI (1 byte per character) \\ but here we need it only for the creation of a file Open "afile" for output as #f Close #f Print file.stamp("afile") 'it is a number in VB6 date format. \\ day format as for Greece Pri...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
FileDate["file","Modification"]
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#MATLAB_.2F_Octave
MATLAB / Octave
f = dir('output.txt'); % struct f contains file information f.date % is string containing modification time f.datenum % numerical format (number of days) datestr(f.datenum) % is the same as f.date % see also: stat, lstat
http://rosettacode.org/wiki/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#JavaScript
JavaScript
  // Plot Fibonacci word/fractal // FiboWFractal.js - 6/27/16 aev function pFibowFractal(n,len,canvasId,color) { // DCLs var canvas = document.getElementById(canvasId); var ctx = canvas.getContext("2d"); var w = canvas.width; var h = canvas.height; var fwv,fwe,fn,tx,x=10,y=10,dx=len,dy=0,nr; // Cleaning ca...
http://rosettacode.org/wiki/Find_common_directory_path
Find common directory path
Create a routine that, given a set of strings representing directory paths and a single character directory separator, will return a string representing that part of the directory tree that is common to all the directories. Test your routine using the forward slash '/' character as the directory separator and the foll...
#J
J
parseDirs =: = <;.2 ] getCommonPrefix =: {. ;@{.~ 0 i.~ *./@(="1 {.)   getCommonDirPath=: [: getCommonPrefix parseDirs&>
http://rosettacode.org/wiki/Find_common_directory_path
Find common directory path
Create a routine that, given a set of strings representing directory paths and a single character directory separator, will return a string representing that part of the directory tree that is common to all the directories. Test your routine using the forward slash '/' character as the directory separator and the foll...
#Java
Java
public class CommonPath { public static String commonPath(String... paths){ String commonPath = ""; String[][] folders = new String[paths.length][]; for(int i = 0; i < paths.length; i++){ folders[i] = paths[i].split("/"); //split on file separator } for(int j = 0; j < folders[0].length; j++){ String th...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Brat
Brat
#Prints [2, 4, 6, 8, 10] p 1.to(10).select { x | x % 2 == 0 }
http://rosettacode.org/wiki/Find_limit_of_recursion
Find limit of recursion
Find limit of recursion is part of Short Circuit's Console Program Basics selection. Task Find the limit of recursion.
#MATLAB_.2F_Octave
MATLAB / Octave
>> get(0,'RecursionLimit')   ans =   500   >> set(0,'RecursionLimit',2500) >> get(0,'RecursionLimit')   ans =   2500
http://rosettacode.org/wiki/Find_limit_of_recursion
Find limit of recursion
Find limit of recursion is part of Short Circuit's Console Program Basics selection. Task Find the limit of recursion.
#Maxima
Maxima
f(p) := f(n: p + 1)$ f(0); Maxima encountered a Lisp error: Error in PROGN [or a callee]: Bind stack overflow. Automatically continuing. To enable the Lisp debugger set *debugger-hook* to nil.   n; 406
http://rosettacode.org/wiki/Find_palindromic_numbers_in_both_binary_and_ternary_bases
Find palindromic numbers in both binary and ternary bases
Find palindromic numbers in both binary and ternary bases You are encouraged to solve this task according to the task description, using any language you may know. Task   Find and show (in decimal) the first six numbers (non-negative integers) that are   palindromes   in   both:   base 2   base 3   Display   0   ...
#zkl
zkl
fcn pal23W{ //--> iterator returning (index,palindromic number) Walker.tweak(fcn(ri,r){ // references to loop start and count of palindromes foreach i in ([ri.value..*]){ n3:=i.toString(3); n:=String(n3,"1",n3.reverse()).toInt(3); // create base 3 palindrome n2:= n.toString(2); if(n2.len().isOdd and...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Frege
Frege
gen n word = cycle (take (n - 1) (repeat "") ++ [word]) pattern = zipWith (++) (gen 3 "fizz") (gen 5 "buzz") fizzbuzz = zipWith combine pattern [1..] where combine word number = if null word then show number else word show $ take 100 fizzbuzz
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#Frink
Frink
println[newJava["java.io.File", "input.txt"].length[]] println[newJava["java.io.File", "/input.txt"].length[]]
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#Gambas
Gambas
Public Sub Main() Dim stInfo As Stat = Stat(User.home &/ "input.txt") Dim stInfo1 As Stat = Stat("/input.txt")   Print User.Home &/ "input.txt = " & stInfo.Size & " bytes" Print "/input.txt = " & stInfo1.Size & " bytes"   End
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Clean
Clean
import StdEnv   copyFile fromPath toPath world # (ok, fromFile, world) = fopen fromPath FReadData world | not ok = abort ("Cannot open " +++ fromPath +++ " for reading") # (ok, toFile, world) = fopen toPath FWriteData world | not ok = abort ("Cannot open " +++ toPath +++ " for writing") # (fromFile,...
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Clojure
Clojure
  (use 'clojure.java.io)   (copy (file "input.txt") (file "output.txt"))  
http://rosettacode.org/wiki/Fibonacci_word
Fibonacci word
The   Fibonacci Word   may be created in a manner analogous to the   Fibonacci Sequence   as described here: Define   F_Word1   as   1 Define   F_Word2   as   0 Form     F_Word3   as   F_Word2     concatenated with   F_Word1   i.e.:   01 Form     F_Wordn   as   F_Wordn-1   concatenated with   F_wordn-...
#C.2B.2B
C++
#include <string> #include <map> #include <iostream> #include <algorithm> #include <cmath> #include <iomanip>   double log2( double number ) { return ( log( number ) / log( 2 ) ) ; }   double find_entropy( std::string & fiboword ) { std::map<char , int> frequencies ; std::for_each( fiboword.begin( ) , fiboword...
http://rosettacode.org/wiki/FASTA_format
FASTA format
In bioinformatics, long character strings are often encoded in a format called FASTA. A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line. Task Write a program that reads a FASTA file such as: >Rosetta_Example_1 THERECANBENOSPACE ...
#Aime
Aime
file f; text n, s;   f.affix(argv(1));   while (f.line(s) ^ -1) { if (s[0] == '>') { o_(n, s, ": "); n = "\n"; } else { o_(s); } }   o_(n);
http://rosettacode.org/wiki/FASTA_format
FASTA format
In bioinformatics, long character strings are often encoded in a format called FASTA. A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line. Task Write a program that reads a FASTA file such as: >Rosetta_Example_1 THERECANBENOSPACE ...
#ALGOL_W
ALGOL W
begin  % reads FASTA format data from standard input and write the results to standard output %  % only handles the ">" line start  % string(256) line;  % allow the program to continue after reaching end-of-file % ENDFILE := EXCEPTION( false, 1, 0, fa...
http://rosettacode.org/wiki/FASTA_format
FASTA format
In bioinformatics, long character strings are often encoded in a format called FASTA. A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line. Task Write a program that reads a FASTA file such as: >Rosetta_Example_1 THERECANBENOSPACE ...
#Arturo
Arturo
parseFasta: function [data][ result: #[] current: ø loop split.lines data 'line [ if? `>` = first line [ current: slice line 1 (size line)-1 set result current "" ] else -> set result current (get result current)++line ] return result ]   t...
http://rosettacode.org/wiki/Fermat_numbers
Fermat numbers
In mathematics, a Fermat number, named after Pierre de Fermat who first studied them, is a positive integer of the form Fn = 22n + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-...
#Haskell
Haskell
import Data.Numbers.Primes (primeFactors) import Data.Bool (bool)   fermat :: Integer -> Integer fermat = succ . (2 ^) . (2 ^)   fermats :: [Integer] fermats = fermat <$> [0 ..]   --------------------------- TEST --------------------------- main :: IO () main = mapM_ putStrLn [ fTable "First 10 Fermats:" show...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#Action.21
Action!
DEFINE MAX="15"   PROC GenerateSeq(CARD ARRAY init BYTE nInit CARD ARRAY seq BYTE nSeq) CARD next BYTE i,j,n   IF nInit<nSeq THEN n=nInit ELSE n=nSeq FI   FOR i=0 TO n-1 DO seq(i)=init(i) OD   FOR i=n TO nSeq-1 DO next=0 FOR j=i-nInit TO i-1 DO next==+seq(j) OD ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#F.C5.8Drmul.C3.A6
Fōrmulæ
  window 1, @"Feignenbaum Constant", ( 0, 0, 200, 300 )   _maxIt = 13 _maxItJ = 10   void local fn Feignenbaum NSUInteger i, j, k double a1 = 1.0, a2 = 0.0, d1 = 3.2   print "Feignenbaum Constant" print " i d"   for i = 2 to _maxIt double a = a1 + ( a1 - a2 ) / d1 for j = 1 to _maxItJ double x = 0, y = 0 for...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#FutureBasic
FutureBasic
  window 1, @"Feignenbaum Constant", ( 0, 0, 200, 300 )   _maxIt = 13 _maxItJ = 10   void local fn Feignenbaum NSUInteger i, j, k double a1 = 1.0, a2 = 0.0, d1 = 3.2   print "Feignenbaum Constant" print " i d"   for i = 2 to _maxIt double a = a1 + ( a1 - a2 ) / d1 for j = 1 to _maxItJ double x = 0, y = 0 for...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#Go
Go
package main   import "fmt"   func feigenbaum() { maxIt, maxItJ := 13, 10 a1, a2, d1 := 1.0, 0.0, 3.2 fmt.Println(" i d") for i := 2; i <= maxIt; i++ { a := a1 + (a1-a2)/d1 for j := 1; j <= maxItJ; j++ { x, y := 0.0, 0.0 for k := 1; k <= 1<<uint(i); k++ { ...
http://rosettacode.org/wiki/File_extension_is_in_extensions_list
File extension is in extensions list
File extension is in extensions list You are encouraged to solve this task according to the task description, using any language you may know. Filename extensions are a rudimentary but commonly used way of identifying files types. Task Given an arbitrary filename and a list of extensions, tell whether the filename...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
ClearAll[CheckExtension] CheckExtension[fn_String, e : {_String ..}] := StringMatchQ[ToLowerCase[FileExtension[fn]], Alternatives @@ ToLowerCase[e]] exts = {"zip", "rar", "7z", "gz", "archive", "A##"}; CheckExtension["MyData.a##", exts] CheckExtension["MyData.tar.gz", exts] CheckExtension["MyData.gzip", exts] CheckExte...
http://rosettacode.org/wiki/File_extension_is_in_extensions_list
File extension is in extensions list
File extension is in extensions list You are encouraged to solve this task according to the task description, using any language you may know. Filename extensions are a rudimentary but commonly used way of identifying files types. Task Given an arbitrary filename and a list of extensions, tell whether the filename...
#Nim
Nim
import os, strutils   let fileNameList = ["MyData.a##", "MyData.tar.Gz", "MyData.gzip", "MyData.7z.backup", "MyData...", "MyData"]   func buildExtensionList(extensions: varargs[string]): seq[string] {.compileTime.} = for ext in extensions: result.add('.' & ext.toLowerAscii())   const ExtList =...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#MAXScript
MAXScript
-- Returns a string containing the mod date for the file, e.g. "1/29/99 1:52:05 PM" getFileModDate "C:\myFile.txt"
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Modula-3
Modula-3
MODULE ModTime EXPORTS Main;   IMPORT IO, Fmt, File, FS, Date, OSError;   TYPE dateArray = ARRAY [0..5] OF TEXT;   VAR file: File.Status; date: Date.T;   PROCEDURE DateArray(date: Date.T): dateArray = BEGIN RETURN dateArray{Fmt.Int(date.year), Fmt.Int(ORD(date.month) + 1), Fmt.Int(date.day), ...
http://rosettacode.org/wiki/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#Julia
Julia
using Luxor, Colors   function fwfractal!(word::AbstractString, t::Turtle) left = 90 right = -90 for (n, c) in enumerate(word) Forward(t) if c == '0' Turn(t, ifelse(iseven(n), left, right)) end end return t end   word = last(fiboword(25))   touch("data/fibonacci...
http://rosettacode.org/wiki/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#Kotlin
Kotlin
// version 1.1.2   import java.awt.* import javax.swing.*   class FibonacciWordFractal(n: Int) : JPanel() { private val wordFractal: String   init { preferredSize = Dimension(450, 620) background = Color.black wordFractal = wordFractal(n) }   fun wordFractal(i: Int): String { ...
http://rosettacode.org/wiki/Find_common_directory_path
Find common directory path
Create a routine that, given a set of strings representing directory paths and a single character directory separator, will return a string representing that part of the directory tree that is common to all the directories. Test your routine using the forward slash '/' character as the directory separator and the foll...
#JavaScript
JavaScript
  /** * Given an array of strings, return an array of arrays, containing the * strings split at the given separator * @param {!Array<!string>} a * @param {string} sep * @returns {!Array<!Array<string>>} */ const splitStrings = (a, sep = '/') => a.map(i => i.split(sep));   /** * Given an index number, return a fu...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Burlesque
Burlesque
  blsq ) 1 13r@{2.%n!}f[ {2 4 6 8 10 12}  
http://rosettacode.org/wiki/Find_limit_of_recursion
Find limit of recursion
Find limit of recursion is part of Short Circuit's Console Program Basics selection. Task Find the limit of recursion.
#.D0.9C.D0.9A-61.2F52
МК-61/52
П2 ПП 05 ИП1 С/П ИП0 ИП2 - x<0 20 ИП0 1 + П0 ПП 05 ИП1 1 + П1 В/О
http://rosettacode.org/wiki/Find_limit_of_recursion
Find limit of recursion
Find limit of recursion is part of Short Circuit's Console Program Basics selection. Task Find the limit of recursion.
#Modula-2
Modula-2
MODULE recur;   IMPORT InOut;   PROCEDURE recursion (a : CARDINAL);   BEGIN InOut.Write ('.'); (* just count the dots.... *) recursion (a + 1) END recursion;   BEGIN recursion (0) END recur.
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Frink
Frink
for i = 1 to 100 { flag = false if i mod 3 == 0 { flag = true print["Fizz"] }   if i mod 5 == 0 { flag = true print["Buzz"] }   if flag == false print[i]   println[] }
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#Go
Go
package main   import "fmt" import "os"   func printFileSize(f string) { if stat, err := os.Stat(f); err != nil { fmt.Println(err) } else { fmt.Println(stat.Size()) } }   func main() { printFileSize("input.txt") printFileSize("/input.txt") }
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#Groovy
Groovy
println new File('index.txt').length(); println new File('/index.txt').length();
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#COBOL
COBOL
$set ans85 flag"ans85" flagas"s" sequential"line"
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#ColdFusion
ColdFusion
<cfif fileExists(expandPath("input.txt"))> <cffile action="read" file="#expandPath('input.txt')#" variable="inputContents"> <cffile action="write" file="#expandPath('output.txt')#" output="#inputContents#"> </cfif>
http://rosettacode.org/wiki/Fibonacci_word
Fibonacci word
The   Fibonacci Word   may be created in a manner analogous to the   Fibonacci Sequence   as described here: Define   F_Word1   as   1 Define   F_Word2   as   0 Form     F_Word3   as   F_Word2     concatenated with   F_Word1   i.e.:   01 Form     F_Wordn   as   F_Wordn-1   concatenated with   F_wordn-...
#Clojure
Clojure
(defn entropy [s] (let [len (count s), log-2 (Math/log 2)] (->> (frequencies s) (map (fn [[_ v]] (let [rf (/ v len)] (-> (Math/log rf) (/ log-2) (* rf) Math/abs)))) (reduce +))))   (defn fibonacci [cat a b] (lazy-seq (cons a (fibonacci b (cat a b)))))   ; ...
http://rosettacode.org/wiki/FASTA_format
FASTA format
In bioinformatics, long character strings are often encoded in a format called FASTA. A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line. Task Write a program that reads a FASTA file such as: >Rosetta_Example_1 THERECANBENOSPACE ...
#AutoHotkey
AutoHotkey
Data = ( >Rosetta_Example_1 THERECANBENOSPACE >Rosetta_Example_2 THERECANBESEVERAL LINESBUTTHEYALLMUST BECONCATENATED )   Data := RegExReplace(RegExReplace(Data, ">\V+\K\v+", ": "), "\v+(?!>)") Gui, add, Edit, w700,  % Data Gui, show return
http://rosettacode.org/wiki/FASTA_format
FASTA format
In bioinformatics, long character strings are often encoded in a format called FASTA. A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line. Task Write a program that reads a FASTA file such as: >Rosetta_Example_1 THERECANBENOSPACE ...
#AWK
AWK
  # syntax: GAWK -f FASTA_FORMAT.AWK filename # stop processing each file when an error is encountered { if (FNR == 1) { header_found = 0 if ($0 !~ /^[;>]/) { error("record is not valid") nextfile } } if ($0 ~ /^;/) { next } # comment begins with a ";" if ($0 ~ /^>/) { # ...
http://rosettacode.org/wiki/Fermat_numbers
Fermat numbers
In mathematics, a Fermat number, named after Pierre de Fermat who first studied them, is a positive integer of the form Fn = 22n + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-...
#J
J
fermat =: 1 1 p. 2 ^ 2 ^ x: (,. fermat)i.10 0 3 1 ...
http://rosettacode.org/wiki/Fermat_numbers
Fermat numbers
In mathematics, a Fermat number, named after Pierre de Fermat who first studied them, is a positive integer of the form Fn = 22n + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-...
#Java
Java
  import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors;   public class FermatNumbers {   public static void main(String[] args) { System.out.println("First 10 Fermat numbers:"); for ( int i ...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#Ada
Ada
package Bonacci is   type Sequence is array(Positive range <>) of Positive;   function Generate(Start: Sequence; Length: Positive := 10) return Sequence;   Start_Fibonacci: constant Sequence := (1, 1); Start_Tribonacci: constant Sequence := (1, 1, 2); Start_Tetranacci: constant Sequence := (1, 1, 2, 4);...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#Groovy
Groovy
class Feigenbaum { static void main(String[] args) { int max_it = 13 int max_it_j = 10 double a1 = 1.0 double a2 = 0.0 double d1 = 3.2 double a   println(" i d") for (int i = 2; i <= max_it; i++) { a = a1 + (a1 - a2) / d1 ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#Haskell
Haskell
import Data.List (mapAccumL)   feigenbaumApprox :: Int -> [Double] feigenbaumApprox mx = snd $ mitch mx 10 where mitch :: Int -> Int -> ((Double, Double, Double), [Double]) mitch mx mxj = mapAccumL (\(a1, a2, d1) i -> let a = iterate (\a -> ...
http://rosettacode.org/wiki/File_extension_is_in_extensions_list
File extension is in extensions list
File extension is in extensions list You are encouraged to solve this task according to the task description, using any language you may know. Filename extensions are a rudimentary but commonly used way of identifying files types. Task Given an arbitrary filename and a list of extensions, tell whether the filename...
#Objeck
Objeck
  class FileExtension { function : Main(args : String[]) ~ Nil { files := ["MyData.a##", "MyData.tar.Gz", "MyData.gzip", "MyData.7z.backup", "MyData...", "MyData", "MyData_v1.0.tar.bz2", "MyData_v1.0.bz2"]; exts := ["zip", "rar", "7z", "gz", "archive", "A##", "tar.bz2"]; each(i : files) { Ha...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) public static parse arg fileName if fileName = '' then fileName = 'data/tempfile01' mfile = File(fileName) m...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#NewLISP
NewLISP
;; print modification time (println (date (file-info "input.txt" 6)))   ;; set modification time to now (Unix) (! "touch -m input.txt")
http://rosettacode.org/wiki/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#Logo
Logo
; Return the low 1-bits of :n ; For example if n = binary 10110111 = 183 ; then return binary 111 = 7 to low.ones :n output ashift (bitxor :n (:n+1)) -1 end   ; :fibbinary should be a fibbinary value ; return the next larger fibbinary value to fibbinary.next :fibbinary localmake "filled bitor :fibbinar...
http://rosettacode.org/wiki/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#Lua
Lua
  RIGHT, LEFT, UP, DOWN = 1, 2, 4, 8 function drawFractals( w ) love.graphics.setCanvas( canvas ) love.graphics.clear() love.graphics.setColor( 255, 255, 255 ) local dir, facing, lineLen, px, py, c = RIGHT, UP, 1, 10, love.graphics.getHeight() - 20, 1 local x, y = 0, -lineLen local pts = {} ...
http://rosettacode.org/wiki/Find_common_directory_path
Find common directory path
Create a routine that, given a set of strings representing directory paths and a single character directory separator, will return a string representing that part of the directory tree that is common to all the directories. Test your routine using the forward slash '/' character as the directory separator and the foll...
#jq
jq
# maximal_initial_subarray takes as input an array of arrays: def maximal_initial_subarray: (map( .[0] ) | unique) as $u | if $u == [ null ] then [] elif ($u|length) == 1 then $u + ( map( .[1:] ) | maximal_initial_subarray) else [] end ;   # Solution: read in the strings, convert to an array of ar...
http://rosettacode.org/wiki/Find_common_directory_path
Find common directory path
Create a routine that, given a set of strings representing directory paths and a single character directory separator, will return a string representing that part of the directory tree that is common to all the directories. Test your routine using the forward slash '/' character as the directory separator and the foll...
#Julia
Julia
function commonpath(ds::Vector{<:AbstractString}, dlm::Char='/') 0 < length(ds) || return "" 1 < length(ds) || return String(ds[1]) p = split(ds[1], dlm) mincnt = length(p) for d in ds[2:end] q = split(d, dlm) mincnt = min(mincnt, length(q)) hits = findfirst(p[1:mincnt] .!= q...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#BQN
BQN
_filter ← {(𝔽𝕩)/𝕩} Odd ← 2⊸|   Odd _filter 1‿2‿3‿4‿5
http://rosettacode.org/wiki/Find_limit_of_recursion
Find limit of recursion
Find limit of recursion is part of Short Circuit's Console Program Basics selection. Task Find the limit of recursion.
#MUMPS
MUMPS
RECURSE IF $DATA(DEPTH)=1 SET DEPTH=1+DEPTH IF $DATA(DEPTH)=0 SET DEPTH=1 WRITE !,DEPTH_" levels down" DO RECURSE QUIT
http://rosettacode.org/wiki/Find_limit_of_recursion
Find limit of recursion
Find limit of recursion is part of Short Circuit's Console Program Basics selection. Task Find the limit of recursion.
#Nanoquery
Nanoquery
def recurse(counter) println counter counter += 1 recurse(counter) end   recurse(1)
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#FutureBasic
FutureBasic
include "NSLog.incl"   long fizz, buzz, i   for i = 1 to 100 fizz = (i mod 3 ) buzz = (i mod 5 ) if fizz + buzz == 0 then NSLog(@"FizzBuzz") : continue if fizz == 0 then NSLog(@"Fizz") : continue if buzz == 0 then NSLog(@"Buzz") : continue NSLog(@"%ld",i) next i   HandleEvents
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#Haskell
Haskell
import System.IO   printFileSize filename = withFile filename ReadMode hFileSize >>= print   main = mapM_ printFileSize ["input.txt", "/input.txt"]
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#HicEst
HicEst
READ(FILE="input.txt", LENgth=bytes) ! bytes = -1 if not existent READ(FILE="C:\input.txt", LENgth=bytes) ! bytes = -1 if not existent
http://rosettacode.org/wiki/File_size
File size
Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.
#Icon_and_Unicon
Icon and Unicon
every dir := !["./","/"] do { write("Size of ",f := dir || "input.txt"," = ",stat(f).size) |stop("failure for to stat ",f) }
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Common_Lisp
Common Lisp
(with-open-file (in #p"input.txt" :direction :input) (with-open-file (out #p"output.txt" :direction :output) (loop for line = (read-line in nil 'foo) until (eq line 'foo) do (write-line line out))))
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#D
D
import std.file: copy;   void main() { copy("input.txt", "output.txt"); }
http://rosettacode.org/wiki/Fibonacci_word
Fibonacci word
The   Fibonacci Word   may be created in a manner analogous to the   Fibonacci Sequence   as described here: Define   F_Word1   as   1 Define   F_Word2   as   0 Form     F_Word3   as   F_Word2     concatenated with   F_Word1   i.e.:   01 Form     F_Wordn   as   F_Wordn-1   concatenated with   F_wordn-...
#CLU
CLU
% NOTE: when compiling with Portable CLU, % this program needs to be merged with 'useful.lib' to get log() % % pclu -merge $CLUHOME/lib/useful.lib -compile fib_words.clu   % Yield pairs of (zeroes, ones) for each Fibonacci word % We don't generate the whole words, as that would take too much % memory. fib_words = iter...
http://rosettacode.org/wiki/Fibonacci_word
Fibonacci word
The   Fibonacci Word   may be created in a manner analogous to the   Fibonacci Sequence   as described here: Define   F_Word1   as   1 Define   F_Word2   as   0 Form     F_Word3   as   F_Word2     concatenated with   F_Word1   i.e.:   01 Form     F_Wordn   as   F_Wordn-1   concatenated with   F_wordn-...
#Common_Lisp
Common Lisp
(defun make-fibwords (array) (loop for i from 0 below 37 for j = "0" then (concatenate 'string j k) and k = "1" then j do (setf (aref array i) k)) array)   (defvar *fib* (make-fibwords (make-array 37)))   (defun entropy (string) (let ((table (make-hash-table :test 'eql)) (entropy 0d0)...
http://rosettacode.org/wiki/FASTA_format
FASTA format
In bioinformatics, long character strings are often encoded in a format called FASTA. A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line. Task Write a program that reads a FASTA file such as: >Rosetta_Example_1 THERECANBENOSPACE ...
#BASIC
BASIC
FUNCTION checkNoSpaces (s$) FOR i = 1 TO LEN(s$) - 1 IF MID$(s$, i, 1) = CHR$(32) OR MID$(s$, i, 1) = CHR$(9) THEN checkNoSpaces = 0 NEXT i checkNoSpaces = 1 END FUNCTION   OPEN "input.fasta" FOR INPUT AS #1   first = 1   DO WHILE NOT EOF(1) LINE INPUT #1, ln$ IF LEFT$(ln$, 1) = ">" THEN ...
http://rosettacode.org/wiki/Faulhaber%27s_formula
Faulhaber's formula
In mathematics,   Faulhaber's formula,   named after Johann Faulhaber,   expresses the sum of the p-th powers of the first n positive integers as a (p + 1)th-degree polynomial function of n,   the coefficients involving Bernoulli numbers. Task Generate the first 10 closed-form expressions, starting with p = 0. R...
#C
C
#include <stdbool.h> #include <stdio.h> #include <stdlib.h>   int binomial(int n, int k) { int num, denom, i;   if (n < 0 || k < 0 || n < k) return -1; if (n == 0 || k == 0) return 1;   num = 1; for (i = k + 1; i <= n; ++i) { num = num * i; }   denom = 1; for (i = 2; i <= n - k; ...
http://rosettacode.org/wiki/Fermat_numbers
Fermat numbers
In mathematics, a Fermat number, named after Pierre de Fermat who first studied them, is a positive integer of the form Fn = 22n + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-...
#jq
jq
# To take advantage of gojq's arbitrary-precision integer arithmetic: def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);   def gcd(a; b): # subfunction expects [a,b] as input # i.e. a ~ .[0] and b ~ .[1] def rgcd: if .[1] == 0 then .[0] else [.[1], .[0] % .[1]] | rgcd end; [a,b] ...
http://rosettacode.org/wiki/Fermat_numbers
Fermat numbers
In mathematics, a Fermat number, named after Pierre de Fermat who first studied them, is a positive integer of the form Fn = 22n + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-...
#Julia
Julia
using Primes   fermat(n) = BigInt(2)^(BigInt(2)^n) + 1 prettyprint(fdict) = replace(replace(string(fdict), r".+\(([^)]+)\)" => s"\1"), r"\=\>" => "^")   function factorfermats(max, nofactor=false) for n in 0:max fm = fermat(n) if nofactor println("Fermat number F($n) is $fm.") ...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#ALGOL_68
ALGOL 68
# returns an array of the first required count elements of an a n-step fibonacci sequence # # the initial values are taken from the init array # PROC n step fibonacci sequence = ( []INT init, INT required count )[]INT: BEGIN [ 1 : required count ]INT result; ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#J
J
Feigenbaum =: conjunction define NB. use: n Feigenbaum m irange=: <. + i.@:>:@:|@:- NB. inclusive range a=. 0 1 delta=. , 3.2 for_i. 3 irange n do. tmp=. ({: + ({:delta) *inv ({: - _2&{)) a for. i. m do. 'b bp'=. 0 for. i. 2 ^ <: i do. 'b bp'=. (tmp - *: b) , 1 _2 p. b * bp end. tmp=. tmp - b...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#Java
Java
public class Feigenbaum { public static void main(String[] args) { int max_it = 13; int max_it_j = 10; double a1 = 1.0; double a2 = 0.0; double d1 = 3.2; double a;   System.out.println(" i d"); for (int i = 2; i <= max_it; i++) { a = ...
http://rosettacode.org/wiki/File_extension_is_in_extensions_list
File extension is in extensions list
File extension is in extensions list You are encouraged to solve this task according to the task description, using any language you may know. Filename extensions are a rudimentary but commonly used way of identifying files types. Task Given an arbitrary filename and a list of extensions, tell whether the filename...
#PARI.2FGP
PARI/GP
lower(s)= { my(v=Vecsmall(s)); for(i=1,#v, if(v[i]<91 && v[i]>64, v[i]+=32) ); \\Strchr(v); \\ Use to return a string rather than a t_VECSMALL v; } checkExt(ext, file)= { ext=apply(lower,ext); my(v=lower(file),e); for(i=1,#ext, e=ext[i]; if(#v>#e && v[#v-#e+1..#v]==e && v[#v-#e]==46, r...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Nim
Nim
import os, strutils, times   if paramCount() == 0: quit(QuitSuccess) let fileName = paramStr(1)   # Get and display last modification time. var mtime = fileName.getLastModificationTime() echo "File \"$1\" last modification time: $2".format(fileName, mtime.format("YYYY-MM-dd HH:mm:ss"))   # Change last modification time...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Objeck
Objeck
use System.IO.File;   class Program { function : Main(args : String[]) ~ Nil { File->ModifiedTime("file_mod.obs")->ToString()->PrintLine(); } }
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Objective-C
Objective-C
NSFileManager *fm = [NSFileManager defaultManager];   // Pre-OS X 10.5 NSLog(@"%@", [[fm fileAttributesAtPath:@"input.txt" traverseLink:YES] fileModificationDate]); [fm changeFileAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] atPath:@"input.txt"];   // OS X ...
http://rosettacode.org/wiki/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
(*note, this usage of Module allows us to memoize FibonacciWord without exposing it to the global scope*) Module[{FibonacciWord, step}, FibonacciWord[1] = "1"; FibonacciWord[2] = "0"; FibonacciWord[n_Integer?(# > 2 &)] := (FibonacciWord[n] = FibonacciWord[n - 1] <> FibonacciWord[n - 2]);   step["0", {_?Eve...
http://rosettacode.org/wiki/Fibonacci_word/fractal
Fibonacci word/fractal
The Fibonacci word may be represented as a fractal as described here: (Clicking on the above website   (hal.archives-ouvertes.fr)   will leave a cookie.) For F_wordm start with F_wordCharn=1 Draw a segment forward If current F_wordChar is 0 Turn left if n is even Turn right if n is odd next n and iterate until e...
#Nim
Nim
import imageman   const Width = 1000 Height = 1000 LineColor = ColorRGBU [byte 64, 192, 96] Output = "fibword.png"     proc fibword(n: int): string = ## Return the nth fibword. var a = "1" result = "0" for _ in 1..n: a = result & a swap a, result     proc drawFractal(image: var Image; fw: string...