美しい整数の世界 (780レス)
1-

581: 2024/05/08(水)22:24 ID:o+7mX6D2(6/8) AAS
■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
1-
あと 199 レスあります
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.005s