简体   繁体   English

PHP 浮点数拼图

[英]PHP Float Number puzzle

How do i code below question in PHP ?我如何在 PHP 中编写以下问题?

To print the curve data to the screen by positioning it with spaces, within a display area 51 chars wide.通过在 51 个字符宽的显示区域内用空格定位曲线数据,将曲线数据打印到屏幕上。

You have the following 39 floats as source data.您有以下 39 个浮点数作为源数据。

14686.744, 14687.067, 14687.363, 14687.633, 14687.958, 14688.257,
14688.530, 14688.777, 14688.997, 14689.209, 14689.419, 14689.614, 
14689.792, 14689.928, 14690.047, 14690.526, 14691.351, 14692.560, 
14693.897, 14695.045, 14696.147, 14697.109, 14697.708, 14697.563,
14696.793, 14696.089, 14695.254, 14694.135, 14693.018, 14691.445, 
14689.647, 14688.055, 14686.720, 14685.607, 14684.638, 14683.800,
14683.081, 14682.794, 14682.572

Notes:笔记:

  • The differences between floats is very small.浮点数之间的差异非常小。

  • Strip away the minimum value and only display the variance between highest and lowest values.去掉最小值,只显示最高值和最低值之间的差异。

  • Space the values to fill the display area of 51 chars wide.将值隔开以填充 51 个字符宽的显示区域。

  • Echo the row number at the start of each line.回显每行开头的行号。

  • The correct output looks like this:正确的输出如下所示:

OUTPUT输出

0               .
1                .
2                 .
3                  .
4                   .
5                    .
6                     .
7                     .
8                      .
9                       .
10                       .
11                        .
12                        .
13                         .
14                          .
15                             .
16                                 .
17                                     .
18                                         .
19                                            .
20                                                .
21                                                  .
22                                                 .
23                                               .
24                                            .
25                                          .
26                                      .
27                                  .
28                             .
29                       .
30                  .
31              .
32          .
33       .
34    .
35  .
36 .
37.
38.

I guess it would be something like: Convert the numbers to percentages, so the lowest float = 0 and the highest = 100.我想这会是这样的:将数字转换为百分比,因此最低浮点数 = 0,最高浮点数 = 100。

then take each percentage as a percentage of the width (which is 51).然后将每个百分比作为宽度的百分比(即 51)。 Eg.例如。 with 10% would be "51 * 0.10 = 5.1". 10% 将是“51 * 0.10 = 5.1”。 Make it an int (floor) and call it spacing (perhaps you need to subtract 1 from the value.).将其设为 int(地板)并将其称为间距(也许您需要从该值中减去 1。)。

Then print as many spaces as defined by "spacing" and append the dot + newline.然后打印“spacing”定义的尽可能多的空格并附加点+换行符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM