Calculator programing problem

Associate
Joined
9 Sep 2009
Posts
1,241
If I've have these numbers and I they can be used or not (they relate to on off switches )
How can I write a program to work out which combination will get closest to a given number up to 128 ?


The letters are just there to label the switches

Thanks


64 A
32 B
16 C
8 D
4 E
2 F
1 G
0.5 H
0.25 I
0.125 J
0.0625 K
0.03125 L
0.015625 M
0.0078125 N
 
Caporegime
Joined
18 Oct 2002
Posts
32,618
You question is not only impossible to parse but is incomplete. What kind of operations are permitted (addition, subtracting, multiplication, power?). Are you trying to minimize the number of ops or do you not care?

As a rough answer, since the values follow a simple double then you can use a greedy algorithm, the only complexity being the degree of operations permitted.
 
Soldato
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
You can make every number exactly up to 128 with those combinations.
Your buttons relate to binary powers. Convert your target number to binary and that'll give you the answer...

(is this some sort of homework?)
 
Associate
OP
Joined
9 Sep 2009
Posts
1,241
You can make every number exactly up to 128 with those combinations.
Your buttons relate to binary powers. Convert your target number to binary and that'll give you the answer...

(is this some sort of homework?)

Thanks, that's brilliant

Its not homework I'm trying to work out how to use some electronics.
 
Associate
OP
Joined
9 Sep 2009
Posts
1,241
You can make every number exactly up to 128 with those combinations.
Your buttons relate to binary powers. Convert your target number to binary and that'll give you the answer...

(is this some sort of homework?)
So I'm using Excel to convert to Binary DEC2BIn is there a way of showing numbers less than 0 ?
 
Back
Top Bottom