little math puzzle. Map 1 0 -1 to 1 0.5 0
05-21-2018, 10:24 AM (This post was last modified: 05-21-2018 10:25 AM by pier4r.)
Post: #1
 pier4r Senior Member Posts: 2,065 Joined: Nov 2014
little math puzzle. Map 1 0 -1 to 1 0.5 0
Similar to "which kind of programmer are you": http://holyjoe.net/hp/flash07.txt
(there the e^x solution was quite neat)

One get in input a value that can be 1 or 0 or -1 .
The objective is to map those input to:
1 -> 1
0 -> 0.5
-1 -> 0

Of course, the first approach is a "switch case" block. Other ideas? (note that the first range is scaled to the second, but one ending point stays the same)

Wikis are great, Contribute :)
05-21-2018, 11:24 AM
Post: #2
 Thomas Okken Senior Member Posts: 1,094 Joined: Feb 2014
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 10:24 AM)pier4r Wrote:  1 -> 1
0 -> 0.5
-1 -> 0

x -> (x + 1) / 2
05-21-2018, 02:33 PM
Post: #3
 Valentin Albillo Senior Member Posts: 612 Joined: Feb 2015
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 10:24 AM)pier4r Wrote:  Of course, the first approach is a "switch case" block. Other ideas? (note that the first range is scaled to the second, but one ending point stays the same)

The Xs are in arithmetic progression with d=-1 while the Ys have d=-0.5 so Y=X/2 plus a constant. As Y(0)=0.5 the constant is precisely 0.5 and so Y=X/2+0.5 which of course is the same solution as Thomas'.

The L.R. (Linear Regression) function on most any HP calc new or old would give you the solution at once (slope and intercept).

Regards.
V.
.

Find All My HP-related Materials here:  Valentin Albillo's HP Collection

05-21-2018, 04:31 PM (This post was last modified: 05-21-2018 04:47 PM by Dieter.)
Post: #4
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 10:24 AM)pier4r Wrote:  One get in input a value that can be 1 or 0 or -1 .
The objective is to map those input to:
1 -> 1
0 -> 0.5
-1 -> 0

That's trivial since changing the input by 1 changes the output by 0,5. So (1|1), (0|0,5) and (–1|0) are points on a straight line with a slope of 0,5. Due to (0|0,5) the y-intercept is 0,5 as well. So you can get the parameters by simply looking at the data. ;-)

Instead of 0,5x + 0,5 you can also write (x+1)/2.
Or in RPN:

1
+
2
/

WP34s users can save a step with

INC X
#1/2
x

BTW, you may vary the puzzle with a non-linear mapping. For three points it can always be done with a parabolic fit. But maybe there also is another and shorter/faster way to do it. ;-)

5 -> 2
2 -> 1
1 -> 0

As a kind of warm-up you may try

1 -> 1
0 -> 0
–1 -> 0

;-)

Dieter
05-21-2018, 05:06 PM
Post: #5
 Jim Horn Member Posts: 189 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 04:31 PM)Dieter Wrote:    1 -> 1
0 -> 0
–1 -> 0

ABS + 2 /
05-21-2018, 05:20 PM
Post: #6
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 05:06 PM)Jim Horn Wrote:  ABS + 2 /

I assume this is supposed to mean
ENTER ABS + 2 /

Yes, this works. But it requires five steps.
What about four? Or three? Or even less?

Dieter
05-21-2018, 05:34 PM
Post: #7
 Joe Horn Senior Member Posts: 1,674 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 04:31 PM)Dieter Wrote:    1 -> 1
0 -> 0
–1 -> 0

1 - NOT

<0|ɸ|0>
-Joe-
05-21-2018, 06:13 PM (This post was last modified: 05-21-2018 06:18 PM by Dieter.)
Post: #8
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 05:34 PM)Joe Horn Wrote:  1 - NOT

Which calculator do you have in mind here?
I tried this on a 35s and it returns

1 -> –1
0 ->   0
–1 ->   1

More important, what do you do on a HP25, HP67 or HP41 ?-)

Dieter
05-21-2018, 06:28 PM (This post was last modified: 05-21-2018 06:32 PM by Werner.)
Post: #9
 Werner Senior Member Posts: 525 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
1->1
0->0
-1->0

Mine:

X<0?
CLX

Cheers, Werner
05-21-2018, 06:34 PM (This post was last modified: 05-21-2018 06:52 PM by Dieter.)
Post: #10
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 06:28 PM)Werner Wrote:  X<0?
CLX

That's what I had in mind. ;-)

And now for the trickier part:

5 -> 2
2 -> 1
1 -> 0

Edit: My current solution does it with 3 steps.
And just 2 on the 34s.

I now see it's not quite as tricky as I thought. ;-)

Dieter
05-21-2018, 07:06 PM
Post: #11
 Logan Member Posts: 138 Joined: Jul 2016
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
2- bytes if in FIX 00 mode

LN
RND
05-21-2018, 07:26 PM (This post was last modified: 05-21-2018 07:30 PM by Dieter.)
Post: #12
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 07:06 PM)Logan Wrote:  2- bytes if in FIX 00 mode

LN
RND

Great. But for a complete solution you'd have to add a FIX 0, and this makes it one of the possible 3 step solutions. But on an HP67 it's even 4 steps, or 4 bytes on the '41.

However, logs usually are a bit slow, and changing the display mode should be avoided, if possible. But it can be done with the same 3 steps without logs and without a special display setting.

Dieter
05-21-2018, 07:28 PM
Post: #13
 Joe Horn Senior Member Posts: 1,674 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 06:13 PM)Dieter Wrote:
(05-21-2018 05:34 PM)Joe Horn Wrote:  1 - NOT

Which calculator do you have in mind here?
I tried this on a 35s and it returns

1 -> –1
0 ->   0
–1 ->   1

Ah yes, models differ. 1 – NOT works in all RPL models.

<0|ɸ|0>
-Joe-
05-21-2018, 07:33 PM
Post: #14
 Joe Horn Senior Member Posts: 1,674 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 06:34 PM)Dieter Wrote:  And now for the trickier part:

5 -> 2
2 -> 1
1 -> 0

Edit: My current solution does it with 3 steps.

1 – SQRT

Works on all RPN/RPL models, I think.

<0|ɸ|0>
-Joe-
05-21-2018, 07:46 PM
Post: #15
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 07:33 PM)Joe Horn Wrote:  1 – SQRT

Works on all RPN/RPL models, I think.

Hey, that's a good one!
My solution is different, but takes the same three steps.
Anyone else with three steps? Or even less?

Dieter
05-21-2018, 07:53 PM
Post: #16
 pier4r Senior Member Posts: 2,065 Joined: Nov 2014
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 04:31 PM)Dieter Wrote:  That's trivial since changing the input by 1 changes the output by 0,5. So (1|1), (0|0,5) and (–1|0) are points on a straight line with a slope of 0,5. Due to (0|0,5) the y-intercept is 0,5 as well. So you can get the parameters by simply looking at the data. ;-)

True. I thought about scaling a range.

Wikis are great, Contribute :)
05-21-2018, 07:56 PM
Post: #17
 Arno K Senior Member Posts: 440 Joined: Mar 2015
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
sqrt
ip

Arno
05-21-2018, 07:57 PM
Post: #18
 Logan Member Posts: 138 Joined: Jul 2016
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 07:56 PM)Arno K Wrote:  What about
sqrt
ip

Arno

Doesn't work with 1 mapping to 0 though
05-21-2018, 07:58 PM
Post: #19
 Arno K Senior Member Posts: 440 Joined: Mar 2015
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
ups
Arno
05-21-2018, 08:07 PM
Post: #20
 J-F Garnier Senior Member Posts: 456 Joined: Dec 2013
RE: little math puzzle. Map 1 0 -1 to 1 0.5 0
(05-21-2018 06:34 PM)Dieter Wrote:  And now for the trickier part:
5 -> 2
2 -> 1
1 -> 0

(05-21-2018 07:46 PM)Dieter Wrote:
(05-21-2018 07:33 PM)Joe Horn Wrote:  1 – SQRT
Works on all RPN/RPL models, I think.

Hey, that's a good one!
My solution is different, but takes the same three steps.
Anyone else with three steps? Or even less?

2 / INT

J-F :-)
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)