代码高尔夫:连接点
您可能还记得小时候的这些图画,但现在是时候让计算机绘制它们了(以完整的 ASCII 格式)。玩得开心!
描述:
输入是描述“字段”的多行(以换行符结尾)。该字段中散布着“数字”(由空格分隔)。所有行都可以被认为是相同的长度(您可以在末尾添加空格)。
- 数字始终从 1 开始
- 它们遵循自然数的顺序:每个“下一个数字”都以 1 递增
- 每个数字的左右两侧(至少)有一个空格
任务:
绘制这些数字之间的线条按其自然顺序排列 (1 -> 2 -> 3 -> ...N)
(假设 N <= 99)具有以下特征:
- 用 '
+' 字符
- 表示水平线:使用 '
-
' - 表示垂直线:使用 '
|
' - 向左、向下或向右和向上:
/
- 向左、向上或向右、向下:
\
重要说明:
当绘制类型 4 和 5 的线时,您可以假设(给定与坐标连接的点) x1, y1 和 x2, y2) 表示距离(x1,x2) == 距离(y1,y2)。或者换句话说(正如用户 jball 评论的那样):“不水平或垂直对齐的连续元素总是与斜杠或反斜杠的斜率对齐”。
遵循点连接的顺序很重要(新线可以删除旧线)。
遵循
-- 示例输入 1 --
8 7 6 10 9 5 3 4 11 12 13 1 2
-- 示例输出 1 --
+ /| / +--+ +--------+ \ / \ / + / | / +--+ + | \ | +------------------------+ +--------------------------+
-- 示例输入 2 --
64 63 62 61 1 65 66 57 58 2 56 59 45 67 55 46 3 44 54 60 47 53 52 49 48 4 51 50 43 5 42 41 6 23 22 25 26 40 20 21 24 34 7 13 12 33 19 27 32 14 35 8 15 16 39 17 18 28 31 36 9 38 10 11 29 30 37
-- 示例输出 2 -- (独角兽参考)
+ /+ // // // /+--+ + + \ | + +-\+ + \ + \ + / + + \ +\ + \ \ | + | + + +/ | +--+ +-------+/ + +--+ + / \ + + | + + + / \ +\ +---+ + \ +--+ + \ /+ + +--+ / \ /+| / | |+ + /+ | / + || / // + + + || / // / \ + || / // / \ | || / +/ / \ +---+ + +\ + + | | | +| +--+ +---+ +
获胜者:< /strong>
最短解决方案(按代码字符数)。可以通过标准输入读取输入。
You may remember these drawings from when you were a child, but now it's time to let the computer draw them (in full ascii splendour). Have fun!
Description:
The input are multiple lines (terminated by a newline) which describe a 'field'. There are 'numbers' scattered across this field (seperated by whitespace). All lines can be considered to be the same length (you can pad spaces to the end).
- the numbers always start at 1
- they follow the ordering of the natural numbers: every 'next number' is incremented with 1
- every number is surrounded by (at least) one whitespace on its left and right
Task:
Draw lines between these numbers in their natural order(1 -> 2 -> 3 -> ...N)
(assume N <= 99) with the following characteristics:
- replace a number with a '
+
' character - for horizontal lines: use '
-
' - for vertical lines: use '
|
' - going left and down or right and up:
/
- going left and up or right and down:
\
Important notes:
When drawing lines of type 4 and 5 you can assume (given the points to connect with coordinates x1, y1 and x2, y2) that
distance(x1,x2) == distance(y1,y2)
. Or in other words (as user jball commented): "consecutive elements that are not horizontally or vertically aligned always align to the slope of the slash or backslash".It is important to follow the order in which the dots are connected (newer lines can strike out older lines).
-- Sample input 1 --
8 7 6 10 9 5 3 4 11 12 13 1 2
-- Sample output 1 --
+ /| / +--+ +--------+ \ / \ / + / | / +--+ + | \ | +------------------------+ +--------------------------+
-- Sample input 2 --
64 63 62 61 1 65 66 57 58 2 56 59 45 67 55 46 3 44 54 60 47 53 52 49 48 4 51 50 43 5 42 41 6 23 22 25 26 40 20 21 24 34 7 13 12 33 19 27 32 14 35 8 15 16 39 17 18 28 31 36 9 38 10 11 29 30 37
-- Sample output 2 -- (unicorn reference)
+ /+ // // // /+--+ + + \ | + +-\+ + \ + \ + / + + \ +\ + \ \ | + | + + +/ | +--+ +-------+/ + +--+ + / \ + + | + + + / \ +\ +---+ + \ +--+ + \ /+ + +--+ / \ /+| / | |+ + /+ | / + || / // + + + || / // / \ + || / // / \ | || / +/ / \ +---+ + +\ + + | | | +| +--+ +---+ +
Winner:
Shortest solution (by code character count). Input can be read via standard input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
Commodore 64 BASIC - 313 个字符
编辑:高尔夫版本见下文
PET 图形、POKE 和 PEEK 以及所有内容:)
该程序直接在屏幕内存中运行,因此您只需继续,清除屏幕,放置点,然后输入RUN:
你必须等待一分钟左右,它才能找到点,然后它开始画画。它并不快 - 你实际上可以看到正在绘制的线条,但这是最酷的部分:)
高尔夫版本:
Commodore BASIC 似乎是一种很棒的高尔夫语言,因为它不需要空格:)您还可以通过输入未移动的第一个字母,然后输入移动的第二个字母来缩短大多数命令。例如,
POKE
可以输入为 P[SHIFT+O],它在屏幕上显示为P┌
:Commodore 64 BASIC - 313 chars
EDIT: See below for the golfed version
A little trip down the memory lane with PET graphics, POKEs and PEEKs and everything :)
The program operates directly in the screen memory, so you just go ahead, clear the screen, place your dots, and type RUN:
You have to wait a minute or so while it finds the dots and then it starts to draw. It isn't fast - you can actually see the lines being drawn, but that's the coolest part :)
Golfed version:
Commodore BASIC seems like a great language for golfing, because it doesn't require whitespace :) You can also shorten most of the commands by entering an unshifted first letter followed by a shifted second letter. For example,
POKE
can be typed as P[SHIFT+O], which appears asP┌
on the screen:Perl,222 字符 (211)
Perl,
384365276273253< Strike>225222218211 个字符(比赛结束时为 222 个)。换行符仅用于“可读性”,不包含在字符数中。最后编辑:不再覆盖
$"
,并直接打印@S
说明:
如果所有行的长度相同(例如 97 个字符),此任务会更容易。
该语句获取每一行输入,将行尾字符替换为
96 个空格,然后将前 96 个字符加上换行符推入数组
@S
中。请注意,我们还设置了
$n=1
,因为 1 是我们要查找的第一个数字输入。
join
语句从数组@S
创建单个字符串。使用标量变量
$_
进行模式匹配更方便,使用数组@S
对图片进行更新更方便。在变量
$_
中搜索数字$n
。在 Perl 中评估正则表达式有几个副作用。一种是设置特殊变量
$-[0]
为匹配字符串中匹配模式的开头位置。这为我们提供了数字$n
在字符串$_
以及数组@S
中的位置。当然,当 $n 足够高以至于我们无法在输入中找到它时,循环就会结束。
令
$q
为数字$n
在字符串$_
和数组@S
中的位置,并在该位置分配字符“+”。
第一次循环时,将
$p
设置为$q
。之后第一次,
$p
将保存$q
的前一个值(其中将参考前一个数字在输入中的位置)。
分配
$P
和$Q
使得$P
=min($p
,$q< /代码>),
$Q
=max($p
,$q
)通过构造,连续的数字要么
由垂直线连接。由于输入已构建
每行有 97 个字符,这种情况意味着
$p-$q
能被 97 整除。“与反斜杠的斜率对齐”,这将使
$p-$q
能被 98 整除“与正斜杠的斜率对齐”,这将使
$p-$q
能被 96 整除在同一水平线上
此列表的元素对可能的位置数进行编码
线段之间,以及对该线段进行编码的字符。
另一个简单的正则表达式评估。作为副作用,它设置了
特殊变量
$&
(MATCH 变量)线段字符(
\ | /
或-
)和$'
(POSTMATCH 变量)到列表元素中编码的数字(98 97 96 或 1)。
该语句绘制两个数字之间的线段。
如果
$Q-$P
能被$'
整除,则继续将$P
增加$'
并将字符
$&
分配给$S[$P]
,直到$P
到达$Q
。更具体地说,例如如果
$Q-$P
能被 97 整除,那么将
$P
加 97 并设置$S[$P]='|'
。重复直到$P>=$Q
。为循环的下一次迭代做好准备。将
$n
增加到要在输入中搜索的下一个数字,并让
$p
保存前一个数字的位置。
输出数组,转换任何剩余的数字(从双
)输入中的数字标识符,我们只覆盖第一个
数字带“+”)到空格。
该语句绘制两个数字之间的线段。
如果
$Q-$P
能被$'
整除,则继续将$P
增加$'
并将字符
$&
分配给$S[$P]
,直到$P
到达$Q
。更具体地说,例如如果
$Q-$P
能被 97 整除,那么将
$P
加 97 并设置$S[$P]='|'
。重复直到$P>=$Q
。为循环的下一次迭代做好准备。将
$n
增加到要在输入中搜索的下一个数字,并让
$p
保存前一个数字的位置。
输出数组,转换任何剩余的数字(从双
||$Q<=($P+=输入中的数字标识符,我们只覆盖第一个
数字带“+”)到空格。
说明:
如果所有行的长度相同(例如 97 个字符),此任务会更容易。
该语句获取每一行输入,将行尾字符替换为
96 个空格,然后将前 96 个字符加上换行符推入数组
@S
中。请注意,我们还设置了
$n=1
,因为 1 是我们要查找的第一个数字输入。
join
语句从数组@S
创建单个字符串。使用标量变量
$_
进行模式匹配更方便,使用数组@S
对图片进行更新更方便。在变量
$_
中搜索数字$n
。在 Perl 中评估正则表达式有几个副作用。一种是设置特殊变量
$-[0]
为匹配字符串中匹配模式的开头位置。这为我们提供了数字$n
在字符串$_
以及数组@S
中的位置。当然,当 $n 足够高以至于我们无法在输入中找到它时,循环就会结束。
令
$q
为数字$n
在字符串$_
和数组@S
中的位置,并在该位置分配字符“+”。
第一次循环时,将
$p
设置为$q
。之后第一次,
$p
将保存$q
的前一个值(其中将参考前一个数字在输入中的位置)。
分配
$P
和$Q
使得$P
=min($p
,$q< /代码>),
$Q
=max($p
,$q
)通过构造,连续的数字要么
由垂直线连接。由于输入已构建
每行有 97 个字符,这种情况意味着
$p-$q
能被 97 整除。“与反斜杠的斜率对齐”,这将使
$p-$q
能被 98 整除“与正斜杠的斜率对齐”,这将使
$p-$q
能被 96 整除在同一水平线上
此列表的元素对可能的位置数进行编码
线段之间,以及对该线段进行编码的字符。
另一个简单的正则表达式评估。作为副作用,它设置了
特殊变量
$&
(MATCH 变量)线段字符(
\ | /
或-
)和$'
(POSTMATCH 变量)到列表元素中编码的数字(98 97 96 或 1)。
该语句绘制两个数字之间的线段。
如果
$Q-$P
能被$'
整除,则继续将$P
增加$'
并将字符
$&
分配给$S[$P]
,直到$P
到达$Q
。更具体地说,例如如果
$Q-$P
能被 97 整除,那么将
$P
加 97 并设置$S[$P]='|'
。重复直到$P>=$Q
。为循环的下一次迭代做好准备。将
$n
增加到要在输入中搜索的下一个数字,并让
$p
保存前一个数字的位置。
输出数组,转换任何剩余的数字(从双
)} $n++;$p=$q}s/\d/ /,print for@S输入中的数字标识符,我们只覆盖第一个
数字带“+”)到空格。
说明:
如果所有行的长度相同(例如 97 个字符),此任务会更容易。
该语句获取每一行输入,将行尾字符替换为
96 个空格,然后将前 96 个字符加上换行符推入数组
@S
中。请注意,我们还设置了
$n=1
,因为 1 是我们要查找的第一个数字输入。
join
语句从数组@S
创建单个字符串。使用标量变量
$_
进行模式匹配更方便,使用数组@S
对图片进行更新更方便。在变量
$_
中搜索数字$n
。在 Perl 中评估正则表达式有几个副作用。一种是设置特殊变量
$-[0]
为匹配字符串中匹配模式的开头位置。这为我们提供了数字$n
在字符串$_
以及数组@S
中的位置。当然,当 $n 足够高以至于我们无法在输入中找到它时,循环就会结束。
令
$q
为数字$n
在字符串$_
和数组@S
中的位置,并在该位置分配字符“+”。
第一次循环时,将
$p
设置为$q
。之后第一次,
$p
将保存$q
的前一个值(其中将参考前一个数字在输入中的位置)。
分配
$P
和$Q
使得$P
=min($p
,$q< /代码>),
$Q
=max($p
,$q
)通过构造,连续的数字要么
由垂直线连接。由于输入已构建
每行有 97 个字符,这种情况意味着
$p-$q
能被 97 整除。“与反斜杠的斜率对齐”,这将使
$p-$q
能被 98 整除“与正斜杠的斜率对齐”,这将使
$p-$q
能被 96 整除在同一水平线上
此列表的元素对可能的位置数进行编码
线段之间,以及对该线段进行编码的字符。
另一个简单的正则表达式评估。作为副作用,它设置了
特殊变量
$&
(MATCH 变量)线段字符(
\ | /
或-
)和$'
(POSTMATCH 变量)到列表元素中编码的数字(98 97 96 或 1)。
该语句绘制两个数字之间的线段。
如果
$Q-$P
能被$'
整除,则继续将$P
增加$'
并将字符
$&
分配给$S[$P]
,直到$P
到达$Q
。更具体地说,例如如果
$Q-$P
能被 97 整除,那么将
$P
加 97 并设置$S[$P]='|'
。重复直到$P>=$Q
。为循环的下一次迭代做好准备。将
$n
增加到要在输入中搜索的下一个数字,并让
$p
保存前一个数字的位置。
输出数组,转换任何剩余的数字(从双
输入中的数字标识符,我们只覆盖第一个
数字带“+”)到空格。
Perl, 222 char (211)
Perl,
384365276273253225222218211 chars (222 when contest ended). Newlines are for "readability" only and are not included in the character count.Last edit: no longer overwriting
$"
, and printing@S
directlyExplanation:
This task will be easier if all the lines are the same length (say, 97 characters).
This statement takes each line of input, replaces the end-of-line character with
96 spaces, then pushes the first 96 characters plus a newline into the array
@S
.Note we are also setting
$n=1
, as 1 is the first number we'll look for inthe input.
The
join
statement creates a single string from the array@S
.It is more convenient to use the scalar variable
$_
for pattern matching, and more convenient to use the array@S
for making updates to the picture.Search for the number
$n
in the variable$_
. Evaluating regular expressions in Perlhas several side-effects. One is to set the special variable
$-[0]
with the position of the start of the matched pattern within the matched string. This gives us the position of the number$n
in the string$_
and also the array@S
.Of course, the loop will end when
$n
is high enough that we can't find it in the input.Let
$q
be the position of the number$n
in the string$_
and the array@S
,and assign the character '+' at that position.
The first time through the loop, set
$p
to$q
. After thefirst time,
$p
will hold the previous value of$q
(whichwill refer to the position in the input of the previous number).
Assign
$P
and$Q
such that$P
=min($p
,$q
),$Q
=max($p
,$q
)By construction, consecutive numbers are either
connected by a vertical line. Since the input is constructed
to have 97 characters on each line, this case means that
$p-$q
is divisible by 97."aligned to the slope of a backslash", which would make
$p-$q
divisible by 98"aligned to the slope of a forward slash", which would make
$p-$q
divisible by 96on the same horizontal line
The elements of this list encode the possible number of positions
between line segments, and the character to encode that segment.
Another trivial regex evaluation. As a side-effect, it sets the
special variable
$&
(the MATCH variable) to the line segmentcharacter (
\ | /
or-
) and$'
(the POSTMATCH variable) tothe number (98 97 96 or 1) encoded in the list element.
This statement draws the line segment between two numbers.
If
$Q-$P
is divisible by$'
, then keep incrementing$P
by$'
and assigning the character
$&
to$S[$P]
until$P
reaches$Q
.More concretely, for example if
$Q-$P
is divisible by 97, thenincrement
$P
by 97 and set$S[$P]='|'
. Repeat until$P>=$Q
.Prepare for the next iteration of the loop. Increment
$n
to thenext number to search for in the input, and let
$p
hold theposition of the previous number.
Output the array, converting any leftover digits (from double
)digit identifiers in the input where we only overwrote the first
digit with a '+') to spaces as we go.
This statement draws the line segment between two numbers.
If
$Q-$P
is divisible by$'
, then keep incrementing$P
by$'
and assigning the character
$&
to$S[$P]
until$P
reaches$Q
.More concretely, for example if
$Q-$P
is divisible by 97, thenincrement
$P
by 97 and set$S[$P]='|'
. Repeat until$P>=$Q
.Prepare for the next iteration of the loop. Increment
$n
to thenext number to search for in the input, and let
$p
hold theposition of the previous number.
Output the array, converting any leftover digits (from double
||$Q<=($P+=digit identifiers in the input where we only overwrote the first
digit with a '+') to spaces as we go.
Explanation:
This task will be easier if all the lines are the same length (say, 97 characters).
This statement takes each line of input, replaces the end-of-line character with
96 spaces, then pushes the first 96 characters plus a newline into the array
@S
.Note we are also setting
$n=1
, as 1 is the first number we'll look for inthe input.
The
join
statement creates a single string from the array@S
.It is more convenient to use the scalar variable
$_
for pattern matching, and more convenient to use the array@S
for making updates to the picture.Search for the number
$n
in the variable$_
. Evaluating regular expressions in Perlhas several side-effects. One is to set the special variable
$-[0]
with the position of the start of the matched pattern within the matched string. This gives us the position of the number$n
in the string$_
and also the array@S
.Of course, the loop will end when
$n
is high enough that we can't find it in the input.Let
$q
be the position of the number$n
in the string$_
and the array@S
,and assign the character '+' at that position.
The first time through the loop, set
$p
to$q
. After thefirst time,
$p
will hold the previous value of$q
(whichwill refer to the position in the input of the previous number).
Assign
$P
and$Q
such that$P
=min($p
,$q
),$Q
=max($p
,$q
)By construction, consecutive numbers are either
connected by a vertical line. Since the input is constructed
to have 97 characters on each line, this case means that
$p-$q
is divisible by 97."aligned to the slope of a backslash", which would make
$p-$q
divisible by 98"aligned to the slope of a forward slash", which would make
$p-$q
divisible by 96on the same horizontal line
The elements of this list encode the possible number of positions
between line segments, and the character to encode that segment.
Another trivial regex evaluation. As a side-effect, it sets the
special variable
$&
(the MATCH variable) to the line segmentcharacter (
\ | /
or-
) and$'
(the POSTMATCH variable) tothe number (98 97 96 or 1) encoded in the list element.
This statement draws the line segment between two numbers.
If
$Q-$P
is divisible by$'
, then keep incrementing$P
by$'
and assigning the character
$&
to$S[$P]
until$P
reaches$Q
.More concretely, for example if
$Q-$P
is divisible by 97, thenincrement
$P
by 97 and set$S[$P]='|'
. Repeat until$P>=$Q
.Prepare for the next iteration of the loop. Increment
$n
to thenext number to search for in the input, and let
$p
hold theposition of the previous number.
Output the array, converting any leftover digits (from double
)} $n++;$p=$q}s/\d/ /,print for@Sdigit identifiers in the input where we only overwrote the first
digit with a '+') to spaces as we go.
Explanation:
This task will be easier if all the lines are the same length (say, 97 characters).
This statement takes each line of input, replaces the end-of-line character with
96 spaces, then pushes the first 96 characters plus a newline into the array
@S
.Note we are also setting
$n=1
, as 1 is the first number we'll look for inthe input.
The
join
statement creates a single string from the array@S
.It is more convenient to use the scalar variable
$_
for pattern matching, and more convenient to use the array@S
for making updates to the picture.Search for the number
$n
in the variable$_
. Evaluating regular expressions in Perlhas several side-effects. One is to set the special variable
$-[0]
with the position of the start of the matched pattern within the matched string. This gives us the position of the number$n
in the string$_
and also the array@S
.Of course, the loop will end when
$n
is high enough that we can't find it in the input.Let
$q
be the position of the number$n
in the string$_
and the array@S
,and assign the character '+' at that position.
The first time through the loop, set
$p
to$q
. After thefirst time,
$p
will hold the previous value of$q
(whichwill refer to the position in the input of the previous number).
Assign
$P
and$Q
such that$P
=min($p
,$q
),$Q
=max($p
,$q
)By construction, consecutive numbers are either
connected by a vertical line. Since the input is constructed
to have 97 characters on each line, this case means that
$p-$q
is divisible by 97."aligned to the slope of a backslash", which would make
$p-$q
divisible by 98"aligned to the slope of a forward slash", which would make
$p-$q
divisible by 96on the same horizontal line
The elements of this list encode the possible number of positions
between line segments, and the character to encode that segment.
Another trivial regex evaluation. As a side-effect, it sets the
special variable
$&
(the MATCH variable) to the line segmentcharacter (
\ | /
or-
) and$'
(the POSTMATCH variable) tothe number (98 97 96 or 1) encoded in the list element.
This statement draws the line segment between two numbers.
If
$Q-$P
is divisible by$'
, then keep incrementing$P
by$'
and assigning the character
$&
to$S[$P]
until$P
reaches$Q
.More concretely, for example if
$Q-$P
is divisible by 97, thenincrement
$P
by 97 and set$S[$P]='|'
. Repeat until$P>=$Q
.Prepare for the next iteration of the loop. Increment
$n
to thenext number to search for in the input, and let
$p
hold theposition of the previous number.
Output the array, converting any leftover digits (from double
digit identifiers in the input where we only overwrote the first
digit with a '+') to spaces as we go.
MS-DOS Batch(是的,你没看错!)
我经常听到(或读到)人们说批处理不是很强大,你不能用它们做太多事情,我对他们说,看吧,BATCH 的力量!
实际脚本 (script.bat):
这就是您如何称呼它
,其中“input.txt”是包含“程序”输入的文件。
PS 这实际上还没有针对行长度进行优化,我已经花了几个小时才达到这一点,现在我需要睡觉......我明天看看是否可以改进它(目前是“script.bat”) ' 位于 2755 字节)
MS-DOS Batch (yes, you read right!)
I often hear (or read) people say batch isn't very powerful and you can't do much with them, well to them I say, behold, the power of BATCH!
The actual script (script.bat):
And this is how you call it
where "input.txt" is a file that contains the input for the "program".
P.S. This isn't actually optimized for line length yet, I've already spent a couple of hours getting to this point and now I need to sleep... I'll see if I can improve it tomorrow (currently 'script.bat' sits at 2755 bytes)
Rebmu:218 个字符
Ma L{-|\/}Qb|[sg?SBaB]Da| [feSm[TfiSrj[spAsp]iT[++Tbr]]t]Xa|[i?A]Ya|[i?FImHDa]Ca|[skPCmSCaBKfsA]wh[Jd++N][roG[xJyJ]]Bf+ GwhB[JcB Ff+GiF[KcF HqXkXj VqYkYju[chCbPClEZv1[ezH2[eeHv3 4]]e?A+bRE[hV]f]]chJeFIlSCj{+}{+ }Jk Bf]wM
我越来越漂亮了擅长以猪拉丁语形式阅读和编辑它。 (虽然我确实使用换行符!):)
但这就是当不区分大小写的“mushing”技巧被煮掉并且人们习惯了它时,解释器如何转换方言。我会添加一些评论。 (提示:
fi
是find,fe
是foreach,sp
是空格字符,i?
是索引,hd
是头,ch
是变化,sk
是跳过,pc
是挑选,bk
是中断,i
是 if,e
是任一,ee
是相等,令人作呕)两者语言和示例是新的并且处于实验阶段。例如,在我对其进行更改以帮助完成此示例之前,
ad
无法用于将向量和矩阵相加。但我认为这正是专门为代码高尔夫设计的语言必须具备的东西。这是“语言”和“图书馆”之间的微妙界限。带注释的最新源代码可在 GitHub 上获取
Rebmu: 218 chars
Ma L{-|\/}Qb|[sg?SBaB]Da|[feSm[TfiSrj[spAsp]iT[++Tbr]]t]Xa|[i?A]Ya|[i?FImHDa]Ca|[skPCmSCaBKfsA]wh[Jd++N][roG[xJyJ]]Bf+GwhB[JcB Ff+GiF[KcF HqXkXj VqYkYju[chCbPClEZv1[ezH2[eeHv3 4]]e?A+bRE[hV]f]]chJeFIlSCj{+}{+ }Jk Bf]wM
I'm getting pretty good at reading and editing it natively in its pig-latin form. (Though I do use line breaks!!) :)
But here's how the dialect is transformed by the interpreter when the case-insensitive "mushing" trick is boiled away, and one gets accustomed to it. I'll add some comments. (Tips:
fi
is find,fe
is foreach,sp
is a space character,i?
is index,hd
is head,ch
is change,sk
is skip,pc
is pick,bk
is break,i
is if,e
is either,ee
is either equal, ad nauseum)Both the language and sample are new and in an experimental stage. For instance,
ad
couldn't be used to add together vectors and matrices before I changed it to help with this sample. But I think that's just the sort of thing that a language designed specifically for code golf has to have anyway. It's a subtle line between "language" and "library".Latest source with comments available on GitHub
Haskell,424 个字符
当前字符数:424
430451466511515<德尔>516 <德尔>518525532541545550556569571577582586< /del>592。这个版本从下面的原始 Haskell 条目中汲取了很多灵感,但做出了一些重大更改。最重要的是,它用单个索引而不是一对坐标表示图像位置。
有一些更改:
原始版本:
(需要< code>-XTupleSections,可能还有
-XNoMonomorphismRestriction
)解释:
(1)
d=...
:将输入拆分为空格和数字,例如(2)
e=...
:将d
转换为每个数字的 (y, x) 坐标列表。(3)
[((y,x),kx)|...]
是一个空板。 (k
返回空格或\n
,具体取决于 x 坐标。)[((y,x),'+'))|.. .]
是数字处的加号。(fj$zip e$tail e)
是连接数字的线。 (j
将一对坐标映射到代表一条线的(坐标、字符)列表中。)这 3 个组件被连接并过滤以形成实际的输出。请注意,顺序很重要,因此
nubBy(...).g
只能将最后一个字符保留在同一位置。Haskell, 424 chars
Current char count: 424
430451466511515516518525532541545550556569571577582586592.This version takes a lot of inspiration from the original Haskell entry below, but makes some significant changes. Most importantly, it represents image locations with a single index, not a pair of coordinates.
There are some changes:
Original version:
(Needs
-XTupleSections
, and maybe-XNoMonomorphismRestriction
)Explanation:
(1)
d=...
: Splits the input into spaces and numbers, e.g.(2)
e=...
: Convertsd
into a list of (y, x) coordinates for each number.(3)
[((y,x),k x)|...]
is an empty board. (k
returns a space or a\n
depending on the x-coordinate.)[((y,x),'+'))|...]
are the plus signs at the numbers.(f j$zip e$tail e)
are the lines connecting the numbers. (j
maps a pair of coordinates into a list of (coordinate, character) which represents a line.)These 3 components are concatenated and filtered to form the actual output. Note that the order is important, so that
nubBy(...).g
can only keep the last character in the same location.AWK - 296
317 321 324 334 340还不是获奖者,但我对我的努力感到满意(用于显示的换行符)。这个新版本使用 VT-100 转义序列。 '^['只是一个字符,Escape!!!在此版本中,剪切和粘贴不起作用,因为序列“^[”必须替换为真正的 ESC 字符。为了使论坛友好,可以将 ESC 指定为“\0x1b”,但它占用太多空间...
旧的标准版本
现在稍微解释一下
AWK - 296
317 321 324 334 340Not a prize winner (yet), but I am pleased with the effort (line breaks for display). This new version uses VT-100 escape sequences. The '^[' is just one character, Escape!!! Cut and paste will not work with this version, since the sequence "^[" has to be replaced with the real ESC character. To make it forum friendly, ESC could be specified as "\0x1b", but it takes too much space...
The older standard version
Now a little explanation
C, 386
402C 中的 386 个字符。第一个后面的换行符仅用于可读性。C, 386
402386 character in C. Newlines after the first are only for readability.英特尔汇编器
汇编大小:506 字节
来源:2252 字节(嘿,这不是一个小问题)
汇编:使用 A86
运行:使用 WinXP DOS 框进行测试。调用
jtd.com <输入>输出
有趣的功能:自修改代码、动画输出(第二个示例有效,但太大而无法显示)、滥用“ret”来实现循环计数器、确定线条/移动方向的有趣方法。
Intel Assembler
Assembled size: 506 bytes
Source: 2252 bytes (hey, it's not a trivial problem this one)
To Assemble: Use A86
To Run: Tested with a WinXP DOS box. Invocation
jtd.com < input > output
Interesting features: self modifying code, animated output (the second example works, but is too big to display), abuse of 'ret' to implement a loop counter, interesting way of determining line/movement direction.
F#,725 个字符
图例:
第 1-6 行:我保留一组 (number, lineNum, xCoord) 元组;当我阅读每一行输入时,我找到所有数字并将它们添加到集合中。
第 7-8 行:然后我创建一个输出字符数组,并初始化为所有空格。
第 9 行:对集合进行排序(按“数字”),然后取每个相邻对并...
第 10-16 行:...排序,使 (a,b) 是两个点中的“最高”点,并且 (x, y) 是另一个。放置“+”号,然后如果水平,则绘制它,否则如果垂直,则绘制它,否则绘制正确的对角线。如果输入不是“有效”,那么谁知道会发生什么(在我将其高尔夫化之前,这段代码就充满了“断言”)。
第 17-19 行:打印结果
F#, 725 chars
Legend:
Lines 1-6: I keep a set of (number, lineNum, xCoord) tuples; as I read in each line of input I find all the numbers and add them to the set.
Line 7-8: Then I create an array of output chars, initialized to all spaces.
Line 9: Sort the set (by 'number'), then take each adjacent pair and ...
Lines 10-16: ... sort so (a,b) is the 'highest' of the two points and (x,y) is the other. Put the '+' signs, and then if horizontal, draw that, else if vertical, draw that, else draw the correct diagonal. If the input is not 'valid', then who knows what happens (this code was littered with 'asserts' before I golf-ized it).
Lines 17-19: Print the result
Powershell,
328304 个字符,这是一个带有注释的漂亮打印版本:
Powershell,
328304 charactersand here's a pretty-printed version with comments:
Python - 381
Python - 381
C#,422 个字符
758754641627584546罢工> <罢工>532 <罢工>486 <罢工>457 <罢工>454 <罢工>443 <罢工>440 422 个字符(下次也许我不会这么快提交。)用法:运行,粘贴(或键入)输入,确保最后一行终止,按 CTRL-Z 或 F6,按 Enter。
格式化但仍然基本无法理解的版本:
C#, 422 chars
758754641627584546532486457454443440422 chars (next time maybe I won't submit so soon.)Usage: run, paste (or type) the input, ensure the last line is terminated, press CTRL-Z or F6, press Enter.
Formatted but still basically unintelligable version:
开始吧!
Here goes!
C#,638 个字符
C#, 638 chars
我无法在注释中进行多行操作,因此我将在这里进行演示。
在以下示例中,距离(x1,x2) == 距离(y1,y2):
根据所解释的规则,距离(x1,x2) == 距离(y1,y2)+2:
I cannot do multi-line in a comment, so I will demonstrate here.
In the following examples, distance(x1,x2) == distance(y1,y2):
With the rules as explained, distance(x1,x2) == distance(y1,y2)+2:
C++ 637
缩进,并带有一些稍微更有意义的名称,看起来像:
尽管表面上有差异,但它是对 morotspaj 代码的公然盗窃。
C++ 637
Indented, and with a few slightly more meaningful names, that looks like:
Despite superficial differences, it's a blatant theft of morotspaj's code.