查克·诺里斯(Chuck Norris)vs旅行推销员


19

介绍

几乎每个人都熟悉旅行商问题(TSP)。任务是在给定N城市列表的情况下,找到最小的汉密尔顿周期,这就是访问每个城市并返回到起点整圈的最短路径。这不是这个挑战的目的。挑战在于如何实现Chuck Norris 的TSP 解决方案

查克·诺里斯(Chuck Norris)O(1)及时解决了旅行推销员问题:将推销员分为N个;踢每件到另一个城市。

挑战

为了以这种方式解决TSP,我们需要一个足够耐用的推销员,该推销员不会回避肢解之类的琐事。许多城市参观;一套要出售的产品;肢解的具体方法;并计算得分。

规格

  • 城市
    • N 是我们的业务员将拜访的引用数量
  • 推销员
    • 主程序或功能
    • 用语言写 X
    • 长度N等于0
  • 产品展示
    • 元素的全名元素周期表中
    • 这包括接受的元素名称
  • 肢解
    • 将推销员切成 N等长的连续片
    • 每个部分都应该是有效的语言功能或程序 X
  • 输出量
    • 执行后,推销员应输出 Chuck Norris,切成薄片的每个应输出不同的产品
    • 仅多余的尾随空格
  • 计分
    • L推销员的长度(字节)除以城市数量(N)的平方。
    • Score = L/(N*N)
    • 最低分获胜
    • 发布十进制分数时,请包含3个有效数字

例子

  1. 该推销员大约访问了3个城市N=3,并且长度为9个L=9。因此,此答案的分数将是S = 9 / (3 * 3) = 9/9 = 1
    • 请注意,推销员和每个切片(每个切片有3个)应该都是相同语言的有效程序或函数。
Program      -> Output
-------         ------
aaaBBBccc    -> Chuck Norris

aaa          -> Helium
BBB          -> Iridium
ccc          -> Tennessine
  1. N=4L=20因此S=20/16=1.25
Program                 -> Output
-------                    ------
aaaaaBBBBBcccccDDDDD    -> Chuck Norris

aaaaa                   -> Hydrogen
BBBBB                   -> Cadmium
ccccc                   -> Mercury
DDDDD                   -> Iron

3
是否ElementData允许像Mathematica一样的内置函数?(我怀疑这样做会节省很多,但我不知道。)
Martin Ender

产出的资本化重要吗?
Martin Ender

1
@MartinEnder ^^是^是
NonlinearFruit

6
亲密的选民能否解释他们实际上不清楚的那一部分?(我知道这不仅仅是我的两个问题,我什至认为在挑战中甚至不需要明确解决这些问题,因为当我发布这些问题时已经获得了非常多的票。)
Martin Ender

2
完全同意@MartinEnder。如果您不喜欢挑战,请尝试另一个挑战。
edc65'9

Answers:


11

CJam,L = 1482,N = 114,得分0.114

'C:L"arbon"  L'h+:L;"Gold"L'u+:L;"Iron"L'c+:L;"Lead"L'k+:L;"Neon"LS+:L;"Argon"L'N+:L"ickel"L'o+:L;"Zinc""Coppe"L'r+:L"Silve"L'r+:LL'i+:L;"Tin" "Boron"      "Radon"      "Barium"     "Cerium"     "Cesium"     "Cobalt"     "Curium"     "Erbium"     "Helium"     "Indium"     "Iodine"     "Osmium"     "Oxygen"     "Radium"     "Sodium"     "Sulfur"     "Arsenic"    "Bismuth"    "Bohrium"    "Bromine"    "Cadmium"    "Calcium"    "Dubnium"    "Fermium"    "Gallium"    "Hafnium"    "Hassium"    "Holmium"    "Iridium"    "Krypton"    "Lithium"    "Mercury"    "Niobium"    "Rhenium"    "Rhodium"    "Silicon"    "Terbium"    "Thorium"    "Thulium"    "Uranium"    "Yttrium"    "Actinium"   "Aluminum"   "Antimony"   "Astatine"   "Chlorine"   "Chromium"   "Europium"   "Fluorine"   "Francium"   "Hydrogen"   "Lutetium"   "Nihonium"   "Nitrogen"   "Nobelium"   "Platinum"   "Polonium"   "Rubidium"   "Samarium"   "Scandium"   "Selenium"   "Tantalum"   "Thallium"   "Titanium"   "Tungsten"   "Vanadium"   "Americium"  "Berkelium"  "Beryllium"  "Flerovium"  "Germanium"  "Lanthanum"  "Magnesium"  "Manganese"  "Moscovium"  "Neodymium"  "Neptunium"  "Oganesson"  "Palladium"  "Plutonium"  "Potassium"  "Ruthenium"  "Strontium"  "Tellurium"  "Ytterbium"  "Zirconium"  "Dysprosium" "Gadolinium" "Lawrencium" "Meitnerium" "Molybdenum" "Phosphorus" "Promethium" "Seaborgium" "Technetium" "Tennessine" "Californium""Copernicium""Einsteinium""Livermorium""Mendelevium""Roentgenium"]L's+"Xenon"?

在线尝试!

每个程序长13个字节。在这里,它们分为几行:

'C:L"arbon"  
L'h+:L;"Gold"
L'u+:L;"Iron"
L'c+:L;"Lead"
L'k+:L;"Neon"
LS+:L;"Argon"
L'N+:L"ickel"
L'o+:L;"Zinc"
"Coppe"L'r+:L
"Silve"L'r+:L
L'i+:L;"Tin" 
"Boron"      
"Radon"      
"Barium"     
"Cerium"     
"Cesium"     
"Cobalt"     
"Curium"     
"Erbium"     
"Helium"     
"Indium"     
"Iodine"     
"Osmium"     
"Oxygen"     
"Radium"     
"Sodium"     
"Sulfur"     
"Arsenic"    
"Bismuth"    
"Bohrium"    
"Bromine"    
"Cadmium"    
"Calcium"    
"Dubnium"    
"Fermium"    
"Gallium"    
"Hafnium"    
"Hassium"    
"Holmium"    
"Iridium"    
"Krypton"    
"Lithium"    
"Mercury"    
"Niobium"    
"Rhenium"    
"Rhodium"    
"Silicon"    
"Terbium"    
"Thorium"    
"Thulium"    
"Uranium"    
"Yttrium"    
"Actinium"   
"Aluminum"   
"Antimony"   
"Astatine"   
"Chlorine"   
"Chromium"   
"Europium"   
"Fluorine"   
"Francium"   
"Hydrogen"   
"Lutetium"   
"Nihonium"   
"Nitrogen"   
"Nobelium"   
"Platinum"   
"Polonium"   
"Rubidium"   
"Samarium"   
"Scandium"   
"Selenium"   
"Tantalum"   
"Thallium"   
"Titanium"   
"Tungsten"   
"Vanadium"   
"Americium"  
"Berkelium"  
"Beryllium"  
"Flerovium"  
"Germanium"  
"Lanthanum"  
"Magnesium"  
"Manganese"  
"Moscovium"  
"Neodymium"  
"Neptunium"  
"Oganesson"  
"Palladium"  
"Plutonium"  
"Potassium"  
"Ruthenium"  
"Strontium"  
"Tellurium"  
"Ytterbium"  
"Zirconium"  
"Dysprosium" 
"Gadolinium" 
"Lawrencium" 
"Meitnerium" 
"Molybdenum" 
"Phosphorus" 
"Promethium" 
"Seaborgium" 
"Technetium" 
"Tennessine" 
"Californium"
"Copernicium"
"Einsteinium"
"Livermorium"
"Mendelevium"
"Roentgenium"
]L's+"Xenon"?

缺少的元素是Darmstadtium,Prseodymium,Protactinium和Rutherfordium,它们的长度为12或13个字符,这意味着我不能分别用13个字符打印它们。

这个想法是,前几个程序使用短名称打印元素,这些程序使用它们的无关字符Chuck Norri在变量中构建字符串,当它们单独使用L时不会影响输出。然后,最终程序检查堆栈中是否已经有任何东西,并使用它在L(plus s)和之间进行选择Xenon

一些额外的字节是通过使用我们刚才添加的字符保存L为元素名称的一部分,专门为C阿尔邦,Nickel,COPPE r和西尔夫r


2

Python,L = 2596,N = 118,得分= 0.186

每个切片的长度为22,因此很长。

lambda:"Gold"; print"""";print "Carbon     "print   "Thorium     "print   "Curium      "print "Calcium       "print "Nickel        "print      "Zinc     "print    "Neon       "print "Boron         "print   "Iron        "print  "Cerium       "print "Barium        "print "Caesium       """[9::22];lambda:"Tin"[0];lambda:"Lead    "#print"Argon          "print"Radon          "print"Xenon          "print"Erbium         "print"Cobalt         "print"Copper         "print"Helium         "print"Indium         "print"Iodine         "print"Osmium         "print"Oxygen         "print"Radium         "print"Silver         "print"Sodium         "print"Sulfur         "print"Arsenic        "print"Bismuth        "print"Bohrium        "print"Bromine        "print"Cadmium        "print"Dubnium        "print"Fermium        "print"Gallium        "print"Hafnium        "print"Hassium        "print"Holmium        "print"Iridium        "print"Krypton        "print"Lithium        "print"Mercury        "print"Niobium        "print"Rhenium        "print"Rhodium        "print"Silicon        "print"Terbium        "print"Thulium        "print"Uranium        "print"Yttrium        "print"Actinium       "print"Antimony       "print"Astatine       "print"Chlorine       "print"Chromium       "print"Europium       "print"Fluorine       "print"Francium       "print"Hydrogen       "print"Lutetium       "print"Nitrogen       "print"Nobelium       "print"Platinum       "print"Polonium       "print"Rubidium       "print"Samarium       "print"Scandium       "print"Selenium       "print"Tantalum       "print"Thallium       "print"Titanium       "print"Tungsten       "print"Vanadium       "print"Nihonium       "print"Aluminium      "print"Americium      "print"Berkelium      "print"Beryllium      "print"Flerovium      "print"Germanium      "print"Lanthanum      "print"Magnesium      "print"Manganese      "print"Neodymium      "print"Neptunium      "print"Palladium      "print"Plutonium      "print"Potassium      "print"Ruthenium      "print"Strontium      "print"Tellurium      "print"Ytterbium      "print"Zirconium      "print"Moscovium      "print"Oganesson      "print"Dysprosium     "print"Gadolinium     "print"Lawrencium     "print"Meitnerium     "print"Molybdenum     "print"Phosphorus     "print"Promethium     "print"Seaborgium     "print"Technetium     "print"Tennessine     "print"Californium    "print"Copernicium    "print"Einsteinium    "print"Livermorium    "print"Mendelevium    "print"Roentgenium    "print"Darmstadtium   "print"Praseodymium   "print"Protactinium   "print"Rutherfordium  "

切片和切块后,这是推销员:

lambda:"Gold"; print""  # <-- This is a function
"";print "Carbon     "
print   "Thorium     "
print   "Curium      "
print "Calcium       "
print "Nickel        "
print      "Zinc     "
print    "Neon       "
print "Boron         "
print   "Iron        "
print  "Cerium       "
print "Barium        "
print "Caesium       "
""[9::22];lambda:"Tin"  # <-- This is a function and the choke point
[0];lambda:"Lead    "#  # <-- This is a function
print"Argon          "
print"Radon          "
print"Xenon          "
print"Erbium         "
print"Cobalt         "
print"Copper         "
print"Helium         "
print"Indium         "
print"Iodine         "
print"Osmium         "
print"Oxygen         "
print"Radium         "
print"Silver         "
print"Sodium         "
print"Sulfur         "
print"Arsenic        "
print"Bismuth        "
print"Bohrium        "
print"Bromine        "
print"Cadmium        "
print"Dubnium        "
print"Fermium        "
print"Gallium        "
print"Hafnium        "
print"Hassium        "
print"Holmium        "
print"Iridium        "
print"Krypton        "
print"Lithium        "
print"Mercury        "
print"Niobium        "
print"Rhenium        "
print"Rhodium        "
print"Silicon        "
print"Terbium        "
print"Thulium        "
print"Uranium        "
print"Yttrium        "
print"Actinium       "
print"Antimony       "
print"Astatine       "
print"Chlorine       "
print"Chromium       "
print"Europium       "
print"Fluorine       "
print"Francium       "
print"Hydrogen       "
print"Lutetium       "
print"Nitrogen       "
print"Nobelium       "
print"Platinum       "
print"Polonium       "
print"Rubidium       "
print"Samarium       "
print"Scandium       "
print"Selenium       "
print"Tantalum       "
print"Thallium       "
print"Titanium       "
print"Tungsten       "
print"Vanadium       "
print"Nihonium       "
print"Aluminium      "
print"Americium      "
print"Berkelium      "
print"Beryllium      "
print"Flerovium      "
print"Germanium      "
print"Lanthanum      "
print"Magnesium      "
print"Manganese      "
print"Neodymium      "
print"Neptunium      "
print"Palladium      "
print"Plutonium      "
print"Potassium      "
print"Ruthenium      "
print"Strontium      "
print"Tellurium      "
print"Ytterbium      "
print"Zirconium      "
print"Moscovium      "
print"Oganesson      "
print"Dysprosium     "
print"Gadolinium     "
print"Lawrencium     "
print"Meitnerium     "
print"Molybdenum     "
print"Phosphorus     "
print"Promethium     "
print"Seaborgium     "
print"Technetium     "
print"Tennessine     "
print"Californium    "
print"Copernicium    "
print"Einsteinium    "
print"Livermorium    "
print"Mendelevium    "
print"Roentgenium    "
print"Darmstadtium   "
print"Praseodymium   "
print"Protactinium   "
print"Rutherfordium  "

在此处输入图片说明


更新资料

  • [16-09-08] Sublime在连接到以注释字符结尾的行时添加了额外的空间
  • [16-09-08]使每个切片长22个字符,并添加了gif

我在Python上相当了解,如何lambda:"Actinium";print""输出Actinium?这可能是Python 3特有的吗?
莱纳斯(Linus)2016年

@Linus lambda关键字创建一个不带参数且返回的匿名函数Actinium。该print ""推销员被肢解后,不会做任何有用的。
NonlinearFruit
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.