The Sidef programming language
  • Introduction
  • Preface
  • Getting Started
    • Installation
    • Running
    • Hello world
  • Sidef interpreter
    • Command-line options
    • One-line programs
    • Interactive mode
    • Parser warnings
    • Dumping the AST
    • Optimization
    • Deparsing
    • Precompilation
    • Compilation
  • Syntax and semantics
    • Comments
    • Built-in types
      • Nil
      • Bool
      • Number
      • Integer
      • Rational
      • Float
      • Complex
      • Fraction
      • Mod
      • Gauss
      • Quadratic
      • Quaternion
      • Polynomial
      • String
      • Regex
      • File
      • FileHandle
      • Dir
      • DirHandle
      • Array
      • Pair
      • NamedParam
      • Vector
      • Matrix
      • Hash
      • Set
      • Bag
      • Block
      • Time
      • Date
      • Sys
    • Language constructs
      • If
      • With
      • Goto
      • While
      • Do/While
      • For
      • Loop
      • Gather/Take
      • Given/When
      • Try/Catch
      • Break
      • Next
      • Continue
    • Methods
    • Operator precedence
    • Method precedence
    • Metaoperators
    • Variables
    • Variable references
    • Constants
    • Multidimensional arrays
    • Blocks
    • Functions
    • Modules
    • Classes
    • Types
    • Subsets
    • Lazy evaluation
    • Lazy methods
    • Multiple dispatch
    • Functional pattern matching
  • Programming tasks
    • 1
      • 10001th prime
      • 100 doors
    • 2
      • 24 game
        • Solve
    • 4
      • 4-rings or 4-squares puzzle
    • 9
      • 99 bottles of beer
      • 9 billion names of God the integer
    • A
      • A* search algorithm
      • A B
      • ABC problem
      • Abstract type
      • Abundant deficient and perfect number classifications
      • Abundant odd numbers
      • Accumulator factory
      • Achilles numbers
      • Ackermann function
      • Add a variable to a class instance at runtime
      • Additive primes
      • Address of a variable
      • AKS test for primes
      • Align columns
      • Almkvist-Giullera formula for pi
      • Almost prime
      • Amicable pairs
      • Anadromes
      • Anagrams
        • Deranged anagrams
      • Anaprimes
      • Angle difference between two bearings
      • Animate a pendulum
      • Anonymous recursion
      • Anti-primes
      • Apéry's constant
      • Append a record to the end of a text file
      • Append numbers at same position in strings
      • Apply a callback to an array
      • Apply a digital filter direct form II transposed
      • Approximate equality
      • Arbitrary-precision integers included
      • Archimedean spiral
      • Arithmetic
        • Complex
        • Integer
        • Rational
      • Arithmetic-geometric mean
        • Calculate Pi
      • Arithmetic coding
        • As a generalized change of radix
      • Arithmetic derivative
      • Arithmetic evaluation
      • Arithmetic numbers
      • Array concatenation
      • Array length
      • Array search
      • Arrays
      • Ascending primes
      • Assertions
      • Associative array
        • Creation
        • Iteration
      • Attractive numbers
      • Audio alarm
      • Audio frequency generator
      • Average loop length
      • Averages
        • Arithmetic mean
        • Mean angle
        • Mean time of day
        • Median
        • Mode
        • Pythagorean means
        • Root mean square
        • Simple moving average
      • AVL tree
    • B
      • Babbage problem
      • Balanced brackets
      • Barnsley fern
      • Base58Check encoding
      • Base64 decode data
      • Base64 encode data
      • Base 16 numbers needing a to f
      • Bell numbers
      • Benford's law
      • Bernoulli numbers
      • Best shuffle
      • Bilinear interpolation
      • Binary digits
      • Binary search
      • Binary strings
      • Bitmap
        • Bresenham's line algorithm
        • Write a PPM file
      • Bitwise operations
      • Blum integer
      • Boolean values
      • Boustrophedon transform
      • Box the compass
      • Brace expansion
      • Brazilian numbers
      • Break OO privacy
      • Brilliant numbers
      • Brownian tree
      • Bulls and cows
        • Player
      • Burrows Wheeler transform
    • C
      • Caesar cipher
      • Calculating the value of e
      • Calendar
      • Calendar - for REAL programmers
      • Calkin-Wilf sequence
      • Call a function
      • Call an object method
      • Cantor set
      • Carmichael 3 strong pseudoprimes
      • Carmichael lambda function
      • Cartesian product of two or more lists
      • Case-sensitivity of identifiers
      • Casting out nines
      • Catalan numbers
        • Pascal's triangle
      • Catamorphism
      • Centroid of a set of N-dimensional points
      • Change e letters to i in words
      • Changeable words
      • Chaos game
      • Character codes
      • Chebyshev coefficients
      • Check Machin-like formulas
      • Check that file exists
      • Checksumcolor
      • Chernick's Carmichael numbers
      • Cheryl's birthday
      • Chinese remainder theorem
      • Chinese zodiac
      • Cholesky decomposition
      • Cipolla's algorithm
      • Circles of given radius through two points
      • Circular primes
      • Classes
      • Closest-pair problem
      • Closures
        • Value capture
      • Collect and sort square numbers in ascending order from three lists
      • Collections
      • Color quantization
      • Color wheel
      • Colour bars
        • Display
      • Colour pinstripe
        • Display
      • Combinations
      • Combinations and permutations
      • Combinations with repetitions
      • Comma quibbling
      • Command-line arguments
      • Comments
      • Compare a list of strings
      • Compare sorting algorithms' performance
      • Compile-time calculation
      • Composite numbers k with no single digit factors whose factors are all substrings of k
      • Compound data type
      • Concatenate two primes is also prime
      • Concurrent computing
      • Conjugate transpose
      • Consecutive primes with ascending or descending differences
      • Constrained genericity
      • Constrained random points on a circle
      • Continued fraction
        • Arithmetic
          • Construct from rational number
      • Continued fraction convergents
      • Convert decimal number to rational
      • Convert seconds to compound duration
      • Convex hull
      • Conway's Game of Life
      • Coprime triplets
      • Coprimes
      • Copy a string
      • CORDIC
      • Count in factors
      • Count in octal
      • Count occurrences of a substring
      • Count the coins
      • Cousin primes
      • Cramer's rule
      • CRC-32
      • Create a file
      • Create a two-dimensional array at runtime
      • Create an HTML table
      • CSV data manipulation
      • CSV to HTML translation
      • Cuban primes
      • Cubic special primes
      • Cullen and Woodall numbers
      • Cumulative standard deviation
      • Currency
      • Currying
      • Curzon numbers
      • Cycle detection
      • Cyclops numbers
      • Cyclotomic polynomial
    • D
      • Damm algorithm
      • Date format
      • Date manipulation
      • Day of the week
      • Days between dates
      • De Polignac numbers
      • Death Star
      • Deceptive numbers
      • Decimal floating point number to binary
      • Decision tables
      • Decorate-sort-undecorate idiom
      • Deepcopy
      • Define a primitive data type
      • Delegates
      • Delete a file
      • Deming's funnel
      • Department numbers
      • Descending primes
      • Detect division by zero
      • Determinant and permanent
      • Determine if a string has all the same characters
      • Determine if a string has all unique characters
      • Determine if a string is collapsible
      • Determine if a string is numeric
      • Determine if a string is squeezable
      • Determine if only one instance is running
      • Dice game probabilities
      • Digit fifth powers
      • Digital root
        • Multiplicative digital root
      • Dijkstra's algorithm
      • Dinesman's multiple-dwelling problem
      • Disarium numbers
      • Discordian date
      • Display a linear combination
      • Distinct palindromes within decimal numbers
      • Distinct power numbers
      • Distribution of 0 digits in factorial series
      • Diversity prediction theorem
      • DNS query
      • Dot product
      • Double Twin Primes
      • Doubly-linked list
        • Element definition
      • Dragon curve
      • Draw a clock
      • Draw a cuboid
      • Draw a sphere
      • Duffinian numbers
      • Dynamic variable names
    • E
      • Earliest difference between prime gaps
      • Egyptian division
      • Egyptian fractions
      • Eisenstein primes
      • EKG sequence convergence
      • Element-wise operations
      • Elementary cellular automaton
        • Infinite length
        • Random number generator
      • Elliptic curve arithmetic
      • Emirp primes
      • Empty directory
      • Empty program
      • Empty string
      • Enforced immutability
      • Entropy
        • Narcissist
      • Enumerations
      • Environment variables
      • Equal prime and composite sums
      • Equilibrium index
      • Erdös-Selfridge categorization of primes
      • Erdős-Nicolas numbers
      • Erdős-primes
      • Esthetic numbers
      • Ethiopian multiplication
      • Euclid-Mullin sequence
      • Euclidean rhythm
      • Euler's constant 0 5772
      • Euler's identity
      • Euler's sum of powers conjecture
      • Euler method
      • Evaluate binomial coefficients
      • Even numbers which cannot be expressed as the sum of two twin primes
      • Even or odd
      • Evolutionary algorithm
      • Exactly three adjacent 3 in lists
      • Exceptions
        • Catch an exception thrown in a nested call
      • Executable library
      • Execute a system command
      • Execute Brain****
      • Execute HQ9
      • Exponentiation operator
      • Exponentiation order
      • Extend your language
      • Extensible prime generator
      • Extra primes
      • Extract file extension
      • Extreme floating point values
      • Extreme primes
    • F
      • Factor-perfect numbers
      • Factorial
      • Factorial primes
      • Factorions
      • Factors of a Mersenne number
      • Factors of an integer
      • Fairshare between two and more
      • Farey sequence
      • Fast Fourier transform
      • FASTA format
      • Faulhaber's formula
      • Faulhaber's triangle
      • Feigenbaum constant calculation
      • Fermat numbers
      • Fermat pseudoprimes
      • Fibonacci matrix-exponentiation
      • Fibonacci n-step number sequences
      • Fibonacci sequence
      • Fibonacci word
        • Fractal
      • File extension is in extensions list
      • File input
        • Output
      • File modification time
      • File size
      • File size distribution
      • Filter
      • Find adjacent primes which differ by a square integer
      • Find common directory path
      • Find duplicate files
      • Find first and last set bit of a long integer
      • Find first missing positive
      • Find largest left truncatable prime in a given base
      • Find limit of recursion
      • Find palindromic numbers in both binary and ternary bases
      • Find prime n such that reversed n is also prime
      • Find prime numbers of the form n*n*n 2
      • Find square difference
      • Find squares n where n 1 is prime
      • Find the intersection of a line with a plane
      • Find the intersection of two lines
      • Find the last Sunday of each month
      • Find the missing permutation
      • Find words whose first and last three letters are equal
      • First-class functions
        • Use numbers analogously
      • First 9 prime Fibonacci number
      • First class environments
      • First missing positive
      • First perfect square in base n with n unique digits
      • First power of 2 that has leading decimal digits of 12
      • Five weekends
      • Fivenum
      • FizzBuzz
      • Flatten a list
      • Flow-control structures
      • Floyd's triangle
      • Floyd-Warshall algorithm
      • Forbidden numbers
      • Forest fire
      • Fork
      • Formatted numeric output
      • Fortunate numbers
      • Forward difference
      • Four bit adder
      • Four is magic
      • Four sides of square
      • Fractal tree
      • Fractran
      • Free polyominoes enumeration
      • French Republican calendar
      • Frobenius numbers
      • FTP
      • Function composition
      • Function definition
      • Function frequency
      • Fusc sequence
    • G
      • Gamma function
      • Gapful numbers
      • Gauss-Jordan matrix inversion
      • Gaussian elimination
      • Gaussian primes
      • General FizzBuzz
      • Generate Chess960 starting position
      • Generate lower case ASCII alphabet
      • Generate random numbers without repeating a value
      • Generator
        • Exponential
      • Generic swap
      • Get system command output
      • Getting the number of decimal places
      • Getting the number of decimals
      • Giuga numbers
      • Globally replace text in several files
      • Golden ratio
        • Convergence
      • Gray code
      • Grayscale image
      • Greatest common divisor
      • Greatest element of a list
      • Greatest prime dividing the n-th cubefree number
      • Greatest subsequential sum
      • Greedy algorithm for Egyptian fractions
      • Guess the number
        • With feedback
        • With feedback player
      • GUI
        • Maximum window dimensions
    • H
      • Hailstone sequence
      • Hamming numbers
      • Handle a signal
      • Happy numbers
      • Harshad or Niven series
      • Hash from two arrays
      • Hash join
      • Haversine formula
      • Hello world
        • Graphical
        • Line printer
        • Newline omission
        • Standard error
        • Text
        • Web server
      • Here document
      • Heronian triangles
      • Hickerson series of almost integers
      • Higher-order functions
      • Hilbert curve
      • History variables
      • Hofstadter-Conway 10 000 sequence
      • Hofstadter Figure-Figure sequences
      • Hofstadter Q sequence
      • Holidays related to Easter
      • Home primes
      • Honaker primes
      • Honeycombs
      • Horizontal sundial calculations
      • Horner's rule for polynomial evaluation
      • Hostname
      • Hough transform
      • HTTP
      • HTTPS
        • Authenticated
      • Huffman coding
      • Humble numbers
    • I
      • IBAN
      • Iccanobif primes
      • Identity matrix
      • Idoneal numbers
      • Imaginary base numbers
      • Implicit type conversion
      • Include a file
      • Inconsummate numbers in base 10
      • Increasing gaps between consecutive Niven numbers
      • Increment a numerical string
      • Index finite lists of positive integers
      • Infinity
      • Inheritance
        • Multiple
        • Single
      • Input loop
      • Integer comparison
      • Integer overflow
      • Integer roots
      • Integer sequence
      • Interactive programming repl
      • Inverted syntax
      • Isqrt integer square root of X
      • Iterated digits squaring
    • J
      • Jacobi symbol
      • Jacobsthal numbers
      • Jaro-Winkler distance
      • Jaro similarity
      • Jensen's Device
      • Jewels and stones
      • Jordan-Pólya numbers
      • JortSort
      • Josephus problem
      • JSON
      • Julia set
    • K
      • K-d tree
      • Kaprekar numbers
      • Keyboard input
        • Flush the keyboard buffer
        • Obtain a Y or N response
      • Knapsack problem
        • 0-1
        • Bounded
        • Continuous
        • Unbounded
      • Knight's tour
      • Knuth's algorithm S
      • Knuth's power tree
      • Knuth-Morris-Pratt string search
      • Knuth shuffle
      • Koch curve
      • Kolakoski sequence
      • Kosaraju
      • Kronecker product
      • Kronecker product based fractals
    • L
      • Lah numbers
      • Langton's ant
      • Largest difference between adjacent primes
      • Largest five adjacent number
      • Largest int from concatenated ints
      • Largest number divisible by its digits
      • Largest palindrome product
      • Largest prime factor
      • Largest product in a grid
      • Largest proper divisor of n
      • Last Friday of each month
      • Last letter-first letter
      • Last list item
      • Leap year
      • Least common multiple
      • Least m such that n m is prime
      • Left factorials
      • Legendre prime counting function
      • Leonardo numbers
      • Letter frequency
      • Levenshtein distance
        • Alignment
      • Linear congruential generator
      • List comprehensions
      • List rooted trees
      • Literals
        • Floating point
        • Integer
        • String
      • Logical operations
      • Long multiplication
      • Long primes
      • Long year
      • Longest common prefix
      • Longest common subsequence
      • Longest common substring
      • Longest increasing subsequence
      • Longest string challenge
      • Look-and-say sequence
      • Loop over multiple arrays simultaneously
      • Loops
        • Break
        • Continue
        • Do-while
        • Downward for
        • For
        • For with a specified step
        • Foreach
        • Infinite
        • N plus one half
        • Nested
        • While
      • LU decomposition
      • Lucas-Carmichael numbers
      • Lucas-Lehmer test
      • Ludic numbers
      • Luhn test of credit card numbers
      • Lychrel numbers
      • LZW compression
    • M
      • Möbius function
      • Mad Libs
      • Magic constant
      • Magic squares of doubly even order
      • Magic squares of odd order
      • Magnanimous numbers
      • Make directory path
      • Man or boy test
      • Mandelbrot set
      • Map range
      • Markov chain text generator
      • Matrix-exponentiation operator
      • Matrix multiplication
      • Matrix transposition
      • Matrix with two diagonals
      • Maximum triangle path sum
      • Maze generation
      • MD4
      • MD5
        • Implementation
      • Meissel Mertens constant
      • Menu
      • Mersenne primes
      • Mertens function
      • Metallic ratios
      • Metaprogramming
      • Metronome
      • Mian-Chowla sequence
      • Middle three digits
      • Miller Rabin primality test
      • Minimum multiple of m where digital sum equals m
      • Minimum numbers of three lists
      • Minimum positive multiple in base 10 using only 0 and 1
      • Minimum primes
      • Modular arithmetic
      • Modular exponentiation
      • Modular inverse
      • Modulinos
      • Monte Carlo methods
      • Montgomery reduction
      • Monty Hall problem
      • Mosaic matrix
      • Most frequent k chars distance
      • Motzkin numbers
      • Move-to-front algorithm
      • Multi-base primes
      • Multifactorial
      • Multiline shebang
      • Multiple distinct objects
      • Multiplication tables
      • Multiplicative order
      • Multiplicatively perfect numbers
      • Multisplit
      • Munchausen numbers
      • Munching squares
      • Mutual recursion
    • N
      • N'th
      • N-queens problem
      • N-smooth numbers
      • Named parameters
      • Names to numbers
      • Narcissist
      • Narcissistic decimal number
      • Native shebang
      • Natural sorting
      • Negative base numbers
      • Neighbour primes
      • Nested function
      • Next highest int from digits
      • Next special primes
      • Nice primes
      • Non-continuous subsequences
      • Non-decimal radices
        • Convert
        • Input
        • Output
      • Nth root
      • Null object
      • Number names
      • Number reversal game
      • Numbers divisible by their individual digits but not by the product of their digits
      • Numbers in base-16 representation that cannot be written with decimal digits
      • Numbers in base 10 that are palindromic in bases 2 4 and 16
      • Numbers which are the cube roots of the product of their proper divisors
      • Numbers whose binary and ternary digit sums are prime
      • Numbers whose count of divisors is prime
      • Numbers with equal rises and falls
      • Numbers with prime digits whose sum is 13
      • Numbers with same digit set in base 10 and base 16
      • Numeric separator syntax
      • Numerical integration
        • Adaptive Simpson's method
        • Gauss-Legendre Quadrature
    • O
      • Odd and square numbers
      • Odd squarefree semiprimes
      • Odd word problem
      • Old lady swallowed a fly
      • Old Russian measure of length
      • One-dimensional cellular automata
      • One-two primes
      • One of n lines in a file
      • Operator precedence
      • Optional parameters
      • Orbital elements
      • Order disjoint list items
      • Order two numerical lists
      • Ordered partitions
      • Ordered words
      • Own digits power sum
    • P
      • Padovan n-step number sequences
      • Palindrome dates
      • Palindrome detection
      • Palindrome pairs
      • Palindromic gapful numbers
      • Palindromic primes
      • Palindromic primes in base 16
      • Pandigital prime
      • Pangram checker
      • Parallel brute force
      • Parallel calculations
      • Parsing
        • RPN calculator algorithm
        • RPN to infix conversion
        • Shunting-yard algorithm
      • Partial function application
      • Partition an integer x into n primes
      • Partition function P
      • Pascal's triangle
        • Puzzle
      • Pascal matrix generation
      • Pathological floating point problems
      • Peano curve
      • Pell's equation
      • Pell numbers
      • Penrose tiling
      • Pentagram
      • Percentage difference between images
      • Percolation
        • Mean run density
        • Site percolation
      • Perfect numbers
      • Perfect shuffle
      • Perfect totient numbers
      • Perlin noise
      • Permutation test
      • Permutations
      • Permutations by swapping
      • Permutations with repetitions
      • Permutations with some identical elements
      • Pernicious numbers
      • Phrase reversals
      • Pi
      • Pick random element
      • Pierpont primes
      • Pig the dice game
        • Player
      • Piprimes
      • Pisano period
      • Plasma effect
      • Playfair cipher
      • Playing cards
      • Plot coordinate pairs
      • Pointers and references
      • Polymorphic copy
      • Polymorphism
      • Polynomial derivative
      • Polynomial long division
      • Polynomial regression
      • Polynomial synthetic division
      • Population count
      • Positive decimal integers with the digit 1 occurring exactly twice
      • Power set
      • Powerful numbers
      • Practical numbers
      • Price fraction
      • Primality by trial division
      • Primality by Wilson's theorem
      • Prime conspiracy
      • Prime decomposition
      • Prime numbers p for which the sum of primes less than or equal to p is prime
      • Prime numbers which contain 123
      • Prime numbers whose neighboring pairs are tetraprimes
      • Prime reciprocal sum
      • Prime triplets
      • Primes - allocate descendants to their ancestors
      • Primes n*2 m 1
      • Primes which contain only one odd digit
      • Primes whose first and last number is 3
      • Primes whose sum of digits is 25
      • Primes with digits in nondecreasing order
      • Primorial numbers
      • Priority queue
      • Probabilistic choice
      • Problem of Apollonius
      • Product of divisors
      • Product of min and max prime factors
      • Program name
      • Program termination
      • Proper divisors
      • Pseudo-random numbers
        • Combined recursive generator MRG32k3a
        • Middle-square method
        • PCG32
        • Splitmix64
        • Xorshift star
      • Pseudorandom number generator image
      • Pythagoras tree
      • Pythagorean quadruples
      • Pythagorean triples
    • Q
      • Quad-power prime seeds
      • Quadrat special primes
      • Quaternion type
      • Queue
        • Definition
        • Usage
      • Quickselect algorithm
      • Quine
    • R
      • Radical of an integer
      • Ramanujan's constant
      • Ramanujan primes
        • Twins
      • Ramer-Douglas-Peucker line simplification
      • Ramsey's theorem
      • Random number generator device
      • Random number generator included
      • Random numbers
      • Range expansion
      • Ranking methods
      • Rate counter
      • Read a configuration file
      • Read a file character by character
        • UTF8
      • Read a file line by line
      • Read a specific line from a file
      • Read entire file
      • Readline interface
      • Real constants and functions
      • Recaman's sequence
      • Reduced row echelon form
      • Reflection
        • List methods
      • Regular expressions
      • Remove duplicate elements
      • Remove lines from a file
      • Rename a file
      • Rep-string
      • Repeat
      • Repeat a string
      • Repunit primes
      • Resistor mesh
      • Respond to an unknown method call
      • Return multiple values
      • Reverse a string
      • Reverse the gender of a string
      • Reverse words in a string
      • Rhonda numbers
      • Rice coding
      • Riordan numbers
      • Rock-paper-scissors
      • Roman numerals
        • Decode
        • Encode
      • Roots of a function
      • Roots of a quadratic function
      • Roots of unity
      • Rosetta Code
        • Count examples
        • Fix code tags
        • Rank languages by popularity
      • Rot-13
      • RSA code
      • Run-length encoding
      • Run as a daemon or service
      • Runge-Kutta method
      • Runtime evaluation
        • In an environment
      • Ruth-Aaron numbers
    • S
      • S-expressions
      • Safe and Sophie Germain primes
      • Safe primes and unsafe primes
      • Sailors coconuts and a monkey problem
      • Same fringe
      • Sattolo cycle
      • Scope
        • Function names and labels
      • Search a list
      • Search a list of records
      • Secure temporary file
      • SEDOLs
      • Self-describing numbers
      • Self numbers
      • Semiprime
      • Semordnilap
      • Send an unknown method call
      • Separate the house number from the street name
      • Sequence nth number with exactly n divisors
      • Sequence of non-squares
      • Sequence of primes by trial division
      • Sequence of primorial primes
      • Sequence smallest number greater than previous term with exactly n divisors
      • Sequence smallest number with exactly n divisors
      • Set
      • Set consolidation
      • Seven-sided dice from five-sided dice
      • Sexy primes
      • SHA-1
      • SHA-256
      • Shell one-liner
      • Shoelace formula for polygonal area
      • Short-circuit evaluation
      • Shortest common supersequence
      • Show the decimal value of a number of 1s appended with a 3 then squared
      • Show the epoch
      • Sierpinski arrowhead curve
      • Sierpinski carpet
      • Sierpinski curve
      • Sierpinski pentagon
      • Sierpinski square curve
      • Sierpinski triangle
        • Graphical
      • Sieve of Eratosthenes
      • Simple windowed application
      • Simulated annealing
      • Singleton
      • Singly-linked list
        • Element definition
        • Element insertion
        • Traversal
      • Sleep
      • Smallest numbers
      • Smallest square that begins with n
      • Smarandache-Wellin primes
      • Smarandache prime-digital sequence
      • Smith numbers
      • Snake
      • Sockets
      • Solve triangle solitaire puzzle
      • Sort a list of object identifiers
      • Sort an array of composite structures
      • Sort an integer array
      • Sort disjoint sublist
      • Sort numbers lexicographically
      • Sort primes from list to a list
      • Sort stability
      • Sort three variables
      • Sort using a custom comparator
      • Sorting algorithms
        • Bead sort
        • Bogosort
        • Bubble sort
        • Circle Sort
        • Cocktail sort
        • Comb sort
        • Counting sort
        • Cycle sort
        • Gnome sort
        • Heapsort
        • Insertion sort
        • Merge sort
        • Pancake sort
        • Patience sort
        • Permutation sort
        • Quicksort
        • Radix sort
        • Selection sort
        • Shell sort
        • Sleep sort
        • Stooge sort
        • Strand sort
      • Soundex
      • Sparkline in unicode
      • Special divisors
      • Special factorials
      • Special neighbor primes
      • Speech synthesis
      • Spelling of ordinal numbers
      • Sphenic numbers
      • Spiral matrix
      • Split a character string based on change of character
      • SQL-based authentication
      • Square-free integers
      • Square but not cube
      • Square form factorization
      • Stable marriage problem
      • Stack
      • Stair-climbing puzzle
      • Standard deviation
      • Statistics
        • Basic
        • Normal distribution
      • Stem-and-leaf plot
      • Stern-Brocot sequence
      • Stirling numbers of the first kind
      • Stirling numbers of the second kind
      • Strange numbers
      • Strange plus numbers
      • Strange unique prime triplets
      • Stream merge
      • String append
      • String case
      • String comparison
      • String concatenation
      • String interpolation included
      • String length
      • String matching
      • String prepend
      • Strip a set of characters from a string
      • Strip block comments
      • Strip comments from a string
      • Strip control codes and extended characters from a string
      • Strip whitespace from a string
        • Top and tail
      • Strong and weak primes
      • Sub-unit squares
      • Subleq
      • Subset sum problem
      • Substitution cipher
      • Substring
        • Top and tail
      • Substring primes
      • Subtractive generator
      • Successive prime differences
      • Sudoku
      • Suffix tree
      • Sum and product of an array
      • Sum and product puzzle
      • Sum digits of an integer
      • Sum multiples of 3 and 5
      • Sum of a series
      • Sum of divisors
      • Sum of first n cubes
      • Sum of primes in odd positions is prime
      • Sum of square and cube digits of an integer are primes
      • Sum of squares
      • Sum of the digits of n is substring of n
      • Sum of two adjacent numbers are primes
      • Sum to 100
      • Summarize primes
      • Summation of primes
      • Sunflower fractal
      • Super-d numbers
      • Superellipse
      • Superpermutation minimisation
      • Sutherland-Hodgman polygon clipping
      • Sylvester's sequence
      • Symmetric difference
      • System time
    • T
      • Table creation
        • Postal addresses
      • Take notes on the command line
      • Tarjan
      • Tau function
      • Tau number
      • Taxicab numbers
      • Temperature conversion
      • Terminal control
        • Clear the screen
        • Coloured text
        • Dimensions
        • Display an extended character
        • Preserve screen
        • Ringing the terminal bell
        • Unicode output
      • Test integerness
      • Text between
      • Text processing
        • 1
        • 2
        • Max licenses in use
      • Textonyms
      • The ISAAC cipher
      • The Twelve Days of Christmas
      • Thiele's interpolation formula
      • Thue-Morse
      • Time a function
      • Tokenize a string
      • Tokenize a string with escaping
      • Tonelli-Shanks algorithm
      • Top rank per group
      • Topic variable
      • Topological sort
      • Totient function
      • Towers of Hanoi
      • Trabb Pardo Knuth algorithm
      • Tree traversal
      • Triangular numbers
      • Trigonometric functions
      • Triplet of three numbers
      • Truncatable primes
      • Truncate a file
      • Truth table
      • Twelve statements
      • Twin primes
      • Two sum
    • U
      • Ulam numbers
      • Ulam spiral for primes
      • Ultra useful primes
      • Unbias a random generator
      • Undefined values
      • Unicode strings
      • Unicode variable names
      • Universal Turing machine
      • Unix
        • Ls
      • Unprimeable numbers
      • URL decoding
      • URL encoding
      • User input
        • Graphical
        • Text
      • UTF-8 encode and decode
    • V
      • Vampire number
      • Van der Corput sequence
      • Van Eck sequence
      • Variable-length quantity
      • Variadic function
      • Vector
      • Vector products
      • Verify distribution uniformity
        • Chi-squared test
      • Vigenère cipher
      • Visualize a tree
      • Vogel's approximation method
      • Voronoi diagram
    • W
      • Wagstaff primes
      • Walk a directory
        • Non-recursively
        • Recursively
      • Water collected between towers
      • Web scraping
      • Weird numbers
      • Welch's t-test
      • Wieferich primes
      • Wilson primes of order n
      • Window creation
      • Wireworld
      • Wolstenholme numbers
      • Word break problem
      • Word frequency
      • Word wrap
      • Write entire file
      • Write float arrays to a text file
      • Write language name in 3D ASCII
    • X
      • Xiaolin Wu's line algorithm
      • XML
        • DOM serialization
        • Input
        • Output
        • XPath
      • XML validation
    • Y
      • Y combinator
      • Yin and yang
    • Z
      • Zebra puzzle
      • Zeckendorf number representation
      • Zero to the zero power
      • Zhang-Suen thinning algorithm
      • Zig-zag matrix
      • Zsigmondy numbers
      • Zumkeller numbers
  • The End
Powered by GitBook
On this page

Was this helpful?

  1. Programming tasks
  2. J

Jordan-Pólya numbers

func jordan_pólya_numbers(n, k, F, callback) {

    var factors = F.sort.uniq
    var factors_end = factors.end

    if (k == 0) {
        callback(1)
        return nil
    }

    func (m, k, i=0) {

        if (k == 1) {

            var L = idiv(n,m)

            for j in (i..factors_end) {
                with (factors[j]) {|q|
                    q > L && break
                    callback(m*q)
                }
            }

            return nil
        }

        var L = idiv(n,m).iroot(k)

        for j in (i..factors_end) {
            with (factors[j]) { |q|
                q > L && break
                __FUNC__(m*q, k-1, j)
            }
        }
    }(1, k)

    return nil
}

func inverse_factorial_W(n) {
    var l = (log(n) - log(Num.tau)/2)
    l / lambert_w(l / Num.e) - 1/2
}

var limit = 100e6
var factors = (2..inverse_factorial_W(limit).int -> map { .factorial })
var terms = Set()

for k in (0 .. limit.ilog2) {
    jordan_pólya_numbers(limit, k, factors, {|v| terms << v })
}

terms.sort!

say "The first 50 Jordan-Pólya numbers:"
terms.first(50).each_slice(10, {|*a|
    a.map { '%5s' % _ }.join(' ').say
})

say "\nThere are #{terms.len} Jordan-Pólya numbers <= #{limit.commify}, where largest is #{terms.last}."

Output:

The first 50 Jordan-Pólya numbers:
    1     2     4     6     8    12    16    24    32    36
   48    64    72    96   120   128   144   192   216   240
  256   288   384   432   480   512   576   720   768   864
  960  1024  1152  1296  1440  1536  1728  1920  2048  2304
 2592  2880  3072  3456  3840  4096  4320  4608  5040  5184

There are 367 Jordan-Pólya numbers <= 100,000,000, where largest is 99532800.
PreviousJewels and stonesNextJortSort

Last updated 5 months ago

Was this helpful?