EntropySink
Technical & Scientific => Programming => Topic started 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!
-
> 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
-
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?
-
Six minutes, twenty two seconds is pretty impressive.
Mostly for being on esink and seeing the question that quickly. ;)
-
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.
-
My maths sucks since I got old :(
(That's a lie - It's always sucked) :rofl:
-
Impressive, Perspective! See, Rob, you should stop by more often
-
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.
-
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
-
Glad I could free up some time for you.
-
Impressive, Perspective! See, Rob, you should stop by more often
:D
-
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