All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Restricted ternary numbers (Posted on 2023-07-24) Difficulty: 3 of 5
Evaluate the quantity of 4-digit numbers such that:
a. Use only 3 digits: 1,2 & 3.
b. None of its neighboring digits differ by 2.

Same question for numbers of 5 and 6 digits- still using only 1,2,3.

Enjoy!

No Solution Yet Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 3 of 4 |
clearvars,clc
global sz ct no lv ct2
sz=4; ct=0; lv=0; ct2=0;
no=[];
addon
ct
ct2

function addon
global sz ct no lv ct2
 lv=lv+1;  
  saveno=no;
  for i=1:3    
    chgd=false;
    if length(no)==0
      no=i;
      chgd=true;
    else
      if abs(i-no(end))~=2
        no=[no i];
        chgd=true;
      end
    end
    if chgd
      if length(no)==sz
        ct=ct+1;
        if length(unique(no))==3
          ct2=ct2+1;
          fprintf('%d%d%d%d  *\n',no)
        else
          fprintf('%d%d%d%d\n',no)
        end
      else
        addon
      end
    end
    no=saveno;
  end
 lv=lv-1;
end

finds 41 such 4-digit numbers, 10 of which use exactly all three of the allowable digits, marked with an asterisk below:

1111
1112
1121
1122
1123  *
1211
1212
1221
1222
1223  *
1232  *
1233  *
2111
2112
2121
2122
2123  *
2211
2212
2221
2222
2223
2232
2233
2321  *
2322
2323
2332
2333
3211  *
3212  *
3221  *
3222
3223
3232
3233
3321  *
3322
3323
3332
3333
ct =
    41
ct2 =
    10
    
Allowing the size of the number to change, not showing each individual case, just the statistics:

digits count   count using all
                three digits
 3        17         2
 4        41        10
 5        99        36
 6       239       112
 7       577       322
 8      1393       882
 9      3363      2340
10      8119      6072
11     19601     15506
12     47321     39130

The 17 for 3-digit numbers are:

111
112
121
122
123  *
211
212
221
222
223
232
233
321  *
322
323
332
333


  Posted by Charlie on 2023-07-24 11:58:42
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information