プログラミングのお題スレ Part22 (854レス)
プログラミングのお題スレ Part22 http://mevius.5ch.net/test/read.cgi/tech/1691038333/
上
下
前次
1-
新
通常表示
512バイト分割
レス栞
抽出解除
必死チェッカー(本家)
(べ)
自ID
レス栞
あぼーん
リロード規制
です。10分ほどで解除するので、
他のブラウザ
へ避難してください。
209: デフォルトの名無しさん [sage] 2024/02/02(金) 22:48:33.27 ID:UezRkqGy >>206 ruby https://ideone.com/eF5lww f = -> a { w = a.map {|s| s.split('=')}.flatten.uniq.map.with_index.to_h a.each_with_object([]) {|s, acc| x, xa, y, ya = s.split('=').map {|k| [k, acc.find {|b| b.include? k}]}.flatten(1) if xa && ya then xa.concat (acc.delete ya) << x << y elsif xa then xa << x << y elsif ya then ya << x << y else acc << [x, y] end }.map {|a| a.uniq.sort_by {|s| w[s]}}.sort_by {|a| w[a[0]]} } http://mevius.5ch.net/test/read.cgi/tech/1691038333/209
210: デフォルトの名無しさん [sage] 2024/02/02(金) 22:51:42.74 ID:UezRkqGy >>206 rust https://ideone.com/MEZMPO fn f<'a>(a: &[&'a str]) -> Vec<Vec<&'a str>> { // ' let h = a.iter().map(|&s| s.split('=')).flatten().rev().enumerate().map(|(p, s)| (s, p)).collect::<HashMap<_, _>>(); let mut acc = Vec::<Vec<&str>>::new(); for xy in a.iter().map(|s| s.split('=').collect::<Vec<_>>()) { match (acc.iter().position(|b| b.contains(&xy[0])), acc.iter().position(|b| b.contains(&xy[1]))) { (Some(xi), Some(yi)) => { let ys = acc[yi].clone(); acc[xi].extend(ys); acc[xi].extend(xy); acc.remove(yi); }, (Some(xi), None) => acc[xi].extend(xy), (None, Some(yi)) => acc[yi].extend(xy), _ => acc.push(xy), } } for b in acc.iter_mut() { b.sort_by(|c, d| h.get(d).cmp(&h.get(c))); b.dedup(); } acc.sort_by(|c, d| h.get(d[0]).cmp(&h.get(c[0]))); acc } http://mevius.5ch.net/test/read.cgi/tech/1691038333/210
211: デフォルトの名無しさん [sage] 2024/02/02(金) 23:24:19.60 ID:UezRkqGy >>206 ruby https://ideone.com/daI0QL ・若干の修正 f = -> a { w = a.map {|s| s.split('=')}.flatten.uniq.map.with_index.to_h a.each_with_object([]) {|s, acc| x, xa, y, ya = s.split('=').map {|k| [k, acc.find {|b| b.include? k}]}.flatten(1) if xa && ya then xa.concat (acc.delete ya) elsif xa then xa << y elsif ya then ya << x else acc << [x, y] end }.map {|a| a.sort_by {|s| w[s]}}.sort_by {|a| w[a[0]]} } http://mevius.5ch.net/test/read.cgi/tech/1691038333/211
212: デフォルトの名無しさん [sage] 2024/02/02(金) 23:24:45.86 ID:UezRkqGy >>206 rust https://ideone.com/dO4xea ・若干の修正 fn f<'a>(a: &[&'a str]) -> Vec<Vec<&'a str>> { // ' let h = a.iter().map(|&s| s.split('=')).flatten().rev().enumerate().map(|(p, s)| (s, p)).collect::<HashMap<_, _>>(); let mut acc = Vec::<Vec<&str>>::new(); for xy in a.iter().map(|s| s.split('=').collect::<Vec<_>>()) { match (acc.iter().position(|b| b.contains(&xy[0])), acc.iter().position(|b| b.contains(&xy[1]))) { (Some(xi), Some(yi)) => { let ys = acc[yi].clone(); acc[xi].extend(ys); acc.remove(yi); }, (Some(xi), None) => acc[xi].push(xy[1]), (None, Some(yi)) => acc[yi].push(xy[0]), _ => acc.push(xy), } } acc.iter_mut().for_each(|b| b.sort_by(|c, d| h.get(d).cmp(&h.get(c)))); acc.sort_by(|c, d| h.get(d[0]).cmp(&h.get(c[0]))); acc } http://mevius.5ch.net/test/read.cgi/tech/1691038333/212
メモ帳
(0/65535文字)
上
下
前次
1-
新
書
関
写
板
覧
索
設
栞
歴
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.042s