Skip to content

Instantly share code, notes, and snippets.

@edofic
Last active December 11, 2015 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save edofic/4574560 to your computer and use it in GitHub Desktop.
Save edofic/4574560 to your computer and use it in GitHub Desktop.
if this was js i would say i minified the code.
import java.util.Scanner;import collection.mutable._;object A{type S=String;def main(a:Array[S]){val s=a(0);val p=a.size==2;val e=if(p)a(1)else(s.sorted);val c=new Scanner(System.in);while(c.hasNextLine){val w=c.nextLine;i(new N(w,if(p)(w==e)else(w.sorted==e&&w!=s)))};val q=Queue[N]();val k=y(s);k.c=0;def x(z:N){if(z.t)return;if(!z.v){z.e.map{e=>;if(e.c>z.c+1)e.p.clear();if(e.c>z.c){e.c=z.c+1;e.p.append(z)};if(!e.v)q.enqueue(e)}};z.v=true;if(!q.isEmpty)x(q.dequeue)};x(k);for{n<-y.values if(!n.p.isEmpty&&n.t)}n.P("")};val y=Map[S,N]();def i(n:N){for(m<-y.values;if(d(m.k,n.k)==1)){m.e.append(n);n.e.append(m)}};def d(s1:S,s2:S)=s1.zip(s2).filter{t=>t._1!=t._2}.size;class N(val k:S,val t:Boolean){val e,p=ListBuffer[N]();var c=Int.MaxValue;var v=false;def P(a:S){if(p.isEmpty)println(k+a)else(p.map(_.P("->"+k+a)))}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment