logic question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting logic question
# 1  
Old 07-01-2008
logic question

Hi, this is logic question, not sure anyone can answer

I have 5 balls, and balance in front of me, this 5 balls look the same, but one of them is heavier, I need to use balance to find the heavier ball

my approach is take any 2 balls, 2 balls in each side of balance, if the weight the same, then fifth ball is the answer, if one of the two balls group is heavier, then take each ball from that 2 balls group to each side of balance, the heavier one is the answer .

can we write it programatically with unix or perl?

Thanks

Chris
# 2  
Old 07-01-2008
Isn't that just comparing? I mean, instead of the balance thing you could do something like:
make array (weigh each ball); testweight is value of balls[0]; unset balls[0]
for item in (sequence of [amount of array items minus 1]); do
if [weight of item] equals testweight then continue
elif [weight of item] greater than testweight then echo item
elif [weight of item] less than testweight then echo testweight
done?
# 3  
Old 07-01-2008
logic

Hi, this is chris

Thank you foir your response about logic question
can you write a program?
you sem use good approach
thanks

Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

More a logic than a programming question

hello, I'm a littlebit lost... i have a table of single names and combination of two names and i want a table of ALL single names with ALL combinations (also the indirect ones). - - - in reality the names are longer, not only a,b,.. and the table is tab-delimited, and the result table... (6 Replies)
Discussion started by: dietmar13
6 Replies

2. Shell Programming and Scripting

Parent/Child Scripting logic Question

I have Parent script that will execute a child script. The child script will take about 2 hours to run and I wanted to somehow build a logic for parent.sh to wait and perform ps -ef|grep cp|grep -v on the child.sh cp process and loop and check return code of child.sh $? as well. Once they are both... (3 Replies)
Discussion started by: jigarlakhani
3 Replies
Login or Register to Ask a Question