Index
Would you like to react to this message? Create an account in a few clicks or log in to continue.

~ Programming Challenge #4

+4
Gecko
ftpatat
Broeder
Gildarts
8 posters

Go down

~ Programming Challenge #4 Empty ~ Programming Challenge #4

Post by Gecko 7/8/2014, 5:12 pm

This is going to be a series of programming based challenges. So I will be starting easy on the first one. These challenges will be extended to two weeks in the hopes of more activity, and based more around solving potential real world problems, or with real world applications.

It doesn't matter what language you use, in fact, do the problem by hand if you feel like it!

This Weeks Problem:
Code:

Sometimes communications break down, and you cannot just give a person a number, numbers can be confusing to read if they lack commas. Such as 536842357425, I mean clearly this is "Five-Hundred-Thirty-Six-Billion Eight-Hundred-Forty-Two-Million Three-Hundred-Fifty-Seven-Thousand Four-Hundred-Twenty-Five"

Btw, there is your challenge, make a program that takes an arbitrarily large number and coverts it to a formatted text string :3

Last Challenge:
Rules:
~IN A SPOILER, post your source code using the code tags.
~IN THE SAME OR ANOTHER SPOILER, post your answer that you got.


Last edited by Gecko on 17/9/2014, 2:32 am; edited 8 times in total
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gildarts 11/8/2014, 4:56 am

Well i may as well, but this isent the highest it can go below 100,000

Spoiler:
Gildarts
Gildarts
Forum Fanatic (1000 posts)
Forum Fanatic (1000 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Broeder 11/8/2014, 7:30 am

Gotta post the code you used, Kid Smile

I know this assignment, in fact Ive solved it with Python and I believe also with C. Too bad I dont have that code anymore.

Fun idea though!
Broeder
Broeder
Grandmaster (2000 posts)
Grandmaster (2000 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gecko 12/8/2014, 11:11 pm

Hey Broeder, why don't you type it up again? This isn't quite the same thing, this challenge is based off a Project Euler problem, but not quite. Next challenge is going to be fun :3

As for me, I'll throw down my code on the 14th when the challenge is over.
Also thank you Kid, but I bet you can do better Razz
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by ftpatat 13/8/2014, 10:23 pm

C#-code:
Answer:

I made a quick program in c#
Let me know if the answer is correct Razz
ftpatat
ftpatat
Grandmaster (2000 posts)
Grandmaster (2000 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gecko 13/8/2014, 10:51 pm

So here is my code. The correct answer will be posted tomorrow when I change the challenge. Very Happy
Thanks to all who participated.
C++:

In there is my personal library where I pull the function isPrime()
isPrime:
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gecko 15/8/2014, 2:43 am

New Challenge / Answer Posted!
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by kalio 15/8/2014, 11:06 pm

Python 3
Python 3:


Last edited by Gecko on 2/9/2014, 6:21 pm; edited 1 time in total (Reason for editing : Spoiler Tags)
kalio
kalio
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by ftpatat 18/8/2014, 1:30 pm

Your answer for the first task is wrong it isn't 28647, but it is 28657 noob Razz
ftpatat
ftpatat
Grandmaster (2000 posts)
Grandmaster (2000 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gecko 19/8/2014, 12:06 am

ftpatat wrote:Your answer for the first task is wrong it isn't 28647, but it is 28657 noob Razz

Psh, typos don't make me a noob. Noobiness is inherited. So That is what makes me a noob. Also Kalio, nice code XD
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gecko 29/8/2014, 3:48 pm

Will post my code tomorrow, any takers?
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Swadq 2/9/2014, 3:23 pm

C++
Spoiler:
Sample IO
Spoiler:
Swadq
Swadq
Grandmaster (2000 posts)
Grandmaster (2000 posts)


http://swadq.com

Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gecko 3/9/2014, 3:38 pm

Have no idea why you were down repped. +rep to even out, Swadq
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gecko 9/9/2014, 1:54 am

My original used pass by reference and was returning false values and all sorts of undef behavior so... here is a smaller neater one. I was originally trying to employ a lot of concepts to make it more teaching oriented.

C++:
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gecko 17/9/2014, 2:33 am

Updated, with one difficult challenge, please try. I will
Gecko
Gecko
Tier 4 (500 posts)
Tier 4 (500 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Minato 30/9/2014, 9:53 pm

In my defence I will say that before this random feeling of wanting to program I hadn't opened eclipse for at least 6 months.
Please don't hate too much, because I know this code can be improved a lot.
Spoiler:

Minato
Grandmaster (2000 posts)
Grandmaster (2000 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Gaz 10/4/2015, 3:18 pm

Bit late to the party with this but I love the idea of this thread so I did the most recent one.
Knocked it up quickly while working on something else in Unity which is why i am using a unity library lol. Only tested it with a few numbers so I can get back to work, don't judge me too harshly Smile

Code:

using UnityEngine;

public class test : MonoBehaviour
{
    string[] nums = { "", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine " };
    string[] posVals = { "", "thousand ", "million ", "billion ", "trillion ", "quadrillion " };
    string[] tys = { "", "", "twenty ", "thirty ", "fourty ", "fifty ", "sixty ", "seventy ", "eighty ", "ninety " };
    string[] teens = { "ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen " };

    int num = 14573856;
    int numLength;
    int htuSets;

    int[] digits;
    string output;

    void Start()
    {
        numLength = Mathf.FloorToInt(Mathf.Log10(num) + 1);
        htuSets = Mathf.CeilToInt((float)numLength / 3);

        digits = new int[numLength];
        for (int i = 0; i < digits.Length; i++)
            digits[i] = num.ToString().ToCharArray()[i] - 48;

        for (int i = 0; i < digits.Length; i++)
        {
            if ((digits.Length - i) % 3 == 0)
                output += nums[digits[i]] + ((digits[i] == 0) ? "" : "hundred ") + ((digits[i+1] == 0 && digits[i+2] == 0) ? "" : "and ");

            if ((digits.Length - i) % 3 == 2)
                output += ((digits[i] == 1) ? teens[digits[i+1]] : tys[digits[i]]);

            if ((digits.Length - i) % 3 == 1)
                output += ((digits[i - ((i == 0) ? 0:1)] == 1 && i != 0) ? "" : nums[digits[i]]) + (checkPrev(i) ? "" : posVals[htuSets - Mathf.FloorToInt(i / 3 + 1)]);
        }
        Debug.Log(output);
    }

    bool checkPrev(int i)
    {
        if (i >= 2)
            if (digits[i] == 0 && digits[i - 1] == 0 && digits[i - 2] == 0)
                return true;
        return false;
    }
}

Some example values of num and their outputs:

14573856:
~ Programming Challenge #4 Captur10

1000000
~ Programming Challenge #4 Captur11

15:
~ Programming Challenge #4 Captur12

619405201:
~ Programming Challenge #4 Captur13

and finally, int.MaxValue:  Cool
~ Programming Challenge #4 Captur14
Gaz
Gaz
Forum Fanatic (1000 posts)
Forum Fanatic (1000 posts)


Back to top Go down

~ Programming Challenge #4 Empty Re: ~ Programming Challenge #4

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum