fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4. no warnings qw(recursion);
  5.  
  6. sub _f {
  7. my ($m, $n, $c) = @_;
  8.  
  9. return ($n <= $m ?
  10. $c :
  11. _f($m, ((($n >= $m * 2) and ($n % 2 == 0)) ? $n / 2 : $n - 1), $c + 1)
  12. );
  13. }
  14.  
  15. sub f { _f($_[0], $_[1], 0) }
  16.  
  17. say f(3, 10);
  18. say f(3, 95);
  19. say f(666, 2014);
  20.  
Success #stdin #stdout 0s 3872KB
stdin
Standard input is empty
stdout
3
10
342