プログラミングのお題スレ Part22 (863レス)
前次1-
抽出解除 レス栞

リロード規制です。10分ほどで解除するので、他のブラウザへ避難してください。
52
(1): デフォルトの名無しさん [sage] 2023/08/19(土)02:12:13.34 ID:7swIlm9f(1/2)
6,11,11,6,11,11,・・・なんでこうなうの?
197: 17 [] 2024/01/19(金)19:43:44.34 ID:hxZRcaHh(1)
>>187
Kotlin

今度は Java のライブラリは使わずに時分秒を保持するクラスを自分で作ってそこで秒に足すとか文字列にするとかやるようにした。

https://paiza.io/projects/7YcPDBTxVFt9EVczvBJ8gQ
467: デフォルトの名無しさん [] 01/03(金)15:34:16.34 ID:aGLRGnDr(2/3)
>>464 python
https://ideone.com/2Xa1tx
488: デフォルトの名無しさん [sage] 01/22(水)23:57:13.34 ID:EHGf/TPZ(2/2)
>>485
Rust 今回は積ライブラリを使わない自力版

fn odai(文字列: &str, 長さ: usize) -> Vec<String> {
let chars = 文字列.chars().collect::<Vec<_>>();
let mut state = vec![0; 長さ];
let mut output = Vec::new();
'Loop: loop {
let s = state.iter().map(|i| chars[*i]).collect();
output.push(s);
for index in state.iter_mut().rev() {
*index += 1;
if *index == chars.len() {
*index = 0;
continue;
}
continue 'Loop;
}
return output;
}
}

検証用main()は>>486と同じ
580: デフォルトの名無しさん [age] 02/12(水)00:01:10.34 ID:hk2aQo3G(1/3)
プログラミングはもっと自由なものなんだよ、思ったとおりにかけば良い
583
(1): デフォルトの名無しさん [sage] 02/12(水)00:13:52.34 ID:SJ0T1N6w(1)
ざっと見たけどmax()を返してるのはC++の人だけで他は皆まともだ
普段からまともなコード書いてるかどうかバレてしまうから自由が面白い
623
(1): デフォルトの名無しさん [] 02/15(土)22:00:12.34 ID:rssRTGdz(4/9)
>>622
>>593のC++プログラムの実行結果を参照。入力数列にINT_MAXが含まれる場合でも問題ない。
663
(1): デフォルトの名無しさん [] 03/01(土)20:18:20.34 ID:H8RpZRUP(1/2)
>>656
PowerShellのBigIntなら、

$b = @(0)
1..8 |% {$b += $b |% {$_ + 1}}

function bit_count([BigInt]$n)
{
  ($b[[BigInt]::Abs($n).ToByteArray()] | measure -sum).Sum
}

65535, 15, 6, 1, 0, -1, -6, -15, -65535, [BigInt]::Pow(123, 45) |% {
  "$_ → $(bit_count $_)"
}

[実行結果]
65535 → 16
15 → 4
6 → 2
1 → 1
0 → 0
-1 → 1
-6 → 2
-15 → 4
-65535 → 16
11110408185131956285910790587176451918559153212268021823629073199866111001242743283966127048043 → 159
733: デフォルトの名無しさん [sage] 04/02(水)20:14:17.34 ID:ZWpp3MuE(1)
5chのプロはどんな変数名使うのか教えて
814
(1): デフォルトの名無しさん [sage] 08/22(金)06:55:21.34 ID:qlaiAqZd(1/2)
>>812
Rust >>799の逆変換の重複順列の何番目か算出

use itertools::Itertools;
use num::{BigUint, One};

// 重複順列の何番目かを求める ex. "222331434114" → "123456"番目
fn to_nth(input: &str) -> String {
// 出現数
let (mut counts, chars): (Vec<usize Vec<char>) = input.chars().sorted().dedup_with_count().multiunzip();
// index化input
let input: Vec<usize> = input.chars().map(|c| chars.iter().position(|&c0| c0 == c).unwrap()).collect();
// 階乗関数
fn factorial(x: usize) -> BigUint { (1..=x).fold(BigUint::one(), |p, x| p * x) }
// 重複順列の総数
let mut whole: BigUint = factorial(input.len()) / counts.iter().map(|&x| factorial(x)).product::<BigUint>();
// nth番目を算出
(1..=input.len()).rev().zip(input).fold(BigUint::one(), |mut nth, (len, index)| {
// 自分より前までの総数をnthに足す
nth += &whole * counts[..index].iter().sum::<usize>() / len;
// 自分の総数へ更新
whole *= counts[index];
whole /= len;
counts[index] -= 1;
nth
})
.to_string()
}
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.033s