Technical & Scientific > Programming
Gaaaah! Stupid question.
Rob:
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!
Perspective:
--- Code: ---> 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
--- End code ---
Rob:
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?
charlie:
Six minutes, twenty two seconds is pretty impressive.
Mostly for being on esink and seeing the question that quickly. ;)
Mike:
--- Quote from: RobR 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?
--- End quote ---
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.
Navigation
[0] Message Index
[#] Next page
Go to full version