Jump to content

Recommended Posts

Posted
2 minutes ago, nag said:

bro.. don't know how time sensitive is your request.. basically I would start it a smaller code and enhance it in iterations.. naa coding style kooda adhey..  as i said I'm done coding for the code.. been a long day 

if you have time..i can give it you later

lite bro… just discussing approaches ..అంతే…

take it lite…

Posted
9 minutes ago, dasari4kntr said:

nice…can you ask how to convert to indian number system…?

i am expecting minimal changes…

def number_to_words_indian(n):
    if n == 0:
        return "zero"

    ones = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    teens = ["", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", 
             "seventeen", "eighteen", "nineteen"]
    tens = ["", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", 
            "eighty", "ninety"]
    
    # Modified for Indian Number System
    indian_place_values = ["", "thousand", "lakh", "crore", "arab", "kharab"]

    # Step 1: Extract digits and push them into a stack
    stack = []
    temp = n
    while temp > 0:
        stack.append(temp % 10)
        temp //= 10

    # Step 2: Process digits from stack
    num_words = []
    position = len(stack)  # Determines the place value (hundreds, thousands, etc.)
    
    # Indian system follows 3,2,2,2 grouping (not 3,3,3)
    groupings = [3, 2, 2, 2, 2]  # First 3 digits as a group, then 2s
    grouping_index = 0

    while stack:
        chunk_size = groupings[grouping_index] if grouping_index < len(groupings) else 2
        chunk = []
        for _ in range(chunk_size):
            if stack:
                chunk.append(stack.pop())

        num_chunk = int("".join(map(str, chunk[::-1])))  # Convert list of digits to number
        words = []
        
        # Process chunk
        if num_chunk >= 100:
            words.append(ones[num_chunk // 100] + " hundred")
            num_chunk %= 100

        if 10 < num_chunk < 20:
            words.append(teens[num_chunk - 10])
        else:
            if num_chunk >= 20:
                words.append(tens[num_chunk // 10])
                num_chunk %= 10
            if num_chunk > 0:
                words.append(ones[num_chunk])

        # Append place value (e.g., lakh, crore)
        if words and grouping_index > 0:
            words.append(indian_place_values[grouping_index])

        num_words.extend(words)
        grouping_index += 1

    return " ".join(num_words)

# Test cases
print(number_to_words_indian(375))           # Output: three hundred seventy five
print(number_to_words_indian(760000))        # Output: seven lakh sixty thousand
print(number_to_words_indian(123456789))     # Output: twelve crore thirty four lakh fifty six thousand seven hundred eighty nine
print(number_to_words_indian(10000000))      # Output: one crore
print(number_to_words_indian(5000000000))    # Output: five arab

Posted
2 minutes ago, ARYA said:

groupings = [3, 2, 2, 2, 2]  # First 3 digits as a group, then 2s

thats the key…

Posted
5 minutes ago, dasari4kntr said:

lite bro… just discussing approaches ..అంతే…

take it lite…

ok

  • Upvote 1
Posted
56 minutes ago, dasari4kntr said:

no…next four years…survive అయ్యి…india కి పోయి రిటైర్మెంట్ తీసుకుంటా…

my target is survive for next four years in usa…honestly saying..

40 key retire???not even work until 45 or 50?

India lo properties or full rich?? India lo ela survive avvali bro

Posted
59 minutes ago, dasari4kntr said:

no…next four years…survive అయ్యి…india కి పోయి రిటైర్మెంట్ తీసుకుంటా…

my target is survive for next four years in usa…honestly saying..

india poyedhi unte..y bought home

Posted
11 hours ago, TeluguTexas said:

40 key retire???not even work until 45 or 50?

India lo properties or full rich?? India lo ela survive avvali bro

already 40+…

11 hours ago, Aquaman said:

india poyedhi unte..y bought home

సొంతూరు తప్ప…ఏ ఆస్తి స్తిరాస్ధి కాదు…ఎప్పుడైనా అమ్ముకోవచ్చు…

  • Haha 1
Posted
10 minutes ago, dasari4kntr said:

already 40+…

సొంతూరు తప్ప…ఏ ఆస్తి స్తిరాస్ధి కాదు…ఎప్పుడైనా అమ్ముకోవచ్చు…

40 is new 30 ani @csrcsr tolded no

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...