Data Visualization: Data values to SVG y positions

SVG's y axis points down, so chart values must be flipped. Write the y scale function.

What to build

A program that converts data values to SVG y coordinates.

Requirements

  • For each value, print its y position in :g format on one line, separated by spaces: the minimum maps to height − padding, the maximum to padding, and values in between linearly.

Input

Line 1: height, padding, min and max. Line 2: the values.

Output

One line.

Constraints

0 ≤ padding and 2 × padding < height ≤ 2000; min < max; values are between min and max.

Example

Input:

200 10 0 100
0 50 100

Output:

190 100 10

Why it works

The fraction (v − min) ÷ (max − min) says how far up the plot area a value is; subtracting that share of the plot height from the bottom turns "up" in the data into "smaller y" in SVG.

Examples

Example 1 · Input
200 10 0 100
0 50 100
Expected output
190 100 10
Example 2 · Input
100 0 0 10
5
Expected output
50

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

The plot area runs from padding to height − padding.

Hint 2

y = height − padding − (v − min) ÷ (max − min) × (height − 2 × padding).

Solution

Show one correct solution (try it yourself first)
h, pad, lo, hi = map(float, input().split())
values = [float(v) for v in input().split()]
print(" ".join(f"{h - pad - (v - lo) / (hi - lo) * (h - 2 * pad):g}" for v in values))

Lesson: Drawing charts with SVG →