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):
20
#151 - theBecwar / @thebecwar

08/19/2019 at 07:03PM

21
#152 - el pollo diablo / @bjagojevich

06/29/2017 at 08:04PM

21
#153 - James / @Dronak

06/29/2017 at 09:46PM

21
#154 - Stop and think / @ms_uncountable

07/06/2017 at 06:36PM

21
#155 - William Dunand / @wdunand

07/11/2017 at 03:51AM

21
#156 - Paul Inc / @hiniol1982

07/18/2017 at 07:19PM

21
#157 - Sinthorion / @sinthorion

08/03/2017 at 03:35PM

21
#158 - dadav 🥀 / @__dadav__

08/15/2017 at 04:25PM

21
#159 - Saul Hardman / @saulhardman

08/16/2017 at 09:06AM

21
#160 - Adam Kożuch / @adamkozuch

08/21/2017 at 08:10AM

21
#161 - Geoff / @RealGeoffErwin

09/28/2017 at 08:38PM

21
#162 - usermod / @g_usermod

11/22/2017 at 01:14PM

21
#163 - c0llision / @sh3llcode

01/26/2018 at 01:07PM

21
#164 - Jonathan Camilleri / @Too_Many_Taken

05/26/2018 at 11:10AM

21
#165 - Majsmanne / @Majsmanne

06/21/2018 at 04:53AM

21
#166 - niwatoco / @yoshitune9

07/19/2018 at 07:14PM

21
#167 - :wq / @write_quit_22

06/24/2021 at 04:39AM

21
#168 - Zsanett Ferenczi / @ferenczizsani

04/23/2025 at 09:12AM

22
#169 - Emmanuel Denloye-Ito / @EmmanuelDenloye

06/29/2017 at 07:59PM

22
#170 - Ezra Zigmond / @ezrazig

06/29/2017 at 08:20PM

22
#171 - Nick Amin / @thenamin

07/04/2017 at 07:20PM

22
#172 - Onse / @real_onse

07/31/2017 at 07:22AM

22
#173 - ؜ / @h43z

10/03/2017 at 10:56PM

22
#174 - sehe / @sehetw

10/10/2017 at 01:59PM

22
#175 - Ron Alexssen / @Ralexhere

10/13/2017 at 11:42PM

22
#176 - ⚫ hgtp://Shifor 🛠️ / @shifor_gnome

11/01/2017 at 02:27PM

22
#177 - mass / @mass256

07/10/2018 at 08:25AM

22
#178 - Nougatine Naja / @NougatineNaja

07/20/2018 at 07:44PM

22
#179 - Mike C / @StrixVariaXIX

04/22/2019 at 04:17PM

22
#180 - Vim Golfer / @VimGolfer6

08/27/2019 at 11:03AM