Skip to content

Instantly share code, notes, and snippets.

@butchi
Created November 2, 2014 16:57
Show Gist options
  • Select an option

  • Save butchi/5d1d78fd0e22d127afb6 to your computer and use it in GitHub Desktop.

Select an option

Save butchi/5d1d78fd0e22d127afb6 to your computer and use it in GitHub Desktop.
No.55 正方形を描くだけの簡単なお仕事です。
(* http://yukicoder.me/problems/no/55 *)
pLi = Complex[#[[1]], #[[2]]] & /@
Partition[ImportString["8 10 14 14 13 9", "Table"][[1]], 2];
dLi = Abs[RotateLeft[pLi, 1] - RotateLeft[pLi, 2]];
permLi = Permutations[pLi];
p4Li = (#[[2]] + I (#[[1]] - #[[3]])) & /@ permLi;
sqLi = Table[Append[permLi[[n]], p4Li[[n]]], {n, 1, Length[permLi]}];
edgeLen[pLi_] := Abs[pLi - RotateLeft[pLi]];
judgeLi = SameQ @@ # & /@ (edgeLen /@ sqLi);
pos = Position[judgeLi, True];
If[pos === {}, -1, ({Re[#], Im[#]} &@p4Li[[pos[[1]][[1]]]])]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment