Matching algorithm

I have a list of pencils and a list of erasers. The goal it to check whether or not all the erasers can be put on pencils. An eraser may fit on multiple different pencils. Pencils can have at most 1 eraser.

If I just loop through all the erasers and put them on pencils, I end up with erasers that fit no unoccupied pencils even though there is a solution that has all the erasers on pencils.

What algorithm could I use to figure out a combination that fits all the erasers on pencils?

public class Eraser(){
    public boolean matches(Pencil p){
    //unimportant
    }
}

public class Pencil(){
}

My attempt

public boolean doMatch(List<Eraser> erasers, List<Pencil> pencils){
for (Eraser e : erasers) {
        boolean found = false;
        Iterator it = pencils.iterator();
        while (it.hasNext()) {
            Pencil p = (Pencil) it.next();
            if (e.matches(p)) {
                found = true;
                it.remove();
                break;
            }
        }
        if (!found) {
            return false;
        }
}
return true;
}

read more

Matching algorithm

I have a list of pencils and a list of erasers. The goal it to check whether or not all the erasers can be put on pencils. An eraser may fit on multiple different pencils. Pencils can have at most 1 eraser.

If I just loop through all the erasers and put them on pencils, I end up with erasers that fit no unoccupied pencils even though there is a solution that has all the erasers on pencils.

What algorithm could I use to figure out a combination that fits all the erasers on pencils?

public class Eraser(){
    public boolean matches(Pencil p){
    //unimportant
    }
}

public class Pencil(){
}

My attempt

public boolean doMatch(List<Eraser> erasers, List<Pencil> pencils){
for (Eraser e : erasers) {
        boolean found = false;
        Iterator it = pencils.iterator();
        while (it.hasNext()) {
            Pencil p = (Pencil) it.next();
            if (e.matches(p)) {
                found = true;
                it.remove();
                break;
            }
        }
        if (!found) {
            return false;
        }
}
return true;
}

read more

Get id of specific div

I need to display channel name when user do subscribe or unsubscribe. Below is two sub buttons and event script.

<script src="https://apis.google.com/js/platform.js"></script>


<div id="chan-1" class="g-ytsubscribe" data-channel="SMOSH" data-layout="default" data-count="default" data-onytevent="onYtEvent"></div>
</div>

<div id="chan-2" class="g-ytsubscribe" data-channel="Apple" data-layout="default" data-count="default" data-onytevent="onYtEvent"></div>
</div>

<script>
function onYtEvent(payload) {


    if (payload.eventType == 'subscribe') {
      // Need to display subscribed channel name

    } else if (payload.eventType == 'unsubscribe') {
      // Need to display unsubscribed channel name

    }
    if (window.console) { // for debugging only
      window.console.log('YT event: ', payload);
    }
  }
</script>

read more

Get id of specific div

I need to display channel name when user do subscribe or unsubscribe. Below is two sub buttons and event script.

<script src="https://apis.google.com/js/platform.js"></script>


<div id="chan-1" class="g-ytsubscribe" data-channel="SMOSH" data-layout="default" data-count="default" data-onytevent="onYtEvent"></div>
</div>

<div id="chan-2" class="g-ytsubscribe" data-channel="Apple" data-layout="default" data-count="default" data-onytevent="onYtEvent"></div>
</div>

<script>
function onYtEvent(payload) {


    if (payload.eventType == 'subscribe') {
      // Need to display subscribed channel name

    } else if (payload.eventType == 'unsubscribe') {
      // Need to display unsubscribed channel name

    }
    if (window.console) { // for debugging only
      window.console.log('YT event: ', payload);
    }
  }
</script>

read more

How to count the number of spots in this image?

I am trying to count the number of hairs transplanted in the following image. So practically, I have to count the number of spots I can find in the center of image.
(I’ve uploaded the inverted image of a bald scalp on which new hairs have been transplanted because the original image is bloody and absolutely disgusting! To see the original non-inverted image click here. To see the larger version of the inverted image just click on it). Is there any known image processing algorithm to detect these spots? I’ve found out that the Circle Hough Transform algorithm can be used to find circles in an image, I’m not sure if it’s the best algorithm that can be applied to find the small spots in the following image though.

read more