#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    15
    Rep Power
    0

    To Check if a List is Cube Free?


    Hey guys,

    I need to write a function that when it is sent a list, it will check the list to see if it is cube-free.

    This means:
    [1,0,1,0,1,0] is not cube-free because 10 three times in a row
    [1,0,0,1,1,0,0,1,1,0,0,1] is not cube free because 1001 three times
    [1,0,0,1,1,0,0,1,1,0,0,0] is cube free.

    Thanks in advance!
    Norm
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    15
    Rep Power
    0
    I believe I would need to generate all substrings first, then check those?
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    [1,0,0,1,1,0,0,1,1,0,0,0] is cube free.

    NO! That list is NOT cube free because
    1 appears 3 or more times.
    0 appears 3 or more times.
    10 appears 3 times.
    100 appears 3 times.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    I believe you're clueless.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    15
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I believe you're clueless.
    Actually, you are clueless. Cube-free means it does not appear three times IN A ROW. Almost any sequence would not be cube free if what you were saying were true...
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    I can define an infinite number of "cube free" sequences. All arrangements of the counting numbers are an infinite number of infinite length "cube free" sequences.
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    15
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I can define an infinite number of "cube free" sequences. All arrangements of the counting numbers are an infinite number of infinite length "cube free" sequences.
    Of course you could, but if you do not know how to write the program, then who cares, go help someone else because you are no help here.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    This may not be the most efficient solution, but one approach:
    • A list L of length 3*n is a perfect cube if and only if L[:n] == L[n:2*n] and L[n:2*n] == L[2*n:].
    • A list L is not cube-free if and only if L[a:a+3*n] is a perfect cube for some values of a and n.
    You can turn those observations directly into a for-loop.

IMN logo majestic logo threadwatch logo seochat tools logo