19
\$\begingroup\$

Introduction

Almost everyone is familiar with the Travelling Salesman Problem (TSP). The task is to, given a list of N cities, find the minimum Hamiltonian cycle which is to say the shortest path that visits each city and comes full-circle back to the start. That is not what this challenge is about. This challenge is to implement Chuck Norris' solution to the TSP:

Chuck Norris solved the Travelling Salesman problem in O(1) time: break salesman into N pieces; kick each piece to a different city.

Challenge

In order to solve the TSP in this way, we need a sufficiently durable Salesman that won't shy away from frivolities like dismemberment; a number of cities to visit; a set of products to sell; a concrete method for dismemberment; and a calculation for scoring.

Specification

  • Cities
    • N is the number of cites our Salesman will visit
  • Salesman
    • The main program or function
    • Written in language X
    • With length mod N equal to 0
  • Products
    • The full names of the elements on the Periodic Table
    • This includes the newly accepted names of elements
  • Dismemberment
    • Slicing the Salesman into N continuous pieces of equal length
    • Each piece is should be a valid function or program in language X
  • Output
    • When executed the Salesman should output Chuck Norris and the sliced pieces should each output a distinct product
    • Only extra trailing white space is acceptable
  • Scoring
    • The length, L, of the Salesman in bytes divided by the number of cities, N, squared.
    • Score = L/(N*N)
    • Smallest score wins
    • Please include 3 significant figures when posting your decimal score

Examples

  1. This Salesman visits 3 cities so N=3 and and it has a length of 9 so L=9. Thus the score for this answer would be S = 9 / (3 * 3) = 9/9 = 1.
    • Note that the Salesman and each sliced piece (of which there are 3), should all be valid programs or functions in the same language.
Program      -> Output
-------         ------
aaaBBBccc    -> Chuck Norris

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

aaaaa                   -> Hydrogen
BBBBB                   -> Cadmium
ccccc                   -> Mercury
DDDDD                   -> Iron
\$\endgroup\$
  • 3
    \$\begingroup\$ Are built-ins like Mathematica's ElementData allowed? (I doubt it'll save much, but I don't know.) \$\endgroup\$ – Martin Ender Sep 5 '16 at 6:29
  • \$\begingroup\$ Is capitalisation of the outputs important? \$\endgroup\$ – Martin Ender Sep 5 '16 at 6:34
  • 1
    \$\begingroup\$ @MartinEnder ^^ yes ^ yes \$\endgroup\$ – NonlinearFruit Sep 5 '16 at 10:05
  • 6
    \$\begingroup\$ Could any of the close voters explain which part they actually find unclear? (I know it can't be just my two questions, which I don't even think need to be explicitly addressed in the challenge, because there were already close votes when I posted them.) \$\endgroup\$ – Martin Ender Sep 5 '16 at 13:17
  • 2
    \$\begingroup\$ Totally agree with @MartinEnder. If you don't like a challenge, just try another one. \$\endgroup\$ – edc65 Sep 5 '16 at 15:11
11
\$\begingroup\$

CJam, L = 1482, N = 114, score 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"?

Try it online!

Each program is 13 bytes long. Here they are split up into individual lines:

'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"?

The missing elements are Darmstadtium, Praseodymium, Protactinium and Rutherfordium which are 12 or 13 characters long which means I can't print them in 13 characters each.

The idea is that the first few programs, which prints the elements with short names use their extraneous characters to build the string Chuck Norri in the variable L, which does not affect the output when used on their own. The final program then checks if anything is already on the stack, and uses it to choose between L (plus s) and Xenon.

A few additional bytes are saved by using the character we just added to L as part of the element name, specifically for Carbon, Nickel, Copper and Silver.

\$\endgroup\$
2
\$\begingroup\$

Python, L = 2596, N = 118, Score = 0.186

The length of each slice is 22 so that makes this pretty lengthy.

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  "

Here is the Salesman after the slicing and dicing:

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  "

enter image description here


Update

  • [16-09-08] Sublime added an extra space when joining to a line that ends in a comment character
  • [16-09-08] Made each slice 22 characters long and added gif
\$\endgroup\$
  • \$\begingroup\$ I'm fairly knew at Python, how does lambda:"Actinium";print"" output Actinium? Is this maybe particular to Python 3? \$\endgroup\$ – Linus Sep 5 '16 at 23:37
  • \$\begingroup\$ @Linus The lambda key word creates an anonymous function that takes no parameters and returns Actinium. The print "" doesn't do anything useful after the Salesman has been dismembered. \$\endgroup\$ – NonlinearFruit Sep 5 '16 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.