Repeating Pattern in a sequence

I am making an encrypting program in java and I have a little problem.
I need to know how I can find repeating patterns in a sequences of numbers:
For Ex:
{1,2,3,1,2,3}
repeating pattern is 1,2,3 and the pattern occurs twice
{1,2,3,2,3}
no repeating pattern
{5,0,0,5,0,0}
500 is the repeating pattern and occurs twice
I hope you get the idea. What the best way to do this efficiently? I think there is an algorithm already designed for this.. but not sure.
Appreciate any help,
John

This little program can detect a period in a list of ints
[not optimal but functional :^]:
public class PeriodDetector {
    public static boolean isCyclic(int list[], int period) {
        for (int i=period; i<list.length; i++) {
            if (list[i-period]!=list[i ]) {
                return false;
        return true;
    public static int detectPeriod(int list[]) {
        for (int period=1; period<=list.length/2; period++) {
            if (list[0]==list[period] && list.length%period==0) {
                if (isCyclic(list, period)) {
                    return period;
        return -1;
    public static void main(String argv[]) {
        int list[] = new int[argv.length];
        for (int l=0; l<list.length; l++) {
            list[l] = Integer.parseInt(argv[l]);
        System.out.println("Period..." + detectPeriod(list));

Similar Messages

  • How can I make a column of sums out of a repeating pattern of 24 changing numbers

    How can I make a column of sums out of a repeating pattern of 24 changing numbers in Numbers.
    I have a long list of 8760 numbers of which I need to take the sum (and store in a column) of each 24 numbers.

    Here's one way. I've reduced the example, taking groups of five numbers from a set of 20. I've used 3 as the data number in all cases to make the sum easily recognizable.
    Original column of numbers in Data::column A.
    Data::B2 (and filled down): =QUOTIENT(ROW()+3,5)
    This adds 3 to the row number, then divides by 5, returning the quotient and ignoring the remainder.
    The result is a 'group number' for each group of five rows.
    Sums of each group are reported in the Sums table.
    Sums::A2 (and filled down): =ROW()-1
    Sums::B2 (anf filled down): =SUMIF(Data::$B,A2,Data::$A)
    For your example, assuming the 8760 numbers are listed in column A of a table named Data, starting at cell A2:
    Add a second column to the table (column B).
    In B2 enter the QUOTIENT formula above, with these two revisions:
    =QUOTIENT(ROW()+22,24)
    Fill down to all cells in the column.
    Provided you have named the first table "Data", both formulas in the Sums table will be as written above. You will need to extend the Sums table to 366 rows (including the Header row) to accommodate all 365 groups of 24.
    Regards,
    Barry
    PS: For details on the functions used, see the iWork Formulas and Functions User Guide. You can download the guide via the Help menu in Numbers '09.

  • How do I make a repeat pattern in Photoshop CC?

    I am trying to make a seamless repeat pattern in photoshop. I used to be able to do this in older versions of Photoshop by adjusting the position of my artboard in Filter -> Other -> Offset.
    Now I can't seem to adjust the offset by adjusting the pixels according to the size of my artboard, but I have to choose a pixel number between -1182 and +1182 instead?
    For instance, if my artboard is 100px I used to be able to set it to 50px so the artboard shifts halfway to the right. Now I have to set it at (1182 : 4=) 295px to get my artboard to that same position.
    Plus, when I use 'wrap around' the objects in my artboard don't appear on the other side of the artboard as should be the case.
    What is going on? Does anyone know how I can easily make a repeat pattern in Illustrator now? Is there something like 'Pattern maker" for Photoshop cc,  like the one that used to be available for older versions of PS but is now disabled for Photoshop CC?
    Thanks a bunch! 

    https://www.google.com/search?sourceid=chrome-psyapi2&rlz=1C1CHFX_enUS546US546&ion=1&espv= 2&ie=UTF-8&q=photoshop%20tutor…

  • How can I create a symbol filled with a repeating pattern?

    Hey there. Iam trying to make a symbol and it should have a repeating pattern (jpg, png, gif) in the back. It should be 100% widht and height and I will move it on the main stage.
    Any ideas for that?
    I just have this code to put it in the background for the whole page. This works pretty good but it is not the thing I am looking for actually.
    $("#Stage").css("background-image","url(images/pattern_small.jpg)","background-repeat","re peat")
    put in Stage/CompositionReady
    1000 thanks in advance!!!

    You need to add the snippet
    sym.getSymbolElement().css({'background-image':'url(images/sprinkles.png)','background-rep eat':'repeat'});
    in the symbol creation complete event.
    Here is a sample
    https://drive.google.com/file/d/0B2k82B_Y-fXCMTdTSi16VHp4em8/edit?usp=sharing

  • Unwanted paths showing after cropping to make a repeat pattern tile.

    I'm trying to make a repeat pattern tile (using CS5 on Windows 7), but when I crop the pattern, the expanded paths underneath become visible as on the flowers below.
    This is what I did after creating the artwork:
    Used the rectangle tool to make a box with fill/stroke directly on top of the artboard..
    Select all > Expand (selecting stroke only, not fill)
    Deselect the cropping box and grouped the remaining objects.
    Reselected the cropping box and grouped all objects
    Pathfinder > Crop
    I'm guessing it may have something to do with the fact I used a gradient on the flowers but have no idea how to resolve it. Does anyone have any suggestions? Thanks.
    PS. Please excuse me if this explanation is really poorly worded...I've only ever used Illustrator for fashion technical sketches so my knowledge is pretty limited.

    Followed your advice above, and hopefully it will work. The only issue is it's a bit time consuming they way I'm doing it, as I'm having to delete the outermost objects first, then delete any objects which are partially inside the rectangle, otherwise I find some of the objects inside the rectangle are deleted too:
    At the moment for the objects that are partially inside the box, I'm using the scissors tool to cut the path where it crosses the rectangle. Is there an easier solution to this problem?

  • Repeating pattern question

    I’m trying to make a repeating pattern that includes a teapot image that I filled with a repeating rose pattern background. After everything has been reflected evenly on all axis, I then try to drag into the swatches panel. However, for some reason when I try to drag this pattern into the swatches panel, illustrator won’t do it. It will do it if I remove the tea pots and tea cups that have that repeating background pattern, but not when it’s there. Any idea what’s going on?
    It seems like ai is confused that I’m trying to make a repeating pattern with an image (the teapot)  that has a repeating pattern for the background.

    Select the teapot and cup and go to Object>Expand before you drag back into the swatches panel.

  • Problems with getting repeating patterns to display properly

    Using Oracle's Map Definition Tool I am trying to import repeating patterns through the "import image" functionality, found under "map metadata --> styles --> area", but I am having problems getting them to work properly (i.e. they don't repeat as they should). Part of the problem is the poor quality of repeating patterns images that where send my way.
    Therefore I have 2 questions I hoped someone here could answer me:
    1) Is there an easily accessible collection of decent+ quality repeating patterns somewhere on the web where I could look for patterns to use?
    2) What is the image resolution used by the Oracle Map Definition Tool, or in other words, what is the minimum resolution I need to make sure the pictures are to make them downscale properly to a single pattern image through the "import image" functionality?

    For starters, you could try any of the pattern images/icons available in your popular word/graphics applications such as Word, Powerpoint, or Adobe. For instance in PowerPoint you can find a set of Patterns under Format Auto Shape > Fill > Fill Effects > Pattern. You can generate your own pattern images that closely follow the design of these from PowerPoint.
    When you import an image, as long as you make sure the preferred width/height of the image is set to identical with the real width/height of the image itself, MapViewer will not attempt any scaling during rendering, thus preserving the native resolution of your pattern image.

  • Seamless repeating pattern - using embedded images with clipping masks

    Hi forum,
    We struggle a bit creating a seemless repeating pattern that includes embedded images with clipping masks applied.
    Our pattern is a 550x550mm black square with various embedded inserted on top. All of these images have Clipping Masks applied to hide unwanted areas.
    These images are placed so they create a seamless repeating pattern and this includes areas that overlap the square.
    Once we create a swatch from this pattern the repeatable area becomes too big as it includes the unwanted areas hidden by the clipping masks.
    Because the repeatable area is now too big it's actually not repeatable.
    We tried various things in order to solve this issue. Pathfinder/crop to delete the unwanted areas in the images etc.
    None of them worked good enough.
    We though of just livetracing the images, but due to the complexity this is not an option.
    Do we really have to do our "cutting" in Photoshop or do you know any fancy tricks for issues like this?
    Appreaciate your insight
    Kenneth

    Kenneth,
    You may try the destructive deed, with the Clipping Mask selected:
    1) In the Transparency palette/panel dropdown list select anything but Normal (Multiply is fine),
    2) Object>Flatten Transparency, just keep the defaults including 100% Vector,
    3) Shudder.
    This should reduce the size to the Bounding Box of the Clipping Path.

  • Can anyone help me with a repeating pattern that is staggered?

    Can anyone help me with a repeating pattern that is staggered and must be aligned perfectly while staggered. Is there a way to do this? I keep staggering it by eyeball and need it to be accurate and each row is offset.
    My art board is 19.25x11.50 I have a repeating logo and name underneath (hard to see) I am setting this up for a print design to go onto tissue paper for insert into a shoe box. Any help is greatly appreciated?
    Thanks,

    Option drag your object horizontally to make a copy or use Move and copy if you need a precise increment. The hit Cmd+D a few times to make duplicates with the same spacing.
    Hit Enter again and make a note of the increment on a piece of paper. Cancel.
    Select everything and use the same increment, now in a vertical direction, to make 2 further copies.
    Take the middle row and move it horizontally by half of the increment. This means that the circles in the middle row are positioned horizontally half way between those in the other two rows.
    Draw your defining rectangle so that its corners are on the centres of those 4 circles. (This gives you its right size but you may possibly need to move it a bit.) Send it to the back of your stack.
    Drag those 8 circles and the rectangle to your Swatches panel.
    (If you’re on Windows read Ctrl instead of Cmd and Alt instead of Option.)

  • Cloning - repeating patterns

    I recently moved from CS to CS4, and found the clone tool worked a little bit differently. In CS, when the clone tool source location ran over an already cloned area in a single drag, you would get a repeating pattern. I found this useful in when the source area was small, and worked great for repeating areas like grass and bricks.  However, with CS4, when the clone tool source location runs over an already cloned area in a single drag of the mouse, it ignores the cloned area and clones the original source that was underlying the cloned area.  This makes it impossible for me to create large repeating areas out of limited source areas.
    I have looked through all the buttons and features of the clone tool, and can't seem to find one that will let me operate like CS did.  Also, this topic is a bit hard to do a web search on, as I get lots of hits on clone but none of them answer my question.
    Any help here would be greatly appreciated, as I am having trouble adjusting to the new way the clone tool works, though I do like all the new clone features.

    Thank you, Bill.  This is driving me nuts.  I could swear all my previous version did this, as it was my favorite trick to use.  For example, if I had a straight object like a curb, fence, belt, post, etc. I could select a target and starting point close together but on same line, and then drag TOWARDS the sample point I had selected and make a curb go on forever and ever, even through other objects.  I seem to recall this only worked when target and starting point were close together and I dragged toward the starting point without lifting the mouse button - all one stroke.  I used this trick daily, and loved it.  I just tried aligned and unaligned on my CS4, and neither did it.  I might have to dig out my older copy of PS and find another computer to try it on, otherwise it is going to keep nagging me...

  • Angled Stripes Repeating pattern

    Vertical  or horizontal stripes are no problem, but they are angled cannot get a seamless repeating pattern. I tried using snppaing 2 lines and running a blend between them, thininig the stroke is half in and half out so this should.
    You can see the seam below. Any idea how to do this with 8° rotation on the line?

    Tried rotating a couple different ways could not get some type to fill with angled stripes. I don't want to use the type as a mask over a big page of stripes, as I am looking to incorporate this into my designing with appearance stacks.

  • Offset feature not creating clean lines when repeating pattern/image

    Using PSE11, I have been working at several repeating patterns using the offset feature, but am having a problem with images not having a clean seam when connecting different layers to create the pattern. 
    Any recommendations?
    Thanks.
    Here's a screenshot of an example..

    Again, how you feel is really of no interest at all. How you feel will not get you one whit closer to solving the problem you have, and will probably even get in the way.  If you have a problem we can help. Any scolding I do is about your aggression. Think of it this way. If someone stops you in the street and politely asks the way to the train station you'll be a lot more likely to help him or her than a person swearing at how awful the street maps are and generally being aggressive.
    Obviously you don't get the fundamental difference, or you wouldn't have the problem. And yes, your photos can remain exactly as you organised them, but if that's what you wanted why did you then use iPhoto? You used the file manager for this job on windows, now you're trying to use a database for the job on your Mac. So you've switched OS and then the method of managing your photos.
    Now you need to decide. Do you want to work exactly as you did on Windows? If so, don't use iPhoto, just use the Finder (that's the file manager on the Mac.) That's what you did on Windows.
    If you want to use iPhoto, and so take advantage of the extra features that it has, then you'll need to rethink your way of working just a little but we can get very close to what you have now. But it will not be identical.
    If you don't want to use iPhoto just copy your folders of images over to the Mac. Job done. Otherwise, come back and let us know how your folders are arranged and we can try help you adapt that to iPhoto.

  • Repeating patterns that are staggered and how to set the alignment perfectly.

    Can anyone help me with a repeating pattern that is staggered and must be aligned perfectly while staggered. Is there a way to do this?
    My art board is 19.25x11.50 I have a repeating logo and name underneath (hard to see) I am setting this up for a print design to go onto tissue paper for insert into a shoe box. Any help is greatly appreciated?
    Thanks,
    B

    For the swatch, I positioned five logos exactly the way I wanted.
    I drew horizontal and vertical straight lines and centered them over the outer four logos (the eventual outside edges of the final swatch).
    I then used Object > Path > Divide Objects Below for each of the lines in turn to cut the outer logos (the lines must be in exactly the same place for each logo).
    After ungrouping the cut logos (may or may not be necessary), I deleted the parts I didn't need and dragged the result (the swatch you see) to the Swatch Pallet.
    --OB
    Here's another picture:

  • Help with a repeating pattern.

    Hey all,
    In Illustrator CS4.  I want to create a repeating pattern, using a swatch.  I've done this before succesfully but not sure why this one isn't working as planned.
    The small image at the bottom (just the area inside the artboard) is the spacing I want between the characters, but the pattern at the top is what I get.  Any advice would be awesome.

    Draw a no-fill, no-stroke rectangle the size you want the tile and move it behind all the other pattern artwork, then drag the art to the Swatch panel. The no-fill, no-stroke rectangle will determine the bounding area of the pattern tiles.

  • [SOLVED]sed: regex repeated pattern

    Hi all,
    Currently I'm struggling with bash script for automatic presorting and converting of photos from camera.
    While man page says that {} is repeated of previous pattern it does not work for me. Here is the example (basically I want extract year of the timestamp).
    % exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp
    Image timestamp : 2008:05:09 10:25:02
    % exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp | sed 's@.*\([0-9]{4}\).*@\1@'
    Image timestamp : 2008:05:09 10:25:02
    % exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp | sed 's@.*\([0-9]{3}\).*@\1@'
    Image timestamp : 2008:05:09 10:25:02
    And this one works
    % exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp | sed 's@.*\([0-9][0-9][0-9][0-9]\).*@\1@'
    2008
    If I need repeated m times this is not acceptable. How to deal with this?
    Last edited by ogronom (2010-04-05 16:26:54)

    Escaping '{' and '}' helps:
    sed 's@.*\([0-9]\{4\}\).*@\1@'
    Last edited by karol (2010-04-05 16:24:22)

Maybe you are looking for

  • How to attach to a mono RCA input

    I would like to plug my iPod into an amplifier that has only one mono RCA input. Do I use a mono miniplug for the iPod? Or a "backwards" RCA Y adapter to merge both channels into one male plug?

  • How to convert a String to Date?

    i have a String "1998-12-31" i would like to convert it to Date so that i can compare the Date in Mysql. i am appreciate for your help. Thanks yuetni Swee

  • Unable to connect Oracle Enterprise Manager 10g

    Good Morning All, I using oracle 10g. http://dt40562:1158/em/console/logon/logon iam connecting successfully in Toad using scott/tiger. Whenever im connecting using Oracle Enterprise Manager im getting below error "The application requires more datab

  • How to update the recorded scripts as per the new interface

    Hi, I am using E-tester 8.20 and generating the scripts by record and playback. Here my problem is how to update the scripts when new version of user interface (UI) comes. For example, page1 of UI has recorded with 5 text boxes. In the new version of

  • Does FCX render faster than FCP7?

    Hi Folks, So I'm using FCP7 and I despite how long it takes to render files. I have a quad 2.66 MP and I know it's not the fastest MP, but it would be nice to use all cores during a render (and for exporting files to self-contained QT files)!!! Of co