Jump to content

Impossible Formula


tsilenzio

Recommended Posts

Example formula (I DID IT WRONG):

(x + 1) - abs(x)

 

The formula X want should output 1 when X = any positive number (including 0 UNLESS you can make the formula output 0 when X = 0)and outputs 0 when X = -1

 

Example of wanted output:

x = -1, formula = 0

x = 0, formula = 1

x = 1, formula = 1

x = 2, formula = 1

x = 3, formula = 1

x = 4, formula = 1

so on..

OR

x = 0, formula = 0

x = 1, formula = 1

x = 2, formula = 1

x = 3, formula = 1

x = 4, formula = 1

x = 5, formula = 1

so on..

 

If you know or think this is impossible then PLEASE let me know. Also if u cab provide an alternative that would work JUST as well! :)

 

Example of alternative:

x = 0, formula = 1

x = 1, formula = 2

x = 2, formula = 2

x = 3, formula = 2

x = 4, formula = 2

x = 5, formula = 2

so on..

 

Thank you in advance!

  - tsilenzio

Link to comment
https://forums.phpfreaks.com/topic/65376-impossible-formula/
Share on other sites

Easy, use:

 

x/{abs(x) + 1} + 1/{abs(x) + 1}

 

Which is the same as

 

(x + 1)/(abs(x) + 1)

 

Hope it helps, cheers.

 

You need to add ceil() otherwise it doesn't work with -2, -3, ...

 

<?php
for ($x=-5; $x<=5; $x++) echo ceil(($x + 1)/(abs($x) + 1)), '<br>' ;
?>

 

But to me, gurroa's

 

$x = $x > 0 ? 1 : 0;

 

seems a somewhat simpler solution

Link to comment
https://forums.phpfreaks.com/topic/65376-impossible-formula/#findComment-326525
Share on other sites

JESUS You guys rock! I spent a couple hours on it and couldn't find an answer (I was half awake, still am) but I couldnt figure ANYTHING out so i started to think it was impossible but very few is impossible with math.

 

I probably would have been able to do it probably if i was more awake and had taken pre-cal or calculus in high school, not that I dont love math :) just my counsolor didn't tell me the alternatives that i asked about that i learned later i could have really done =/

 

Anyways you guys dont ned to hear that stuff, thanx SOO much again guys!! MUCH MUCH appreciation :)

Link to comment
https://forums.phpfreaks.com/topic/65376-impossible-formula/#findComment-326555
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.