Click here to Skip to main content
15,886,664 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Nuts and bolts - Programming contest Pin
PIEBALDconsult30-Dec-20 16:41
mvePIEBALDconsult30-Dec-20 16:41 
GeneralRe: Nuts and bolts - Programming contest Pin
Kornfeld Eliyahu Peter28-Dec-20 23:12
professionalKornfeld Eliyahu Peter28-Dec-20 23:12 
GeneralRe: Nuts and bolts - Programming contest Pin
Sander Rossel29-Dec-20 3:20
professionalSander Rossel29-Dec-20 3:20 
GeneralRe: Nuts and bolts - Programming contest Pin
Harrison Pratt29-Dec-20 4:20
professionalHarrison Pratt29-Dec-20 4:20 
GeneralRe: Nuts and bolts - Programming contest Pin
Harrison Pratt29-Dec-20 5:07
professionalHarrison Pratt29-Dec-20 5:07 
GeneralRe: Nuts and bolts - Programming contest Pin
Dan Sutton29-Dec-20 6:15
Dan Sutton29-Dec-20 6:15 
GeneralRe: Nuts and bolts - Programming contest Pin
Kirk 1038982129-Dec-20 10:41
Kirk 1038982129-Dec-20 10:41 
GeneralRe: Nuts and bolts - Programming contest Pin
James Lonero29-Dec-20 15:00
James Lonero29-Dec-20 15:00 
Assuming a mixed pile of nuts and bolts where
1. Each nut matches exactly one bolt.
2. Must fit a nut and bolt together to compare “which is bigger” (size)
3. Not possible to (cannot) directly compare two nuts or bolts

Staying within the parameters:
* From #1, we know that each bolt has a corresponding matching nut. Then the matching bolt and nut are eliminated from further searches.
* From #2, ‘bigger’ assumes size. Not head configuration, pitch, left or right-handed, or composition. Also, since we need to fit the nut onto the bolt, we are only concerned about the width/diameter (of the bolt and nut) and not the length.
* From #3, we cannot compare the nuts or the bolts therefore, we are not allowed to sort them. (This includes measuring the size of each bolt

To go into the algorithm with this set of parameters, we are not to sort the list of bolts and nuts and we are only comparing the diameters. So, we know that we have a set of N nuts to match up with a similar number of bolts. Here is a simple algorithm:
int boltDiameters[n]  // Resizable array
int nutDiameters[n]   // Resizable array

do {
    boltsize = boltDiameters[0]
    for (int i = 0; i < nutDiameters.Length; i++) {
       if (nutDiameters[i] == boltsize) {
            println("Found nut-bolt with size of: " + boltsize)
            nutDiameters.RemoveAt(i)
            boltDiameters.RemoveAt(0)
       }
    }   
} Until (boltDiameters.Length == 0)

Each iteration through the loop, we reduce the arrays by one element. So, the average number of comparisons are N/2 + (N-1)/2 + (N-2)/2 + … + (N-(N-1))/2 + 1 = (N + N-1 + N-2 + … + N-(N-1))/2 + 1, which by my guess is (N^2)/4
GeneralRe: Nuts and bolts - Programming contest Pin
PIEBALDconsult30-Dec-20 12:59
mvePIEBALDconsult30-Dec-20 12:59 
GeneralRe: Nuts and bolts - Programming contest Pin
OldDBA31-Dec-20 3:56
OldDBA31-Dec-20 3:56 
GeneralRe: Nuts and bolts - Programming contest Pin
PIEBALDconsult31-Dec-20 12:22
mvePIEBALDconsult31-Dec-20 12:22 
GeneralThought of the Day Pin
OriginalGriff28-Dec-20 4:39
mveOriginalGriff28-Dec-20 4:39 
GeneralRe: Thought of the Day Pin
W Balboos, GHB28-Dec-20 5:41
W Balboos, GHB28-Dec-20 5:41 
GeneralRe: Thought of the Day Pin
jeron128-Dec-20 5:57
jeron128-Dec-20 5:57 
GeneralRe: Thought of the Day Pin
Johnny J.28-Dec-20 21:56
professionalJohnny J.28-Dec-20 21:56 
GeneralRe: Thought of the Day Pin
jeron129-Dec-20 8:10
jeron129-Dec-20 8:10 
GeneralJust one well placed virtual function saves the day Pin
honey the codewitch28-Dec-20 4:08
mvahoney the codewitch28-Dec-20 4:08 
GeneralRe: Just one well placed virtual function saves the day Pin
Josh Gray228-Dec-20 4:57
Josh Gray228-Dec-20 4:57 
GeneralRe: Just one well placed virtual function saves the day Pin
honey the codewitch28-Dec-20 5:18
mvahoney the codewitch28-Dec-20 5:18 
GeneralRe: Just one well placed virtual function saves the day Pin
DRHuff28-Dec-20 5:27
DRHuff28-Dec-20 5:27 
GeneralRe: Just one well placed virtual function saves the day Pin
honey the codewitch28-Dec-20 5:33
mvahoney the codewitch28-Dec-20 5:33 
GeneralSynchro/Servo? Stepper? What? Pin
GenJerDan28-Dec-20 0:11
GenJerDan28-Dec-20 0:11 
GeneralRe: Synchro/Servo? Stepper? What? Pin
Mircea Neacsu28-Dec-20 0:42
Mircea Neacsu28-Dec-20 0:42 
GeneralRe: Synchro/Servo? Stepper? What? Pin
GenJerDan28-Dec-20 1:05
GenJerDan28-Dec-20 1:05 
GeneralRe: Synchro/Servo? Stepper? What? Pin
glennPattonWork328-Dec-20 2:43
professionalglennPattonWork328-Dec-20 2:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.