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
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
Share on other sites

Whoops, thanks for clarifying. Didn't test it with anything less than -1.

 

And gurroa's alternative is indeed simpler and nicer, but I got the impression that he was looking for some math/algebraic formula (excluding boolean  ;D). [/disclaimer]

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.