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
#91 - Viktor Styrud / @ViktorStyrud

10/14/2019 at 07:25AM

16
#92 - vimgolfer / @vimgolfer7

10/22/2019 at 03:04AM

16
#93 - Melvin Cheung / @MelvinCheung

11/10/2019 at 05:04AM

16
#94 - Lory / @Lory46845742

11/14/2019 at 08:01AM

16
#95 - James Casey / @hanavi

12/22/2019 at 01:30AM

16
#96 - Jason Neylon / @jasonneylon

03/08/2020 at 04:14PM

16
#97 - chocolate / @chocola81394123

12/01/2020 at 02:30AM

16
#98 - hepebexè / @hepebexe

01/03/2021 at 09:10PM

16
#99 - Duncan / @Duncan31503119

01/07/2021 at 01:26AM

16
#100 - Jean George / @JeanGeo20504212

10/01/2021 at 06:33PM

16
#101 - russellzhaomao / @russellzhaomao

06/26/2022 at 12:50AM

16
#102 - jonas-grobe / @jonas-grobe

02/03/2024 at 05:10PM

16
#103 - かみひろ / @km_hr

03/17/2024 at 02:08PM

16
#104 - Nathan Priego / @nspriego

03/02/2025 at 05:11AM

17
#105 - Kai Yuan / @kentyuan

06/29/2017 at 06:01PM

17
#106 - Cristian Lupașcu / @clupasq

06/29/2017 at 07:27PM

17
#107 - Per Forser / @perforcer

06/29/2017 at 08:41PM

17
#108 - flykule / @flykule

06/30/2017 at 08:31AM

17
#109 - Rowan Tree / @RowanTr88447528

07/21/2017 at 09:38AM

17
#110 - Joonas Pihlajamaa / @jokkebk

08/03/2017 at 12:11PM

17
#111 - 郑晓东 / @DGivxLTVopiOQap

09/15/2017 at 02:27AM

17
#112 - F / @gofilby

09/26/2017 at 09:45PM

17
#113 - merphant / @merphant

10/04/2017 at 06:39AM

17
#114 - Florian Kluck / @KluckF

10/27/2017 at 06:54PM

17
#115 - popo5colo / @popo5colo1

10/31/2017 at 10:13PM

17
#116 - Arijus / @argshook

02/09/2018 at 09:39AM

17
#117 - PCS Solutions / @PeteSolutions

08/18/2018 at 10:21PM

17
#118 - phoibos92@gmail.com / @phoibos92

11/13/2018 at 02:56PM

17
#119 - 默罕默德 / @Rt6RjEAJ987Woes

01/22/2019 at 01:18PM

17
#120 - churaki / @churaki

01/30/2019 at 12:10PM