Set right-adjacent bits: Difference between revisions

Realize in F#
(Realize in F#)
Line 52:
* Print the output aligned in a way that allows easy checking by eye of the binary input vs output.
 
=={{header|F_Sharp|F#}}==
<lang fsharp>
// Set right-adjacent bits. Nigel Galloway: December 21st., 2021
let fN g l=let rec fG n g=[|match n,g with ('0'::t,0)->yield '0'; yield! fG t 0
|('0'::t,n)->yield '1'; yield! fG t (n-1)
|(_::t,_) ->yield '1'; yield! fG t l
|_ ->()|]
fG (g|>List.ofSeq) 0|>System.String
 
[("1000",2);("0100",2);("0010",2);("0001",2);("0000",2);("010000000000100000000010000000010000000100000010000010000100010010",0);("010000000000100000000010000000010000000100000010000010000100010010",1);("010000000000100000000010000000010000000100000010000010000100010010",2);("010000000000100000000010000000010000000100000010000010000100010010",3)]|>List.iter(fun(n,g)->printfn "%s\n%s" n (fN n g))
</lang>
{{out}}
<pre>
1000
1110
0100
0111
0010
0011
0001
0001
0000
0000
010000000000100000000010000000010000000100000010000010000100010010
010000000000100000000010000000010000000100000010000010000100010010
010000000000100000000010000000010000000100000010000010000100010010
011000000000110000000011000000011000000110000011000011000110011011
010000000000100000000010000000010000000100000010000010000100010010
011100000000111000000011100000011100000111000011100011100111011111
010000000000100000000010000000010000000100000010000010000100010010
011110000000111100000011110000011110000111100011110011110111111111
</pre>
=={{header|Perl}}==
<lang perl>#!/usr/bin/perl
2,171

edits