滚动我的D＆D角色的能力得分

18

``````Bard - Charisma
Cleric - Wisdom
Druid - Wisdom
Fighter - Stregth
Monk - Wisdom
Rogue - Dexterity
Sorcerer - Charisma
Wizard - Intelligence
``````

``````Input: R
Rolls: 4316 3455 3633 5443 2341 6122
Scores: 13 14 12 13 9 10
Ordering: Highest goes to dexterity. Second goes to Constitution.
Output: 13 14 13 12 9 10
or
Output: 9 14 13 10 12 13
or etc.
``````

6

CJam，43 41 40字节

``````{6a4*:mr\$0Zt:+}6*]\$2m<"FRXWCDM"r#4e<3e\p
``````

CJam解释器中在线尝试。

怎么运行的

``````{             }6*                       e# Repeat 6 times:
6a4*                                   e#   Push [6 6 6 6].
:mr                                e#   Replace each six with a pseudo-randomly
e#   generated integer in [0 ... 5].
\$                               e#   Sort the results.
0Zt                            e#   Replace the lowest result by 3.
:+                          e#   Add all four integers
]                       e# Wrap the 6 generated integers in an array.
\$                      e# Sort.
2m<                   e# Rotate 2 units to the left to assign the
e# second highest result to Constitution.
"FRXWCDM"          e# Push that string.
r#        e# Find the index of the input.
e# The string doesn't contain B, P or S, so
e# those push -1.
4e<     e# Truncate the index at 4. This way, C, D
e# M all push 4.
3e\  e# Swap the integer at that index with the
e# one at index 3, i.e., the highest one.
p e# Print.
``````

6

Python 3，137个字节

``````from random import*
S=sorted
*L,c,h=S(3+sum(S(map(randrange,[6]*4))[1:])for _ in[0]*6)
L[:"FRW BPS".find(input())]+=h,
L[:2]+=c,
print(L)``````

• 根据输入将最高滚动到正确位置，然后
• 排名第二高的是构成指标。

``````Index    Ability          Input(s)
----------------------------------
0        Strength         F
1        Dexterity        R
2        Intelligence     W
3        Wisdom           CDM
4        Charisma         BPS
``````

• `FRW` 按预期工作，给出各自的指标，
• `CDM`不存在，因此`find`给出`-1`，对于4元素列表，其索引为3，并且
• `BPS` 分别给出4、5、6，但是过冲并不重要，因为我们只能在末尾附加一个元素。

1

J，100 97字节

``````(0;0,b)C.^:(b>0)(0;1 2)C.\:~+/"1]1}."1/:~"1]1+?6 4\$4\$6[b=.('BCDFMPRSW'i.1!:1[1){5 4 4 0 4 5 1 5 3
``````

Alex A.

@AlexA。我们只是休息一下，在此同时我可以尝试其他事情……
Fatalize 2015年

0

C ++-387字节

``````#include<cstdlib>
#include<cstdio>
#include<time.h>
int main(int c,char**v){char*o=*v,l=*v[1];int b=-1,s=-1,i=6,x=0,q=l>=67&&l<=68||l==77?4:l==70?0:l==87?3:l==82?1:5;srand(time(0));for(;i-->0;){int w=9,d=4,u=3,t;for(;d-->0;){t=rand()%6;if(t<w){u+=w<9?w:0;w=t;}else u+=t;}if(u>s){c=s;s=u;u=c;}if(s>b){c=s;s=b;b=c;}if(u>=0)o[x++]=u;}for(i=0;i<6;i++)printf("%d ",i==2?s:(i==q?b:o[--x]));}
``````

``````#include<cstdlib>
#include<cstdio>
#include<time.h>
int main(int c,char**v)
{
//name of program must be at least 4 chars
char*others=*v,clas=*v[1];
int desired = clas>=67&&clas<=68||clas==77?4:clas==70?0:clas==87?3:clas==82?1:5; //TODO:

srand(time(0));
int best=-1,second=-1,i=6,otherIndex=0;
for(;i-->0;)
{
int lowest=9,diecount=4,sum=3;
for(;diecount-->0;)
{
int loc=rand()%6;
if (loc<lowest)
{
sum+=lowest<9?lowest:0;
lowest=loc;
}
else
{
sum+=loc;
}
}
if(sum>second)
{
c=second;second=sum;sum=c;
}
if(second>best)
{
c=second;second=best;best=c;
}
if(sum>=0)
{
others[otherIndex++]=sum;
}
}

for(i=0;i<6;i++)
{
printf("%d ",i==2?second:(i==desired?best:others[--otherIndex]));
}

getchar();
}
``````