Create Leading Zeros


#1

http://www.vimgolf.com/challenges/52552abfb089a00002000007

Best vim score: 23

Create Leading Zeros only for id columns

Start file:

id      data    age     parent_id
11      "Test"  12      123
123     "Test2  11      null
155     "Test5  19      123
111     "Test"  12      1123
1123    "Test2  11      11
1155    "Test5  19      1123
211     "Test"  12      123
2123    "Test2  11      11
2155    "Test5  19      123
2111    "Test"  12      1123
3123    "Test2  11      11
3155    "Test5  19      1123
1       "root"  9       null

End file:

id      data    age     parent_id
0011    "Test"  12      0123
0123    "Test2  11      null
0155    "Test5  19      0123
0111    "Test"  12      1123
1123    "Test2  11      0011
1155    "Test5  19      1123
0211    "Test"  12      0123
2123    "Test2  11      0011
2155    "Test5  19      0123
2111    "Test"  12      1123
3123    "Test2  11      0011
3155    "Test5  19      1123
0001    "root"  9       null

#2

I’ve got 32: j99CQi000<esc><a-i>ws.*(.{4})<ret>"1RQglbq,q


#3
37 or 41 if you count alt as separate key

fpsi|p<ret>j12C<a-i>n&3Hs<space><ret>r0<a-i>ps<space>"<ret>&3Hd<a-w><a-w>l&hd


#4
18 keys

jGe<a-s>_<a-S><a-i>w&3Hs<space><ret>r0,q

@andreyorst it’s best to use golf script for counting keys


#5

@TeddyDD but in your solution text isn’t aligned back in all columns.

fixed solution

jGe<a-s>_<a-S><a-i>w&3Hs<space><ret>r0<a-i>ps<space>"<ret>&3Hd<a-w><a-w>l&3Hs<space><ret>d


#6

Columns are separated by tabs in oryginal files, my solution won’t work on copy-pasted version from forum.

It passes golf.sh test tho:

/home/teddy/src/golf/52552abfb089a00002000007 $ ../golf.sh
http://vimgolf.com/challenges/. OK (18 keys, vim 23)

-----------------------------
1 Better
0 Same
0 Worse
0 Fail
-----------------------------

It seems that using scripts form golf repo is really good idea :wink:


#7

Eeegh, tabs… My solution will not work at all then.


#8

Sorry about that. I’ll try to pay attention next time to at least put a warning.


#9

np

We should post some kind guide for golfing that would mention scripts from golf repo. They are best way to get challange file since they download them directly from VimGolf site.