Git Product home page Git Product logo

palindrome's Introduction

Palindrome

Checks if a string is a palindrome.

If you complile a binary you then you can run it as a CLI tool. This assumes you have golang installed.

Install

go get -u github.com/nbw/palindrome

Code Summary

palindorome/palindrome.go

The steps are:

  1. Remove any punctuation (operation: O(n))
  2. Lower case the string (operation: O(n))
  3. Run through the string and check if it's a palindrome (operation: O(n/2))

The complexity is O(n) + O(n) + O(n/2) = O(2.5n) => effectively O(n)

Tests

Tests are in palindrome_test.go. You can run them with Make test

Thoughts

I considered running through the string only once and performing punctuation removal and lowercasing on a per-letter basis, but you'd lose efficiency checking for punctation on a per-letter basis versus once with the entire string. Same thing with lowercase.

CLI Usage

# Compile a binary
Make install

# Using the CLI tool
# - from the root of the project

palindrome "racecar"
palindrome" "A toyota's a Toyata"

Compile binary

You can compile a binary with Make install

Testing

Run Make test

palindrome's People

Contributors

nbw avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.