在这个密码-高尔夫挑战中,您必须输出一个随机模具辊的ascii技术.
就像这样:
________
/\ \
/ \ 6 \
{ 4 }-------}
\ / 5 /
\/_______/请注意:
________
/\ \
/ \ 3 \
{ 4 }-------}
\ / 5 /
\/_______/是无效的输出,因为这不是模具上可能的结果。
有6(faces that could be up)*4(faces that could be the left face after the top is determined)*1(faces that could be the right face after the other two are determined)=24种可能的模具辊。
您的程序必须以ascii技术的形式输出其中的一个模卷(模型如下,x和zs替换为数字),每个输出的发生概率都大于0,但概率不必为偶数(与现实生活不同,它们被允许为骰子)。您的程序无法输出无效的模具辊或非模具辊。您的程序必须有输出有效卷的概率为1。
请注意,您的模具不一定一定是一个右手模具,如第一张图片所示。(右手和左撇子描述模具的网)
right-handed die
________
/\ \ net
/ \ z \ _|4|_ _
{ x }-------} |6|2|1|5|
\ / y / |3|
\/_______/
left handed die
________
/\ \ net
/ \ y \ _|3|_ _
{ x }-------} |6|2|1|5|
\ / z / |4|
\/_______/如果您的模具是左手,下面是有效的输出,但如果您的模具是右手:
________
/\ \
/ \ 2 \
{ 1 }-------}
\ / 3 /
\/_______/虽然你可以选择左手或右手,但你的模具必须是一致的:它不能从左到右变化,反之亦然。
下面是模具的有效输出列表。关于X的位置,请参阅上面的图片:
X-Y-Z
-----
5-4-1
1-5-4
4-1-5
5-6-4
4-5-6
6-4-5
5-3-6
6-5-3
3-6-5
5-1-3
3-5-1
1-3-5
2-6-3
3-2-6
6-3-2
2-4-6
6-2-4
4-6-2
2-1-4
4-2-1
1-4-2
2-3-1
1-2-3
3-1-2同样,这是密码-高尔夫,所以更少的字节更好
发布于 2016-08-09 00:10:19
f(r){r=rand()%24;r=(5545>>r%4*3&63^256-(r*2&8))*513>>r/8*3;printf(" ________\n /\\%9s / \\%4d \\\n{ %d }-------}\n \\ /%4d /\n \\/_______/","\\\n",7&r,7&r/8,7&r/64);}测试程序
f(r){r=rand()%24;
r=(5545>>r%4*3&63^256-(r*2&8))*513>>r/8*3;
printf(" ________\n /\\%9s / \\%4d \\\n{ %d }-------}\n \\ /%4d /\n \\/_______/","\\\n",7&r,7&r/8,7&r/64);}
j;
main(){
for(j=99;j--;puts(""))f();
}r= \\after calculation, assign to r (in order to use only one variable.)
(5545>>r%4*3&63 \\5545 is 12651 in octal. Select 2 digts for the equator
^256-(r*2&8)) \\if 4's bit of r is 0, prepend 4=256/64. Else prepend 3 and reverse one of the faces by xoring with 7. 256-8 = 248 = 3*64+7*8.
*513 \\now we have a 3 digit octal number. duplicate all digits by multiplying by 1001 octal.
>>r/8*3 \\rightshift 0,1 or 2 digits to rotate. 发布于 2016-08-07 19:57:27
r="replace";a=()=>(0|Math.random()*6)+1;b=(x,y)=>3*x*y*(x*x+6*y*y)%7;u=()=>{x=a(),y=a();z=b(x,y);if(z==0)u();return" ________\r\n \/\\ \\\r\n \/ \\ 1 \\\r\n{ 2 }-------}\r\n \\ \/ 3 \/\r\n \\\/_______\/"[r](1,x)[r](2,y)[r](3,z);}使用u();调用
这是很长的,但这是一个答案,我已经很久没有回答了。
发布于 2016-08-08 10:58:44
DECLARE @ char(87)=(SELECT
REPLACE(REPLACE(REPLACE(' ________
/\ \
/ \ 7 \
{ 8 }-------}
\ / 9 /
\/_______/',7,a),8,b),9,3*ABS(a*a*a*b-a*b*b*b)%7)
FROM(SELECT*,SUBSTRING(REPLACE(STUFF(123456,a,1,''),7-a,''),CAST(RAND()*4as int)+1,1)b
FROM(SELECT CAST(RAND()*6as int)+1a)x)x)PRINT @SELECT
REPLACE(REPLACE(REPLACE(' ________
/\ \
/ \ 7 \
{ 8 }-------}
\ / 9 /
\/_______/',7,a),8,b),9,3*ABS(a*a*a*b-a*b*b*b)%7)
FROM(SELECT*,SUBSTRING(REPLACE(STUFF(123456,a,1,''),7-a,''),CAST(RAND()*4as int)+1,1)b
FROM(SELECT CAST(RAND()*6as int)+1a)x)x注意:通过删除打印和声明部分,并直接从SELECT输出结果。然而,这在小提琴上行不通。
https://codegolf.stackexchange.com/questions/89052
复制相似问题