# 进行冥王星飞越

21

• 该探测器将最接近冥王星于25/12/2015
• `d`到冥王星的距离由以下公式给出：`square root of ((difference in days to christmas) ^ 2 + 10)`
• `r`照片上冥王星图像的半径为：`22 / d`
• `(x, y)`在网格上具有坐标的字符必须设置为`#`if `x^2 + y^2 <= r^2`; 否则必须将其设置为空格。
• 有星星的位置`(-3, -5)``(6, 2)``(-5, 6)``(2, 1)``(7, -2)`。星星由点表示`.`，而它们当然被冥王星隐藏。

• 当到冥王星的距离<= 4时，在坐标处添加一个冥王星`(-3,-1)``(^_^)`

``````

.

#      .
###
#####
###.
#     .

.

``````

``````
#######
#########
###########
#############
#############.
###(^_^)#####
#############
#############
#############
#############
###########
#########
. #######

``````

1

ETHproductions's

1
@SuperChafouin我```赞成删除了s `<pre><code>`；如果您不喜欢，可以随时回滚。

1
`You can assume the entered date will be in the year 2015 or 2016.`但是，为什么还要指定一年呢？
mınxomaτ

intrepidcoder

Answers:

3

# JavaScript（ES6），237个字节

``````f=(n)=>(t=new Date('201'+n[3],n[4]+n[5],n[6]+n[7])/864e5-403805/24,r=484/(t*t+10),(g=(i)=>(++i<8?(h=(j)=>(i*i+j*j<=r?r>30.25&!~i&&'(^_^)'[j+3]||'#':~'p-3-5p62p-56p21p7-2'.indexOf('p'+j+i)?'.':' ')+(++j<8?h(j):''))(-7)+'\n'+g(i):''))(-8))
``````

## 原始版本

``````f=function(n) {
t = (new Date('201'+n[3],''+n[4]+n[5],''+n[6]+n[7]) // Find the time difference in milliseconds,
- new Date(2015,12,25)) / 864e5;                    // then divide by 86400000 to convert to days.

r=22 / Math.sqrt(t*t+10);                           // Calculate the radius.

s=[]; // s is the array that contains each line as a string.

for(i=-7;i<8;i++)               // Loop through rows.
for(j=-7,s[i+7]='';j<8;j++) // Loop through columns, appending one character per column.
// s is zero based, so add 7 to the row.
s[i+7]+=i*i+j*j<=r*r ?  // Choose which character to add to s.
(r>5.5&i==-1&&'(^_^)'[j+3]||'#') :  // Add a '#' if the position is inside the radius.
// If distance < 4, then the radius > 5.5
// Then add the face at the right position.
{'-3-5':1,'62':1,'-56':1,'21':1,'7-2':1} // Add the stars if outside. Create an associative array.
[j+''+i]?'.':' ';                        // If i concat j is in the array, the expression will be 1,
// which is truthy, else it will be undefined, which is falsey.
return s.join`\n` // Join all the rows with a new-line.
}
``````

## 打高尔夫球

``````t=(new Date('201'+n[3],n[4]+n[5],n[6]+n[7])-new Date(2015,12,25))/864e5 // Before
t=new Date('201'+n[3],n[4]+n[5],n[6]+n[7])/864e5-403805/24 // After
``````

``````{'-3-5':1,'62':1,'-56':1,'21':1,'7-2':1}[j+''+i]?'.':' ' // Before
~'p-3-5p62p-56p21p7-2'.indexOf('p'+j+i)?'.':' ' // After
``````

``````s=[];for(i=-7;i<8;i++)for(j=-7,s[i+7]='';j<8;j++)s[i+7]+= /* Chooses char at i,j */ ;return s.join`\n` // Before
(g=(i)=>(++i<8?(h=(j)=>( /* Chooses char at i,j */ )+(++j<8?h(j):''))(-7)+'\n'+g(i):''))(-8) // After
``````

``````r=22/Math.sqrt(t*t+10),(g=(i)=>(++i<8?(h=(j)=>(i*i+j*j<=r*r?r>5.5 // Before
r=484/(t*t+10),(g=(i)=>(++i<8?(h=(j)=>(i*i+j*j<=r?r>30.25 // After
``````

## 问题

“ 20151215”的照片：

``````

.

#      .
###
#####
###.
#     .

.
``````

“ 20151225”的照片：

``````
#######
#########
###########
#############
#############.
###(^_^)#####
#############
#############
#############
#############
###########
#########
. #######
``````

2015年

3

# C＃4.0，393个字节

``string p(string s){int i=Convert.ToInt32(s),Y=i/10000,m,x,y;s="";i-=Y*10000;m=i/100;i-=m*100;double d=Math.Sqrt(Math.Pow((new DateTime(2015,12,25)-new DateTime(Y,m,i)).Days,2)+10);string o,k=".-3-5.62.-56.21.7-2";for(y=-7;y<8;y++){for(x=-7;x<8;x++){o="#";if(d<=4&&x==-3&&y==-1){o="(^_^)";x+=4;}s+=Math.Pow(x,2)+Math.Pow(y,2)<=Math.Pow(22/d,2)?o:k.Contains("."+x+y)?".":" ";}s+="\n";}return s;}``

## 例：

``````string userInput = Console.ReadLine();
Console.WriteLine(p(userInput));``````

## 输出：

``````20151216

.

###     .
#####
#####
#####
###    .

.

20151224

#####
#########
###########
###########
#############.
###(^_^)#####
#############
#############
#############
###########
###########
#########
.  #####``````

2

## CJam，165个字节

``````q'-%:i~\0\({X1=29W\$2%-X7<X+2%30+?+}fX+\2%-359 6?+:DD*A+mq:Z22Z/_*:R-7:Y];F{-7:X;F{XX*YY*+R>XYF*+[-78II+85H-23]#)'.S?Z4<Y-1=X-4>X2<&&&X-3="(^_^)"L?'#??X):X;}*NY):Y;}*
``````

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.