Answer by ბიმო for City names game
Husk, 10 bytes←fΛ~=o_←→PTry it online!Explanation←fΛ~=(_←)→P -- example input: ["Xbc","Abc","Cba"] P -- all permutations: [["Xbc","Abc","Cba"],…,[Xbc","Cba","Abc"]] f -- filter by the following...
View ArticleAnswer by Hille for City names game
C# (.NET Core), 374 bytes 302 bytesusing System;using System.Linq;class Program{static void Main(string[] s){Func<char, char>u=(c)=>char.ToUpperInvariant(c);var S="";int...
View ArticleAnswer by Angs for City names game
Haskell, 94 74 bytesg[a]=[[a]]g c=[b:r|b<-c,r<-g[x|x<-c,x/=b],last b==[r!!0!!0..]!!32]head.gRecursively finds all solutions. -7 bytes if it's ok to output all solutions instead of the first....
View ArticleAnswer by habs for City names game
Jelly, 25 18 bytes (Improvements welcome!)UżḢŒuEḲŒ!çƝẠ$ÐfḢKTry it online!UżḢŒuE dyadic (2-arg) "check two adjacent city names" function:Uż pair (żip) the letters of the reversed left argument with the...
View ArticleAnswer by Akim for City names game
C#, 398And here is C# with Linq 5 centsIEnumerable<string>CityNameGame(string[]input){var cities=new List<string>(input);string lastCity=null;while(cities.Any()){var...
View ArticleAnswer by Gareth for City names game
J, 69656059 54 charactersSomewhat off the pace.{.l\:+/2=/\|:tolower;"2({.,{:)@>l=.(i.@!@#A.]);:1!:1[1Example: {.l\:+/2=/\|:tolower;"2({.,{:)@>l=.(i.@!@#A.]);:1!:1[1Neapolis Yokogama Sydney...
View ArticleAnswer by Howard for City names game
Ruby, 5855 44 charactersp$*.permutation.find{|i|i*?,!~/(.),(?!\1)/i}Yet another ruby implementation. Uses also case insensitive regex (as Ventero's old solution) but the test is done...
View ArticleAnswer by Ventero for City names game
Ruby 1.9, 63 54 charactersNew solution is based on Howard's solution:p$*.permutation.max_by{|i|(i*?,).scan(/(.),\1/i).size}This uses the fact that there'll always be a valid solution.Old solution,...
View ArticleAnswer by tmartin for City names game
K, 96{m@&{&/(~).'+(,_1_1#'x),,-1_-1#'x}@'$m:{$[x=1;y;,/.z.s[x-1;y]{x,/:{x@&~x in y}[y;x]}\:y]}[#x;x]}.k){m@&{&/(~).'+(,_1_1#'x),,-1_-1#'x}@'$m:{$[x=1;y;,/.z.s[x-1;y]{x,/:{x@&~x...
View ArticleAnswer by Howard for City names game
GolfScript, 78 characters" ":s/.{1${1$=!},{:h.,{1$-1={1$0=^31&!{[1$1$]s*[\](\h\-c}*;}+/}{;.p}if}:c~;}/;A first version in GolfScript. It also does a brute force approach. You can see the script...
View ArticleAnswer by Nolen Royalty for City names game
Python, 113Very similar to @beary605's answer, and even more brute-forced.from random import*l=raw_input().split()while any(x[-1]!=y[0].lower()for x,y in zip(l,l[1:])): shuffle(l)print l
View ArticleAnswer by baby-rabbit for City names game
C, 225#define S t=v[c];v[c]=v[i];v[i]=t#define L(x)for(i=x;i<n;i++)char*t;f;n=0;main(int c,char**v){int...
View ArticleAnswer by DavidC for City names game
Mathematica 236 charsDefine the list of cities:d = {"Neapolis", "Yokogama", "Sidney", "Amsterdam", "Madrid", "Lviv", "Viden", "Denver"}Find the path that includes all cities:c = Characters; f =...
View ArticleAnswer by Cristian Lupascu for City names game
Ruby 74 72 104 103 71 70p$*.permutation.find{|i|i.inject{|a,e|a[-1].casecmp(e[0])==0?e:?,}>?,}Demo:http://ideone.com/MDK5c (in the demo I've used gets().split() instead of $*; I don't know if Ideone...
View ArticleAnswer by beary605 for City names game
Python (162141 124)Brute force for the win.from itertools import*print[j for j in permutations(raw_input().split())if all(x[-1]==y[0].lower()for x,y in zip(j,j[1:]))]
View ArticleCity names game
If you like, write a program which sorts cities according to the rules of city name game.Each name of the city should start from the last letter in the previous city name. E.g. Lviv -> v -> Viden...
View Article
More Pages to Explore .....