高尔夫代码:旋转迷宫 [英] Code Golf: Rotating Maze

查看:119
本文介绍了高尔夫代码:旋转迷宫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

制作一个程序,该程序接收由迷宫组成的文件.迷宫的墙壁由#给出.迷宫必须包括由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编写的示例: http://trinithis.awardspace.com/rotatingMaze/maze.html

Example written in javascript: http://trinithis.awardspace.com/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

这篇关于高尔夫代码:旋转迷宫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆