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/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.
#JavaScript
JavaScript
  function recurse(depth) { try { return recurse(depth + 1); } catch(ex) { return depth; } }   var maxRecursion = recurse(1); document.write("Recursion depth on this system is " + maxRecursion);
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   ...
#Ring
Ring
  # Project: Find palindromic numbers in both binary and ternary bases   max = 6 nr = 0 pal = 0 see "working..." + nl see "wait for done..." + nl while true binpal = basedigits(nr,2) terpal = basedigits(nr,3) bool1 = ispalindrome(binpal) bool2 = ispalindrome(terpal) if bool1 = 1 and bool2 ...
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   ...
#Ruby
Ruby
pal23 = Enumerator.new do |y| y << 0 y << 1 for i in 1 .. 1.0/0.0 # 1.step do |i| (Ruby 2.1+) n3 = i.to_s(3) n = (n3 + "1" + n3.reverse).to_i(3) n2 = n.to_s(2) y << n if n2.size.odd? and n2 == n2.reverse end end   puts " decimal ternary ...
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) ...
#Fennel
Fennel
(for [i 1 100] (print (if (= (% i 15) 0) :FizzBuzz (= (% i 3) 0) :Fizz (= (% i 5) 0) :Buzz i)))
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.
#Delphi
Delphi
program SizeOfFile;   {$APPTYPE CONSOLE}   uses SysUtils;   function CheckFileSize(const aFilename: string): Integer; var lFile: file of Byte; begin AssignFile(lFile, aFilename); FileMode := 0; {Access file in read only mode} Reset(lFile); Result := FileSize(lFile); CloseFile(lFile); end;   begin Writeln(...
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.
#E
E
for file in [<file:input.txt>, <file:///input.txt>] { println(`The size of $file is ${file.length()} bytes.`) }
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 ...
#BASIC
BASIC
OPEN "INPUT.TXT" FOR INPUT AS #1 OPEN "OUTPUT.TXT" FOR OUTPUT AS #2 DO UNTIL EOF(1) LINE INPUT #1, DATA$ PRINT #2, DATA$ LOOP CLOSE #1 CLOSE #2 SYSTEM
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-...
#Ada
Ada
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO, Ada.Numerics.Long_Elementary_Functions, Ada.Long_Float_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO, Ada.Numerics.Long_Elementary_Functions, Ada.Long_Float_Text_IO...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#Ada
Ada
  with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;   procedure Main is procedure feigenbaum is subtype i_range is Integer range 2 .. 13; subtype j_range is Integer range 1 .. 10;   -- the number of digits in type Real is reduced to 15 to produce the ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#ALGOL_68
ALGOL 68
# Calculate the Feigenbaum constant #   print( ( "Feigenbaum constant calculation:", newline ) ); INT max it = 13; INT max it j = 10; REAL a1 := 1.0; REAL a2 := 0.0; REAL d1 := 3.2; print( ( "i ", "d", newline ) ); FOR i FROM 2 TO max it DO REAL a := a1 + (a1 - a2) / d1; FOR j TO max it j DO REAL...
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...
#Factor
Factor
USING: formatting kernel qw sequences splitting unicode ; IN: rosetta-code.file-extension-list   CONSTANT: extensions qw{ zip rar 7z gz archive A## tar.bz2 } CONSTANT: filenames qw{ MyData.a## MyData.tar.Gz MyData.gzip MyData.7z.backup MyData... MyData MyData_v1.0.tar.bz2 MyData_v1.0.bz2 }   : ext-in-list? ( fi...
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...
#Fortran
Fortran
IT = ICHAR(TEXT(I:I)) - ICHAR("a") !More symbols precede "a" than "A". IF (IT.GE.0 .AND. IT.LE.25) TEXT(I:I) = CHAR(IT + ICHAR("A")) !In a-z? Convert!
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Haskell
Haskell
import System.Posix.Files import System.Posix.Time   do status <- getFileStatus filename let atime = accessTime status mtime = modificationTime status -- seconds since the epoch curTime <- epochTime setFileTimes filename atime curTime -- keep atime unchanged -- set...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#HicEst
HicEst
CHARACTER timestamp*18   timestamp = ' ' ! blank timestamp will read: SYSTEM(FIle="File_modification_time.hic", FileTime=timestamp) ! 20100320141940.525   timestamp = '19991231235950' ! set timestamp to Millenium - 10 seconds SYSTEM(FIle="File_modification_time.hic", FileTime=timestamp)
http://rosettacode.org/wiki/File_size_distribution
File size distribution
Task Beginning from the current directory, or optionally from a directory specified as a command-line argument, determine how many files there are of various sizes in a directory hierarchy. My suggestion is to sort by logarithmn of file size, since a few bytes here or there, or even a factor of two or three, may no...
#zkl
zkl
pipe:=Thread.Pipe(); // hoover all files in tree, don't return directories fcn(pipe,dir){ File.globular(dir,"*",True,8,pipe); } .launch(pipe,vm.arglist[0]); // thread   dist,N,SZ,maxd:=List.createLong(50,0),0,0,0; foreach fnm in (pipe){ sz,szd:=File.len(fnm), sz.numDigits; dist[szd]+=1; N+=1; SZ+=sz; maxd...
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...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import ( "github.com/fogleman/gg" "strings" )   func wordFractal(i int) string { if i < 2 { if i == 1 { return "1" } return "" } var f1 strings.Builder f1.WriteString("1") var f2 strings.Builder f2.WriteString("0") for j := i - 2; j ...
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...
#Go
Go
package main   import ( "fmt" "os" "path" )   func CommonPrefix(sep byte, paths ...string) string { // Handle special cases. switch len(paths) { case 0: return "" case 1: return path.Clean(paths[0]) }   // Note, we treat string as []byte, not []rune as is often // done in Go. (And sep as byte, not rune). ...
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.
#AWK
AWK
$ awk 'BEGIN{split("1 2 3 4 5 6 7 8 9",a);for(i in a)if(!(a[i]%2))r=r" "a[i];print r}'
http://rosettacode.org/wiki/Find_if_a_point_is_within_a_triangle
Find if a point is within a triangle
Find if a point is within a triangle. Task   Assume points are on a plane defined by (x, y) real number coordinates.   Given a point P(x, y) and a triangle formed by points A, B, and C, determine if P is within triangle ABC.   You may use any algorithm.   Bonus: explain why the algorithm you chose works. Re...
#XPL0
XPL0
func real Dot(W,X,Y,Z); \Return the dot product of two 2D vectors real W,X,Y,Z; \ (W-X) dot (Y-Z) real WX(2), YZ(2); [WX(0):= W(0)-X(0); WX(1):= W(1)-X(1); YZ(0):= Y(0)-Z(0); YZ(1):= Y(1)-Z(1); return WX(0)*YZ(0) + WX(1)*YZ(1); ];   real A,B,C; \triangle   func PointInTr...
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.
#jq
jq
def zero_arity: if (. % 1000000 == 0) then . else empty end, ((.+1)| zero_arity);   1|zero_arity
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.
#Julia
Julia
  function divedivedive(d::Int) try divedivedive(d+1) catch return d end end  
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   ...
#Scala
Scala
import scala.annotation.tailrec import scala.compat.Platform.currentTime   object Palindrome23 extends App { private val executionStartTime = currentTime private val st: Stream[(Int, Long)] = (0, 1L) #:: st.map(xs => nextPalin3(xs._1))   @tailrec private def nextPalin3(n: Int): (Int, Long) = {   @inline ...
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) ...
#FOCAL
FOCAL
01.10 FOR I=1,100; DO 2.0 01.20 QUIT   02.10 SET ZB=I/15 - FITR(I/15) 02.20 IF (ZB) 2.4, 2.3, 2.4 02.30 TYPE "FizzBuzz" ! 02.35 RETURN 02.40 SET Z=I/3 - FITR(I/3) 02.50 IF (Z) 2.7, 2.6, 2.7 02.60 TYPE "Fizz" ! 02.65 RETURN 02.70 SET B=I/5 - FITR(I/5) 02.80 IF (B) 2.99, 2.9, 2.99 02.90 TYPE "Buzz" ! 02.95 RETURN 02.99 T...
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.
#Eiffel
Eiffel
  class APPLICATION create make feature {NONE} -- Initialization make -- Run application. do create input_file.make_open_read ("input.txt") print(input_file.count) print("%N") input_file.close create environment inpu...
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.
#Elena
Elena
import system'io; import extensions;   public program() { console.printLine(File.assign("input.txt").Length);   console.printLine(File.assign("\input.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 ...
#Batch_File
Batch File
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-...
#Aime
Aime
real entropy(data b) { integer count, i; real ones, zeros;   ones = zeros = 0;   i = -(count = ~b); while (i) { if (b[i] == '0') { zeros += 1; } else { ones += 1; }   i += 1; }   return -(ones /= count) * log2(ones) - (zeros /= count) *...
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-...
#ALGOL_68
ALGOL 68
# calculate some details of "Fibonacci Words" #   # fibonacci word 1 = "1" # # fibonacci word 2 = "0" # # 3 = word 2 cat word 1 = "01" # # n = word n-1 cat word n-2 #   # note...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#AWK
AWK
  # syntax: GAWK -f FEIGENBAUM_CONSTANT_CALCULATION.AWK BEGIN { a1 = 1 a2 = 0 d1 = 3.2 max_i = 13 max_j = 10 print(" i d") for (i=2; i<=max_i; i++) { a = a1 + (a1 - a2) / d1 for (j=1; j<=max_j; j++) { x = y = 0 for (k=1; k<=2^i; k++) { y = 1 - 2 * y * x ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#BASIC
BASIC
maxIt = 13 : maxItj = 13 a1 = 1.0 : a2 = 0.0 : d = 0.0 : 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 x = 0.0 : y = 0.0 for k = 1 to 2 ^ i y = 1 - 2 * y * x...
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...
#Go
Go
package main   import ( "fmt" "strings" )   var extensions = []string{"zip", "rar", "7z", "gz", "archive", "A##", "tar.bz2"}   func fileExtInList(filename string) (bool, string) { filename2 := strings.ToLower(filename) for _, ext := range extensions { ext2 := "." + strings.ToLower(ext) i...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Icon_and_Unicon
Icon and Unicon
  every dir := !["./","/"] do { if i := stat(f := dir || "input.txt") then { write("info for ",f ," mtime= ",ctime(i.mtime),", atime=",ctime(i.ctime), ", atime=",ctime(i.atime)) utime(f,i.atime,i.mtime-1024) i := stat(f) write("update for ",f ," mtime= ",ctime(i.mtime),", atime=",ctime(i.cti...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#J
J
load 'files' fstamp 'input.txt' 2009 8 24 20 34 30
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...
#Go
Go
package main   import ( "github.com/fogleman/gg" "strings" )   func wordFractal(i int) string { if i < 2 { if i == 1 { return "1" } return "" } var f1 strings.Builder f1.WriteString("1") var f2 strings.Builder f2.WriteString("0") for j := i - 2; j ...
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...
#Groovy
Groovy
def commonPath = { delim, Object[] paths -> def pathParts = paths.collect { it.split(delim) } pathParts.transpose().inject([match:true, commonParts:[]]) { aggregator, part -> aggregator.match = aggregator.match && part.every { it == part [0] } if (aggregator.match) { aggregator.commonParts << pa...
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.
#Batch_File
Batch File
  @echo off setlocal enabledelayedexpansion   set numberarray=1 2 3 4 5 6 7 8 9 10 for %%i in (%numberarray%) do ( set /a tempcount+=1 set numberarray!tempcount!=%%i )   echo Filtering all even numbers from numberarray into newarray... call:filternew numberarray echo numberarray - %numberarray% echo newarray -%n...
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.
#Kotlin
Kotlin
// version 1.1.2   fun recurse(i: Int) { try { recurse(i + 1) } catch(e: StackOverflowError) { println("Limit of recursion is $i") } }   fun main(args: Array<String>) = recurse(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.
#Liberty_BASIC
Liberty BASIC
  'subroutine recursion limit- end up on 475000   call test 1   sub test n if n mod 1000 = 0 then locate 1,1: print n call test n+1 end sub  
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   ...
#Scheme
Scheme
(import (scheme base) (scheme write) (srfi 1 lists)) ; use 'fold' from SRFI 1   ;; convert number to a list of digits, in desired base (define (r-number->list n base) (let loop ((res '()) (num n)) (if (< num base) (cons num res) (loop (cons (remainder num base) res) ...
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) ...
#Fermat
Fermat
  for i = 1 to 100 do if i|15=0 then !'FizzBuzz ' else if i|5=0 then !'Buzz ' else if i|3=0 then !'Fizz ' else !i;!' ' fi fi fi od
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.
#Elixir
Elixir
IO.puts File.stat!("input.txt").size IO.puts File.stat!("/input.txt").size
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.
#Emacs_Lisp
Emacs Lisp
(message "sizes are %s and %s" (nth 7 (file-attributes "input.txt")) (nth 7 (file-attributes "/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.
#Erlang
Erlang
-module(file_size). -export([file_size/0]).   -include_lib("kernel/include/file.hrl").   file_size() -> print_file_size("input.txt"), print_file_size("/input.txt").   print_file_size(Filename) -> case file:read_file_info(Filename) of {ok, FileInfo} -> io:format("~s ~p~n", [Filename, FileInfo#file_info...
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 ...
#BBC_BASIC
BBC BASIC
*COPY input.txt output.txt
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 ...
#BCPL
BCPL
GET "libhdr"   LET start() BE $(   // Attempt to open the named files. LET source = findinput("input.txt") LET destination = findoutput("output.txt")   TEST source = 0 THEN writes("Unable to open input.txt*N") ELSE TEST destination = 0 THEN writes("Unable to open output.txt*N") E...
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-...
#APL
APL
  F_WORD←{{⍵,,/⌽¯2↑⍵}⍣(0⌈⍺-2),¨⍵} ENTROPY←{-+/R×2⍟R←(+⌿⍵∘.=∪⍵)÷⍴⍵} FORMAT←{'N' 'LENGTH' 'ENTROPY'⍪(⍳⍵),↑{(⍴⍵),ENTROPY ⍵}¨⍵ F_WORD 1 0}  
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-...
#Arturo
Arturo
entropy: function [s][ if 1 >= size s -> return 0.0 strlen: to :floating size s count0: to :floating size match s "0" count1: strlen - count0 return neg add (count0/strlen) * log count0/strlen 2 (count1/strlen) * log count1/strlen 2 ]   fibwords: function [n][ x: 0 a: "1" b: "0" resu...
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-...
#Arturo
Arturo
nPowers: [1 2 4 8 16 32 64 128 256 512] fermatSet: map 0..9 'x -> 1 + 2 ^ nPowers\[x]   loop 0..9 'i -> print ["F(" i ") =" fermatSet\[i]]   print ""   loop 0..9 'i -> print ["Prime factors of F(" i ") =" factors.prime fermatSet\[i]]
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#C
C
#include <stdio.h>   void feigenbaum() { int i, j, k, max_it = 13, max_it_j = 10; double a, x, y, d, a1 = 1.0, a2 = 0.0, d1 = 3.2; printf(" i d\n"); for (i = 2; i <= max_it; ++i) { a = a1 + (a1 - a2) / d1; for (j = 1; j <= max_it_j; ++j) { x = 0.0; y = 0.0; ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#C.23
C#
using System;   namespace FeigenbaumConstant { class Program { static void Main(string[] args) { var maxIt = 13; var maxItJ = 10; var a1 = 1.0; var a2 = 0.0; var d1 = 3.2; Console.WriteLine(" i d"); for (int i = 2; i <...
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...
#Haskell
Haskell
import Data.List import qualified Data.Char as Ch   toLower :: String -> String toLower = map Ch.toLower   isExt :: String -> [String] -> Bool isExt filename extensions = any (`elem` (tails . toLower $ filename)) $ map toLower extensions
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...
#J
J
isSuffix=: -~&# = {:@I.@E. isExt=: ('.'&,&.>@[ ([: +./ isSuffix&(tolower@>)/) boxopen@])
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Java
Java
import java.io.File; import java.util.Date; public class FileModificationTimeTest { public static void test(String type, File file) { long t = file.lastModified(); System.out.println("The following " + type + " called " + file.getPath() + (t == 0 ? " does not exist." : " was modified at " +...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#JavaScript
JavaScript
var fso = new ActiveXObject("Scripting.FileSystemObject"); var f = fso.GetFile('input.txt'); var mtime = f.DateLastModified;
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...
#Icon_and_Unicon
Icon and Unicon
global width, height   procedure main(A) n := integer(A[1]) | 25 # F_word to use sl := integer(A[2]) | 1 # Segment length width := integer(A[3]) | 1050 # Width of plot area height := integer(A[4]) | 1050 # Height of plot area w := fword(n) drawFractal(n,w,sl) end   p...
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...
#GW-BASIC
GW-BASIC
10 REM All GOTO statements can be replaced with EXIT FOR in newer BASICs. 110 X$ = "/home/user1/tmp/coverage/test" 120 Y$ = "/home/user1/tmp/covert/operator" 130 Z$ = "/home/user1/tmp/coven/members" 150 A = LEN(X$) 160 IF A > LEN(Y$) THEN A = LEN(Y$) 170 IF A > LEN(Z$) THEN A = LEN(Z$) 180 FOR L0 = 1 TO A 190 IF ...
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.
#BBC_BASIC
BBC BASIC
REM Create the test array: items% = 1000 DIM array%(items%) FOR index% = 1 TO items% array%(index%) = RND NEXT   REM Count the number of filtered items: filtered% = 0 FOR index% = 1 TO items% IF FNfilter(array%(index%)) filtered% += 1 NEXT   RE...
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.
#LIL
LIL
/* Enable limiting recursive calls to lil_parse - this can be used to avoid call stack * overflows and is also useful when running through an automated fuzzer like AFL */ /*#define LIL_ENABLE_RECLIMIT 10000*/
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.
#Logo
Logo
make "depth 0   to recurse make "depth :depth + 1 recurse end   catch "ERROR [recurse]  ; hit control-C after waiting a while print error  ; 16 Stopping... recurse [make "depth :depth + 1] (print [Depth reached:] :depth)  ; some arbitrarily large number
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   ...
#Sidef
Sidef
var format = "%11s %24s %38s\n" format.printf("decimal", "ternary", "binary") format.printf(0, 0, 0)   for n in (0 .. 2e5) { var pal = n.base(3)||'' var b3 = (pal + '1' + pal.flip) var b2 = Num(b3, 3).base(2) if (b2 == b2.flip) { format.printf(Num(b2, 2), b3, b2) } }
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   ...
#Swift
Swift
import Foundation   func isPalin2(n: Int) -> Bool { var x = 0 var n = n   guard n & 1 != 0 else { return n == 0 }   while x < n { x = x << 1 | n & 1 n >>= 1 }   return n == x || n == x >> 1 }   func reverse3(n: Int) -> Int { var x = 0 var n = n   while n > 0 { x = x * 3 + (n % 3) ...
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) ...
#Forth
Forth
: fizz ( n -- ) drop ." Fizz" ; : buzz ( n -- ) drop ." Buzz" ; : fb ( n -- ) drop ." FizzBuzz" ; : vector create does> ( n -- ) over 15 mod cells + @ execute ; vector .fizzbuzz ' fb , ' . , ' . , ' fizz , ' . , ' buzz , ' fizz , ' . , ' . , ' fizz , ' buzz , ' . , ' fizz , ' . , ' . ,
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.
#Euphoria
Euphoria
include file.e   function file_size(sequence file_name) object x x = dir(file_name) if sequence(x) and length(x) = 1 then return x[1][D_SIZE] else return -1 -- the file does not exist end if end function   procedure test(sequence file_name) integer size size = file_size(file_...
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.
#F.23
F#
open NUnit.Framework open FsUnit   [<Test>] let ``Validate that the size of the two files is the same`` () = let local = System.IO.FileInfo(__SOURCE_DIRECTORY__ + "\input.txt") let root = System.IO.FileInfo(System.IO.Directory.GetDirectoryRoot(__SOURCE_DIRECTORY__) + "input.txt") local.Length = root.Length |> sho...
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 ...
#Befunge
Befunge
0110"txt.tupni"#@i10"txt.tuptuo"#@o@
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 ...
#Bracmat
Bracmat
put$(get$"input.txt","output.txt",NEW)
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-...
#AutoHotkey
AutoHotkey
SetFormat, FloatFast, 0.15 SetBatchLines, -1 OutPut := "N`tLength`t`tEntropy`n" . "1`t" 1 "`t`t" Entropy(FW1 := "1") "`n" . "2`t" 1 "`t`t" Entropy(FW2 := "0") "`n" Loop, 35 { FW3 := FW2 FW1, FW1 := FW2, FW2 := FW3 Output .= A_Index + 2 "`t" StrLen(FW3) (A_Index > 33 ? "" : "`t") "`t" Entropy(FW3...
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-...
#C
C
gcc -o fermat fermat.c -lgmp
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-...
#C.2B.2B
C++
#include <iostream> #include <vector> #include <boost/integer/common_factor.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/miller_rabin.hpp>   typedef boost::multiprecision::cpp_int integer;   integer fermat(unsigned int n) { unsigned int p = 1; for (unsigned int i = 0; i < n; +...
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}} ...
#11l
11l
T Fiblike Int addnum [Int] memo   F (start) .addnum = start.len .memo = copy(start)   F ()(n) X.try R .memo[n] X.catch IndexError V ans = sum((n - .addnum .< n).map(i -> (.)(i))) .memo.append(ans) R ans   V fibo = Fiblike([1, 1]) print((0.<10).map(...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#C.2B.2B
C++
#include <iostream>   int main() { const int max_it = 13; const int max_it_j = 10; double a1 = 1.0, a2 = 0.0, d1 = 3.2;   std::cout << " i d\n"; for (int i = 2; i <= max_it; ++i) { double a = a1 + (a1 - a2) / d1; for (int j = 1; j <= max_it_j; ++j) { double x = 0.0;...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#D
D
import std.stdio;   void main() { int max_it = 13; int max_it_j = 10; double a1 = 1.0; double a2 = 0.0; double d1 = 3.2; double a;   writeln(" i d"); for (int i=2; i<=max_it; i++) { a = a1 + (a1 - a2) / d1; for (int j=1; j<=max_it_j; j++) { double x = 0....
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...
#Java
Java
import java.util.Arrays; import java.util.Comparator;   public class FileExt{ public static void main(String[] args){ String[] tests = {"text.txt", "text.TXT", "test.tar.gz", "test/test2.exe", "test\\test2.exe", "test", "a/b/c\\d/foo"}; String[] exts = {".txt",".gz","",".bat"};   System.out.println("Extensions: ...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Jsish
Jsish
/* File modification times, in Jsi */   var fileTime = File.mtime('fileModificationTime.jsi'); puts("Last mod time was: ", strftime(fileTime * 1000));   exec('touch fileModificationTime.jsi');   fileTime = File.mtime('fileModificationTime.jsi'); puts("Mod time now: ", strftime(fileTime * 1000));
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Julia
Julia
using Dates   fname, _ = mktemp()   println("The modification time of $fname is ", Dates.unix2datetime(mtime(fname))) println("\nTouch this file.") touch(fname) println("The modification time of $fname is now ", Dates.unix2datetime(mtime(fname)))
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...
#Haskell
Haskell
import Data.List (unfoldr) import Data.Bool (bool) import Data.Semigroup (Sum(..), Min(..), Max(..)) import System.IO (writeFile)   fibonacciWord :: a -> a -> [[a]] fibonacciWord a b = unfoldr (\(a,b) -> Just (a, (b, a <> b))) ([a], [b])   toPath :: [Bool] -> ((Min Int, Max Int, Min Int, Max Int), String) toPath = fold...
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...
#Haskell
Haskell
import Data.List   -- Return the common prefix of two lists. commonPrefix2 (x:xs) (y:ys) | x == y = x : commonPrefix2 xs ys commonPrefix2 _ _ = []   -- Return the common prefix of zero or more lists. commonPrefix (xs:xss) = foldr commonPrefix2 xs xss commonPrefix _ = []   -- Split a string into path components. splitPa...
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...
#HicEst
HicEst
CHARACTER a='/home/user1/tmp/coverage/test', b='/home/user1/tmp/covert/operator', c='/home/user1/tmp/coven/members'   minLength = MIN( LEN(a), LEN(b), LEN(c) ) lastSlash = 0   DO i = 1, minLength IF( (a(i) == b(i)) * (b(i) == c(i)) ) THEN IF(a(i) == "/") lastSlash = i ELSEIF( lastSlash ) THEN WRITE(Messageb...
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.
#BCPL
BCPL
get "libhdr"   // Copy every value for which p(x) is true from in to out // This will also work in place by setting out = in let filter(p, in, ilen, out, olen) be $(  !olen := 0 for i = 0 to ilen-1 do if p(in!i) do $( out!!olen := in!i  !olen := !olen + 1 $) $)   // Write N eleme...
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.
#LSL
LSL
integer iLimit_of_Recursion = 0; Find_Limit_of_Recursion(integer x) { llOwnerSay("x="+(string)x); iLimit_of_Recursion = x; Find_Limit_of_Recursion(x+1); } default { state_entry() { Find_Limit_of_Recursion(0); llOwnerSay("iLimit_of_Recursion="+(string)iLimit_of_Recursion); } }  
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.
#Lua
Lua
  local c = 0 function Tail(proper) c = c + 1 if proper then if c < 9999999 then return Tail(proper) else return c end else return 1/c+Tail(proper) -- make the recursive call must keep previous stack end end   local ok,check = pcall(Tail,true) print(c, ok, check) c=0 ok,check = pcall(Tail,false) print...
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   ...
#Tcl
Tcl
proc format_%t {n} { while {$n} { append r [expr {$n % 3}] set n [expr {$n / 3}] } if {![info exists r]} {set r 0} string reverse $r }
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   ...
#VBA
VBA
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long 'palindromes both in base3 and base2 'using Decimal data type to find number 6 and 7, although slowly Private Function DecimalToBinary(DecimalNum As Long) As String Dim tmp As String Dim n As Long   n = DecimalNum   tmp = Trim(CStr(n Mod...
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) ...
#Fortran
Fortran
program fizzbuzz_if integer :: i   do i = 1, 100 if (mod(i,15) == 0) then; print *, 'FizzBuzz' else if (mod(i,3) == 0) then; print *, 'Fizz' else if (mod(i,5) == 0) then; print *, 'Buzz' else; print *, i end if end do end program fizzbuzz_if
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.
#Factor
Factor
"input.txt" file-info size>> . 1321 "file-does-not-exist.txt" file-info size>> "Unix system call ``stat'' failed:"...
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.
#FBSL
FBSL
#APPTYPE CONSOLE   PRINT FileLen("sync.log") PRINT FileLen("\sync.log") PAUSE  
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.
#Forth
Forth
: .filesize ( addr len -- ) 2dup type ." is " r/o open-file throw dup file-size throw <# #s #> type ." bytes long." cr close-file throw ;   s" input.txt" .filesize s" /input.txt" .filesize
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
C
#include <stdio.h>   int main(int argc, char **argv) { FILE *in, *out; int c;   in = fopen("input.txt", "r"); if (!in) { fprintf(stderr, "Error opening input.txt for reading.\n"); return 1; }   out = fopen("output.txt", "w"); if (!out) { fprintf(stderr, "Error opening output.txt for writing.\n...
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
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h>   void print_headings() { printf("%2s", "N"); printf(" %10s", "Length"); printf(" %-20s", "Entropy"); printf(" %-40s", "Word"); printf("\n"); }   double calculate_entropy(int ones, int zeros) { double result = 0;   int total = ones + ze...
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 ...
#11l
11l
V FASTA = |‘>Rosetta_Example_1 THERECANBENOSPACE >Rosetta_Example_2 THERECANBESEVERAL LINESBUTTHEYALLMUST BECONCATENATED’   F fasta_parse(infile_str) V key = ‘’ V val = ‘’ [(String, String)] r L(line) infile_str.split("\n") I line.starts_with(‘>’) I key != ‘’ r [+]= (key...
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-...
#Common_Lisp
Common Lisp
This uses the 'factor' function defined in the page Prime Decomposition http://rosettacode.org/wiki/Prime_decomposition#Common_Lisp
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-...
#Crystal
Crystal
This uses the `factor` function from the `coreutils` library that comes standard with most GNU/Linux, BSD, and Unix systems. https://www.gnu.org/software/coreutils/ https://en.wikipedia.org/wiki/GNU_Core_Utilities
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}} ...
#360_Assembly
360 Assembly
* Fibonacci n-step number sequences - 14/04/2020 FIBONS CSECT USING FIBONS,R13 base register B 72(R15) skip savearea DC 17F'0' savearea SAVE (14,12) save previous context ST R13,4(R15) link backward ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#F.23
F#
open System   [<EntryPoint>] let main _ = let maxIt = 13 let maxItJ = 10 let mutable a1 = 1.0 let mutable a2 = 0.0 let mutable d1 = 3.2 Console.WriteLine(" i d") for i in 2 .. maxIt do let mutable a = a1 + (a1 - a2) / d1 for j in 1 .. maxItJ do let mutable ...
http://rosettacode.org/wiki/Feigenbaum_constant_calculation
Feigenbaum constant calculation
Task Calculate the Feigenbaum constant. See   Details in the Wikipedia article:   Feigenbaum constant.
#Factor
Factor
USING: formatting io locals math math.ranges sequences ;   [let 1 :> a1! 0 :> a2! 3.2 :> d!   " i d" print   2 13 [a,b] [| exp | a1 a2 - d /f a1 + :> a! 10 [ 0 :> x! 0 :> y! exp 2^ [ 1 2 x y * * - y! a x sq - x! ...
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...
#jq
jq
# Input: filename # Output: if the filename ends with one of the extensions (ignoring case), output that extension; else output null. # Assume that the list of file extensions consists of lower-case strings, including a leading period. def has_extension(list): def ascii_downcase: explode | map( if 65 <= . and . <= 90...
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...
#Julia
Julia
isext(filename, extensions) = any(x -> endswith(lowercase(filename), lowercase(x)), "." .* extensions)   # Test extensions = ["zip", "rar", "7z", "gz", "archive", "A##", "tar.bz2"] for f in ["MyData.a##", "MyData.tar.Gz", "MyData.gzip", "MyData.7z.backup", "MyData...", "MyData", "MyData_v1.0.tar.bz2", "MyData_v1.0.bz2"...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Kotlin
Kotlin
// version 1.0.6   import java.io.File   fun main(args: Array<String>) { val filePath = "input.txt" // or whatever val file = File(filePath) with (file) { println("%tc".format(lastModified())) // update to current time, say setLastModified(System.currentTimeMillis()) println(...
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Lasso
Lasso
local(f) = file('input.txt') handle => { #f->close } #f->modificationDate->format('%-D %r') // result: 12/2/2010 11:04:15 PM
http://rosettacode.org/wiki/File_modification_time
File modification time
Task Get and set the modification time of a file.
#Lua
Lua
require "lfs" local attributes = lfs.attributes("input.txt") if attributes then print(path .. " was last modified " .. os.date("%c", attributes.modification) .. ".")   -- set access and modification time to now ... lfs.touch("input.txt")   -- ... or set modification time to now, keep original access tim...