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
#31 - "Smylers" / @Smylers2

06/30/2017 at 04:18AM

16
#32 - 杨洋 / @176795444

06/30/2017 at 10:58AM

16
#33 - Brian Hall / @_bruab_

06/30/2017 at 02:35PM

16
#34 - dogfooter / @dogfooter219

06/30/2017 at 07:07PM

16
#35 - Pfhor / @PfhorShark

07/01/2017 at 04:46PM

16
#36 - Christian Stammen / @c0smiq

07/01/2017 at 07:38PM

16
#37 - Ivan Poroliev / @p0pac

07/02/2017 at 06:58AM

16
#38 - io / @iovis9

07/02/2017 at 12:17PM

16
#39 - John Marks / @__jmarks

07/03/2017 at 09:12PM

16
#40 - Michael Brown / @mbrown1413

07/06/2017 at 03:52AM

16
#41 - Jan Bundesmann / @janbundesmann

07/07/2017 at 11:58AM

16
#42 - kkh / @kkhdlut

07/09/2017 at 11:26AM

16
#43 - Gurukandhamoorthi / @Gurukandhamoor1

07/09/2017 at 12:17PM

16
#44 - Amalie Stokholm / @amalie_stokholm

07/09/2017 at 02:05PM

16
#45 - Dan Simmons / @simmons_dan

07/10/2017 at 01:07PM

16
#46 - Jon Barker / @j0nbarker

07/12/2017 at 09:36AM

16
#47 - Blake Tereau / @BlakeTereau

07/12/2017 at 06:18PM

16
#48 - Gabriel Siqueira / @gabrielhsiq

07/14/2017 at 11:20PM

16
#49 - huho / @huho_xu

07/25/2017 at 09:30PM

16
#50 - Julian Felix / @h4wked

07/27/2017 at 09:08AM

16
#51 - devoh / @devvohh

07/29/2017 at 09:43AM

16
#52 - Will / @obiwan__k3n00bi

08/03/2017 at 04:09AM

16
#53 - Terry Ding / @TerryDing77

08/23/2017 at 06:32PM

16
#54 - Solomon / @Trugbildjaeger

08/27/2017 at 01:28PM

16
#55 - zava / @znl1087

09/04/2017 at 03:24PM

16
#56 - bazkila@gmail.com / @bazkila

09/07/2017 at 12:57AM

16
#57 - aselaIllayaparachchi / @asela38

09/11/2017 at 04:32AM

16
#58 - Charlie OConor / @charlieoconor

10/03/2017 at 04:08PM

16
#59 - herbage / @herbage2

10/04/2017 at 11:21AM

16
#60 - Gaël Delalleau / @gaeldelalleau

10/13/2017 at 12:06PM