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 59553bd164628d0009000038

Missing Library and a Typo

I forgot to add a c library, please add it for me. Also I'm bad at typing so fix my typo too.

Start file
#define MIN_NUMBER 1
#define MAX_NUMBER 100
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int getGuess(){
    int c;
    int guess = 0;

    while(guess < MIN_NUMBER || guess > MAX_NUMBER){
        printf("Guess: ");
        scanf("%d", &guess);

        while((c = getchar()) != '\n' && c != EOF);
    }

    return guess;
}

int main(){
    srand(time(NULL));
    int number = rand()%(MAX_NUMBER-MIN_NUMBER+1)+MIN_NUMBER;

    printf("Let's start a game.\n");
    printf("I've picked a number between %d and %d\n",MIN_NUMBER,MAX_NUMBER);
    printf("Guess what it is and I'll tell you \n");
    printf("if it's higher or lower.\n");
    printf("You win if you guess it in 7 turns or less\n\n");

    int turn;
    for(turn = 0; turn < 7; turn++){
        int guess = getGuess();
        assert(guess>=MIN_NUMBER && guess<=MAX_NUMBER);

        if(guess < number){
            printf("Higher\n\n");
        }else if(guess > number){
            printf("Lower\n\n");
        }else{
            break;
        }
    }

    if(turn < 7)
        printf("\nYou Win!\n");
    else
        printf("You Lose the answer was %d.\n", number);

    return 0;
}
// I think I forgot to include the library assetr
End file
#define MIN_NUMBER 1
#define MAX_NUMBER 100
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <assert.h>

int getGuess(){
    int c;
    int guess = 0;

    while(guess < MIN_NUMBER || guess > MAX_NUMBER){
        printf("Guess: ");
        scanf("%d", &guess);

        while((c = getchar()) != '\n' && c != EOF);
    }

    return guess;
}

int main(){
    srand(time(NULL));
    int number = rand()%(MAX_NUMBER-MIN_NUMBER+1)+MIN_NUMBER;

    printf("Let's start a game.\n");
    printf("I've picked a number between %d and %d\n",MIN_NUMBER,MAX_NUMBER);
    printf("Guess what it is and I'll tell you \n");
    printf("if it's higher or lower.\n");
    printf("You win if you guess it in 7 turns or less\n\n");

    int turn;
    for(turn = 0; turn < 7; turn++){
        int guess = getGuess();
        assert(guess>=MIN_NUMBER && guess<=MAX_NUMBER);

        if(guess < number){
            printf("Higher\n\n");
        }else if(guess > number){
            printf("Lower\n\n");
        }else{
            break;
        }
    }

    if(turn < 7)
        printf("\nYou Win!\n");
    else
        printf("You Lose the answer was %d.\n", number);

    return 0;
}
// I think I forgot to include the library assert

View Diff

5a6
> #include <assert.h>
52c53
< // I think I forgot to include the library assetr
---
> // I think I forgot to include the library assert

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 55 remaining solutions by signing in and submitting your own entry
#56 Daniel K. / lan4k - Score: 23 - 06/29/17 @ 19:42
G$xP47ko#in<C-P> <as<C-P>.h><Esc>ZZ

0 comments

#57 Nathan Gober / thegobernador - Score: 23 - 06/29/17 @ 19:49
}kYPj3wcwassert<Esc>G$d PZZ

0 comments

#58 Miki Tebeka / tebeka - Score: 23 - 06/30/17 @ 04:06
:5<CR>yypfscwassert<Esc>G$xPZZ

0 comments

#59 grigouille / grigouille2 - Score: 24 - 06/30/17 @ 19:42
:5t5<CR>fscwassert<Esc>/tr<CR>xpZZ

0 comments

#60 Andrei Gasparovici / AGasparovici - Score: 24 - 07/06/17 @ 16:02
5Gyypfscwassert<Esc>G5ftxpZZ

0 comments

#61 Christian Panadero / PaNaVTEC - Score: 25 - 07/13/17 @ 12:50
:5t5<CR>fsdiwiassert<Esc>G$x<Left>pZZ

0 comments

#62 Kevin Traver / kevintraver - Score: 26 - 07/04/17 @ 13:16
4jyypfsci<assert.h<Esc>G$xhpZZ

0 comments

#63 Hugo Hornquist / HugoNikanor - Score: 27 - 07/12/17 @ 18:34
}kyypfsct.assert<Esc>53G$xir<Esc>ZZ

0 comments

#64 Fatalis / fatalis_ - Score: 28 - 07/09/17 @ 01:40
4<Down>yypfscwassert<Esc>/etr<CR>ar<End><BS><Esc>ZZ

0 comments

#65 Josh Callender / Saponifi3d - Score: 28 - 07/09/17 @ 18:53
}kVYPj$vi<diassert.h<Esc>G$hxpZZ

0 comments

#66 Hendry Sadrak / hendrysadrak - Score: 28 - 07/14/17 @ 10:11
:5t5<CR>fscwassert<Esc>/fr<BS><BS>tr<CR>xpZZ

0 comments

#67 Gustavo Roscoe / gusroscoe - Score: 39 - 06/29/17 @ 19:27
4jy2wop<BS><Esc>pa<assert.h><Esc>:%s/etr/ert/<CR>:wq<CR>

0 comments

#68 Petro Тrouq / zulolosi - Score: 40 - 07/07/17 @ 21:24
<C-End>xP<C-Home><C-Right><C-Left>wwwwwwwwwwwwwwwwwwwwwwwYpwwwRa<C-P><Esc>ZZ

zulolosi: Text keycode in solutions is good again with vim 8.0.697, and is wrong between vim 7.4.1433 and 8.0.696. I tested with vim 8.0.647 this solution : <C-Home>xP<C-Right><C-Left><C-Right>wwwwwwwwwwwwwwwwwwwwwwwwwwYpwwwRa<C-P><Esc>ZZ The keystrokes in vimgolf client: <fd-57>xP<fd-56><fd-55><fd-54>wwwwwwwwwwwwwwwwwwwwwwwwwwYpwwwRa<C-P><Esc>ZZ Text keystrokes really used in order: <C-End>xP<C-Home><C-Right><C-Left>wwwwwwwwwwwwwwwwwwwwwwwwwwYpwwwRa<C-P><Esc>ZZ

zulolosi: Now with vim 8.0.697, the keystroke in vimgolf client are (changed, +1): <fd-58>xP<fd-57><fd-56><fd-55>wwwwwwwwwwwwwwwwwwwwwwwYpwwwRa<C-P><Esc>ZZ

2 comments

#69 Bennett Bernardoni / BBernardoni - Score: 115 - 06/29/17 @ 17:42
jjjjo#include <assert.h><Esc>jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjlllllllllllllllllllllllllllhhcwassert<Esc>:x<CR>

BBernardoni: Sorry for the resubmissions. I caught several solution that I didn't want to be possible. This should be the last one, even if I did miss something.

zulolosi: You forget to add a header file .h, not a library

BBernardoni: Yeah, you're right. I meant I forgot to include the header file for a library.

zulolosi: https://stackoverflow.com/questions/3996651/what-is-compiler-linker-loader

BBernardoni: I did miss something. My intended solution was "G$xP9%YpWlcwa<C-P><Esc>ZZ" but I forgot 5G would do the same as 9%. In order to do that though I would have had to make the file 101 lines long.

zulolosi: Nice 9% to have a different approach ...

6 comments

Created by: BBernardoni

69 active golfers, 209 entries

Leaderboard (lowest score wins):
15
#1 - tPenguinLTG / tpenguinltg

06/30/2017 at 12:24PM

15
#2 - Barnaby Colby / BarnabyColby

07/02/2017 at 06:47PM

15
#3 - David / Revan4Vendetta

07/05/2017 at 10:46AM

15
#4 - Adrian Englhardt / _englhardt

07/05/2017 at 01:35PM

15
#5 - Cody Heimberger / certifiedloud

07/08/2017 at 04:26AM

15
#6 - LR / TextsFromChaCha

07/25/2017 at 07:04AM

16
#7 - Urtica dioica / udioica

06/29/2017 at 07:44PM

16
#8 - Song Zheng / songz

06/29/2017 at 09:14PM

16
#9 - Saki Gw / Sakigw

06/29/2017 at 09:42PM

16
#10 - Smylers / Smylers2

06/30/2017 at 04:18AM

16
#11 - 杨洋 / 176795444

06/30/2017 at 10:58AM

16
#12 - Brian Hall / _bruab_

06/30/2017 at 02:35PM

16
#13 - dogfooter / dogfooter2

06/30/2017 at 07:07PM

16
#14 - J / J02108006

07/01/2017 at 04:46PM

16
#15 - Christian Stammen / c0smiq

07/01/2017 at 07:38PM

16
#16 - Ivan Poroliev / p0pac

07/02/2017 at 06:58AM

16
#17 - io / iovis9

07/02/2017 at 12:17PM

16
#18 - John Marks / __jmarks

07/03/2017 at 09:12PM

16
#19 - John Braxler / braxler

07/05/2017 at 03:57PM

16
#20 - Michael Brown / mbrown1413

07/06/2017 at 03:52AM

16
#21 - Jan Bundesmann / ixjab

07/07/2017 at 11:58AM

16
#22 - kkh / kkhdlut

07/09/2017 at 11:26AM

16
#23 - Gurukandhamoorthi / Gurukandhamoor1

07/09/2017 at 12:17PM

16
#24 - Amalie Stokholm / amalie_stokholm

07/09/2017 at 02:05PM

16
#25 - Dan Simmons / simmons_dan

07/10/2017 at 01:07PM

16
#26 - Jon Barker / j0nbarker

07/12/2017 at 09:36AM

16
#27 - Blake Tereau / BlakeTereau

07/12/2017 at 06:18PM

16
#28 - Gabriel Siqueira / Gabriel_HSiq

07/14/2017 at 11:20PM

16
#29 - huho / huho_xu

07/25/2017 at 09:30PM

16
#30 - Julian Felix / h4wked

07/27/2017 at 09:08AM

17
#31 - Kai Yuan / kentyuan

06/29/2017 at 06:01PM

17
#32 - Cristian Lupașcu / clupasq

06/29/2017 at 07:27PM

17
#33 - Per Forser / perforcer

06/29/2017 at 08:41PM

17
#34 - flykule / flykule

06/30/2017 at 08:31AM

17
#35 - Rowan Tree / RowanTr88447528

07/21/2017 at 09:38AM

18
#36 - Kieron Browne / KieronBrowne1

06/29/2017 at 06:11PM

18
#37 - Brendan G / Brendan314

06/30/2017 at 03:18PM

18
#38 - Jacob Buete / JBuete

07/03/2017 at 01:56AM

18
#39 - Andreas Bricelj / mcbric

07/04/2017 at 07:55PM

18
#40 - Scott Mills / smm1729

07/08/2017 at 07:21PM

18
#41 - apartment1812 / apartment18121

07/13/2017 at 03:40AM

18
#42 - Ewoud Smeur / Ewoud90

07/17/2017 at 08:50AM

18
#43 - Jonathan Eidsness / jonathaneidsnes

07/25/2017 at 04:59PM

19
#44 - Louis Caruana / louiecaruana

07/02/2017 at 12:15AM

19
#45 - Dick Quixly / DickQuixly

07/06/2017 at 12:18AM

20
#46 - 黒澤亮二 / rjkuro

07/18/2017 at 03:03PM

21
#47 - el pollo diablo / bjagojevich

06/29/2017 at 08:04PM

21
#48 - James / Dronak

06/29/2017 at 09:46PM

21
#49 - Stop and think / ms_uncountable

07/06/2017 at 06:36PM

21
#50 - William Dunand / wdunand

07/11/2017 at 03:51AM

21
#51 - Paul Inc / hiniol1982

07/18/2017 at 07:19PM

22
#52 - Emmanuel Denloye-Ito / EmmanuelDenloye

06/29/2017 at 07:59PM

22
#53 - Ezra Zigmond / ezrazig

06/29/2017 at 08:20PM

22
#54 - Nick Amin / thenamin

07/04/2017 at 07:20PM

23
#55 - Ben Hill / KaizenSoze70

06/29/2017 at 06:30PM

23
#56 - Daniel K. / lan4k

06/29/2017 at 07:42PM

23
#57 - Nathan Gober / thegobernador

06/29/2017 at 07:49PM

23
#58 - Miki Tebeka / tebeka

06/30/2017 at 04:06AM

24
#59 - grigouille / grigouille2

06/30/2017 at 07:42PM

24
#60 - Andrei Gasparovici / AGasparovici

07/06/2017 at 04:02PM

25
#61 - Christian Panadero / PaNaVTEC

07/13/2017 at 12:50PM

26
#62 - Kevin Traver / kevintraver

07/04/2017 at 01:16PM

27
#63 - Hugo Hornquist / HugoNikanor

07/12/2017 at 06:34PM

28
#64 - Fatalis / fatalis_

07/09/2017 at 01:40AM

28
#65 - Josh Callender / Saponifi3d

07/09/2017 at 06:53PM

28
#66 - Hendry Sadrak / hendrysadrak

07/14/2017 at 10:11AM

39
#67 - Gustavo Roscoe / gusroscoe

06/29/2017 at 07:27PM

40
#68 - Petro Тrouq / zulolosi

07/07/2017 at 09:24PM

115
#69 - Bennett Bernardoni / BBernardoni

06/29/2017 at 05:42PM