4 kyu

Twice linear

584 of 24,305g964

Description:

Consider a sequence u where u is defined as follows:

  1. The number u(0) = 1 is the first one in u.
  2. For each x in u, then y = 2 * x + 1 and z = 3 * x + 1 must be in u too.
  3. There are no other numbers in u.

Ex: u = [1, 3, 4, 7, 9, 10, 13, 15, 19, 21, 22, 27, ...]

1 gives 3 and 4, then 3 gives 7 and 10, 4 gives 9 and 13, then 7 gives 15 and 22 and so on...

Task:

Given parameter n the function dbl_linear (or dblLinear...) returns the element u(n) of the ordered (with <) sequence u (so, there are no duplicates).

Example:

dbl_linear(10) should return 22

Note:

Focus attention on efficiency

Mathematics
Algorithms

Similar Kata:

More By Author:

Check out these other kata created by g964

Stats:

CreatedDec 17, 2015
PublishedDec 17, 2015
Warriors Trained87785
Total Skips22260
Total Code Submissions237301
Total Times Completed24305
Ruby Completions584
Python Completions8146
JavaScript Completions5932
CoffeeScript Completions23
Java Completions3051
C# Completions1411
Haskell Completions348
Clojure Completions95
C++ Completions1931
PHP Completions428
TypeScript Completions411
Crystal Completions14
F# Completions45
C Completions823
Rust Completions592
Swift Completions179
Go Completions504
R Completions95
Shell Completions20
OCaml Completions42
Objective-C Completions17
Kotlin Completions235
Julia Completions53
Fortran Completions15
NASM Completions13
Elixir Completions34
Scala Completions147
PowerShell Completions25
Nim Completions11
Reason Completions4
Racket Completions25
Prolog Completions16
Haxe Completions11
Dart Completions117
CommonLisp Completions33
Pascal Completions12
Factor Completions9
Raku Completions11
Perl Completions17
Lua Completions56
Elm Completions3
COBOL Completions10
D Completions10
Erlang Completions5
Total Stars2902
% of votes with a positive feedback rating89% of 2841
Total "Very Satisfied" Votes2299
Total "Somewhat Satisfied" Votes432
Total "Not Satisfied" Votes110
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • joh_pot Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • LesnyRumcajs Avatar
  • Voile Avatar
  • Bubbler Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • Kacarott Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad