制作一个程序,该程序接收由迷宫组成的文件.迷宫的墙壁由#给出.迷宫必须包括由o给出的单个球和由@给出的任意数量的孔.迷宫文件可以通过命令行输入,也可以通过标准输入作为一行读取.请指定您的解决方案中的哪个.
Make a program that takes in a file consisting of a maze. The maze has walls given by #. The maze must include a single ball, given by a o and any number of holes given by a @. The maze file can either be entered via command line or read in as a line through standard input. Please specify which in your solution.
您的程序然后执行以下操作:
Your program then does the following:
1: If the ball is not directly above a wall, drop it down to the nearest wall. 2: If the ball passes through a hole during step 1, remove the ball. 3: Display the maze in the standard output (followed by a newline). Extraneous whitespace should not be displayed. Extraneous whitespace is defined to be whitespace outside of a rectangle that fits snugly around the maze. 4: If there is no ball in the maze, exit. 5: Read a line from the standard input. Given a 1, rotate the maze counterclockwise. Given a 2, rotate the maze clockwise. Rotations are done by 90 degrees. It is up to you to decide if extraneous whitespace is allowed. If the user enters other inputs, repeat this step. 6: Goto step 1.您可以假设所有输入迷宫都已关闭.注意:在这方面,孔有效地充当了墙.
You may assume all input mazes are closed. Note: a hole effectively acts as a wall in this regard.
您可能会假设所有输入迷宫都没有多余的空格.
You may assume all input mazes have no extraneous whitespace.
按字符数计算的最短源代码获胜.
The shortest source code by character count wins.
用javascript编写的示例: trinithis.awardspace/rotatingMaze/maze.html
Example written in javascript: trinithis.awardspace/rotatingMaze/maze.html
迷宫的例子:
###### #o @# ################# #o # # ####### # ###@ # #########
########################### # # # # @ # # # # ## # # ####o#### # # # # # # ######### # @ ######################
推荐答案
GolfScript-97个字符
n/['']/~{;(@"zip-1%":|3*~{{." o"/"o "*"@o"/"@ "*.@>}do}%|~.n*."o"/,(}{;\~(2*)|*~\}/\[n*]+n.+*])\;做得比我希望的要好(也许以后).
This isn't done as well as I hoped (maybe later).
(这些是我的笔记,而不是解释)
(These are my notes and not an explanation)
n/['']/~ #[M I] { ;(@ #[I c M] "zip-1%":|3*~ #rotate {{." o"/"o "*"@o"/"@ "*.@>}do}% #drop |~ #rotate back .n* #"display" -> [I c M d] ."o"/,( #any ball? -> [I c M d ?] }{ #d is collected into an array -> [I c M] ;\~(2*)|*~ #rotate \ #stack order }/ \[n*]+n.+*])\; #output更多推荐
高尔夫代码:旋转迷宫
发布评论