Created
January 3, 2015 17:27
-
-
Save raydive/be48edab1b249f27a6d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# タクシー数の4乗バージョン ruby | |
test = [] | |
(1..300).each {|i| (1..300).each {|j| test << [i, j].sort }} | |
test.uniq! | |
by = test.group_by {|i,j| i**4 + j**4 }.select {|key, value| value.count > 1 } | |
p by # => {3262811042=>[[7, 239], [157, 227]], 635318657=>[[59, 158], [133, 134]], 8657437697=>[[193, 292], [256, 257]]} |
Array#combinationだったか(あったはずだと思ったがリファレンスを引くのがめんどかったw)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
短くしてみた。
(1..300).to_a.combination(2).group_by{|i,j|i4+j4}.select{|k,v|v.count>1}