2

I am trying to code the following:

there will be six inputs, say 1,2,3,4,5,6

inputs 2-6 have two possible options (say yes and no)

input 1 has seven possible options (say a-g)

depending on which inputs are selected, a specific output will be generated.

So if you had - a, yes, yes, no, no, no - it would generate outcome 'x'

I have managed to create a list with all the possible input combinations (using python):

list = [[23,24,25,26,27,28,29],["male","female"],["true","false"],["true","false"],["true","false"],["true","false"]]

r=[[]]
for e in list:
    table = []
    for item in e:
            for i in r:
                table.append(i+[item])
    r = table

print r

My next stage is to allocate an outcome to each of these options. I guess the best way to do this is just append the output to each list item so that

for e in index, if e[0]-e[5] matches the input then print out e[6]

Is this an ok way to do it?

EDIT

Just to make it clearer I just thought I'd explain what I am actually trying to do. It's a free tool for doctors (I'm a doc - it's not for commercial purposes just to improve patient care).

It is a way of calculating risk for the patient, so there will be five questions the doc will input - e.g. male/female etc and depending on their inputs it will produce the outcome as a % risk for the patient. We are using years of previous patient outcome data to produce the table of outcome.

4
  • So 7*2*2*2*2*2 is 224 possible outcomes. You're saying you want to hard code all of those into a giant map of some sort? Commented Jun 6, 2012 at 15:02
  • 1
    Any more context available? Got any code you've tried already (regardless of language)? Commented Jun 6, 2012 at 15:02
  • Mike - yes, that's right. A giant map that I can then look up to match the input. Commented Jun 7, 2012 at 0:13
  • Daniel - thanks. I am at the very beginning and just trying to work out how to approach it. I'm going to get started with the idea below and see how I get on. Will post back with my progress Commented Jun 7, 2012 at 0:15

1 Answer 1

2

You can think of input 2-6 as 5 bits (5 boolean values), and input 1 as 3 higher bits (to encode 7 values). Then loop from 0 to 223, and generate all the possible combination by decoding the number as the scheme above.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this. I will get started with this and will post back to let you know how I get on. Much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.