kata

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 0 Imported by: 0

README

Kata 形🤺

GoDoc Go Report Card BuildStatus codecov.io coveralls.io

Kata is a Japanese word (型 or 形) meaning literally "form" referring to a detailed choreographed pattern of movements made to be practised alone, and within groups and in unison when training. It is practised in Japanese martial arts as a way to memorize and perfect the movements being executed.

Install

brew tap arvenil/kata
brew install kata

Usage

bsearch

In computer science, binary algorithms, also known as half-interval algorithms, logarithmic algorithms, or binary chop, is a algorithms algorithm that finds the position of a target value within a sorted array. Binary algorithms compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the algorithms continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the algorithms ends with the remaining half being empty, the target is not in the array.

$ bsearch
Usage of bsearch:
  -algorithm string
        choose from: exponential, interpolation, loop, loopslicing, recursive, recursiveslicing, standard (default "interpolation")
  -haystack value
        comma-separated, sorted, list of integers e.g. 1,5,7
  -needle int
        an integer to search for in haystack e.g. 5
$ bsearch --needle 5 --haystack 1,3,5,7
2
$ make bench
...
pkg: github.com/arvenil/kata/bsearch/algorithms
BenchmarkSearch/interpolation-12                 2656200               449 ns/op
BenchmarkSearch/loop-12                          3742628               327 ns/op
BenchmarkSearch/exponential-12                   3817282               308 ns/op
BenchmarkSearch/loopslicing-12                   4105732               293 ns/op
BenchmarkSearch/recursive-12                     2615310               459 ns/op
BenchmarkSearch/recursiveslicing-12              3311100               358 ns/op
BenchmarkSearch/standard-12                      2132502               558 ns/op
...

ladder

A word-ladder puzzle begins with two words, and to solve the puzzle one must find a chain of other words to link the two, in which two adjacent words (that is, words in successive steps) differ by one letter.

$ ladder
Usage of ladder:
  -d string
        path to dictionary (default "/usr/share/dict/words")
  -json
        print results as json
  -p value
        two words separated by comma e.g. dog,cat
  -template string
        pretty-print results using a Go template
$ ladder -p dog,cat -p gold,lead
start  end   word-ladder            error (if any)
dog    cat   [dog dot cot cat]     
gold   lead  [gold goad load lead]  
$ ladder -p above,below -json | jq .
[
  {
    "Start": "above",
    "End": "below",
    "Words": [
      "above",
      "amove",
      "amoke",
      "smoke",
      "smoky",
      "sooky",
      "booky",
      "booly",
      "bolly",
      "bally",
      "balli",
      "balai",
      "balao",
      "baloo",
      "balow",
      "below"
    ]
  }
]

Release

GITHUB_TOKEN=secret_token make release

Documentation

Overview

Package kata 形🤺 provides playground for various code exercises.

Kata is a Japanese word (型 or 形) meaning literally "form" referring to a detailed choreographed pattern of movements made to be practised alone, and within groups and in unison when training. It is practised in Japanese martial arts as a way to memorize and perfect the movements being executed.

Commands

bsearch

In computer science, binary algorithms, also known as half-interval algorithms, logarithmic algorithms, or binary chop, is a algorithms algorithm that finds the position of a target value within a sorted array. Binary algorithms compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the algorithms continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the algorithms ends with the remaining half being empty, the target is not in the array.

Usage of bsearch:
  -algorithm string
		choose from: exponential, interpolation (default), loop, loopslicing, recursive, recursiveslicing, standard
  -haystack value
		comma-separated, sorted, list of integers e.g. 1,5,7
  -needle int
		an integer to search for in haystack e.g. 5

ladder

A ladder puzzle begins with two words, and to solve the puzzle one must find a chain of other words to link the two, in which two adjacent words (that is, words in successive steps) differ by one letter.

Usage of ladder:
  -d string
		path to dictionary (default "/usr/share/dict/words")
  -json
		print results as json
  -p value
		two words separated by comma e.g. dog,cat
  -template string
		pretty-print results using a Go template

Benchmark

cmd/bsearch:

pkg: github.com/arvenil/kata/bsearch/algorithms
BenchmarkSearch/interpolation-12                 2656200               449 ns/op
BenchmarkSearch/loop-12                          3742628               327 ns/op
BenchmarkSearch/exponential-12                   3817282               308 ns/op
BenchmarkSearch/loopslicing-12                   4105732               293 ns/op
BenchmarkSearch/recursive-12                     2615310               459 ns/op
BenchmarkSearch/recursiveslicing-12              3311100               358 ns/op
BenchmarkSearch/standard-12                      2132502               558 ns/op

cmd/ladder:

$ time ladder -p dog,cat -p godo,loto -p kot,pies -p gold,lead -p above,below -p soup,rice
start  end    ladder                                                                                        error (if any)
dog    cat    [dog dot cot cat]
godo   loto   []                                                                                                 could not find 'godo' in dictionary
kot    pies   []                                                                                                 words 'kot'(3) and 'pies'(4) have different length
gold   lead   [gold goad load lead]
above  below  [above amove amoke smoke smoky sooky booky booly bolly bally balli balai balao baloo balow below]
soup   rice   [soup roup roue role rile rice]
5.44s user 0.50s system 197% cpu 3.010 total

Directories

Path Synopsis
Package bsearch provides binary search functions.
Package bsearch provides binary search functions.
algorithms
Package algorithms allows easy access to all available binary search algorithms.
Package algorithms allows easy access to all available binary search algorithms.
cmd
bsearch
bsearch command usage.
bsearch command usage.
ladder
ladder command usage.
ladder command usage.
Package ladder implements word-ladder puzzle solver.
Package ladder implements word-ladder puzzle solver.
Package template provides additional functions for text/template.
Package template provides additional functions for text/template.
format
Package format provides configuration for output formatting.
Package format provides configuration for output formatting.
format/flags
Package flags provides -template and -json flags for output formatting.
Package flags provides -template and -json flags for output formatting.

Jump to

Keyboard shortcuts

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