A man from the stars has come to Earth! Luckily the president of the United States, Donald Trump, has an infinity-sided die. Using this die, he can conjure up a number which you, the mayor of Podunk, must use to determine who should be sent to stop the invader! But be careful, you can only send a limited amount of bytes on the back of your frog!

Given a user input (which will be a positive integer), you must return a string depending on what category the number is in.

  • If the number is a Fibonacci number, you must output Ness.
  • If the number is a Lucas number, you must output Lucas.
  • If the number is both a Lucas number and a Fibonacci number, you must output Travis.
  • If the number is neither a a Lucas number nor a Fibonacci number, you must output Pippi.


Here are a bunch of test cases:

1 => Travis
2 => Travis
3 => Travis
4 => Lucas
5 => Ness
6 => Pippi
7 => Lucas
8 => Ness
610 => Ness
722 => Pippi
843 => Lucas


  • This is , the shortest answer in bytes wins.
  • You program may be a full program or a(n anonymous) function.


There are a couple bonuses that you can use to help your frog get the data to President Trump faster:

  • For -15 bytes: If the input number is 2016, you must output Trump, as he is at the peak of his presidency.
  • 30
    \$\begingroup\$ For the record, I am not one of those Starmen. \$\endgroup\$ Nov 22 '15 at 0:15
  • 1
    \$\begingroup\$ Giygas isn't happy about this (ctrl+f "Giygas") \$\endgroup\$
    – Cilan
    Nov 22 '15 at 0:27
  • \$\begingroup\$ @DavidCarraher Just like how some definitions start the Fibonacci series off with 0, 1 while others start with 1, 1, I believe this depends on the definition you use. It's not uncommon to see the Lucas numbers start with 2, 1, e.g. OEIS has both versions (1, 2), but the one starting with 2 is the definition phase has gone with. \$\endgroup\$
    – Sp3000
    Nov 22 '15 at 1:44
  • 2
    \$\begingroup\$ Votes are supposed to be hidden, but I'll still say I really don't like politics and that it has affected my voting on this question. Would the asker mind removing politics from the question or at least explain me any pun I may have missed? A political reference is baked into the spec for good, but it can still be removed from the title. \$\endgroup\$ Nov 22 '15 at 19:38
  • 3
    \$\begingroup\$ @JanDvorak: I think it's very tongue-in-cheek. For example, consider that presidential terms are 4 years, and that the next election is in November 2016. If Trump is at the peak of his presidency in 2016... \$\endgroup\$ Nov 23 '15 at 22:47

22 Answers 22


Pyth, 59 - 15 = 44 bytes

or 42 bytes after a bug was fixed



0000000: 2651 7240 632e 2261 7601 c061 15dc 2873  &Qr@c."av..a..(s
0000010: fde0 6b57 8bd0 a1ed ed0f 225c 623f 7132  ..kW......"\b?q2
0000020: 3031 3651 342f 684d 7374 2a32 2e75 4c2c  016Q4/hMst*2.uL,
0000030: 654e 734e 515f 4253 3251 34              eNsNQ_BS2Q4

The first two characters (&Q) are necessary because of a Pyth parsing bug that makes Q after ." fail. Fix has been applied. If the post-bugfix interpreter is allowed, -2 bytes.

Without unreadable string compression:

Pyth, 63 - 15 = 48 bytes

49 bytes without Trump

@c"Pippi Ness Lucas Travis Trump")?nQ2016/hMst*2.uL,eNsNQ_BS2Q4

Test Suite

Pretty straightforward, just generate the sequences, duplicate one and check for membership.

Sequences are generated by starting with [1, 2] and [2, 1], and then applying the fibonacci rule.


Julia, 146 142 121 120 bytes

n->split("Pippi Lucas Ness Travis")[2any(isinteger,sqrt([5n^2+4,5n^2-4]))+(n∈[2;[(g=golden)^i+(-g)^-i for i=1:n]])+1]

This creates an unnamed function that returns a boolean. To call it, give it a name, e.g. f=n->....


function trump(n::Integer)
    # Determine if n is a Fibonacci number by checking whether
    # 5n^2 ± 4 is a perfect square
    F = any(isinteger, sqrt([5n^2 + 4, 5n^2 - 4]))

    # Determine if n is a Lucas number by generating Lucas
    # numbers and testing for membership
    # golden is a built-in constant containing the golden ratio
    L = n ∈ [2; [golden^i + (-golden)^-i for i = 1:n]]

    # Select the appropriate Earthbound charater using array
    # indexing on a string split into an array on spaces
    return split("Pippi Lucas Ness Travis")[2F+L+1]

Fixed an issue and saved 7 bytes thanks to Glen O!


Mathematica 143 156 - 15 (bonus) = 141 bytes

With 2 bytes saved thanks to LegionMammal978.

  • 1
    \$\begingroup\$ False and True can be replaced with 1<0 and 1>0 respecively. \$\endgroup\$ Nov 22 '15 at 1:29

Mathematica, 92 87 bytes

Inspired by Sp3000's answer.


Python 2, 107

f=lambda i,n=input():abs(5*n*n+i)**.5%1>0

The key is two purely arithmetical checks for Fibonacci and Lucas numbers:

  • n is a Fibonacci number exactly if 5*n*n+4 or 5*n*n-4 is a perfect square
  • n is a Lucas number exactly if 5*n*n+20 or 5*n*n-20 is a perfect square

This site has proof sketches.

So, the output depends on the values of 5*n*n+i for i in {4,-4,20,-20}. The function f tests a value of i, by checking if the corresponding value does not have a whole-number square root The abs is there just to avoid an error of taking the root of a negative for n=1, i=-20.

The function f takes the value of the number n to test from STDIN. Python only evaluates this once, not once per function call.

Whether the number is not Fibonacci is evaluated as f(4)*f(-4) using the implicit boolean to number conversion and similarly for not Lucas, and the corresponding string is taken. If trailing spaces were allowed, string interleaving would be shorter.

  • \$\begingroup\$ The proof sketches are a dead link. \$\endgroup\$
    – SQB
    Jun 16 '17 at 8:16
  • \$\begingroup\$ @SQB The page seems to have gone down, I can't find it again. \$\endgroup\$
    – xnor
    Jun 16 '17 at 22:08

Python 2, 117 bytes

exec 2*n*"F,L=L+[sum(L[-2:])],F;"
print["Pippi","Lucas","Ness","Travis"][(n in F)*2+(n in L)]

For the string list, "Pippi Lucas Ness Travis".split() is the same length.


CJam, 58 55 54 bytes

ri5Zbe!f{1${_-2>:++}*&!}2b"Travis Ness Lucas Pippi"S/=

Naïve approach of generating the Fibonacci and Lucas numbers then counting occurences in both, converting to binary, and picking the appropriate string.

Try it online.


Perl, 133 (146-15=)131 (144-15=)129 (136-15=)121 bytes

+1 byte for the -n flag.


With newlines after semicolons, for readability:



llama@llama:...code/perl/ppcg64476trump$ for x in 1 2 3 4 5 6 7 8 610 722 843 2016; do echo -n "$x => "; echo $x | perl -n trump.pl; done
1 => Travis
2 => Travis
3 => Travis
4 => Lucas
5 => Ness
6 => Pippi
7 => Lucas
8 => Ness
610 => Ness
722 => Pippi
843 => Lucas
2016 => Trump


  • You might be wondering why my variables are named $a, $b, $%, and $d. That is an excellent question! In fact, it allows me to save a byte.

    (stuff) ... ,$l+=$_==$%while$a<$_

    is one byte shorter than

    (stuff) ... ,$l+=$_==$c while $a<$_

    This no longer applies because I golfed my code by rearranging things, causing the variable name change to no longer save bytes. I changed it back so that variable names make sense again.

  • $_-2?$f+$l*2:3 is mildly interesting. Basically, I had to special-case 2 for Lucas numbers because my program checks whether a number is a Lucas number after "updating" the Fibonacci and Lucas numbers. So 2 was considered a not-Lucas number. $_-2?foo:bar is a char shorter than $_==2?bar:foo. Same thing is used for the 2016 test.

    This is also no longer true because I was able to restructure the program to not require special-casing 2. But I still use $_-2016?stuff:Trump instead of $_==2016?Trump:stuff, which is one byte longer.

  • Speaking of which, you may be wondering how I did this restructuring. I just made the program do 9 times more iterations than necessary, which only costs 2 bytes (*9) but allows me to make assumptions elsewhere that help golf stuff down.

  • Because variables default to zero,


    is shorter than

  • Perl supports barewords, so I don't have to quote any of my strings (\o/).

  • \$\begingroup\$ Isn't it two bytes shorter? \$\endgroup\$ Nov 22 '15 at 1:50
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ The program itself is 132 bytes, and I added one because it needs to be called with the -n flag (as noted in the answer). \$\endgroup\$
    – Doorknob
    Nov 22 '15 at 1:51
  • \$\begingroup\$ Oh, I see. What does the -n flag do? \$\endgroup\$ Nov 22 '15 at 1:52
  • 1
    \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ It assumes a while(<>) { ... } loop around your program. See: Perl docs. \$\endgroup\$
    – Doorknob
    Nov 22 '15 at 1:54
  • 1
    \$\begingroup\$ @DomHastings He wasn't, but I <s>converted</s> convinced him to try perl. \$\endgroup\$ Nov 23 '15 at 17:37

Seriously, 69 bytes


Before this challenge, Seriously had the builtin f (index in Fibonacci numbers, -1 if not a Fibonacci number)... but not index in a list or "is in list"! (It's since been added as í.)

As a result, this is what I spend finding if the input is a Fibonacci number:

,                              f0≤

This is what I spend generating a list of Lucas numbers:


And this is what I spend finding if the input is in the list of Lucas numbers:

 ;                @#":%d:="%£MΣ

That's a string being formatted using Python's % notation into something like :610:=, and converted to a function, which is then mapped over the array and summed. (The Lucas numbers are unique, so the sum is always 0 or 1.)

Thanks to @Mego for that last bit with the string formatting.


Julia, 101 100 bytes

n->split("Pippi Lucas Ness Travis")[[2;1]⋅(sum(i->[i[];trace(i)].==n,Any[[1 1;1 0]].^(0:n)).>0)+1]


function f(n)
  k=Any[[1 1;1 0]].^(0:n) # Produces characteristic matrices of Fibonacci
                          # numbers from 0 to n
  F=sum(i->i[]==n,k)      # Check if n is a Fibonacci number by checking
                          # the first value in each matrix for n
  L=sum(i->trace(i)==n,k) # Check if n is a Lucas number by checking
                          # the trace of each matrix for n
  I=[2;1]⋅[F;L]+1         # Calculate 2F+L+1, which is the index for the next step
  S=split("Pippi Lucas Ness Travis") # Creates array with four strings
                          # saves a byte compared with directly creating array
  return S[I]
      # This uses the above calculations to determine which of the four to return
  • \$\begingroup\$ Awesome solution! The matrix and trace approach is genius. It's too bad the {} alternative syntax for Any[] is deprecated; that would save a couple bytes. \$\endgroup\$
    – Alex A.
    Nov 22 '15 at 20:51

Octave, 93 bytes


This approach is similar to my MATLAB answer with the exception that Octave allows you to index directly into a fresh array:

{'a', 'b', 'c'}{2}    %// b

MATL (Non-Competing), 57 55 54 (67-15) = 52 bytes

20Kht_vi2^5*+X^Xj1\~a2:*sG2016=-'Lucas Ness Travis Trump Pippi'Ybw)

Try it Online!


Again, similar logic to my other answers here and here.

20      % Number literal
K       % Retrieve the number 4 from the K clipboard (the default value)
h       % Horizontal concatenation to produce [20 4]
t       % Duplicate elements
_v      % Negate and vertically append elements (yields [20, 4; -20 -4])
i2^     % Explicitly grab the input and square it
5*      % Multiply by 5
+       % Add this to the matrix ([20, 4; -20 -4])
X^      % Take the square root
Xj      % Ensure that the result is a real number
1\      % Get the decimal component
~       % Create a logical arrays where we have TRUE when no remainder
a       % For each column determine if any element is TRUE
2:      % Create the array 1:2
*       % Perform element-wise multiplication with boolean
s       % Sum the result to yield an index
G       % Explicitly grab the input (again)
2016=   % Check to see if it is 2016 (yields TRUE (1) if equal)
-       % Then subtract the boolean from the index. Since 2016 is NOT a
        % Fibonacci or Lucas number, the original index is 0. Subtracting
        % this boolean, will make this index now -1. For all other non-2016
        % numbers this will have no effect on the index.
'Lucas Ness Travis Trump Pippi' % Create the possible strings values 
        % Note: the 0 index wraps around to the end hence Pippi being at the end.
        % The next to last entry ('Trump') is ONLY accessible via a -1 index as
        % discussed above
Yb      % Split at the spaces to create a cell array
w       % Flip the top two stack elements
)       % Retrieve the desired value from the cell array

C++11, 176 + 15 (#include) = 191

[](int n){std::function<int(int,int)>c=[&](int f,int s){return f-s>n?0:s-n?c(s,f+s):1;};int l=c(2,1),f=c(1,1);l&f?puts("Travis"):l?puts("Lucas"):f?puts("Ness"):puts("Pippi");}

Ungolfed with usage. I can add explanation if requested tomorrow, gtg to bed now!

#include <functional>
#include <cstdio>
int main()
    auto r = [](int n)
        std::function<int(int, int)> c = [&](int f, int s)
            return f - s > n ? 0 : f - n ? c(s, f + s) : 1;
        int l = c(2, 1), f = c(1, 1);
        l & f ? puts("Travis") : l ? puts("Lucas") : f ? puts("Ness") : puts("Pippi");

    for (int i : { 1, 2, 3, 4, 5, 6, 7, 8, 610, 722, 843 })
        printf("%i - ", i); r(i);
  • 1
    \$\begingroup\$ @sysreq I don't think that's for the bonus, just the include statement. \$\endgroup\$
    – jado
    Nov 22 '15 at 2:46
  • \$\begingroup\$ @phase I know, I am dividing byte size into two parts (code+include), when I do post just function and not whole program. \$\endgroup\$
    – Zereges
    Nov 22 '15 at 8:50

Javascript (ES6), 108 bytes


Same function for Fibonnacci and Lucas. It's a recursive function that takes the first two values as init.


Java, 151 bytes

You could argue that Trump would never outsource this crucial decision, so we wouldn't have to make the method public, saving another 7 bytes.

public String t(int n){return"Pippi,Lucas,Ness,Travis".split(",")[2*f(n,1,1)+f(n,2,1)];}int f(int a,int x,int y){return a==x||a==y?1:a<y?0:f(a,y,x+y);}

Ungolfed including test-main invocation

public class Trump {

    //Test Invokation
    public static void main(String[] args) {
        int[] n = {1, 2, 3, 4, 5, 6, 7, 8, 610, 722, 843, 2016 };
        for(int i = 0; i < n.length; ++i) {
            System.out.println(""+ n[i] + " => " + new Trump().t(n[i]));

    public String t(int n) {        
        return "Pippi,Lucas,Ness,Travis".split(",")[2*f(n,1,1)+f(n,2,1)];               
    int f(int a,int x,int y) {             
        return a==x||a==y?1:a<y?0:f(a,y,x+y);           


I found no way so far to test for 2016 and return "Trump" in code that's less than 15 bytes in code.

  • \$\begingroup\$ Love that first line of your explanation! \$\endgroup\$
    – Scott
    Nov 23 '15 at 19:50

C (gcc),  128   120   116  110 bytes


Try it online!


Let's name F(n) the n-th Fibonacci number, and L(n) the n-th Lucas number.
a, b are F(n-1), F(n) respectively.
Then we can calculate L(n) == F(n-1)+F(n+1) == 2*F(n-1) + F(n) == 2*a+b
This function will successively calculate Fibonacci and Lucas numbers, up to n, and check if n is any of them.
If n is a Fibonacci number, the 1st bit of o will be set to 1
If n is a Lucas number, the 2nd bit of o will be set to 1
o will then be used to determine which name to output


  • Saved 8 bytes by golfing the condition of the for-loop : starting at second iteration, we have a<b<c and a<a+c=L(n), so ( b<=n || a+c<=n ) => a<n. I actually needed a<=n to handle correctly n=1
  • Saved 4 bytes thanks to ceilingcat ! (also corrected a mistake, my code was outputting "2 => Ness")
  • Saved 6 bytes:
    • 2 thanks to ceilingcat again
    • 4 by removing the variable c, equal to F(n+1), which was useless since we can already calculate F(n+1) with a and b
  • \$\begingroup\$ Suggest b+=a instead of b=a+b \$\endgroup\$
    – ceilingcat
    Oct 27 '19 at 3:46

Perl 5.10, 119 - 15 (bonus) = 104 bytes



# Read line from stdin
$_ = <>;

# Find first Fibonacci number greater than or equal to input.
# Store this number in $i and the next Fibonacci number in $j.
$j = 1;
($i, $j) = ($j, $i + $j) while $_ > $i;

say $_ - 2016
  ? (Pippi,Lucas,Ness,Travis)[
      ($_ == $i) * 2 |          # Bitwise OR with 2 if Fibonacci number
      $_ == 3 * $j - 4 * $i |   # Bitwise OR with 1 if Lucas number >= 3
      $_ - 1 >> 1 == 0          # Bitwise OR with 1 if Lucas number <= 2
  : Trump

This exploits the fact that

L(n-2) = 3 * F(n+1) - 4 * F(n)

is the greatest Lucas number lower to or equal than F(n).


Groovy, 149 bytes


Test code:

[1,2,3,4,5,6,7,8,610,722,843].each {
    print "$it => "

g is a closure that generates a list of numbers based on a seed (s) and a max value (m). (g(i,[1,1]).contains(i)?1:0)+(g(i,[2,1]).contains(i)?2:0) finds the index to use based on the number being lucas or fibonacci.


MATLAB, 122 119 bytes


Brief Explanation

We first create a cell array containing the values to print: {'Pippi', 'Lucas', 'Ness', 'Travis'}. Then to figure out which value to display, we check to see whether n is a Fibonacci or Lucas number.

For Fibonnaci, we use the following formula:

any(~rem(sqrt(5*n^2 + [-4 4]), 1))

This checks to see if either 5*n^2 + 4 or 5*n^2 - 4 are a perfect square. If any of them are, then it is a Fibonacci number.

The formula for a Lucas number is very similar with the exception that we use +/- 20 instead of 4:

any(~rem(sqrt(5*n^2 + [-20 20]), 1))

In this solution I combined these two cases into one by using the matrix:

M = [-20 -4
      20  4]

By applying the same equation as those above, but force any to consider only the first dimension, I get a two element logical array where if the first element is true, then it is a Lucas number and if the second element is true, it is a fibonacci number.

any(~rem(sqrt(5*n^2 + [-20 -4;20 4]), 1))

Then to compute the index into my initial cell array, I treat this as a binary sequence by performing element-wise multiplication of this boolean with [2^0, 2^1] or simply [1,2]. And sum the elements. Obviously I have to add 1 because of MATLAB's one-based indexing.

index = (1:2) * any(~rem(real(sqrt(5*n^2+[-20,-4;20,4])),1)).' + 1;

Then I have to use subsref and substruct to index into the initial cell array to obtain the final result.


JavaScript (ES6), 97 bytes


The a==1 check is needed otherwise I don't notice that 1 is a Lucas number.


Jelly, 47 bytes - 15 = 32 (non-competing...?)


Try it online!


05AB1E, 39 37 (52 - 15 bonus) bytes


Try it online or verify all test cases.


2016Qi                # If the input equals 2016:
      .•ªb‚•          #  Push "trump" to the stack
ë                     # Else:
 >ÅG                  #  List of Lucas numbers up to and including the input+1
    ¹å                #  Check if the input is in this list (1 if truthy; 0 if falsey)
      _               #  Invert the boolean (0→1 and 1→0)
 ¹ÅF                  #  List of Fibonacci numbers up to and including the input
    ¹åi               #  If the input is in this list:
       .•F_ïk|»9•     #   Push string "travisnessi" to the stack
    ë                 #  Else:
     .•?®B'5n•        #   Push string "pippilucas" to the stack
    }                 #  Close the inner if-else
     2ä               #  Split the string into two parts
                      #   i.e. "travisnessi" → ["travis","nessi"]
                      #   i.e. "pippilucas" → ["pippi","lucas"]
       sè             #  Index the Lucas result into the list of two strings
}                     # Close the outer if-else
 ™                    # And output the top of the stack in title-case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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