g | x | w | all
Bytes Lang Time Link
011Pip250805T174653ZDLosc
050Kotlin230717T181208ZCactusro
004Thunno 2 S!230715T101525ZThe Thon
003Vyxal G230604T135011Zlyxal
027Desmos230604T104931ZAiden Ch
048Scala230604T073852Z138 Aspe
038C clang230604T044503Zc--
004Nekomata + e230604T013635Zalephalp
041Desmos230603T224045ZDadsdy
054Lua230603T214720Zbluswimm
016StackCell230603T202356ZStarwort
027><> Fish230602T190035Zchunes
006Pyt230228T131816ZKip the
028Arturo230228T025042Zchunes
041Proton200919T201343Zhyperneu
015Wolfram Language Mathematica200215T090555ZRoman
100Rockstar200915T202507ZShaggy
011Pip r200916T041050ZRazetime
065C++ gcc200215T102505ZVarad Ma
064TSQL200217T130243Zt-clause
018Octave200217T132635ZSanchise
051C gcc200214T143942ZS.S. Ann
040Clojure200213T173335ZMattPutn
00305AB1E200213T080025ZKevin Cr
031Octave200212T183620ZHiddenBa
045Jelly200212T185502ZRGS
008Dyalog APL200213T220549ZFrownyFr
018APL Dyalog Extended200213T210457ZJeff Zei
004Husk200213T134032ZFyr
049PowerShell200212T183420ZAdmBorkB
052Python 3200213T112435ZÉmi
015Burlesque200213T164500ZDeathInc
nanPHP200212T220532ZGuillerm
052Python 3200213T151201Zruohola
043Python 3200212T211155ZNoodle9
029Zsh200213T112526ZGammaFun
029Python 3200213T010149Zovs
011Pyth200213T081009Zar4093
013Keg200213T033329Zlyxal
031Ruby200213T073104ZG B
028GolfScript200213T022924Zuser9206
026Perl 5 apl MListUtil=reduce200213T002853ZXcali
011x8616 machine code200212T224633Z640KB
089Clojure200212T223119Zsoweli N
028Retina 0.8.2200212T220917ZNeil
014J200212T202706ZGalen Iv
026R200212T191628ZKirill L
030Haskell200212T192818Z79037662
024JavaScript ES6200212T184902ZArnauld
006Japt v2.0a0200212T182930ZShaggy

Pip, 11 bytes

$<=g*R E,#g

Accepts the sequence of numbers as command-line arguments. Attempt This Online!

Explanation

A different approach than Razetime's 11-byte answer.

$<=g*R E,#g
          g  List of command-line args
         #   Length
        ,    Range
       E     2 to the power of each number in the range
     R       Reverse, giving a list of descending powers of 2
   g*        Multiply itemwise by the list of args
$<=          Is each element of the result <= the next element?

Kotlin, 50 bytes

{a:IntArray->(0..a.size-2).first{a[it]*2>a[it+1]}}

Try it online!

Int for false and Nothing for true (throws NoSuchElementException)

Thunno 2 S!, 4 bytes

Ṣ$ṫ<

Try it online! Link is to verify all test cases.

Explanation

Ṣ$ṫ<  # Implicit input
Ṣ     # Deltas of input
 $ṫ   # Input without last item
   <  # Compare the two lists
      # Check if the sum is 0
      # Implicit output

Vyxal G, 3 bytes

¯>Ṫ

Try it Online!

A port of 05AB1E

Explained

¯>Ṫ
¯   # deltas
 >  # greater than original input
  Ṫ # last item removed
# G flag gets biggest item.

Desmos, 27 bytes


f(l)=\{l[2...]<2l,0\}.\max

Returns 0 for doubling sequences and 1 for non-doubling sequences.

Try It On Desmos!

Try It On Desmos! - Prettified

Scala, 48 bytes

Golfed version. Try it online!

_.sliding(2).map{case Seq(a,b)=>b/a}.exists(_<2)

Ungolfed version. Try it online!

object Main {

  def f(x: List[Double]): Boolean = {
    x.sliding(2).map { case List(a, b) => b / a }.exists(_ < 2)
  }

  def main(args: Array[String]): Unit = {
    val data = List(
      List(10.0, 20.0, 30.0),
      List(10.0, 20.0, 40.0),
      List(1.0, 2.0, 3.0),
      List(1.0, 2.0, 4.0),
      List(1.0, 2.0, 10.0),
      List(1.0, 1.0),
      List(10.0, 1.0)
    )

    println(data.map(f))
  }
}

C (clang), 38 bytes

Returns 0 for doubling sequences, 1 otherwise.

f(*a,s){return--s?*a*2>*++a|f(a,s):0;}

Try it online!

Nekomata + -e, 4 bytes

∆$i≥

Attempt This Online!

-e      Check that
∆       the delta
   ≥    is greater than or equal to
 $i     the original list without the last item

Desmos, 41 Bytes

f(n)=1-l(n[2n[0...l(n)]>n])
l(n)=n.length

Try It Over Here

Lua, 54 bytes

for i=2,#arg do b=b or arg[i-1]*2>0+arg[i]end print(b)

Try it online!

true and false are swapped.

StackCell, 16 bytes

:[{::+}x>?.:]'Y;

Explanation:

><> (Fish), 27 bytes

rl1)?v1n;n0<
@:$+:<|.!:0^?)

Try it

Pyt, 6 bytes

↔ʁ/2≥Π

Try it online!

Outputs 1 if doubling array, 0 otherwise

↔           implicit input; flip array
 ʁ/         ʁeduce by division
   2≥       is each element greater than or equal to 2?
     Π      take product of list; implicit print

Arturo, 29 28 bytes

$=>[l:0every?&'x[x>=l*2l:x]]

Try it

Proton, 41 bytes

a=>all([a[x+1]/a[x]>=2for x:0..len(a)-1])

Try it online!

This isn't very efficient because Proton is too buggy to do this right.

Wolfram Language (Mathematica), 25 15 bytes

Min@Ratios@#<2&

Returns True for false and False for true.

-10 bytes thanks to @att

Try it online!

Rockstar, 101 100 bytes

listen to F
D's0
while F
listen to T
let R be F/T-.5
turn up R
let D be D or R
let F be T

say not D

Try it here (Code will need to be pasted in, with each input integer on an individual line)

Pip -r, 11 bytes

$&2*_<=BMPg

Try it online!

Takes input numbers separater by newlines. (-r flag)

Explanation

$&2*_<=BMPg  g → input
        MP   pass pairs from g to function on the left
  2*_<=B     a ≤ b? for pair (a, b)
$&           Fold with & operator

C++ (gcc), 75 71 67 65 bytes

int f(int*a,int s){int r=1;for(;--s;)r*=a[s]>=2*a[s-1];return r;}

Try it online!

T-SQL, 64 bytes

This can handle positive values above 0

Returns -1 for true, 0 for false

SELECT~min(1/~x)FROM(SELECT a/lag(2*a)over(ORDER BY i)x FROM @)y

Try it online

Octave, 18 bytes

@(e)istril(e<2*e')

Try it online!

Octave has a nice feature known as broadcasting. Here, we take broadcast less-than of the input and the input doubled, by transposing the input. This creates a matrix of ones and zeroes. Iff this matrix is lower triangular (no nonzero entries above the diagonal), the sequence is a doubling sequence.

C (gcc), 51 bytes

r;f(a,l)int*a;{for(r=--l;l--;)r=*a*2>*++a?0:r;a=r;}

Pretty simple. For every element of the array, check if the current element times two is greater than the next element.

Returns zero if it is not a doubling sequence and non-zero (or more specifically the length minus one) otherwise.

-10 bytes thanks to ceilingcat!

Try it online!

Clojure, 42 40 bytes

(fn[s](every? #(<= 2%)(map /(rest s)s)))

Try it online!

Basically the obvious pairwise thing, with a fun way to generate consecutive pairs of a sequence.

05AB1E, 4 3 bytes

Crossed out 4 is still regular 4 ;(

¥›à

Outputs 0 for truthy and 1 for falsey.

Port of @RGS' first Jelly answer, so make sure to upvote him!
-1 byte thanks for @Grimmy for mentioning any two distinct truthy/falsey values are allowed, so I can drop the invert at the end

Try it online or verify all test cases.

Explanation:

¥    # Get the deltas (forward differences) of the (implicit) input-list
 ›   # Check for each whether it's larger than value at the same position in the (implicit)
     # input-list, which automatically ignores the trailing item of the input
  à  # Get the maximum of this, to check if any are truthy
     # (after which it is output implicitly as result)

Octave, 46 33 31 bytes

@(n)all(2*n(1:end-1)<=n(2:end))

Try it online!

Thanks to Luis Mendo for all. Much shorter!

Jelly, 4 (5?) bytes

Monadic link taking the list as input.

I<ṖẸ

If I am allowed to output 0 for Truthy and 1 for Falsy... Otherwise,

I<ṖẸ¬

You can try all test cases!

Notice that \$x_{i+1} \geq 2x_i \iff x_{i+1} - x_i \geq x_i\$.

 <      Compare
I       the forward differences
  Ṗ     with the original list without the last item.
   Ẹ    Check if any comparison returned true
    ¬   and negate that

Jelly, 6 bytes

We can instead take pairwise quotients and check directly if they satisfy the inequality with this monadic link:

÷Ɲ>.Ẹ¬

You can verify all test cases!

÷Ɲ      Compute the quotient for all pairs of elements in the input list.
  >.    See if the elements are greater than 0.5
    Ẹ   and take the "OR" of that list,
     ¬  finishing off with the negation of that.

Dyalog APL, 8 bytes

∧/2≤2÷/÷

Try it online!

APL (Dyalog Extended), 18 bytes

∧/{(2ׯ1↓⍵)≤(1↓⍵)}

Try it online!

Decomposition/Explanation:

⍵ is the input vector (test cases). Output will be 1 or 0; 1 is TRUE/truthy, 0 is FALSE/falsey.

            (1↓⍵)  - Drop the first element from the input vector (call it LASTN)
      ¯1↓⍵         - Drop the last element from the input vector, separately, and
   (2×    )        - multiply it by two (call the result DFIRSTN)
           ≤       - compare corresponding elements - Each element of LASTN should be 
                     equal to or greater than the corresponding element of DFIRSTN.
  {              } - encapsulate as a dfn to apply to the input vector. This dfn will
                     return 0 for elements where the comparison is FALSE, 1 where TRUE
∧/                 - AND (Boolean conjunction) reduction of the vector. ∧/ A B C D ... is
                     equivalent to A ∧ B ∧ C ∧ D ∧ ..., and if there are any FALSE values
                     in the vector, the result will be FALSE (0)

The linked TIO has the test cases and a REPL; you can test your own vectors by changing the input field, one vector per line.

Husk, 4 bytes

Λ·≤D

Try it online!

Returns 0 if False, a positive number if True.

Λ     Check if adjacent pairs of elements satisfy the predicate
 · D    by doubling the first number
  ≤     and checking if the second number is less than it

PowerShell, 49 bytes

param($n)($n|?{$_-ge2*$l;$l=$_}).count-eq$n.count

Try it online!

Takes input $n then uses a Where-Object to pull out those elements that are -greaterthanorequal to 2 times the $last element. Those are left on the pipeline, and we set our $last element for the next iteration. We then take the .count of that collection and make sure it's -equal to the .count of our input array. That Boolean value is left on the pipeline and output is implicit.


If we don't need to worry about negative numbers, we can use the following instead, thanks to mazzy:

PowerShell, 27 bytes

!($args|?{$_-lt2*$l;$l=$_})

Try it online!

This again takes input $args, and pulls out those items where they're -lessthan 2 times the $last element (i.e., they're not "big enough" to make the doubling sequence). If there are any left, then the Boolean-not surrounding the collection results in False, otherwise if the collection is empty we get True. That's left on the pipeline and output is implicit.

Python 3, 52 bytes

lambda l:all(2*l[i]<=l[i+1]for i in range(len(l)-1))

Try it online!

Burlesque, 15 bytes

raJ0{2.*>=}LO==

Try it online!

Finally got an answer where using LO is advantageous.

ra   # Read as array
J    # Duplicate
0    # 0 (start of loop)
{2.* # Double
 >=  # Greater than or equal to previous elem
}LO  # Loop through array performing op on each pair
     # Push to array if true
==   # Arrays are the same

Burlesque, 16 bytes

Alternative (but longer) solutions using 2-grams and map-reduce

ra2CO{./2>=}m^r&
ra2CO{p^./2>=}al

Try it online!

PHP, 53 49 47 43 bytes

for(;$argv[$i++]*2<=$k=$argv[$i];);echo!$k;

Try it online!

-4 bytes thanks to @Kaddath.

Python 3, 52 bytes

lambda l:all(l[i-1]*2<=l[i]for i in range(1,len(l)))

Try it online!

Python 3, 57 \$\cdots\$ 44 43 bytes

Saved a byte thanks to kaya3!!!

lambda l:all(b>=a*2for a,b in zip(l,l[1:]))

Try it online!

Zsh, 29 bytes

(($1*2<=$2))&&${=3+$0 ${@:2}}

Try it online!

(($1*2<=$2))&&     # return false if 2 * $1 > $2
  ${=3+$0 ${@:2}}  # recursive call:
  ${ 3+         }  # if there is a third parameter
       $0 ${@:2}   # ... substitute the program name ($0), " ", "$2 $3 $4 "...
  ${=           }  # ... then split on spaces

In cases like a && or b ||, Zsh will simply return with the exit code of the previous command.

Python 3, 37 29 bytes

-8 bytes thanks to xnor.

Fails for doubling sequences, completes otherwise.

f=lambda a,*b:2*a<=b[0]>f(*b)

Try it online!

Python 3, 40 bytes

f=lambda a,*b:b==()or 2*a<=b[0]and f(*b)

Try it online! Test suite by Noodle9.

Pyth, 11 bytes

<1hS/MP.T,t

Try it online!

Explanation

<1hS/MP.T,tQQ  # full program, last two Q (=input) are implicit

         ,tQQ  # [Q[1:], Q]
       .T      # Transpose -> [[Q[1],Q[0]], [Q[2],Q[1]], ...,  [Q[-1]]]
      P        # all but last element (gets rid of lone Q[-1])
    /M         # Map all pairs by division
   S           # Sort quotients
  h            # first element (minimum quotient)
<1             # is 1 smaller than this?

Keg, -rR, 15 13 bytes

1&÷{!;|":'½≤⑾

Try it online!

-2 bytes thanks to @a'_'

Answer History

15 Bytes

1&÷^{!;|":'2*≥⑾

Try it online!

I'm quite happy with this answer, and I'm quite happy with the explanation.

Explained

1&

First, we store the number 1 in the register. This will end up being the means by which the result is shown.

÷^

We then item split the input list and reverse it, so that things are in descending order.

{!;|

Now, we start a while loop that will run while the length of the stack - 1 is not zero.

":'

This bit of the algorithm took me a while to visualise and write... I had to resort to move playing cards around my living room floor to understand which stack shifting mechanics to use.

Lets say the input stack (after item splitting and reversal) is [4, 2, 1]. Right shifting the stack (") gives [1, 4, 2], duplicating the top gives [1, 4, 2, 2] and then left shifting the stack (') gives [4, 2, 2, 1].

We do this so that we can compare the top of the stack with the next item and preserve that second item (in other words, circumnavigate the side effects of operators consuming stack items).

2*≥

We then multiply the top item by two and see if the result is greater than or equal to the next item in the series.

The result is then augmented multiplied into the register and the while loop continues.

-rR prints the value of the register at the end of execution as an integer.

Ruby, 31 bytes

->l{x,*l=l;l.all?{|y|x*2<=x=y}}

Try it online!

GolfScript, 28 bytes

GolfScript has its clunky zip function (I need a lot of code to convert the string to a list of codepoints).

.1>]zip);{1/~0=\0=2*<!}%{&}*

Try it online!

Explanation

.1>]zip                      # Zip itself with itself without the first item
       );                    # Discard the extra trailing item
         {1/~0=\0=2*<!}%     # Is the first item * 2 greater than or equal to the next item?
                        {&}* # All of them?

GolfScript, 31 bytes

.(+{2/}%]zip);{1/{0=}%~>!}%{&}*

Try it online!

Perl 5 -apl -MList::Util=reduce, 26 bytes

reduce{$_&&=$a<=$b/2;$b}@F

Try it online!

x86-16 machine code, 11 bytes

49          DEC  CX                 ; adjust to loop N-1 times
        N_LOOP:
AD          LODSW                   ; load N1 into AX 
D1 E0       SHL  AX, 1              ; double AX 
39 04       CMP  WORD PTR[SI], AX   ; compare to N2
7C 02       JL   DONE               ; if less, return
E2 F7       LOOP N_LOOP             ; keep looping 
        DONE:
C3          RET                     ; return to caller

Input array at [SI], length in CX. Returns ZF if truthy, NZ if falsey.

Clojure, 89 bytes

(fn[x](#(cond(empty? %)true(>=(first %)(* %2 2))(recur(rest %)(first %)):else false)x 0))

Try it online!

The obvious (and longest) solution to the problem.

Retina 0.8.2, 28 bytes

\d+
$*
((^|,(?=\3\3))(1+))+$

Try it online! Link includes test cases. Explanation:

\d+
$*

Convert to unary.

  ^|

On the first repeat, match at the beginning, otherwise...

    ,(?=\3\3)

... match a comma followed by a number which is at least twice as big as the previous match.

              (1+)

Capture the number so that it can be compared on the next repeat.

(                 )+$

All entries in the list need to satisfy the above conditions.

J, 14 bytes

[:*/0.5>:2%/\]

Try it online!

R, 27 26 bytes

all(diff(log2(scan()))>=1)

Try it online!

1 byte saved by Giuseppe.

Haskell, 30 bytes

f(x:s)=any(<2)$zipWith(/)s$x:s

Try it online!

True for false and False for true.

JavaScript (ES6),  26  24 bytes

Saved 2 bytes thanks to @Grimmy

a=>!a.some(n=>2*a>(a=n))

Try it online!

Japt v2.0a0, 6 bytes

ä÷ e§½

Try it

ä÷ e§½     :Implicit input of array
ä          :Consecutive pairs
 ÷         :  Reduced by division
   e       :All
    §½     :  Less than or equal to 0.5