帮助重新计算您的代表!


12

几个月前,我们在meta上进行了讨论,讨论如何提高因问题投票而获得的声誉。这是我们目前的投票信誉系统的基础:1

  • 问题投票U值得5个声望。
  • 回答投票u值得10个声誉。
  • 问题或答案不满意d的人值得-2声望。

对于新系统,已经有许多不同的建议,但是当前最受欢迎的与上面的相同,但是问题投票的比例扩大到+10个代表。这项挑战是要计算出安装该系统后您将获得多少代表。

让我们来看一个例子。如果投票活动为UUUUuuuuUUUUUduuudUU,则在当前系统下,您的收入为121:

U x 4 x  5 =  20 =  20
u x 4 x 10 =  40 =  60
U x 5 x  5 =  25 =  85
d x 1 x -2 =  -2 =  83
u x 3 x 10 =  30 = 113
d x 1 x -2 =  -2 = 111
U x 2 x  5 =  10 = 121
Total:             121

但是在新系统下,相同的活动将获得176的收入:

U x 4 x 10 =  40 =  40
u x 4 x 10 =  40 =  80
U x 5 x 10 =  50 = 130
d x 1 x -2 =  -2 = 128
u x 3 x 10 =  30 = 158
d x 1 x -2 =  -2 = 156
U x 2 x 10 =  20 = 176
Total:             176

您将从这种情况下获得55个声望

到目前为止,计算更改后的代表并不困难。只需计算Us 的数量并乘以5。幸运的是,代表制度不是那么简单:还有一个rep cap,这是您在某个UTC一天中从投票中获得的最高声誉。在所有站点上都将其设置为200。

而且,代表上限是实时适用的:如果您已经获得196个代表并且收到了答覆投票,那么您现在将有200个代表。如果此后立即收到降票,则2个代表将从200中减去,因此您将获得198个代表。

通过投票活动UUUuuuuUUUUuuuuUUUUUUUd,在当前系统下,您将获得148个代表:

U x 3 x  5 =  15 =  15
u x 4 x 10 =  40 =  55
U x 4 x  5 =  20 =  75
u x 4 x 10 =  40 = 115
U x 7 x  5 =  35 = 150
d x 1 x -2 =  -2 = 148
Total:             148

但是在新系统下,您将获得198:

U x 3 x 10 =  30 =  30
u x 4 x 10 =  40 =  70
U x 4 x 10 =  40 = 110
u x 4 x 10 =  40 = 150
U x 7 x 10 =  70 = 200 (rep capped)
d x 1 x -2 =  -2 = 198
Total:             198

因此,增加为50 rep

挑战

您面临的挑战是编写一个包含多行字符串并输出使用上述算法可获得的总代表的程序或函数。每行算作1个UTC天,因此代表上限仅适用于每行一次。

测试用例

(一或多行输入,后跟输出整数。)

UUUuudd
15

UUUuUUUUuUuuUUUUudUUUUuU
57

UUUuUUUUuUuuUUUUudUUUUuU
UUUuudd
72

uuuuuuu
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
uuuuuuuuuuuuuuuuuuuu
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
0

UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
5

(empty string)
0

UUUuuuuuUUUuuUUUUUUuuuUUUuuUUUUuuuuUUUdddddddUU
4

UUUuuuuuUUUuuUUUUUUuuuUUUuuUUUUuuuuUUUdddddddUU
UuuUUUudUU
UUUUUUUUUuuuuuuUUUUUUuuUUUUUUuuuuuUUUUUUUUuUUUuuuuUUUUuuuUUUuuuuuuUUUUUUUUuuUUUuuUU
UUu
U
d
UU
UUUUUUUUUUUU
119

这是代码高尔夫,因此以字节为单位的最短代码获胜。

相关挑战:计算向量的有界累计和计算堆栈交换信誉

1这是系统的高度简化版本。您还会因投票否决而失去1个代表,并且存在未投票的情况,这很奇怪并且遵循自己的规则;和undownvotes,甚至没有要遵循的规则


1
很好的挑战。太糟糕了,它不太可能发生 ...
AdmBorkBork

2
¹您不会因为拒绝回答问题而失去代表;只是答案。相信我:P
Geobits,2016年

@Mego可能,但我看到以下差异:A)不需要完整的累积数组,只需最后一项。B)没有下限,并且上限是固定的。C)输入是一个字符串,而不是数字数组。D)这些字符串的任意数量,用换行符分隔,必须分别进行遍历并求和以得出结果。
ETHproductions 2016年

1
@ETHproductions除B以外的所有都是I / O差异。核心问题仍然是相同的。
Mego 2016年

Answers:


0

Perl,104 91 + 2 = 93字节

sub f{200*$.>$_[0]?$_[0]:200*$.}for(/./g){$a=/d/?-2:10;$s=f$s+$a;$o=f$o+$a-5*/U/}}{$_=$s-$o

需要-p标志:

$ echo UUUuUUUUuUuuUUUUudUUUUuU | perl -p recalc.pl
57
$ echo "UUUuUUUUuUuuUUUUudUUUUuU
UUUuudd" | perl -p recalc.pl
72

分解:

sub f {
  # '$.' contains the line number (1, 2, ... n)
  200*$. > $_[0] ? $_[0] : 200*$.
}
for(/./g){
  $a= /d/ ? -2  : 10;
  $s=f( $s + $a );
  # /U/ returns `1` if true
  $o=f( $o + $a - 5*/U/ )
}
}{ # Eskimo exit while loop (do this after the outer (from -p) iteration)
$_=$s-$o

2

ES6,104个字节

s=>s.split`
`.map(l=>(g=U=>[...l].map(c=>(r+=eval(c))>200?r=200:0,r=0)|r,t+=g(10)-g(5)),u=10,d=-2,t=0)|t

计算每行的pre和after rep。我第一次使用eval


2

Haskell,98 93字节

感谢BlackCap进一步打高尔夫球。现在,我想现在尝试在以后的挑战中使用lambda。

x#'U'=x
_#'u'=10
_#'d'=(-2)
a&b=foldl1(\d g->min 200$d+a#g)
g=sum.map(\x->(10&x)-(5&x)).lines

前3行是得分,a&b是得分,f是差异,g是使规格标准化的函数。

用法:

g"UUUuuuuuUUUuuUUUUUUuuuUUUuuUUUUuuuuUUUdddddddUU" -- 4

您可以合并最后两行并获得1个字节:g = sum.map(\ x->(10&x)-(5&x))。lines您还可以删除另外四个字节的括号:g = sum.map(\ x-> 10&x-5&x).lines
BlackCap

还有3个字节(如果您将地图和折叠合并):a&b = foldl(\ d g-> min 200 $ d + a#g)0b
BlackCap,

1

Lua,196字节

该程序将单个多行参数作为输入,并在rep'中打印总差异

e,f,a=0,0,{u=10,U=10,d=-2}arg[1]:gsub(".-\n",function(s)x=0 y=0 s:gsub("[^\n]",function(c)t=x+a[c]x,t=t>199 and 200 or t,y+a[c]-(c<"V"and 5 or 0)y=t>199 and 200 or t end)e=e+x f=f+y end)print(e-f)

我以为我可以在输入中要求输入尾随新行,如果不是这样,这里有一个204字节的解决方案,不需要它。

e,f,a=0,0,{u=10,U=10,d=-2}(arg[1].."\n"):gsub(".-\n",function(s)x=0 y=0 s:gsub("[^\n]",function(c)t=x+a[c]x,t=t>199 and 200 or t,y+a[c]-(c<"V"and 5 or 0)y=t>199 and 200 or t end)e=e+x f=f+y end)print(e-f)

脱节和解释

a={u=10,U=10,d=-2}            -- define the table containing the vote values
e,f=0,0                       -- initialize the total sums of rep'

arg[1]:gsub(".-\n",function(s)-- iterate over each line
  x=0                         -- score by the new scoring method for this UTC day
  y=0                         -- score by the old method
  s:gsub("[^\n]",function(c)  -- iterate over each non new-line character
    t=x+a[c]                  -- new score for today
    x=t>199 and 200 or t      -- reduce it to 200 if >=200
                        -- Do the same thing with the old scoring method
    t=y+a[c]-(c<"V"and 5 or 0)-- if c=="U", this question vote gives only 5
    y=t>199 and 200 or t      
  end)
  e=e+x f=f+y                 -- sum the scores over multiple days
end)
print(e-f)                    -- output the difference
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.