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):
22
#181 - Lukasz Anforowicz / @LAnforowicz

05/27/2020 at 04:59AM

22
#182 - Brandon / @Brandon10678836

08/26/2022 at 12:49PM

22
#183 - DayuanX / @DayuanX

10/08/2024 at 11:29AM

23
#184 - Ben Hill / @KaizenSoze70

06/29/2017 at 06:30PM

23
#185 - Daniel K. / @lan4k

06/29/2017 at 07:42PM

23
#186 - Nathan Gober / @thegobernador

06/29/2017 at 07:49PM

23
#187 - Miki Tebeka / @tebeka

06/30/2017 at 04:06AM

23
#188 - Sebastian Aburto / @saburto_m

10/08/2017 at 07:01PM

23
#189 - Apox / @apox159

07/20/2018 at 07:40PM

23
#190 - Paul McDowell / @etothepi16

06/16/2024 at 09:43PM

24
#191 - grigouille / @grigouille2

06/30/2017 at 07:42PM

24
#192 - Andrei Gasparovici / @agasparovici

07/06/2017 at 04:02PM

24
#193 - Marcin Paliwoda / @eukaliptuss

08/25/2017 at 01:31PM

25
#194 - Christian Panadero / @PaNaVTEC

07/13/2017 at 12:50PM

25
#195 - Paul Jones / @thepauljones

06/25/2018 at 09:39PM

25
#196 - 安藤 / @andou2106

09/07/2018 at 01:16AM

25
#197 - Phoon / @justflashhim

05/10/2019 at 09:08PM

25
#198 - Josefina Alconada / @jochiAlconada

10/06/2019 at 10:19AM

26
#199 - Kevin Traver / @kevintraver

07/04/2017 at 01:16PM

26
#200 - jfdw102 / @jfdw102

08/24/2017 at 12:05PM

27
#201 - Hugo Hornquist / @HugoNikanor

07/12/2017 at 06:34PM

28
#202 - Fatalis / @fatalis_

07/09/2017 at 01:40AM

28
#203 - Josh Callender / @Saponifi3d

07/09/2017 at 06:53PM

28
#204 - Hendry Sadrak / @hendrysadrak

07/14/2017 at 10:11AM

28
#205 - Jurica / @Jurica34581259

11/16/2018 at 11:59AM

28
#206 - Aaron / @_Lordofthevoid_

12/01/2019 at 02:29PM

30
#207 - Chun Chanjun / @CChanjun

03/23/2022 at 01:19PM

31
#208 - William Hamilton / @BobHamiltonijk

08/03/2018 at 06:05AM

34
#209 - fff / @fff51460170

02/21/2021 at 07:08AM

35
#210 - Chris AtLee / @chrisatlee

03/01/2019 at 10:45PM