pzlr

command module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 4 Imported by: 0

README

pzlr

CI

Puzzler pzlr(1) is a command-line tool to locally develop solutions to various programming puzzles using Go (golang). Current, it supports

Install

Binaries

Find the latest pre-compiled binaries here or download and install it now with:

curl https://i.jpillora.com/pzlr! | bash

Source

go get github.com/jpillora/pzlr@latest
Usage

See either the

Leetcode example: pzlr leetcode 151

  1. Create directory

    mkdir pzlr
    cd pzlr
    
  2. Open terminal, start leetcode problem 151 with:

    pzlr --open leetcode 151
    
    Found problem #0151 https://leetcode.com/problems/reverse-words-in-a-string/
    Created directory leetcode/0151/
    Fetching problem code for reverse-words-in-a-string...
    Created stub answer file leetcode/0151/code.go
    Created stub test file leetcode/0151/code_test.go
    Starting gotestsum: Watching 1 directories. Use Ctrl-c to to stop a run or exit.
    
  3. Open in VS Code (or another editor)

    code leetcode/0151
    
  4. File leetcode/0151/code.go will contain:

    package p0151
    
    func reverseWords(s string) string {
    
    }
    
  5. File leetcode/0151/code_test.go will contain:

    package p0151
    
    import "testing"
    
    func TestReverseWords(t *testing.T) {
    	type input struct {
    		s string
    	}
    	tests := []struct {
    		name string
    		input input
    		output string
    	}{
    		// TODO: Add test cases.
    	}
    	for _, tt := range tests {
    		tt := tt
    		t.Run(tt.name, func(t *testing.T) {
    			t.Parallel()
    			if got := reverseWords(tt.input.s); got != tt.output {
    				t.Errorf("reverseWords() = %v, output %v", got, tt.output)
    			}
    		})
    	}
    }
    
  6. You will need to read the question and copy the example input/outputs into the code_test.go file

     	// for example, here are two test cases for problem 151
     	{
     		input:  input{s: "the sky is blue"},
     		output: "blue is sky the",
     	},
     	{
     		input:  input{s: "  hello world  "},
     		output: "world hello",
     	},
    
  7. You will need to implement the solution in code.go

    // for example, here is one solution to problem 151
    func reverseWords(s string) string {
    	spaces := regexp.MustCompile(`\s+`)
    	words := spaces.Split(strings.TrimSpace(s), -1)
    	last := len(words) - 1
    	mid := last / 2
    	for i := range words {
    		if i > mid {
    			break
    		}
    		words[i], words[last-i] = words[last-i], words[i]
    	}
    	return strings.Join(words, " ")
    }
    
  8. Once tests are passing, you will need to copy your solution into leetcode.com and submit there (TODO submit via CLI)

or the

Advent of Code example: pzlr aoc 3

  1. Foobar
  2. Foobar
  3. Foobar
TODO
  • Leetcode
    • Improve test stub file
    • Convert problem HTML into markdown and store as leetcode/NNNN/problem.md
    • Implement (or borrow) leetcode login code to allow pzlr leetcode NNNN --submit (automatically submits if all tests are passing)
  • Advent of Code
    • Implement...
Caveats
  • Only supports Go (but could support other languages with a PR)
  • Go must be installed (if you're brave, you can run curl https://jpillora.com/dotfiles/bin/install-go | bash)
  • Unit test cases need to be manually filled in (code_test.go will contain an empty "test table")
  • Answers need to be manually submitted (code.go will contain the link to submission page)
Credits

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL