Help with algorithm about distrbuting numbers in a matrix

Hi,
I have to do the following:
I need to distribute N numbers in a (Y,N) matrix. The only problem is that each number should be unique on its row and its column (sth like sudoku). Number N is always the same as the columns.
For example in a simple situation where there are 3 rows and 3 columns I should distribute 1, 2 and 3 like this (in rows): 1,2,3 - 2,3,1 - 3,1,2
Rows should always be less than or equal number of columns.
Any help would be appreciated.

Here's my go: no claim how good it is.
Start off with the matrix filled with a basic
rotation:
12345
23451
34512
45123
51234Then shuffle. Repeatedly:
1. Randomly choose to swap rows or cols.
2. Randomly pick a pair of rows/cols. Swap them.
For example, swapping the first and last row on
the original matrix yields:
51234
23451
34512
45123
12345
this sounds nice and easy. At the moment I am trying to do the following (which I am sure is bad) : a while (true) loop that picks a random number and random place and checks horizontally and vertically if it is ok to put the number in the randomly chosen place if not then another place is chosen. This is really time consuming though.

Similar Messages

  • Help with queries about boot camp and partition, please.

    Hi, I am hoping to partition my HDD. I have done this before, when I first got my macbook but got rid of it, and now I can't fully remember the do's and don'ts' of boot camp. I just need a few questions answered before I take any action.
    1. I have a 120GB HDD with about 15GB free space. If I partition the drive will I lose any data on my existing HDD?
    2. What is the minimal amount of space I can partition the drive and install Windows?
    (I have a copy of Windows XP SP2, and really only need to install it for the use of one program that isn't available on the Apple operating systems.)
    3. I tried using Parallels in which Windows took up about 6GB, will it be about the same again? I uninstalled it because I found it to lag a bit.
    If you can help with any of these queries I would really appreciate it, thanks!

    Maybe you should first get a larger drive; you don't have much more than the minimum 10% free space that Mac OS needs.
    Retry with Sun's VirtualBox. Maybe you just need more memory.
    Lose data? Step #1: backup.
    You may need to backup and erase your hard drive and then restore.
    I'd invest in 300GB drive though.

  • Help with iPad Identifying Phone Numbers in iMessage Send & Receive Settings / iMessage Syncing Help - iOS 6 - iPhone - iPad

    With iOS6, iPhone and iPad users will see that their Send & Receive iMessage settings have updated across their devices to be made available at both phone numbers and email addresses. You may have also seen alerts on one or more of your devices advising that another device is now using the same Apple ID/phone number for iMessage.
    Being able to be reached on iMessage on both Apple ID and phone numbers across devices means that iMessage can keep the same thread and sync across devices.
    Due to having 2 iPhones on different phone numbers running along side my iPad at one time, (whilst I was waiting for my phone number to be moved to a new provider), my iMessage settings on my iPad lost my phone number completely. I thought I would document the steps to recover this for anyone in the same boat.
    1. Check that you are signed in with the same iCloud Account on both iPad and iPhone.
    2. Turn off iMessage on your iPad from Settings > Messages.
    3. On your iPhone, go to Settings > Messages > Send & Receive. You should see your phone number and your iCloud email address in the 'Your can be reached by iMessage at:' list. Make sure both are ticked.
    4. At this point, I synced my iPhone with iTunes, then synced my iPad with iTunes.
    5. On your iPad, turn iMessage back on - your phone number should now show in the 'You can be reached by iMessage at:' list. Tick the phone number. You should receive an alert on your iPhone.
    This should resolve the issue.
    With the above set up and with the iOS 6 updates, iMessage should now sync fine across devices however I have still found the most successful way to run iMessage is to always start new conversations from your Apple ID and to start new threads by addressing the first message to an Apple ID from an Apple ID.
    To do this, go to Settings > iMessage > Send & Receive and tick your Apple ID in the 'Start new conversations from:' list, then start a new iMessage thread to the recipients Apple ID. This way, the thread will sync across iPad and iPhone. Note that a thread set up this way will not fall back on SMS, so you get a clean iMessage thread. This method also worked/works on iOS 5, as long as you send the first message of a new thread from an iPad (which can only send via Apple ID) to an Apple ID.
    Hopefully this helped someone!

    ipad has no phone number, you use a same email address for both devices. and set it in Settings>Messages>Send & Receive

  • I need help with just about everything...........

    I realize that this is a site dedicated to all things Apple, but I am hoping I can't get some honest and impartial help on building the best home network and entertainment system.
    I currently have an XP Media Center desktop computer in an office of my home where all of the network stuff is at and is connected via ethernet. I also have a Mac G4 MDD 1.0 that I am using in another room for Adobe Creative Suite to do my own promotional items and I have about a 50' Cat 6 cable running back to the router in the office. I also have a Vista laptop that is connected wirelessly but believe it is only a "g" network? I don't really use this a whole lot but take it out to job sites and such so there is information I need to send back and forth to my external drives hooked up via ethernet to my router. I am in the process of getting a new MacBook Pro as well.
    I have a PS3 hooked up to my home entertainment center but unsure of how to make everything work the way that I want. Here is what I would like to be able to do. 1) Networking of all computers and external drives, 2) Operate my Mac G4 Wirelessly, 3) Addition of internal bluetooth to G4 so I can get a wireless keyboard and mouse, 4) Ability to play iTunes from external hard drives on home entertainment center, 3) Ability to stream media from internet and hard drives to HDTV in home entertainment center
    I am looking to upgrade my router to dual band with either the Airport Extreme or the Netgear WNDR3700. I don't know which to get and have found about the same amount of pros and cons for each on the web. Any suggestions and why?
    Do I need an Apple TV or a Netgear WNHDEB111 or other Digital Media Reciever???
    What else would you recommend to accomplish my goals and why do you recommend the part and brand that you do.
    Thank you in advance for any and all assistance I can get.

    I getting a message saying[ a blackberry identity update is needed. Would you like to install it now yes or no /when I click yes I also getting this message[ BlackBerry identity installation failed please try again later. Keep getting this same message over and over

  • Help with algorithm

    HI !
    I need your help please.
    I have a series of n real numbers.
    I need to find the max sub-series (I mean the sub-series that its sum is the
    max).
    I need to find the first index and the last index of this sub series.
    Can you help me
    and tell me how can I do this ?
    Thank you
    Gil

    So the brute force method has polynomial time complexity [around O(n^3) intuitively], case closed!Spot the complexity theorist. Satisfied with n^3.
    I propose a divide and conquer approach. Of the pairs of consecutive numbers which are one positive and one negative, choose that which is nearest the middle of the list. For the left half, find the optimal subseries recursively, and find the optimal subseries ending at the last element in linear time. For the right half, find the optimal subseries recursively, and find the optimal subseries starting at the first element in linear time. Then the optimal series is either the best from the left, the best from the right, or the concatenation of the ones ending at the join point.
    Implementation details: don't subdivide a list all of whose elements are positive: the optimal subseries is the series. Assuming series of zero length are permitted (not specified), the optimal subseries at an end may be the series of zero length. (If not, it may still be, but caution is needed to avoid concatenating two zero length lists).
    Running time analysis: worst case (actually, I'm not sure it's possible, but I'm being pessimistic) - T(n) = O(n) + 2T(n-1). Exponential. Best case: O(n) (all elements positive). Average case: T(n) = O(n) + 2T(n/2)? If so, O(n lg n).
    If anyone can be bothered to bring down the worst case time estimate, I'd be interested to see what they can obtain. It's fairly clear that a bad split one time constrains how bad one of the splits from the recursive calls can be, so it's not obvious that exponential time will ever result.

  • Help with IF statement in numbers

    Hi Community
    Please could someone assist with creating a formula.
    I have created an exercise log (see image). Now when I input a formula in E, =D2/C2 it gives me my Minutes/km, but in a row containing 'Resistance' it obviously gives me the enoying red beacon.
    How can I create an IF/THEN statement, basically IF column C = "0", then 'leave field black', otherwise 'calculate my Minutes/km'.
    A solution will be greatly appreciated.
    Cheers,
    Mike

    I suggest the following changes:
    1) omit the "km" from in each entry of the "Distance" column and simply place it in the column header
    2) use the following formula for the "Min / km" column:
    E2=IF(C2>0,DURATION(,,,DUR2MINUTES(D2)/C2,), "")
    the problem is you cannot divide by 0 (EVER).  so you were correct to consider using an if to omit entries where the was no distance.
    I hop this helps.
    Wayne

  • Need help with info about the possibility of altering images when saved in a different format

    I am very new to the design world.  I have a printing business and received and image to be printed in Adobe Acrobat (I think).  I needed to resize the image to be printed and took it into Photoshop CS6 where I cropped the edges.  I then resave it as a PDF and took into a printer software, Fiery.  Fiery has an Impose function where you can repeat an image to layout it on the correct paper size.  It essentially just copies the original image several times depending on the layout.  This particular image I repeated to 3 up and 1 across.  When printed it came out with a magenta streak through the center image only.  I have had the machine checked and they are adamant it's not a printer issue but a software issue.  That once I altered the original image by resizing it that I altered the image and that I can't expect it to come out as seen on the screen.  I've printed it all sorts of different ways and it only occurs with the 3 up 1 across image.  I know that images can be changed when saved from program to program but this situation does not make sense that it is only the one area and layout that this shows up. I would appreciate any help, input, answers that anyone has.  Again, I'm new to this and would like to understand if this is a potential for further printing jobs so that I can do what I need to avoid this situation. 
    Thank you for your time.
    Jessica

    Jessica,
    Without knowing how the original graphic was created it is hard to tell you how to handle it. What is the name of the file? (Only the file suffix is important). If the file's origin was in a drawing program and/Or InDesign, then the document should be handled differently if the document is a raster image best handled by a program like Photoshop.

  • Pages 5.1 can anyone help with removing previous page numbers please?

    Hi.  in the new pages 5.1  I have made a section break at page 10 in a document and found how to start numbering from page 10 as page 1. Can anyone please tell me how to remove the page numbers from 1 to 10 that preceed this section?

    from the speed can I assume that it was adsl (copper) and not fibre connection?
    which hub do you have?
    can you enter your phone number and post results remember to delete number  https://www.btwholesale.com/includes/adsl/main.html
    If you like a post, or want to say thanks for a helpful answer, please click on the Ratings star on the left-hand side of the post.
    If someone answers your question correctly please let other members know by clicking on ’Mark as Accepted Solution’.

  • Need help with question about Microsoft Excel?

    I have recently begun using Microsoft Office for Mac. My question is related to the Excel program. I have used this for years on a PC where when the program opens, it shows a Workbook with a single page. However, on the Mac, when it opens, it shows many pages, the first going from column A to G, the second going from H to N, etc. and each page with the text "Click to add data". This continues forever. I would like to have just one sheet as on the PC. I have not found a way to limit this view to a single page. I have looked in the Preferences and in "View", but nothing seems to change the configuration. Any suggestions?
    Thanks

    My zoom only shows the magnification and does not give a "one page" option. However, I did find an icon that I loaded into the menu bar which gives the one page view. This may be due to the version 2004 that I am using.
    I also find that if I want to change the number of columns and rows, I change the size of each. I assume this is correct.
    Thanks for the help. This is slightly different that the PC version, but I am sure over time, there will be no problem.

  • Could someone help with question about PNG export from Illustrator?

    I am having issues with PNG exports from Illustrator not opening up once exported.

    ANd exactly sorry, this is useless. You have not provided any details about your export settings, version of AI, system info, how you are trying to view and so on. Just saying that it doesn't work is simply not good enough.
    Mylenium

  • Need help with Automatic Generating Form Numbers

    Hello,
    I am new to all this and have found myself stuck trying to figure out how to have my forms automatiacally generate a new number each time it is used. I tried looking through similar posts but do not understand the directions given there. If someone could help me figure this out I would really appreciate it. Thank you.

    Before opening my forms for responses I am creating a column with my starting form number - 1.  in the cell above(first response) I am setting an equation =B2 +1.  All incoming responses automatically generate an ID number within my responses table.  The form itself will not present the number, but if you were looking for an easy way to track responses w/ an ID it has worked well for me so far.

  • Help with algorithm design

    You are given an array of n keys, each with one of the values red, white, and blue.
    Give an O(n) algorithm for rearranging the keys so that all the reds come before all the whites,
    and all the whites come before all the blues. The only operations permitted are examination
    of a key to nd out what color it is, and swap of two keys

    Rahulm5000 wrote:
    You are given an array of n keys, each with one of the values red, white, and blue.
    Give an O(n) algorithm for rearranging the keys so that all the reds come before all the whites,
    and all the whites come before all the blues. The only operations permitted are examination
    of a key to nd out what color it is, and swap of two keys1. Put the keys one-at-a-time in a magical box -- O(n)
    2. Shake -- O(1).
    Or, if you lost your magical box, here's a start:
    {noformat}
    Cursors l <- first element, r <- last element
    do:
       while l isn't blue, l++
       while r is blue, r--
       swap l, r
    while l < r
    repeat for white.
    {noformat}It really is simple to create and prove an algorithm to be O(n) in this case, since the number of options is a constant, and is therefore irrelevant. If there were m colours, this approach would be O(n*m), but there arent.
    Edited by: endasil on 27-Oct-2009 11:58 PM

  • Hello, I need help with info about upgrading windows.

    Hi, after having my PC for almost a year, I'm now I'm wondering if it's possible to upgrade my windows 7 32-bit to a windows 7 64-bit?
    Here's a link to a website which has my PC and it's specs....
    http://www.tigerdirect.com/applications/SearchTools/item-details.asp?EdpNo=6288750&CatId=4928#
    If it is possible to upgrade my windows 7 32-bit to a windows 7 64-bit, then how do I do it? And what things will be required?
    Thanks.

    upgrade is the wrong word (you can't upgrade from 32 to 64)you can install 64 bit you can use the lenovo disc to just write over whats on your HDD or you can formate your HDD then install 64 bit using the lenovo media info is here http://support.lenovo.com/en_US/downloads/detail.page?DocID=HT002492 Edit: everything you need is on the disc...drivers & Apps, windows once you get it installed run system update to get system drivers up to date
    Thinkpad R61 7733-1GU
    Thinkpad X61T 7762-54U
    Thinkpad X60T 6363-4GU
    Did a member help you today? Thank them with a Kudo!
    If a post answers your question, please mark it as an "Accepted Solution"!
    Regards,
    GMAC

  • Help with questions about upgrading iLife'08 onto an older PowerBook G4

    I am seeking help/advice for a very low tech guy. I upgraded my PowerBook G4 (ancient I know but I have trouble with our thow away society), to Leopard 10.5.2. However, my iDVD no longer works. I plan on upgrading to iLife'08, but based on the system requirements, I am not certain all of the features (i.e. iMovie'08) will work on my older processor. Before I upgrade to iLife, can anyone tell me if I should do it and if they will work on my all the features will work on my PowerBook G4?

    You can upgrade to iLife 08. All the apps should install except iMovie.
    However, if you have iMovie 06, it will still work. And if you don't have iMovie 06, you can get it as a free download on the iMovie 08 Support Page.

  • Need Help With ePub Book Page Numbering

    I'm not understanding how to get the page numbers set in sequential order for an ePub.
    I've created a Book with 10 sections (all independent files).
    But, as you can see in the attached image, the file numbers do not progress from one "section" to another. This is messing up the TOC and the ePub navigation.
    What am I doing incorrectly?

    Book and Page Numbering Options were set correctly to:
    Continue from previous document
    Automatically Update Page & Section Numbers
    What I missed was setting Document Numbering Options to:
    Start Section >> Auto Page Numbering
    Document Chapter Numbering >> AutoChapter Numbering
    Each of my ten Book documents were defaulting to Start Page Numbering at: 1 which was causing each document/section to begin at 1.

Maybe you are looking for

  • Ipod touch wi-fi does not work

    I have not been able to access my wi-fi on ipod touch since upgrading to iOS6.  I have trid every recommendation that has been posted through the Apple Communities, I have also called Apple, however their response was to contact my wireless provider.

  • Can't get the "timing grid" to work

    I can't get the "grid" to work. There's no magnetism in the elements. I turn it on and off, but it makes no difference. Does anyone have the same problem or know what I do wrong??? Could it be a program failure. I'd be very gratefull to anyone who ca

  • Can the bookmark toolbar share a line with a plug-in toolbar?

    I want to tidy up the the toolbars. If there is space why can't the bookmark toolbar share the line with end-note plug-in toolbar?

  • Any suggestions how to display iframe of sharepoint 2013 page in 2010 page?

    Any suggestions how to display iframe of sharepoint 2013 page in 2010 page? keren tsur

  • Importing VHS tape into iMovie.

    I am importing VHS tapes into either imovie 09 or 06. When I play back in the program, it has good quality. But when I save it, no matter what format: mp4, .avi, .mov, etc. The quality is very poor when played back on DVD player. Any suggestions as t