美しい整数の世界 (780レス)
美しい整数の世界 http://rio2016.5ch.net/test/read.cgi/math/1686749616/
上
下
前
次
1-
新
通常表示
512バイト分割
レス栞
581: 132人目の素数さん [sage] 2024/05/08(水) 22:24:13.53 ID:o+7mX6D2 ■haskellに移植 import Data.List import Data.List.Split m = 5 -- 縦マス(短軸) n = 6 -- 横マス(長軸) k = 5 -- 宝の数 q = [0..m*n-1] matQ = chunksOf n q matP = transpose matQ --行列を転置して p = concat matP -- 配列に変換 combinations :: Int -> [a] -> [[a]] combinations 0 _ = [ [] ] combinations n xs = [ y:ys | y:xs' <- tails xs, ys <- combinations (n-1) xs'] treasure = combinations k q -- 宝の組み合わせ ip y = minimum $ map(\x -> elemIndices x p!!0) y -- 宝の、配列pでのindex列を求めて最小値を返す iq y = minimum $ map(\x -> elemIndices x q!!0) y idxp = map ip treasure -- 宝の組み合せで実行して idxq = map iq treasure p_q = zipWith (-) idxp idxq -- 差をとって大小判別 p1st = length $ filter (<0) p_q -- 短軸方向探索pが先に宝をみつける q1st = length $ filter (>0) p_q draw = length $ filter (==0) p_q main = do putStrLn $ "p1st = " ++ show p1st ++ ", q1st = " ++ show q1st ++ ", draw = " ++ show draw >matrix.exe p1st = 55469, q1st = 54036, draw = 33001 http://rio2016.5ch.net/test/read.cgi/math/1686749616/581
メモ帳
(0/65535文字)
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 199 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.006s