It is also possible to do this combinatorially. If allowed digits are 1,2,3, and we have six slots to use, then there are a total of 3^6 = 729 arrangements.
So we just need to count all arrangements that have 3 or more consecutive digits that are the same. Consider the slots as such _ _ _ _ _ _ Use | (pipe) to denote the last slot that is in a 3-series (3 or more consecutive digits). Important point is that we are choosing the LAST slot that is part of a 3-or-more series. e.g. _ _ _ | _ _ _ can be 1 1 1 | _ _ _ 2 2 2 | _ _ _ 3 3 3 | _ _ _ where the right hand of | needs to be counted. There are 3 ways of choosing the LHS. RHS depends on whether index 4 and index 5 slots contain the same digit. If they do then there are 3 * 2 * 2 ways. If not then there are 3* 2 * 2 * 3 ways. Next consider _ _ _ _ | _ _ The first item can be any. Use 3 to denote that it canbe any three of the digits. 3 _ _ _ | _ _ Using the previous argument we have 3 * 3 * 2 * 3 ways. Next, _ _ _ _ _ | _ We have 3 * 3 *3 * 2 ways. Lastly _ _ _ _ _ _| We have 3 ^ 4. Total is (3^4) + (3*3*3*2) + (3*3*2*3) + (3*2*2*3) + (3*2*2) Subtract from the total number of possible arrangements: 729 - (3^4) + (3*3*3*2) + (3*3*2*3) + (3*2*2*3) + (3*2*2) 492 -------------------------------------------- On Mon, 4/9/18, 'Jon Hough' via Programming <programm...@jsoftware.com> wrote: Subject: Re: [Jprogramming] Quora Problem To: programm...@jsoftware.com Date: Monday, April 9, 2018, 3:57 PM Not the fastest method... f=: -.@:(1&e.)@:(#@:~."1)@(3&(]\))`0:@.(1&e.@:('0456789'&e.))@:": D=: 1e5 + i. 1e6 - 1e5 +/ f"0 D 492 -------------------------------------------- On Mon, 4/9/18, Skip Cave <s...@caveconsulting.com> wrote: Subject: [Jprogramming] Quora Problem To: "programm...@jsoftware.com" <programm...@jsoftware.com> Date: Monday, April 9, 2018, 2:51 PM Here's a fun math challenge on Quora: Find the number of 6-digit numbers made up of the digits 1, 2, and 3 which have no digit recurring three or more times, consecutively? The link to my answer on Quora is: https://goo.gl/BzBDQe Skip Cave Cave Consulting LLC ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm