Click here to Skip to main content
16,018,057 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list of possible values for x. I need a math formula that will spit out certain results depending on the value of x. I could use a list of if/thens, but I was hoping there was a more graceful way of doing it. I need it to weight the values of a search algorithm.

if x = 1 then y = 2
if x = 2 then y = 1
if x = 3 then y = 0.5
if x = 4 then y = 0.25

The closest I've gotten is y = x/(x*2), but that falls apart below 3. I'm gonna keep thinking about it, but if you beat me to it, thanks!
Posted

1 solution

Isn't that just
y = 2^(2-x)
 
Share this answer
 

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