Skip to content

Instantly share code, notes, and snippets.

@butchi
Created October 14, 2014 15:18
Show Gist options
  • Save butchi/d643ffa83f760e9dfda9 to your computer and use it in GitHub Desktop.
Save butchi/d643ffa83f760e9dfda9 to your computer and use it in GitHub Desktop.
yukicoder No.39 桁の数字を入れ替え
(* http://yukicoder.me/problems/no/39 *)
maxPos[li_] := Last[Position[li, Max[li]]][[1]]
replace[li_] := ReplacePart[li, {maxPos[li] -> First[li], 1 -> Max[li]}]
f[n_] := FromDigits[replace[IntegerDigits[n]]]
@butchi
Copy link
Author

butchi commented Oct 14, 2014

不正解
× f[9978] = 9978
○ f[9978] = 9987

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment