EntropySink

Technical & Scientific => Programming => Topic started by: Rob on June 13, 2019, 10:59:03 AM

Title: Gaaaah! Stupid question.
Post by: Rob on June 13, 2019, 10:59:03 AM
Sorry to post such a stoopid question here, but I need some help. I'm getting bogged down on a calculation and I can't wrap my head around it.

Basically I need to do the following mapping.

14 -> 69
15 -> 69
16 -> 69
17 -> 69
18 -> 73
19 -> 73
20 -> 73
21 -> 73
22 -> 77
23 -> 77
24 -> 77
25 -> 77
26 -> 81
27 -> 81
28 -> 81
29 -> 81

etc etc.

I know there must be a function where fn(x) = y, and it's probably really simple, but I just can't see it.

Currently I have a switch case which is ugly as fuck.

HELP!
Title: Re: Gaaaah! Stupid question.
Post by: Perspective on June 13, 2019, 11:05:25 AM
Code: [Select]
> python
Python 2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range(14,29):
...     print 69 + (4*((i-14)/4))
...
69
69
69
69
73
73
73
73
77
77
77
77
81
81
81
Title: Re: Gaaaah! Stupid question.
Post by: Rob on June 13, 2019, 11:08:17 AM
See, I knew it was simple. Thanks Perspective. Have a virtual beer.

Props++

Just out of interest, what was your approach, or was it obvious?
Title: Re: Gaaaah! Stupid question.
Post by: charlie on June 13, 2019, 11:08:32 AM
Six minutes, twenty two seconds is pretty impressive.


Mostly for being on esink and seeing the question that quickly. ;)
Title: Re: Gaaaah! Stupid question.
Post by: Mike on June 13, 2019, 11:39:06 AM
See, I knew it was simple. Thanks Perspective. Have a virtual beer.

Props++

Just out of interest, what was your approach, or was it obvious?

The output increments in groups of 4.  So, 4 inputs go to the same output.  So for me that indicates a modulus operation.  With some math to get the initial values lined up.
Title: Re: Gaaaah! Stupid question.
Post by: Rob on June 13, 2019, 12:03:33 PM
My maths sucks since I got old :(

(That's a lie - It's always sucked) :rofl:
Title: Re: Gaaaah! Stupid question.
Post by: Jake on June 13, 2019, 12:52:28 PM
Impressive, Perspective! See, Rob, you should stop by more often
Title: Re: Gaaaah! Stupid question.
Post by: Perspective on June 13, 2019, 04:35:31 PM
See, I knew it was simple. Thanks Perspective. Have a virtual beer.

Props++

Just out of interest, what was your approach, or was it obvious?

Well, ignoring the shift in the input to output (from 14 to 69 etc..), you basically just want to output a number 4 times, then increase that number by 4. So integer division (by 4) gives you the "epoch" you're at (how many times have I incremented by 4). Multiply that by 4 and you get the factor you should add. Then you add the two shifts, input starting at 14 and output starting at 69.
Title: Re: Gaaaah! Stupid question.
Post by: Perspective on June 13, 2019, 04:36:52 PM
Six minutes, twenty two seconds is pretty impressive.


Mostly for being on esink and seeing the question that quickly. ;)

Yeah, the timing was pretty good. I just happened to have stopped by for my (second) morning coffee. And since Micah's update was light I had some extra time on my hands :D
Title: Re: Gaaaah! Stupid question.
Post by: micah on June 13, 2019, 07:59:39 PM
Glad I could free up some time for you.
Title: Re: Gaaaah! Stupid question.
Post by: Rob on June 14, 2019, 04:39:51 AM
Impressive, Perspective! See, Rob, you should stop by more often

:D
Title: Re: Gaaaah! Stupid question.
Post by: ober on June 14, 2019, 08:51:57 AM
Six minutes, twenty two seconds is pretty impressive.


Mostly for being on esink and seeing the question that quickly. ;)

Yeah, the timing was pretty good. I just happened to have stopped by for my (second) morning coffee. And since Micah's update was light I had some extra time on my hands :D
LOL - Micah's updates are largely the determining factor in my morning routine as well.  :D