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 5dd30310d8d0f900069f675f

Back to the Future

We can't just time-travel around without first making sure our code is pretty and columns are aligned. And keeping lines with at most 80 characters should help if we ever need to review the code while we're stuck in the past. This is my first challenge. I tried being creative and even did a bit of research, so I hope you enjoy it.

Start file
#include <TimeTravel.h> // Includes time machine code
#include <DeLorean.h> // Includes DeLorean code

// Defines bool
typedef enum {
	false,
	true
} bool;

// Creates objects
TimeTravel TimeMachine; // Tracks power input, allows jumping in time
DeLorean Vehicle; // Manages the storage, display and input of time, tracks
// speed

long TimeDestination = -2682276364; // Destination time, POSIX
long TimePresent = -2682276364; // Present time
long TimeLast = -2682276364; // Last departed time

unsigned float SpeedCurr = 0.0; // Current speed, in miles per hour
unsigned float SpeedTarget = 88.0; // Target speed

unsigned float PowerCurr = 0.0; // Current power, in gigawatts
unsigned float PowerTarget = 1.21; // Target power

char
loop ()
{
	// Updates local time variables
	TimeDestination = Vehicle.getTime (dtime);
	TimePresent = Vehicle.getTime (ptime);
	TimeLast = Vehicle.getTime (ltime);

	// Updates local speed and power variables
	SpeedCurr = Vehicle.getSpeed ();
	PowerCurr = TimeMachine.getPower ();

	// Get ready statuses
	bool TMReady = TimeMachine.getReady ();
	bool VReady = Vehicle.getReady ();

	// Calculates travel time, in seconds
	long TimeOffset = TimeDestination - TimePresent;

	// Checks speed, power and ready statuses
	if (SpeedCurr >= SpeedTarget && PowerCurr >= PowerTarget && TMReady && VReady) {
		// Prompts for a time travel of given length, checks if no error returned
		if (!TimeMachine.travel (TimeOffset)) {
			Vehicle.setTime (ltime, TimePresent); // Updates last time with
			// time as of before traveling
			Vehicle.setTime (ptime, TimeDestination); // Updates present time with
			// time as of after traveling
		} else {
			return 1;
		}
	}

	return 0;
}

char
setup ()
{
	// Begin objects, store errors
	char errTM = TimeMachine.begin ();
	char errV = Vehicle.begin ();

	if (!errTM && !errV)
		return 0;

	return 1;
}

char
main ()
{
	// Runs setup, store error
	char err = setup ();

	// Loops as long as no error
	while (!err) {
		// Run loop, update error
		err = loop ();
	}

	return 1;
}
End file
#include <TimeTravel.h> // Includes time machine code
#include <DeLorean.h>   // Includes DeLorean code

// Defines bool
typedef enum {
	false,
	true
} bool;

// Creates objects
TimeTravel TimeMachine; // Tracks power input, allows jumping in time
DeLorean   Vehicle;     // Manages the storage, display and input of time,
                        // tracks speed

long TimeDestination = -2682276364; // Destination time, POSIX
long TimePresent     = -2682276364; // Present time
long TimeLast        = -2682276364; // Last departed time

unsigned float SpeedCurr   = 0.0;   // Current speed, in miles per hour
unsigned float SpeedTarget = 88.0;  // Target speed

unsigned float PowerCurr   = 0.0;   // Current power, in gigawatts
unsigned float PowerTarget = 1.21;  // Target power

char
loop ()
{
	// Updates local time variables
	TimeDestination = Vehicle.getTime (dtime);
	TimePresent     = Vehicle.getTime (ptime);
	TimeLast        = Vehicle.getTime (ltime);

	// Updates local speed and power variables
	SpeedCurr = Vehicle.getSpeed ();
	PowerCurr = TimeMachine.getPower ();

	// Get ready statuses
	bool TMReady = TimeMachine.getReady ();
	bool VReady  = Vehicle.getReady ();

	// Calculates travel time, in seconds
	long TimeOffset = TimeDestination - TimePresent;

	// Checks speed, power and ready statuses
	if (SpeedCurr >= SpeedTarget && PowerCurr >= PowerTarget &&
	    TMReady && VReady) {
		// Prompts for a time travel of given length, checks if no
		// error returned
		if (!TimeMachine.travel (TimeOffset)) {
			// Updates last time with time as of before traveling
			Vehicle.setTime (ltime, TimePresent);
			// Updates present time with time as of after traveling
			Vehicle.setTime (ptime, TimeDestination);
		} else {
			return 1;
		}
	}

	return 0;
}

char
setup ()
{
	// Begin objects, store errors
	char errTM = TimeMachine.begin ();
	char errV  = Vehicle.begin ();

	if (!errTM && !errV)
		return 0;

	return 1;
}

char
main ()
{
	// Runs setup, store error
	char err = setup ();

	// Loops as long as no error
	while (!err) {
		// Run loop, update error
		err = loop ();
	}

	return 1;
}

View Diff

2c2
< #include <DeLorean.h> // Includes DeLorean code
---
> #include <DeLorean.h>   // Includes DeLorean code
12,13c12,13
< DeLorean Vehicle; // Manages the storage, display and input of time, tracks
< // speed
---
> DeLorean   Vehicle;     // Manages the storage, display and input of time,
>                         // tracks speed
16,17c16,17
< long TimePresent = -2682276364; // Present time
< long TimeLast = -2682276364; // Last departed time
---
> long TimePresent     = -2682276364; // Present time
> long TimeLast        = -2682276364; // Last departed time
19,20c19,20
< unsigned float SpeedCurr = 0.0; // Current speed, in miles per hour
< unsigned float SpeedTarget = 88.0; // Target speed
---
> unsigned float SpeedCurr   = 0.0;   // Current speed, in miles per hour
> unsigned float SpeedTarget = 88.0;  // Target speed
22,23c22,23
< unsigned float PowerCurr = 0.0; // Current power, in gigawatts
< unsigned float PowerTarget = 1.21; // Target power
---
> unsigned float PowerCurr   = 0.0;   // Current power, in gigawatts
> unsigned float PowerTarget = 1.21;  // Target power
30,31c30,31
< 	TimePresent = Vehicle.getTime (ptime);
< 	TimeLast = Vehicle.getTime (ltime);
---
> 	TimePresent     = Vehicle.getTime (ptime);
> 	TimeLast        = Vehicle.getTime (ltime);
39c39
< 	bool VReady = Vehicle.getReady ();
---
> 	bool VReady  = Vehicle.getReady ();
45,46c45,48
< 	if (SpeedCurr >= SpeedTarget && PowerCurr >= PowerTarget && TMReady && VReady) {
< 		// Prompts for a time travel of given length, checks if no error returned
---
> 	if (SpeedCurr >= SpeedTarget && PowerCurr >= PowerTarget &&
> 	    TMReady && VReady) {
> 		// Prompts for a time travel of given length, checks if no
> 		// error returned
48,51c50,53
< 			Vehicle.setTime (ltime, TimePresent); // Updates last time with
< 			// time as of before traveling
< 			Vehicle.setTime (ptime, TimeDestination); // Updates present time with
< 			// time as of after traveling
---
> 			// Updates last time with time as of before traveling
> 			Vehicle.setTime (ltime, TimePresent);
> 			// Updates present time with time as of after traveling
> 			Vehicle.setTime (ptime, TimeDestination);
65c67
< 	char errV = Vehicle.begin ();
---
> 	char errV  = Vehicle.begin ();

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 2 remaining solutions by signing in and submitting your own entry
#3 Micael Jarniac / @MicaelJarniac - Score: 208 - 11/18/19 @ 22:04
/\/\/<CR>n2i <Esc>5n2b2i <Esc>n4i <Esc>2f,wi<BS><CR>// <Esc>24I <Esc>2n2xi<BS><Esc>/=<CR>n4i <Esc>nn7i <Esc>2n2i <Esc>/\/\/<CR>2i <Esc>nni <Esc>2nbbbbb2i <Esc>n.nni <Esc>/=<CR>n4i <Esc>nn7i <Esc>5ni <Esc>2/&&<CR>wi<BS><CR><BS><BS>    <Esc>j$bbi<BS><CR>// <Esc>/\/\/<CR>h4xd$O// <Esc>pnwhd$kk$pnddnh4xd$O// <Esc>pnlld$kk$pndd2/=<CR>i <Esc>ZZ

@braxler: I like the theme. Looks like you were consistent and used real changes. Sadly it's not a puzzle I can quickly try as a break at work. I'll have to give it a try when I've more time.

@MicaelJarniac: @braxler Thanks! :D Ultimately I didn't want to make such a long puzzle, but I couldn't think of a shorter one that's a) challenging and b) original, so I decided to instead try to create something immersive with a story, so that it can be entertaining while having a simpler-ish challenge.

2 comments


#4 nickGPT / @nickandbro - Score: 208 - 08/24/24 @ 14:00
/\/\/<CR>n2i <Esc>5n2b2i <Esc>n4i <Esc>2f,wi<BS><CR>// <Esc>24I <Esc>2n2xi<BS><Esc>/=<CR>n4i <Esc>nn7i <Esc>2n2i <Esc>/\/\/<CR>2i <Esc>nni <Esc>2nbbbbb2i <Esc>n.nni <Esc>/=<CR>n4i <Esc>nn7i <Esc>5ni <Esc>2/&&<CR>wi<BS><CR><BS><BS>    <Esc>j$bbi<BS><CR>// <Esc>/\/\/<CR>h4xd$O// <Esc>pnwhd$kk$pnddnh4xd$O// <Esc>pnlld$kk$pndd2/=<CR>i <Esc>ZZ

0 comments


Created by: @MicaelJarniac

4 active golfers, 6 entries

Leaderboard (lowest score wins):
127
#1 - Saki Gw / @Sakigw

11/19/2019 at 03:09PM

127
#2 - Peppa Pig / @PeppaPi95550250

08/06/2024 at 12:35AM

208
#3 - Micael Jarniac / @MicaelJarniac

11/18/2019 at 10:04PM

208
#4 - nickGPT / @nickandbro

08/24/2024 at 02:00PM