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):
17
#121 - 임덕윤 / @SnLHUF5ZYJXqI1m

01/07/2020 at 10:43PM

17
#122 - pikjes / @pikjes2

07/16/2021 at 11:20AM

18
#123 - Kieron Browne / @KieronBrowne1

06/29/2017 at 06:11PM

18
#124 - Brendan G / @Brendan314

06/30/2017 at 03:18PM

18
#125 - Jacob Buete / @JBuete

07/03/2017 at 01:56AM

18
#126 - Andreas Bricelj / @mcbric

07/04/2017 at 07:55PM

18
#127 - Scott Mills / @smm1729

07/08/2017 at 07:21PM

18
#128 - apartment1812 / @apartment18121

07/13/2017 at 03:40AM

18
#129 - Ewoud Smeur / @Ewoud90

07/17/2017 at 08:50AM

18
#130 - Jonathan Eidsness / @jonathaneidsnes

07/25/2017 at 04:59PM

18
#131 - Bruce Park / @bpark0

08/28/2017 at 01:59AM

18
#132 - Philipp Aeschbach / @ihbmifqerg

11/22/2017 at 04:34PM

18
#133 - Sebastian Wieland / @oktupol

01/19/2018 at 02:42PM

18
#134 - Bart Reynolds / @bartums

03/01/2018 at 05:26AM

18
#135 - Roger Bongers / @RogerBongers

10/05/2018 at 09:58PM

18
#136 - vg / @vg53210350

10/29/2018 at 03:43AM

18
#137 - robinro / @robinro

11/22/2018 at 07:39PM

19
#138 - Louis Caruana / @louiecaruana

07/02/2017 at 12:15AM

19
#139 - Dick Quixly / @DickQuixly

07/06/2017 at 12:18AM

19
#140 - Elton Kamami / @pixel_grid

10/09/2017 at 06:09PM

19
#141 - BouboulouVimGolf / @BouboulouVG

11/02/2017 at 08:12AM

19
#142 - Rasmus Bergström / @JRasmusBm

09/29/2018 at 07:51AM

19
#143 - pankaj singh / @pankajsingh013

01/15/2019 at 11:55AM

19
#144 - Ivo Blöchliger / @aigledesalpes

08/05/2019 at 08:45PM

19
#145 - Jason / @roosjason

05/30/2020 at 07:38AM

19
#146 - RockerZZY / @rocker_zzy

05/30/2020 at 01:15PM

20
#147 - 黒澤亮二 / @rjkuro

07/18/2017 at 03:03PM

20
#148 - Foo Bar / @FooBarely

08/15/2018 at 10:59PM

20
#149 - wrglprmft / @wrglprmft

01/19/2019 at 10:37PM

20
#150 - albalitz / @_albalitz

06/07/2019 at 03:02PM