30
\$\begingroup\$

A Cullen Number is any number that is contained in the sequence generated using the formula:

C(n) = (n*2^n)+1.

Your Task:

Write a program or function that receives an input and outputs a truthy/falsy value based on whether the input is a Cullen Number.

Input:

A non-negative integer between 0 and 10^9 (inclusive).

Output:

A truthy/falsy value that indicates whether the input is a Cullen Number.

Test Cases:

Input:    Output:
1   --->  truthy
3   --->  truthy
5   --->  falsy
9   --->  truthy
12  --->  falsy
25  --->  truthy

Scoring:

This is , so the lowest score in bytes wins.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ What's the range of n? In particular, is 1 a Cullen Number? \$\endgroup\$
    – user62131
    Jun 17, 2017 at 20:15
  • 4
    \$\begingroup\$ @ais523 according to OEIS, it is. n seems to be 0-based. \$\endgroup\$
    – steenbergh
    Jun 17, 2017 at 20:25
  • \$\begingroup\$ Fair enough. Just needed to know whether my Jelly answer should have an or R in it :-) \$\endgroup\$
    – user62131
    Jun 17, 2017 at 20:25
  • 2
    \$\begingroup\$ Related \$\endgroup\$
    – DJMcMayhem
    Jun 17, 2017 at 20:36
  • \$\begingroup\$ Umm, what's with the downvote? \$\endgroup\$
    – Gryphon
    Jun 20, 2017 at 13:47

35 Answers 35

1
2
0
\$\begingroup\$

QBIC, 24 bytes

[0,:|~a*(2^a)+1=b|_Xq}?0

Explanation

[0,:|           FOR a = 0 to b (input from cmd line)
~a*(2^a)+1=b    IF calculating this a results in b
|_Xq            THEN quit, printing 1
}               NEXT a
?0              We haven't quit early, so print 0 and end.
\$\endgroup\$
0
\$\begingroup\$

k, 19 bytes

{&1=x-{x**/x#2}'!x}

Try it online. Truthy is an array with a number in it: ,3 or ,0 et cetera. Falsey is an empty array: () or !0 depending on your interpreter.

\$\endgroup\$
0
\$\begingroup\$

Java (OpenJDK 8), 56 bytes

i->{int n,c;for(n=0;(c=n*(2<<n++-1)+1)<i;);return c==i;}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Pari/GP, 25 bytes

n->!prod(i=0,n,n-i*2^i-1)

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Thunno 2 -c, 5 bytes

ĖıỴ;Ƈ

Try it online!

Port of user62131's Jelly answer.

Thunno 2, 6 bytes

ĖDO×⁺Ƈ

Try it online!

Explanation

ĖıỴ;Ƈ  # Implicit input
       # Decrement the input
Ė      # Push [0..input-1]
  Ỵ    # Left bit-shift each
 ı ;   # number by itself
    Ƈ  # Is (input - 1)
       # in this list?
       # Implicit output
ĖDO×⁺Ƈ  # Implicit input
Ė       # Push [0..input]
 D      # Duplicate it
  O     # Push 2 ** that
   ×    # Multiply together
    ⁺   # Increment each
     Ƈ  # Is the input
        # in this list?
        # Implicit output
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.