Enigmatic Code

Programming Enigma Puzzles

Enigma 1153: Luconacci numbers

From New Scientist #2309, 22nd September 2001 [link]

In the Fibonacci sequence the first two terms are 1 and 1, and each subsequent term is the sum of the previous two terms; so the sequence starts 1, 1, 2, 3, 5. Less well known is the Lucas sequence, whose first two terms are 1 and 3, and each subsequent term is the sum of the previous two terms; so the sequence starts 1, 3, 4, 7, 11. In the Tribonacci sequence (so named by Mark Feinberg) the first three terms are 1, 1 and 2, as in the Fibonacci sequence, and each subsequent term is the sum of the previous three terms; so it starts 1, 1, 2, 4, 7.

Harry, Tom and I were looking to find a 2-digit Fibonacci number, a 2-digit Lucas number and a 2-digit Tribonacci number that used six different digits. We each found a different solution; our three Fibonacci numbers were all different from each other; our three Lucas numbers were all different from each other; and our three Tribonacci numbers were all different from each other. None of the numbers in my solution appeared in either Harry’s or Tom’s solution.

List in ascending order the numbers in my solution.

[enigma1153]

Advertisements

2 responses to “Enigma 1153: Luconacci numbers

  1. Jim Randell 22 August 2016 at 8:47 am

    This Python program runs in 37ms.

    from itertools import product, combinations
    from enigma import join, printf
    
    # collect n-digit numbers from an (increasing) generator as strings
    def numbers(g, n=2):
      for x in g:
        t = str(x)
        m = len(t)
        if m < n: continue
        if m > n: break
        yield t
    
    # generator for fibonacci-type sequences
    def fib(*s):
      s = list(s)
      while True:
        s.append(sum(s))
        yield s.pop(0)
    
    # 2-digit fibonacci numbers
    fibs = list(numbers(fib(1, 1)))
    
    # 2-digit lucas numbers
    lucs = list(numbers(fib(1, 3)))
    
    # 2-digits tribonacci numbers
    tribs = list(numbers(fib(1, 1, 2)))
    
    # find triples consisting of 6-different digits
    ts = list()
    for (n1, n2, n3) in product(fibs, lucs, tribs):
      if len(set(n1 + n2 + n3)) == 6:
        printf("[fib={n1}, luc={n2}, trib={n3}]")
        ts.append((n1, n2, n3))
    
    # choose numbers for D, H, T
    for D in ts:
      for (H, T) in combinations(ts, 2):
        # the numbers in each category are all different
        if any(len(set(s)) < 3 for s in zip(D, H, T)): continue
        # D is disjoint from H and T
        if set(D).intersection(H + T): continue
        # output solution
        printf("D=({D}) [H/T=({H})/({T})]", D=join(D, sep=', '), H=join(H, sep=', '), T=join(T, sep=', '))
    

    Solution: The numbers in your solution are 29, 34, 81.

    The Fibonacci number is 34. The Lucas number is 29. The Tribonacci number is 81.

    Harry and Tom’s (Fibonacci, Lucas, Tribonacci) numbers are (13, 76, 24) and (89, 47, 13), but we don’t know who chose which set, but one of them chose 13 as a Fibonacci number, and one of them chose 13 as a Tribonacci number.

  2. geoffrounce 3 April 2018 at 2:42 pm
    % A Solution in MiniZinc
    include "globals.mzn";
    
    % Three Fibonacci numbers
    var 10..99: F1;  var 10..99: F2;  var 10..99: F3;  
    
    % Three Lucas numbers
    var 10..99: L1;  var 10..99: L2;  var 10..99: L3;  
    
    % Three Tribonacci numbers
    var 10..99: T1;  var 10..99: T2;  var 10..99: T3;  
    
    % All Fibonacci numbers are different
    constraint all_different ( [F1, F2, F3] ); 
    
    % All Lucas numbers are different
    constraint all_different ( [L1, L2, L3] );
     
    % All Tribonacci numbers are different
    constraint all_different ( [T1, T2, T3] ); 
    
    % All Tom, Harry and Dick's numbers are different
    constraint all_different ( [F1, L1, T1] );  % Tom
    constraint all_different ( [F2, L2, T2] );  % Harry
    constraint all_different ( [F3, L3, T3] );  % Dick
    
    var set of int: Fib2 = {13, 24, 34, 55, 89};
    
    var set of int: Lucas2 = {11, 18, 29, 47, 76};
    
    var set of int: Trib2 = {13, 24, 44, 81};
    
    % Tom's numbers (F1, L1, T1) - 6 different digits
    var set of int: Tom = {F1 div 10, F1 mod 10, L1 div 10, L1 mod 10, T1 div 10, T1 mod 10};
    
    constraint F1 in Fib2 /\ L1 in Lucas2 /\ T1 in Trib2;
    
    constraint all_different ([F1 div 10, F1 mod 10, L1 div 10, L1 mod 10, T1 div 10, T1 mod 10]);
    
    constraint card(Tom) == 6;
    
    % Harry's numbers (F2, L2, T2)- 6 different digits
    var set of int: Harry = {F2 div 10, F2 mod 10, L2 div 10, L2 mod 10, T2 div 10, T2 mod 10};
    
    constraint F2 in Fib2 /\ L2 in Lucas2 /\ T2 in Trib2;
    
    constraint all_different ([F2 div 10, F2 mod 10, L2 div 10, L2 mod 10, T2 div 10, T2 mod 10]);
    
    constraint card(Harry) == 6;
    
    % Dick's numbers (F3, L3, T3)- 6 different digits
    var set of int: Dick = {F3 div 10, F3 mod 10, L3 div 10, L3 mod 10, T3 div 10, T3 mod 10};
    
    constraint F3 in Fib2 /\ L3 in Lucas2 /\ T3 in Trib2;
    
    constraint all_different ([F3 div 10, F3 mod 10, L3 div 10, L3 mod 10, T3 div 10, T3 mod 10]);
    
    constraint card(Dick) == 6;
    
    % None of the numbers in Dick's solution appeared in either Harry’s or Tom’s solution
    constraint F3 != L1 /\ F3 != T1 /\ F3 != L2 /\ F3 != T2;
    
    constraint L3 != F1 /\ L3 != T1 /\ L3 != F2 /\ L3 != T2;
    
    constraint T3 != L1 /\ T3 != F1 /\ T3 != L2 /\ T3 != F2;
    
    solve satisfy;
    
    output [ "Tom's numbers = " ++ show([F1, L1, T1]) ++ "\n" ++
    "Harry's numbers = " ++ show([F2, L2, T2]) ++ "\n" ++
    "Dick's numbers = " ++ show([F3, L3, T3]) ];
     
    % In ascending order the numbers in my (Dick's) solution are 29, 34 and 81
    
    % [Fibonacci, Lucas, Tribonacci]
    % Tom's numbers = [13, 76, 24]
    % Harry's numbers = [89, 47, 13]
    % Dick's numbers = [34, 29, 81]
    % ----------
    % Tom's numbers = [89, 47, 13]
    % Harry's numbers = [13, 76, 24]
    % Dick's numbers = [34, 29, 81]
    %----------
    % ==========
    % Finished in 264msec
    

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: