lcsp
About
A tool for showing and counting solutions from LeetCode.
How to use
Installation
Download gem from RubyGems
$ gem i lcsp
As local installed gem
Build and install gem from sources:
$ gem build lcsp.gemspec
$ gem i lcsp
Print solution
You need to provide 3 arguments for run print command:
| Parameter | Description | Example |
|---|---|---|
user |
GitHub user name | fartem |
repo |
Repository name | leetcode-ruby |
number |
Number of problem | 11 |
One of valid input variants be like:
$ lcsp print --user=fartem --repo=leetcode-ruby --number=11
Count solutions
You need to provide 2 arguments for run count command:
| Parameter | Description | Example |
|---|---|---|
user |
GitHub user name | fartem |
repo |
Repository name | leetcode-ruby |
One of valid input variants be like:
$ lcsp count --user=fartem --repo=leetcode-ruby
Clean local cache
Just run next command from any folder:
$ lcsp clean
Contacts
You can see actual author contacts by following command:
$ lcsp author
Version
If you need to check installed version of lcsp, run from shell:
$ lcsp author
How to write your own LCSPFinder
Read before start
lcsp works with custom finders - classes that should placed in your project and that will perform
search locally.
You need to write finder classes in Ruby because only this format accepting right now, but all work around search and parse for your repository you can place in classes/scripts/files in any other programming language.
One of the correct and working example available by this link.
Template class
path and number are default parameters that are presenting for every repository. This arguments describes user needs
and gives you parameters to search.
# frozen_string_literal: true
module LCSP
# Solutions finder.
class LCSPFinder
# @param {String} path
# @param {String} number
def initialize(path, number)
@path = path
@number = number
end
# @return {String}
def solution
end
end
end
Reference class example
# frozen_string_literal: true
module LCSP
# Solutions finder.
class LCSPFinder
# @param {String} path
# @param {String} number
def initialize(path, number)
@path = path
@number = number
end
# @return {String}
def solution
dirs = []
fill_directories(@path, dirs)
dirs.each do |directory|
::Dir.foreach(directory) do |entry|
return "#{directory}/#{entry}" if entry.start_with?(@number)
end
end
end
# @param {String} path
# @param {String[]} dirs
def fill_directories(path, dirs)
::Dir.foreach(path).reject { |name| name.start_with?('.') }.each do |entry|
unless ::File.file?("#{path}/#{entry}")
dirs << "#{path}/#{entry}"
fill_directories("#{path}/#{entry}", dirs)
end
end
end
end
end
How to write your own LCSCCounter
Read before start
lcsc works with custom counters - classes that should placed in your project and that will perform
count locally.
You need to write counter classes in Ruby because only this format accepting right now, but all work around search and parse for your repository you can place in classes/scripts/files in any other programming language.
One of the correct and working example available by this link.
Template class
path are default parameter that are presenting for every repository. It is a path to repository in cache.
# frozen_string_literal: true
require 'find'
module LCSC
# Solutions counter.
class LCSCCounter
# @param {String} path
def initialize(path)
@path = path
end
# @return {Integer}
def count
dir_sub = "#{@path}/lib"
easy = find_for_dir("#{dir_sub}/easy")
medium = find_for_dir("#{dir_sub}/medium")
easy + medium
end
private
def find_for_dir(dir)
::Find.find(dir).count { |file| ::File.file?(file) }
end
end
end
Reference class example
# frozen_string_literal: true
module LCSC
# Solutions counter.
class LCSCFinder
# @param {String} path
def initialize(path)
@path = path
end
# @return {Integer}
def count
end
end
end
Contributors
- @fartem as Artem Fomchenkov