Run
はA<'T, FromReturn>
のみを受け取る
if then else
で死にそう
Obsolete
…なるほど、考えてもみなかったですね
printfn "%A" (System.IO.Path.GetFileName str)
printfn
では2進出力ができない、ということかもしれません。
module TestBitOperator =
let test a (x:int, y:int) =
match a with
| "and" -> "0b" + System.Convert.ToString(x &&& y, 2).PadLeft(4, '0')
| "or" -> "0b" + System.Convert.ToString(x ||| y, 2).PadLeft(4, '0')
| "xor" -> "0b" + System.Convert.ToString(x ^^^ y, 2).PadLeft(4, '0')
| _ -> failwith "error!"
printfn "%A" (test "and" (0b0101, 0b1100)) // "0b0100"
printfn "%A" (test "or" (0b0101, 0b1100)) // "0b1101"
printfn "%A" (test "xor" (0b0101, 0b1100)) // "0b1001"
度々すみません。お手すきの時にでも。。。下記コードは組み合わせをビットで求めるコードなのですが、while
ループを再帰にしたいです。がなかなかにうまくいきません。ヒントいただければ幸いです。。。
module Combi =
let first n = int(uint32 1 <<< n ) - int( uint32 1 )
let nextset x =
let smallest = x &&& -x
let ripple = x + smallest
let newSmallest = ripple &&& -ripple
let ones = ((newSmallest / smallest ) >>> 1) - 0b1
ripple + ones
[<EntryPoint>]
let main (args:string[]) =
let n = System.Int32.Parse(args.[0])
let r = System.Int32.Parse(args.[1])
let pr (x:int) = System.Convert.ToString( x, 2 ).PadLeft(n,'0')
let mutable x = first r
// ★ここの while ループを再帰にしたい!
while ( x < (first n)) do
printfn "%A" (pr x)
x <- nextset x
0
ちなみに僕が考えた再帰ですが、、、途中で何が何だかわからなくなりました(苦笑)
let rec combi n r acc =
match acc with
| x::xs ->
match x with
| 7 -> acc
| _ -> combi (nextset x) 2 (nextset x)::acc