Solved

# Algorithm

Posted on 1998-09-04
198 Views
I am looking for an algorithm that will allow you to add up squares and determine the individuals.  OK...that doesn't make much sense.  Here's an example.  There are 4 options.  The values to the options are 1, 2, 4, and 8 respectively.  If the total of the options is 14, what routine would let me know that the 2nd, 3rd, and 4th option were picked?
0
Question by:IsleOfView
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3

LVL 84

Expert Comment

ID: 1204693
\$_ = unpack'b*',pack'V',14;
print pos,"\n"  while( /1/g );
0

Author Comment

ID: 1204694
That works perfectly.  (I think I need to hit the books to understand the syntax, though) :)

0

LVL 84

Accepted Solution

ozo earned 10 total points
ID: 1204695
\$_ = unpack'b*',pack'V',14;
print pos,"\n"  while( /1/g );
#or
for( 1..4 ){ print if \$_&14 }
0

LVL 84

Expert Comment

ID: 1204696
#sorry, that second one should have been
for( 1..4 ){ print if 1<<\$_-1 & 14 }
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
###### Suggested Courses
Course of the Month7 days, 22 hours left to enroll