Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
def func(number1,number2,number3):
    
    add_div_1 = (number1 + number2 + number3) / 3
    add_div_2 = (number1 - number2 - number3)/ 3
    add_div_3 = (number1 + number2 - number3) / 3
    add_div_4 = (number1 - number2 + number3) / 3
    
    cond1 = abs(add_div_1/add_div_3)
    cond2 = abs(add_div_2/add_div_4)
    
    opt = cond1*cond2
    return opt

one_num = func(1.5,2.5,3.5)
print one_num


VB
array_n = [10,20,30]

b = 0
bt = 1   # step

while b < 10:

    b = b + bt

    for i in array_n:
        MAX = 31
        r = rand(3)
        r = abs(2*MAX*(r-0.5))

        num1 = array_n[0]
        num2 = array_n[1]
        num3 = array_n[2]

        n1,n2,n3 = r

        new_num1 = num1 + n1
        new_num2 = num2 + n2
        new_num3 = num3 + n3

        newnums = [new_num1,new_num2,new_num3]
        print newnums

one_num = func(new_num1,new_num2,new_num3)

if one_num < 27.0:

    print "The number is lower than 27.0 .","The number is:", one_num
    print "The number values are:", newnums

else:

    print "The number is larger than 27.0 .","The number is:", one_num
    print "The number values are:", array_n



The code above works with no problems, but does not do the job I want it to do. And, I am not sure how to do that. You will need to run the code in order to understand what I am about to explain.

At the end, after you see the thirty arrays of values, you will see either the two statements with "The number is lower..." or "The number is larger...". For either pair of statements, the values are selected from the last array of those thirty arrays. Instead, I want the program to choose the best array that gives me the "one_num" as low as possible from 27. Then, when I run the program again, the program will create all new arrays, and from that it should choose the best array that gives me the "one_num" as low as possible from 27. But, if the "one_num" in the 2nd second run or any in other run after its previous is higher than its previous "one_num", then keep the good value (lower one_num).

I am sorry, if that is confusing, but it is hard to explain programming.
Posted
Comments
Sergey Alexandrovich Kryukov 15-Nov-14 19:37pm    
Everything can be explained, at least when it is about such a formal system as a program. If you explain it formally and precisely (first of all, to yourself), consider half of your problems is solved (well, in most cases).
It's not the best idea to start explanation from what one can see. It would be better to start with your goals.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900