Coder Social home page Coder Social logo

dragonxdev / words-to-numbers Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 12 KB

A difficult challenge to convert a number > 0 to words form without packages or libraries in a single line.

License: MIT License

Python 100.00%
challenge oneliner poetry python3 words-to-numbers

words-to-numbers's Introduction

Words to Numbers

The challenge is simple: Convert numbers into their word form, with no tricks like libraries, packages, caching, etc.

The "Words to Numbers" project is a challenging Python script that converts numbers (greater than 0) into their word form only with a single line of code. Originally aimed to produce this program in under 90 lines in Python, I refined and rewrote it over and over to achieve its final state.

Table of Contents

Installation

To set up the project environment and run the script, you must have Poetry installed. If you do not have Poetry, you can install it by following the instructions here.

After installing Poetry, clone this repository to your local machine:

git clone https://your-repository-url/words_to_numbers.git
cd words_to_numbers
poetry install    # No dependencies to install

Usage

To run the script, use the following command:

poetry run python -m words_to_numbers

Features

  • Single-Line Conversion: The core feature of this script is its ability to convert numbers into words in a single line of Python code.
  • Expanding: Expanding the range of the program's output is simple, just add more elements to the 3 lists each currently created as
[ "", "hundred ", "thousand ", "million ", "billion ", "trillion ", "quadrillion ", "quintillion ", "hextillion ", "septillion "]

and increment the number 9 found in 3 different places within the program, all in places with boilerplate:

if (
    0
    if (len(x) - i) == 1
    else (
        (0 if x[i] == "0" else 1)
        if (len(x) - i) % 3 == 0
        else (
            (((len(x) - i) - 4) // 3) + 2
            if ((len(x) - i) - 4) % 3 == 0
            and (
                x[i] != "0"
                or x[i if (i - 1) < 0 else i - 1] != "0"
                or x[i if (i - 2) < 0 else i - 2] != "0"
            )
            else 0
        )
    )
) > 9:       # Update the 9 in 3 locations all with this context (expanded version)

Contributors

I am the sole contributor for this project.

License

This project is licensed under the MIT License - see the LICENSE.md

words-to-numbers's People

Contributors

dragonxdev avatar

Stargazers

 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.