Giter VIP home page Giter VIP logo

anagrammer's Introduction

anagrammer

Purpose: takes words and lists all possible rearrangements of them, perfect for scrambling/unscrambling words (JUMBO doesn't recommend)

Functions:

contains (takes string slice and string, returns boolean) This function determines if the string slice argument contains the string argument by iteration. If the string slice contains the string, the function returns true. If not, the function returns false.

factorial (takes integer, returns integer) This function determines the factorial of the integer argument with a for loop. If the integer is negative or a 0, the function returns 0. If not, it calculates and returns the integer's factorial as an integer.

stringToCharArray (takes string, returns string slice and error) This function converts a string to a slice of its seperate characters. If the string contains a space, the conversion fails and returns an error. If not, each character becomes a part of the string slice, and the slice is returned with no error.

listAnagrams (takes string) •This function contains the previous three functions listed.

•It lists all anagrams and the original form of the string.

•First, the string is converted to a slice using stringToCharArray().

•The function also returns an error, so if there is an error, the error is printed, and anagrams can't be listed.

•Otherwise, the function continues to the stage where the number of letters is calculated.

•This is critical for words that repeat the same letter more than once.

•A for loop counts the number of each letter in the string and deducts it from the length of the string slice of letters.

•The loop also adds letters that appear more than once in the string to a seperate string slice, while using the contains() function.

•Afterwards, the function creates a new string slice of the anagrams to be printed, which has an initial value of the string argument.

•It continues to a big loop of for loops and conditional statements.

•The first loop switches letters of the slice a random number of times.

•Then, the rearranged slice is converted to a string, then added to the slice of anagrams, if the slice doesn't contain it.

•The next loop uses a boolean value to check if it's a duplicate.

•Another conditional statement checks if the length of the anagrams slice is equal to the factorial of the number of letters, using the factorial() function.

•If the length of the slice is equal to the calculated factorial, the loop is exited, then each element of the anagram slice is printed.

Next Steps:

I plan to add user input to this program, so that anyone can import their own words and see which anagrams are created. I also want to rearrange the anagram slice so that each element is printed in alphabetical order.

What is an anagram exactly?

Dictionary.com defines an anagram as a word, phrase, or sentence formed from another by rearranging its letters. My program, on the other hand, counts non-sensical words as anagrams. Go ahead and use it for secret code too!

Hope you like this project! BTW, it's written in Golang

anagrammer's People

Contributors

azoght avatar

Watchers

Tony Zoght avatar James Cloos 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.