Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recamans

Build Status Coverage

Recamán's sequence $a_0, a_1, a_2\ldots$ is defined as:

$$ a_n = \begin{cases} 0 && \text{if } n = 0 \\ a_{n - 1} -n && \text{if } a_{n - 1} -n > 0 \text{ and is not already in the sequence} \\ a_{n - 1} + n && \text{otherwise} \end{cases} $$

This code in this package is performant, for simple code. But it is far from research code.

Here are some examples

julia> using Recamans
julia> r = recaman(10); # construct the first 10 entries in the sequence
julia> r[1]
0
julia> numunique(recaman(100))
91

A list of the entries among the first 50 with multiplicity 2.

julia> print(multmap(recaman(50))[2])
[43, 42, 79, 78]

A list of multiplicities of entries and the number of values with that multiplicity.

julia> sort(Dict( m => length(v) for (m, v) in multmap(recaman(10_000))))
OrderedCollections.OrderedDict{Int64, Int64} with 7 entries:
  1 => 6276
  2 => 1009
  3 => 294
  4 => 64
  5 => 22
  6 => 74
  7 => 2

The return type of recaman is Recaman, which contains the sequence as a Vector and a Set of the entries. The latter is necessary when building the sequence and is preserved in the result. Base.in(::Recaman) is forwarded to the set.

See Recamans.multmap. Recamans.numunique.

Several methods that forward the call to the list (the Vector) are present.

  • StatsBase.countmap
  • In Base: getindex, maximum, minimum, extrema, length, unique, sort, view

About

Recamáns sequence, pedagogical implementation for Julia

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Packages

Contributors

Languages