Inspired by this question earlier today, I'd like to see interesting ways various programming languages can turn a numpad into probabilities. Commonly, tile-based games will allow you to use a numpad to move in any direction based on where your character currently is. When making an AI for these games, Math.random() * 8
is not sufficient, so I had to get a little creative to make the movement look and feel somewhat natural.
A numpad is defined as such:
7 | 8 | 9
- - - - -
4 | x | 6
- - - - -
1 | 2 | 3
Please note, 5 is an invalid number, as you cannot move onto yourself.
All examples will use these probabilities: [50, 40, 30, 20, 10]
If I wanted to generate probabilities around 8
, it would look like this:
40 | 50 | 40
-- | -- | --
30 | xx | 30
-- | -- | --
20 | 10 | 20
The output would be [20, 10, 20, 30, 30, 40, 50, 40]
(with 5 omitted) or [20, 10, 20, 30, null, 30, 40, 50, 40]
(with 5 present)
If I wanted to generate them around 1
, it would look like this:
30 | 20 | 10
-- | -- | --
40 | xx | 20
-- | -- | --
50 | 40 | 30
The output would be [50, 40, 30, 40, 20, 30, 20, 10]
(with 5 omitted) or [50, 40, 30, 40, null, 20, 30, 20, 10]
(with 5 present)
You may write a full program that takes the input in any usual way (command line, stdin) and prints the output, or you may write a function with a number argument, that prints or returns the output. Your program or function should accept one number - the position to generate around. You should use these probabilities: [50, 40, 30, 20, 10]
(they do not have to be hardcoded).
Shortest code in bytes wins. Standard loopholes are disallowed. Answers posted in the linked thread are disallowed. Trailing or leading spaces are allowed. You may treat position 4
as absent or empty, depending on your preference. I'm not too picky on output format - print it out as comma-separated strings or as an array.
(This is my first question, go easy on me!)