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

215 active golfers, 900 entries

Leaderboard (lowest score wins):
16
#61 - Turkey Man / @lvturkeyman

11/08/2017 at 07:32AM

16
#62 - Benoit Mortgat / @Benoit_Mortgat

11/14/2017 at 07:32AM

16
#63 - Jon Krause / @jkrause314

11/30/2017 at 09:24PM

16
#64 - BareTull / @BareTull3

12/04/2017 at 08:09PM

16
#65 - 梧桐王子 / @WutongYujie

12/11/2017 at 01:23PM

16
#66 - BarbaJol / @drpproteus

01/05/2018 at 03:09PM

16
#67 - TpouHuK / @TpouHuK_

02/04/2018 at 04:41PM

16
#68 - Lisa Ugray / @lisa_ugray

03/16/2018 at 12:33PM

16
#69 - DHM / @DHM29978992

04/14/2018 at 02:04AM

16
#70 - Rakesh P / @rakeshpgopal

04/28/2018 at 06:46PM

16
#71 - kodemaan / @kodemaan

05/01/2018 at 03:14PM

16
#72 - platypusDancing / @platypusDancing

05/03/2018 at 05:25AM

16
#73 - 赤佐田奈葉 / @akasatanaha_

06/29/2018 at 09:43AM

16
#74 - Jeff / @sir_wiggles3

09/09/2018 at 06:50AM

16
#75 - Robin De Mol / @RobinDeMol

09/14/2018 at 09:11AM

16
#76 - Benjamin Kiesl / @BenjaminKiesl

10/20/2018 at 03:09PM

16
#77 - Bruce Adams / @bruceadams1054

11/08/2018 at 08:37AM

16
#78 - Dax / @zacoxi

11/09/2018 at 06:00AM

16
#79 - name / @name65894813

11/19/2018 at 04:31PM

16
#80 - Mihai / @mihaicristiant

12/04/2018 at 01:49PM

16
#81 - Sebastien Nicoud / @sebnukem

02/05/2019 at 01:25AM

16
#82 - Mateen Ulhaq / @sicariusnoctis

02/13/2019 at 05:37AM

16
#83 - alekfed / @alek_fed

04/15/2019 at 12:18PM

16
#84 - Grant / @grant_7788

05/06/2019 at 06:32AM

16
#85 - majo senf / @majo_senf

06/18/2019 at 10:03AM

16
#86 - mkaminaga / @mkmng3

07/03/2019 at 04:47AM

16
#87 - ささ / @nick11033

07/29/2019 at 07:41AM

16
#88 - Miłosz Łakomy / @foobar01123

08/04/2019 at 07:50AM

16
#89 - sooqua / @sooqua

08/09/2019 at 08:17AM

16
#90 - Aioriya / @AioriyaDonk

09/06/2019 at 03:25AM