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 105 remaining solutions by signing in and submitting your own entry
#106 Emmanuel Denloye-Ito / EmmanuelDenloye - Score: 22 - 06/29/17 @ 19:59
}O#i<C-X><C-P> <a<C-X><C-N><C-N>.h><Esc>G$XpZZ

0 comments


#107 Ezra Zigmond / ezrazig - Score: 22 - 06/29/17 @ 20:20
4jYpfsct.assert<Esc>G$xPZZ

0 comments


#108 Nick Amin / thenamin - Score: 22 - 07/04/17 @ 19:20
:5t5<CR>fscwassert<Esc>G$xPZZ

0 comments


#109 Onse / real_onse - Score: 22 - 07/31/17 @ 07:22
5Gyypfscwassert<Esc>G$xPZZ

0 comments


#110 h43z / h43z - Score: 22 - 10/03/17 @ 22:56
4jYpG$hxpyiw6Gfsvt.pZZ

0 comments


#111 sehe / sehetw - Score: 22 - 10/10/17 @ 13:59
}O<C-X><C-L><Esc>3bciwassert<Esc>G$.ZZ

0 comments


#112 Ron Alexssen / Ralexhere - Score: 22 - 10/13/17 @ 23:42
5Gyypfscwassert<Esc>G$xPZZ

0 comments


#113 Tim Varley / varleti - Score: 22 - 11/01/17 @ 14:27
4jYpG$hxpyiw6Gfsvt.pZZ

0 comments


#114 Ben Hill / KaizenSoze70 - Score: 23 - 06/29/17 @ 18:30
4jYpWci<assert.h<Esc>G$XpZZ

0 comments


#115 Daniel K. / lan4k - Score: 23 - 06/29/17 @ 19:42
G$xP47ko#in<C-P> <as<C-P>.h><Esc>ZZ

0 comments


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

0 comments


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

0 comments


#118 Sebastian Aburto / saburto_m - Score: 23 - 10/08/17 @ 19:01
4jyypwwwcwass<C-N><Esc>/tr<CR>xpZZ

0 comments


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

0 comments


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

0 comments


#121 Marcin Paliwoda / eukaliptuss - Score: 24 - 08/25/17 @ 13:31
2jyy3jPfscwassert<Esc>G$xPZZ

0 comments


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

0 comments


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

0 comments


#124 jfdw102 / jfdw102 - Score: 26 - 08/24/17 @ 12:05
4jYpww<Right>Rassert.h<Esc>G$i<BS><Right>t<Esc>ZZ

0 comments


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

0 comments


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

0 comments


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

0 comments


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

0 comments


#129 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


#130 Petro Тrouq / zulolosi - Score: 40 - 07/07/17 @ 21:24
<fd-59>xP<C-End><C-Home><C-Right>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


#131 Austin Ware / AustinWare17 - Score: 43 - 03/12/18 @ 20:38
5Go#include <assert.h><Esc>:%s/assetr/assert<CR>ZZ

0 comments


#132 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

132 active golfers, 494 entries

Leaderboard (lowest score wins):
19
#91 - BouboulouVimGolf / BouboulouVG

11/02/2017 at 08:12AM

20
#92 - 黒澤亮二 / rjkuro

07/18/2017 at 03:03PM

21
#93 - el pollo diablo / bjagojevich

06/29/2017 at 08:04PM

21
#94 - James / Dronak

06/29/2017 at 09:46PM

21
#95 - Stop and think / ms_uncountable

07/06/2017 at 06:36PM

21
#96 - William Dunand / wdunand

07/11/2017 at 03:51AM

21
#97 - Paul Inc / hiniol1982

07/18/2017 at 07:19PM

21
#98 - Sinthorion / sinthorion

08/03/2017 at 03:35PM

21
#99 - Daniel / 0x9ABC

08/15/2017 at 04:25PM

21
#100 - Saul Hardman / saulhardman

08/16/2017 at 09:06AM

21
#101 - Adam Kożuch / adamkozuch

08/21/2017 at 08:10AM

21
#102 - Jeff / RealJeffIrwin

09/28/2017 at 08:38PM

21
#103 - George Angelopoulos / g_usermod

11/22/2017 at 01:14PM

21
#104 - c0llision / 0xc0llision

01/26/2018 at 01:07PM

21
#105 - Jonathan Camilleri / Too_Many_Taken

05/26/2018 at 11:10AM

22
#106 - Emmanuel Denloye-Ito / EmmanuelDenloye

06/29/2017 at 07:59PM

22
#107 - Ezra Zigmond / ezrazig

06/29/2017 at 08:20PM

22
#108 - Nick Amin / thenamin

07/04/2017 at 07:20PM

22
#109 - Onse / real_onse

07/31/2017 at 07:22AM

22
#110 - h43z / h43z

10/03/2017 at 10:56PM

22
#111 - sehe / sehetw

10/10/2017 at 01:59PM

22
#112 - Ron Alexssen / Ralexhere

10/13/2017 at 11:42PM

22
#113 - Tim Varley / varleti

11/01/2017 at 02:27PM

23
#114 - Ben Hill / KaizenSoze70

06/29/2017 at 06:30PM

23
#115 - Daniel K. / lan4k

06/29/2017 at 07:42PM

23
#116 - Nathan Gober / thegobernador

06/29/2017 at 07:49PM

23
#117 - Miki Tebeka / tebeka

06/30/2017 at 04:06AM

23
#118 - Sebastian Aburto / saburto_m

10/08/2017 at 07:01PM

24
#119 - grigouille / grigouille2

06/30/2017 at 07:42PM

24
#120 - Andrei Gasparovici / agasparovici

07/06/2017 at 04:02PM