首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASCII-艺术文恩图

ASCII-艺术文恩图
EN

Code Golf用户
提问于 2017-05-11 19:02:47
回答 1查看 1.7K关注 0票数 9

给定两个不包含重复元素ab的列表,找到两个列表之间的交叉,并输出一个ASCII。为了简单起见,Venn图将使用传统圆圈的规模化版本。

示例

Given:

代码语言:javascript
复制
a = [1, 11, 'Fox', 'Bear', 333, 'Bee']
b = ['1', 333, 'Bee', 'SchwiftyFive', 4]

输出(顺序是100%任意的,只要Venn图正确):

代码语言:javascript
复制
+-----+----+-------------+
|11   |333 |SchwiftyFive |
|Fox  |Bee |4            |
|Bear |1   |             |
+-----+----+-------------+

程序可以考虑'1' == 1'1' != 1,直至您的实现。您还可以选择将所有内容都作为字符串处理,并且只接受字符串输入。

Given:

代码语言:javascript
复制
a=[]
b=[1,2,3]

输出(注意这两个空部分如何仍然有正确的衬垫空间):

代码语言:javascript
复制
+-+-+--+
| | |1 |
| | |2 |
| | |3 |
+-+-+--+

Given:

代码语言:javascript
复制
a=[1]
b=[1]

输出:

代码语言:javascript
复制
+-+--+-+
| |1 | |
+-+--+-+

规则

  • Venn图的元素是左对齐的,并填充到最大长度条目加1.
  • 维恩图子部分中元素的排序是任意的.
  • 维恩图( |-相遇的地方)的角必须由+表示。
  • 如果a.join(b).length() > 0都是空的,你可以做任何事情。
    • 你甚至可以印一张亚伯·林肯的照片,别在意。

  • 这是密码-高尔夫ascii-art集合论

奖金

木炭很自然地呈现出这样的盒子,但是整套理论部分.不知道它做得有多好。+100赏金,以最短的木炭提交,然后我才能增加一个赏金的问题(2天后被问)。

EN

回答 1

Code Golf用户

发布于 2021-01-25 10:21:30

05AB1E,47 字节数

代码语言:javascript
复制
ʒå}©K®¹®Kr)õζ'|ìøε€SζøJ}ø'|δªðý¬„|+`:D¬мS'-:.ø»

在网上试试验证所有测试用例.

解释:

代码语言:javascript
复制
ʒ               # Filter the first (implicit) input-list by:
 å              #  Check if the current item is in the second (implicit) input-list
}©              # After the filter: store this overlap in variable `®` (without popping)
  K             # Pop and remove those items from the second (implicit) input-list
®               # Push overlap `®`
¹               # Push the first input-list again
 ®K             # Remove overlap `®`
r               # Reverse the three lists on the stack
 )              # And wrap them into a list
 ζ              # Zip/transpose this list, swapping rows/columns,
õ               # with "" as filler if the lists are of unequal length
  '|ì          '# Prepend an "|" in front of each inner string
ø               # Zip/transpose back, swapping rows/columns
 ε              # Map over each row:
  €             #  Map over each string in this row:
   S            #   Convert it to a list of characters
    ζ           #  Zip/transpose, swapping rows/columns, with " " as default filler
     ø          #  And then zip/transpose back
      J         #  And join the strings back together
 }ø             # After the map: zip/transpose back
  δ             # Map over each row:
'| ª           '#  And append an "|" to it
    ðý          # Then join each inner-most list by spaces
¬               # Push the first row (without popping the list)
 „|+`:          # Replace all "|" with "+"
      D         # Duplicate this string
       ¬        # Push its first characters (without popping), which is a "+"
        м       # Remove all "+" from the duplicated string
         S      # Convert what remains to a list of characters
          '-:  '# Replace each character (except for "+") with "-"
             .ø # Surround the list of rows with this string as leading/trailing items
»               # And finally join the list by newlines
                # (after which the result is output implicitly)
票数 1
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/120121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档