描述
这项挑战的任务是设计一个程序或函数来跟踪空间中的给定对象。
输入输出
您的程序将获得3个输入,可以以任何明智的方式获取:
n
将是飞机侧面的大小。(因此,对于,您的平面将为)。您可能会假设n
它将始终是一个奇数整数。
s
将是对象的起始位置,以一对坐标给出。
D
将是有序对的向量。D
将遵循格式,其中将始终是一个的'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'
,对于基数和初级intercardinal方向,和将是的“滴答”的数量的整数。
有了这些输入,您的程序必须输出对平面中对象的跟踪。
规则
输出必须包含平面的边界。例如:
-21012 + +┌─────┐ 2││ 1││ 0││ 1││ 2││ -└─────┘
将是一个空的平面的示例。上方和侧面的数字仅供参考,不需要打印。
您可以使用任何字符作为边界,只要它不是空格(或呈现为空格)即可。您选择的字符必须描绘整个平面,这意味着它们之间不能有间隙。
一些可接受的飞机包括: ┌──┐.... ---- +-+ ││。。| | | | ││。。| | | | └── ....; ----; +-+ 不可接受的飞机包括: .... .... ++++。。 。。+ +。。 。+ +。。 ; ....; ....; + +; 。。
要跟踪的对象可以是您选择的任何字符,只要它在平面上仅占用1个空间并且与边界字符不同即可。
跟踪对象的轨迹也可以是您选择的任何字符,只要它们在平面上仅占据1个空间并且与对象不同即可。
对于每个元素在中,对象必须移动朝向空间,并留下痕迹。
如果物体碰到边界,它将被反映出来。如果对象还剩下任何移动,它将继续沿被反射的方向移动。
作为参考,这些指示相互反映:
→当顶部或底部边界被满足;
→当横向边界被满足;
最终输出将包含最新的跟踪信息,也就是说,如果对象将跟踪信息留在已经存在跟踪信息的空间中,则更新的跟踪字符将覆盖较旧的跟踪字符。
像往常一样,默认情况下禁止标准漏洞。
得分:
这是一个代码高尔夫挑战。
例子:
输入:,,
解决:
0 ┌──────┐ ││ ││ 0│○│ ││ ││ └──────┘
0 ┌──────┐ │○│ │\│ 0│\│ ││ ││ └──────┘
0 ┌──────┐ │∧│ │| \│ 0│○\│ ││ ││ └──────┘
,这将是输出。
0 ┌──────┐ │∧│ │| \│ 0│└○\│ ││ ││ └──────┘
(0仅作为参考,它们不需要出现在最终输出中。)
输入:,,
注意,当:
0 ┌──────────┐ ││ ││ ││ │∧│ 0│/ | │ │○/ | │ │⟨/│ │\ /│ │∨│ └──────────┘
对象已经被反射两次:一次是在到达时底部,当去朝向平面的,在那里它反映到 ; 然后再次到达时,左侧面,其中反映。
最终输出为:
0 ┌──────────┐ │○│ │\│ │\│ │\│ 0│/ |⟩│ │∧/ /│ │⟨\ / /│ │\ \ /│ │∨│ └──────────┘
测试用例:
输入:Ñ = 5,š = (0 ,0 ),d = [ (' Ñ w ^ ',2 ),(' 小号',2 ),(' é ',1 )
输出:
0 ┌──────┐ │∧│ │| \│ 0│└○\│ ││ ││ └──────┘
输入:,,
输出:
0 ┌──────────┐ │○│ │\│ │\│ │\│ 0│/ |⟩│ │∧/ /│ │⟨\ / /│ │\ \ /│ │∨│ └──────────┘
输入:,,
输出:
0 ┌───┐ │|│ 0│-○┐│ │|│ └───┘
输入:,,
输出:
0 ┌──────────┐ │∧│ │/ \│ │┌-/-\ \│ │\ | / \ \│ │\ | \ \│ 0│| /⟩│ │| \ / /│ │| /○│ │| / \│ │∨\│ │\│ └──────────┘
'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'
代替0索引(或1索引)的整数吗?因此[('NW',2),('S',2),('E',1)]
成为[[7,2],[4,2],[2,1]]
例如。