fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4.  
  5. sub prestr { $_[1] >= 0 ? substr($_[0], 0, $_[1]) : '' }
  6. sub poststr { join '', sort split //, substr($_[0], $_[1]) }
  7.  
  8. sub f {
  9. my $p = index $_[0], '01';
  10. return prestr($_[0], $p) . '10' . poststr($_[0], $p + 2);
  11. }
  12.  
  13. say f('111');
  14. say f('1110');
  15. say f('101100');
  16. say f('1101');
  17.  
Success #stdin #stdout 0s 3692KB
stdin
Standard input is empty
stdout
1011
10011
110001
1110