Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 4e379f2fdfb67a000100002e

PHP <--> Java class conversion Part 2

Same class but reverse!

Start file
public class Foo
{
       
private double var1;
       
private double var2;

       
public Foo(double val)
       
{
                init
(val);
                doSomething
();
       
}

       
private void init(double val)
       
{
                var1
= val;
       
}
       
       
private void doSomething()
       
{
                var2
= Math.sqrt(var1);
       
}

       
public double getResult()
       
{
               
return var2;
       
}
}
End file
<?php
class Foo
{
       
private $var1;
       
private $var2;

       
public function Foo($val)
       
{
                $this
->init($val);
                $this
->doSomething();
       
}

       
private function init($val)
       
{
                $this
->var1 = $val;
       
}
       
       
private function doSomething()
       
{
                $this
->var2 = sqrt($this->var1);
       
}

       
public function getResult()
       
{
               
return $this->var2;
       
}
}
?>

View Diff

1c1,2
< public class Foo
---
> <?php
> class Foo
3,4c4,5
<       private double var1;
<       private double var2;
---
>       private $var1;
>       private $var2;
6c7
<       public Foo(double val)
---
>       public function Foo($val)
8,9c9,10
<               init(val);
<               doSomething();
---
>               $this->init($val);
>               $this->doSomething();
12c13
<       private void init(double val)
---
>       private function init($val)
14c15
<               var1 = val;
---
>               $this->var1 = $val;
17c18
<       private void doSomething()
---
>       private function doSomething()
19c20
<               var2 = Math.sqrt(var1);
---
>               $this->var2 = sqrt($this->var1);
22c23
<       public double getResult()
---
>       public function getResult()
24c25
<               return var2;
---
>               return $this->var2;
26a28
> ?>

Solutions

The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!

Check out these helpful resources to improve your Vim skills... Game on.

Unlock 38 remaining solutions by signing in and submitting your own entry
#39 Sergey Kim / @skim1776 - Score: 227 - 08/05/11 @ 05:27
O<?php<Esc>jldbxx<F2>jwwdwi$<Esc>jdwi$<Esc>jjhifunction <Esc>wwdwdwi($<Esc>jj^R$this <BS>->init($val);<Esc>j^i$this-><Esc>j2<Esc>jjhdbifunction <Esc>wwwdwi$<Esc>jj^i$this-><Esc>wwwi$<Esc>jjjbbdwfuifunction <Esc>jj^i$this-><Esc>wwwdwxww$uxwa$this-><Esc>jjjbbbdwifunction <Esc>jji$this-><Esc>jjj<CR>A<CR>?><Esc>ZZ

0 comments


Created by: @robrob12

39 active golfers, 98 entries

Leaderboard (lowest score wins):
138
#31 - jacobcr / @jacobcr

08/23/2011 at 04:03PM

144
#32 - Simon Scarfe / @simonscarfe

09/15/2011 at 01:59PM

144
#33 - ise0615 / @ise0615

05/05/2012 at 11:26AM

147
#34 - David Andrews / @k00ka

08/03/2011 at 02:51PM

147
#35 - Terrance Kennedy / @Cyphus

08/18/2011 at 04:14PM

148
#36 - Roel Bondoc / @roelbondoc

01/30/2012 at 02:45PM

180
#37 - Gregory Igelmund / @grekko

12/06/2011 at 10:18PM

218
#38 - shahanavaz m / @shahanavazm

03/15/2024 at 03:38AM

227
#39 - Sergey Kim / @skim1776

08/05/2011 at 05:27AM