Click here to Skip to main content
15,881,380 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
Jörgen Andersson30-Dec-20 9:33
professionalJörgen Andersson30-Dec-20 9:33 
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 
So, if I have this right.
I can tell if a Bolt+NUT is Bigger OR FITS or "not" meaning it is clearly smaller.

The simplest algorithm is a bubble sort type loop/loop (O(n^2)).
// Z = Number of nuts/bolts, N[1..Z], B[1..Z] hold the nuts/bots

For X = 1 to Z
  For Y = 1 to Z
    If Fits(B[X],N[Y]) then F[X]=Y : Break;
  Next Y
Next X

For X = 1 to Z
  Print "Bolt " & X & " Fits with Nut " & F[X]
Next X

// Accepting that if the output is all that is needed, do the print in the main loop, before the break;
// If "Fits()" is an expensive function, then pre-check F[X] for 0 or something to skip it if assigned

// No optimizations here.  But short, clear, concise.
// Simplest optimization is to process the second loop in reverse, deleting an element as it is matched

// The list of Nuts will shrink by one with each pass, cutting the comparisons in half.
// Unfortunately requires a modifiable array.

For X = 1 to Z
  For Y = Length(N) to 1 Step -1
    If Fits(B[X],N[Y]) then F[X]=Y :  N.delete(Y) : Break;
  Next Y
Next X

GeneralRe: Nuts and bolts - Programming contest Pin
James Lonero29-Dec-20 15:00
James Lonero29-Dec-20 15:00 
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 

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.