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 146 remaining solutions by signing in and submitting your own entry
#147 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

147 active golfers, 539 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

15
#7 - Baine Wedlock / @BaineWedlock

08/10/2017 at 07:56PM

15
#8 - Ky Statham / @ijustwannacode

08/15/2017 at 09:42PM

15
#9 - Philippe Brouillard / @_kurowasan

08/17/2017 at 09:52PM

15
#10 - Darren Weston / @dazWestonUK

08/30/2017 at 11:44AM

15
#11 - Birger / @Birger_Ni

10/01/2017 at 06:11PM

15
#12 - Chris Atanasian / @ChrisAtanasian

10/12/2017 at 05:52PM

15
#13 - Wolly Woodpecker / @WollyWoodpecker

11/13/2017 at 08:11PM

15
#14 - Henrique Malheiro / @rike09

12/12/2017 at 12:56AM

15
#15 - ParasamGateZero / @ParasamGateZero

01/21/2018 at 07:35AM

15
#16 - Guirec CORBEL / @GuirecCorbel

03/06/2018 at 02:21AM

15
#17 - Daniël De Koker / @daniel_koker

06/17/2018 at 10:41AM

16
#18 - Urtica dioica / @udioica

06/29/2017 at 07:44PM

16
#19 - Song Zheng / @songz

06/29/2017 at 09:14PM

16
#20 - Saki Gw / @Sakigw

06/29/2017 at 09:42PM

16
#21 - Smylers / @Smylers2

06/30/2017 at 04:18AM

16
#22 - 杨洋 / @176795444

06/30/2017 at 10:58AM

16
#23 - Brian Hall / @_bruab_

06/30/2017 at 02:35PM

16
#24 - dogfooter / @dogfooter219

06/30/2017 at 07:07PM

16
#25 - Pfhor / @PfhorShark

07/01/2017 at 04:46PM

16
#26 - Christian Stammen / @c0smiq

07/01/2017 at 07:38PM

16
#27 - Ivan Poroliev / @p0pac

07/02/2017 at 06:58AM

16
#28 - io / @iovis9

07/02/2017 at 12:17PM

16
#29 - John Marks / @__jmarks

07/03/2017 at 09:12PM

16
#30 - John Braxler / @braxler

07/05/2017 at 03:57PM