Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

#CJam, 90 bytes

This is based on a iterative flood fill explained herehere and can be golfed a lot!

q~:Q{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p 

Requires the input in order of ABCDEFGH like:

[0 1 1 2 1 0 5 5 1] 

and output is the connected nodes:

[1 1 2 1 5 5 1] 

Brief Explanation

  • First, I iterate over the input array for each label.
  • In each iteration, I perform floodfill to figure out disconnected nodes.
  • If the number of disconnected nodes is greater than 1, then that label is disconnected.
  • 1 because a label can have just 1 occurrence in the input array too.
  • Then I simply filter out disconnected labels and print the array.

Full explanation to follow

Try it online here

#CJam, 90 bytes

This is based on a iterative flood fill explained here and can be golfed a lot!

q~:Q{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p 

Requires the input in order of ABCDEFGH like:

[0 1 1 2 1 0 5 5 1] 

and output is the connected nodes:

[1 1 2 1 5 5 1] 

Brief Explanation

  • First, I iterate over the input array for each label.
  • In each iteration, I perform floodfill to figure out disconnected nodes.
  • If the number of disconnected nodes is greater than 1, then that label is disconnected.
  • 1 because a label can have just 1 occurrence in the input array too.
  • Then I simply filter out disconnected labels and print the array.

Full explanation to follow

Try it online here

#CJam, 90 bytes

This is based on a iterative flood fill explained here and can be golfed a lot!

q~:Q{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p 

Requires the input in order of ABCDEFGH like:

[0 1 1 2 1 0 5 5 1] 

and output is the connected nodes:

[1 1 2 1 5 5 1] 

Brief Explanation

  • First, I iterate over the input array for each label.
  • In each iteration, I perform floodfill to figure out disconnected nodes.
  • If the number of disconnected nodes is greater than 1, then that label is disconnected.
  • 1 because a label can have just 1 occurrence in the input array too.
  • Then I simply filter out disconnected labels and print the array.

Full explanation to follow

Try it online here

added 406 characters in body
Source Link
Optimizer
  • 26.6k
  • 7
  • 67
  • 144

#CJam, 9290 bytes

This is based on a recursiveiterative flood fill explained here and can be golfed a lot!

q~:Q_&Q{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p 

Requires the input in order of ABCDEFGH like:

[0 1 1 2 1 0 5 5 1] 

and output is the connected nodes:

[1 1 2 5]1 5 5 1] 

Full explanation to followBrief Explanation

  • First, I iterate over the input array for each label.
  • In each iteration, I perform floodfill to figure out disconnected nodes.
  • If the number of disconnected nodes is greater than 1, then that label is disconnected.
  • 1 because a label can have just 1 occurrence in the input array too.
  • Then I simply filter out disconnected labels and print the array.

Full explanation to follow

Try it online here

#CJam, 92 bytes

This is based on a recursive flood fill explained here and can be golfed a lot!

q~:Q_&{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p 

Requires the input in order of ABCDEFGH like:

[0 1 1 2 1 0 5 5 1] 

and output is the connected nodes:

[1 2 5] 

Full explanation to follow

Try it online here

#CJam, 90 bytes

This is based on a iterative flood fill explained here and can be golfed a lot!

q~:Q{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p 

Requires the input in order of ABCDEFGH like:

[0 1 1 2 1 0 5 5 1] 

and output is the connected nodes:

[1 1 2 1 5 5 1] 

Brief Explanation

  • First, I iterate over the input array for each label.
  • In each iteration, I perform floodfill to figure out disconnected nodes.
  • If the number of disconnected nodes is greater than 1, then that label is disconnected.
  • 1 because a label can have just 1 occurrence in the input array too.
  • Then I simply filter out disconnected labels and print the array.

Full explanation to follow

Try it online here

Source Link
Optimizer
  • 26.6k
  • 7
  • 67
  • 144

#CJam, 92 bytes

This is based on a recursive flood fill explained here and can be golfed a lot!

q~:Q_&{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p 

Requires the input in order of ABCDEFGH like:

[0 1 1 2 1 0 5 5 1] 

and output is the connected nodes:

[1 2 5] 

Full explanation to follow

Try it online here