Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / AGK code challenge

Author
Message
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Oct 2016 23:23 Edited at: 20th Oct 2016 19:13
Anyone remember the DBC/DBP challenges from years back? Anyone interested in starting back up again with AppGameKit?



Rules:
1. Anyone may enter at any time.
2. Deadline is always at midnight GMT of the last day of the challenge.
3. The challenge setter may extend the deadline with sufficient reasoning.
4. The challenge setter may enter but can not win their own challenge as they are the judge.
5. The judge will choose a winner and runner-up, preferably leaving feedback about each entry.
6. The winner will become the new judge and will pick the next challenge.
7. No external media is allowed. All graphics must be created internally with code. The one exception is AGK's default font file.
8. Should the judge disappear during judgement day, the runner-up shall take his place to keep things moving.
9. If there are no entries, the judge will select a new challenge.
10. When you post a code snippet as your official entry to be graded, put Entry 1 in bold just above the code snippet. If you have multiple versions, number them accordingly.


Challenge 1
Title: Decimal to words
Deadline: Wednesday, Oct 27
Description:
You will write a function that accepts a number, whether it be integer or a string type(for big numbers), and return a string spelling out the number. For example, "2475" would return "Two thousand four hundred seventy five". Grammatically speaking, using "and" in the string sentence represents a decimal point. So 2.5 would be "two and five tenths". Decimal values are not a requirement in this challenge, but bonus points will be given. You will be graded on the accuracy of the translation and the efficiency of your code. Because numbers are infinite, I will cap the size required at the billions. Any function accepting larger values may earn extra points. You may earn a teacher's pet award if you win with all these requirements and write a second function which can take a written number and translate it back into an integer and/or float value.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Oct 2016 08:25
Would be nice. I would suggest starting with very small simple challenges to build up interest and hopefully some momentum.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Mobiius
Valued Member
16
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 19th Oct 2016 11:13
Would be a good idea.
Jeff Miller
14
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 19th Oct 2016 11:35
Here is the link to the grand-daddy of them all, which drew over 7400 posts:

https://forum.thegamecreators.com/thread/48011

Unfortunately, the link to the 10 rules that explained "no media" no longer works. From what I recall, we would procedurally generate all media.
In the case of advanced terrain, there was one file that had to be "loaded" as an image, so it was deemed OK to procedurally generate it, save it out, load it back it and then delete the file.

Bear in mind that in DBP text was not considered media. There were system fonts which every Windows user had, and so there was no need to create bitmap fonts. So, for example, in the case of a game involving playing cards, you were told to use the suit symbols from the "Symbols" font. You may want to think over how you want to deal with text in AppGameKit in this kind of setting.

Scraggle
Moderator
15
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Oct 2016 11:50
Quote: "You may want to think over how you want to deal with text in AppGameKit in this kind of setting."

Use the default font?
AGK V2 user - Tier 1 (mostly)
Jeff Miller
14
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 19th Oct 2016 13:03
The default font is really ugly. However, I can't think of a good alternative for an exercise such as this.
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Oct 2016 13:56
Here is your 10 rules Jeff:
http://dbcc.zimnox.com/?page=about

My original domain expired this past year and I didn't see a need to keep it. But I plan on Zimnox being around until I die. I might integrate it into my actual site or keep it as is. Haven't decided yet.

I agree BatVink and already had an idea in mind. I'll give it another day to attract people and post the first challenge Thursday.

Another thing we'll need to keep in mind is that not everyone has agk2 yet.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
CJB
Valued Member
15
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 19th Oct 2016 13:58
I'm in!
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
IBOL
Retired Moderator
15
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 19th Oct 2016 15:16
i clicked on this instantly and with much excitement.
yes, i used to do those, and
YES we should start them again
Rickynzx
7
Years of Service
User Offline
Joined: 19th Dec 2011
Location: Troon, Scotland
Posted: 19th Oct 2016 15:17
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Oct 2016 16:54
The challenge has been set, see top of the page. Good luck to all you AppGameKit minions!

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 20th Oct 2016 18:12 Edited at: 19th Jan 2017 19:16
...
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Oct 2016 19:11
That's correct. Though you're welcome to share the code as you work on it if you like, which sometimes we do on difficult challenges. Because the ultimate goal is to help out everyone. But you're only required to post the code you want submitted as your official entry. And you can always continue to update your entry and repost it before the deadline. To make things easier for the judge who has to sort through the submissions, I ask everyone to place Entry # in bold above your code snippet. Trust me, it makes things way easier. Before I created my website, we had over 100 pages in the challenge thread I had to painfully comb through to find all entries.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Scraggle
Moderator
15
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 20th Oct 2016 20:10
This challenge requires further clarification.
Are we talking about the correct version of billions which is a million million (1,000,000,000,000) or the billion that only Americans use but seems to be the prevailing wisdom of what a billion is which is a thousand million (1,000,000,000)?
AGK V2 user - Tier 1 (mostly)
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Oct 2016 21:30
I've never heard anyone say a million million. To mean, 1,000,000,000,000 is 1 trillion.

1,000 = one thousand
1,000,000 = one million
1,000,000,000 = one billion
1,000,000,000,000 = one trillion
1,000,000,000,000,000 = one quadrillion
10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 = googol

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Oct 2016 22:10
Nice challenge. I just spent 15 minutes thinking through the logic and trying to rationalise it. I think I have a plan of attack. But not now, it is twenty two hundred hours and nine minutes. (See what I did there?)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Ortu
DBPro Master
11
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 20th Oct 2016 22:20
Pfft, that's about the time I can usually get *started* on coding for the night


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Scraggle
Moderator
15
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 20th Oct 2016 23:41
It seems it is more epidemic than I thought

AGK V2 user - Tier 1 (mostly)
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 20th Oct 2016 23:47 Edited at: 19th Jan 2017 19:16
...
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 21st Oct 2016 00:31 Edited at: 19th Jan 2017 19:16
...
MadBit
Valued Member
9
Years of Service
Recently Online
Joined: 25th Jun 2009
Location: Germany
Posted: 21st Oct 2016 01:57 Edited at: 21st Oct 2016 01:59
ok, thats funny.

here is my entry.

Output of numbers up to 1063 and 3 position behind the point. And negative numbers.

example: "678,312,110,001.256"
I post only the functions. Accept string as parameter.

Entry #2 (i hope this is correct )

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
Scraggle
Moderator
15
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 21st Oct 2016 08:20
You might want to look at that again MadBit.
I just tried 100, 1000, 109 and 1090 and they all gave the wrong results - I stopped checking after that.
AGK V2 user - Tier 1 (mostly)
MadBit
Valued Member
9
Years of Service
Recently Online
Joined: 25th Jun 2009
Location: Germany
Posted: 21st Oct 2016 10:21
thank you.

i have test it at last only with decimal numbers so i've overlook this.

now i hope it works corect.

Entry #2
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
CJB
Valued Member
15
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 21st Oct 2016 12:09 Edited at: 21st Oct 2016 12:11
Nice challenge. Before 1975, ONE BILLION in the UK was 1,000,000,000,000. After 1975, it became 1,000,000,000. Found this on t'internet:

Quote: "The original meaning of billion, established in the 15th century, was "a million of a million" (1,000,000 to the power of 2, hence the name billion), or 10 to the power of 12 = 1 000 000 000 000. This system, known in French as the "long scale", is currently used in most countries where English is not the primary language. In the late 17th century a change was made in the way of writing large numbers. Numbers had been separated into groups of six digits, but at this time the modern grouping of three digits came into use. As a result, a minority of Italian and French scientists began using the word "billion" to mean 10 to the power of 9 (one thousand million, or 1 000 000 000), and correspondingly redefined trillion etc. to mean powers of one thousand rather than one million. This is known in French as the "short scale" and is now officially used by all English-speaking countries, as well as Brazil, Puerto Rico, Russia, Turkey and Greece."


Maybe the function could include a "Long Scale Flag" in order for the user to select which method to use

Also: Could be taken further to include quadrillion, quintillion, sextillion, septillion, octillion, nonillion, and decillion. Other terms follow the same linguistic pattern (ending with -illion) but do not refer to precise numbers. These include jillion, zillion, squillion, gazillion, kazillion, bajillion, and bazillion. All of these words are used informally to refer to an extremely or indefinitely large number, if the input is sufficiently high, we could simply output a random selection of one of those i.e.: print( myfunction("1,2987,3421,1456,7465,9999,8899,9999,9999,9999,9999,9999,9999,9999,9999,9999"))- result: Gazillions! Haha!!!

There's also a googol = 10 to the 100th power (which is 10 to the power of 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000), and a Googolplex is 10 to the power of a googol. Apparently, Frank Pilhofer has determined that, given Moore's Law (which is that computer processor power doubles about every 1 to 2 years), it would make no sense to try to print out a googolplex for another 524 years - since all earlier attempts to print a googolplex out would be overtaken by the faster processor! I bet we could do it sooner - just set syncrate(0)!!! Mwahahaha!
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 21st Oct 2016 12:14 Edited at: 19th Jan 2017 19:16
....
Scraggle
Moderator
15
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 21st Oct 2016 12:21
If you want to make things easier - Use this
AGK V2 user - Tier 1 (mostly)
Sph!nx
10
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 21st Oct 2016 13:45 Edited at: 21st Oct 2016 13:45
@ Scraggle: Thanks! Love articles like that.
Regards Sph!nx
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Oct 2016 13:46
I suppose if you guys want to get super crazy, add a language selector.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 21st Oct 2016 13:56 Edited at: 19th Jan 2017 19:17
...
CJB
Valued Member
15
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 21st Oct 2016 14:05 Edited at: 21st Oct 2016 14:06
Quote: "or take care of spelling mistakes too"
You could do that with a levenstein distance algorithm. I built something similar for a "fuzzy company lookup" on our CRM at work (because MS don't have a fuzzy search built in as standard !?!?!?). You could search for example: Tek 1 ltd, and it would find Tech One Limited. I was quite pleased with it!
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Oct 2016 14:12 Edited at: 21st Oct 2016 14:32
My version of AppGameKit does not recognize this method of array initialization: Global num3 As String[3] = ["tenth","hundredth","thousandth"]

Ugh, I been doing so much php and js lately, writing a string variable like x$ instead of $x is driving me insane!

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 21st Oct 2016 14:31 Edited at: 19th Jan 2017 19:17
...
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Oct 2016 14:36 Edited at: 21st Oct 2016 16:27
If you guys think about it, you really only need to figure out how to convert from 1 to 3 digit numbers. Just a hint.

Even though I can't officially enter this challenge, I had a go at it. Mine supports a theoretical limit of 999 septendecillion. I did write up to centillion, but for whatever reason, AppGameKit returns an empty string for all elements if I initialize the array greater than 18.


On second though, I think I'll wait a few days to release my code.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 21st Oct 2016 16:26
I have my solution down (excluding decimal points) and just throwing a random set of numbers at it to test. It is 52 lines of code at one command per line.

Quote: "If you guys think about it, you really only need to figure out how to convert from 1 to 3 digit numbers. Just a hint."

That is where my 15 minutes of thinking got me to last night. I have used this principle plus a couple of exception handlers (e.g what if there are no "hundreds" in any part of the number)

It might be a good idea in future to specify that the challenge is wrapped in a function, and that function can be dropped into a testing app. In this case the required function might be:

ConvertNumsToWords(num)

This will allow solutions to be benchmarked against one another (eg how long to convert 1,000,000 numbers to words).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Oct 2016 16:33
Well that was the requirement for this challenge.
Quote: "You will write a function that accepts a number,"


I'm working on a test to run the entries through, checking for accuracy and overall speed.

Quote: " It is 52 lines of code at one command per line."

I've got my function in at 35 lines. That's not counting the array declarations or anything.


I just got an idea for a speed boost. It may be possible to use some bit operations to avoid using string manipulation at all (except for the output of course).

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 21st Oct 2016 17:30
Quote: "I've got my function in at 35 lines. That's not counting the array declarations or anything.
I just got an idea for a speed boost. It may be possible to use some bit operations to avoid using string manipulation at all (except for the output of course)."


This is what I like about these challenges. You don't just get solutions, you get competition to create better solutions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 21st Oct 2016 18:01 Edited at: 19th Jan 2017 19:17
...
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 21st Oct 2016 23:13 Edited at: 19th Jan 2017 19:18
...
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Oct 2016 23:45 Edited at: 21st Oct 2016 23:49
I tried your final entry Damo, it crashes on my first test number. AppGameKit throws an uncaught exception. The number I tested was 50001475171417. From your arrays, I thought it handled trillions, but then I saw your function.

It's got me thinking now though, I'll have to revamp my test for functions that ask for integers instead of a string, since the range would be limited to about 4 billion. So I think yours crashed cause I fed it a number way larger than an integer, oops!

On the plus side, numbers 1 billion and less did work so I was able to do some bit of testing. It's much faster than mine, though more limited due to integer input.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Oct 2016 23:55 Edited at: 21st Oct 2016 23:55
Here is the speed test I will be using. It will calculate the average of 10 runs, each run consisting of 10,000 iterations. Here is one of my test numbers: 50,001,475,171,417
I have ignored the returned value from the function on purpose, so that variable assignment after the fact isn't considered in the speed.


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 22nd Oct 2016 00:24 Edited at: 19th Jan 2017 19:18
...
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Oct 2016 13:10
Posting before I forget. It does everything except decimals at the moment. I took Madbits definition of numbers beyond "lots"


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
damothegreat
2
Years of Service
User Offline
Joined: 18th Sep 2016
Location:
Posted: 24th Oct 2016 21:03 Edited at: 19th Jan 2017 19:18
...
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Oct 2016 21:44 Edited at: 24th Oct 2016 22:08
Damo, three three tests fail...

7 - "seven hundred"
17 - "ten seven hundred"
107 - "One hundred and zero seven hundred"


Madbit, there are no "and"s in your conversion...
[EDIT] I realise that American-English is different; the "and" is dropped. (Although that makes a number like 999,001 sound very strange!)

107 - "One hundred seven"

Can someone check mine and let me know if you find any bugs
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Oct 2016 22:36
I guess I'll have to be lenient on the use of "and", cause ya know, the Britts gotta be different. I was taught in Math class that 'and' was only used to represent the decimal, which makes sense to me.


2.5 days left, so I thought I'd share mine now that others have gotten there out there . No decimal support in mine either. I added negative and zero but code function is still under 40 if you're not counting the arrays.


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Oct 2016 22:54
I tried to test yours batvink, but I can't without modifications. The array structure is no problem, but I'm using AppGameKit 1 and don't have a 'length' variable for arrays.

damothegreat, I'm pretty impressed with your more recent submission. It's a marginally faster than mine but a very short code. I'd be surprised if anyone writes a smaller function than yours. I am however unable to output your answers.
I can run the function just fine for my speed test, but if I try to get the return output I get an "array does not exist" on this line:
stripped[digithigh+1]=number

Could be a bug with my old version of AGK.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
AGK Developer
Gold Codemaster
6
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 25th Oct 2016 04:06 Edited at: 25th Oct 2016 04:09
Nice function Mr Vink but if i call it more than once it returns garbage and eventually crashes
Scraggle
Moderator
15
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 25th Oct 2016 07:10
Quote: "cause ya know, the Britts gotta be different."

When it comes to the English language - we got there first
AGK V2 user - Tier 1 (mostly)
Ortu
DBPro Master
11
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 25th Oct 2016 19:48 Edited at: 25th Oct 2016 19:48
Iteration is the key to perfection. We fixed it for you, you're welcome.


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Oct 2016 20:10
Quote: "cause ya know, the Britts gotta be different"

..and English came from which part of the world? oh, and it's "because", "you know" and "have got to"

Quote: "I was taught in Math class that 'and' was only used "

Maths is plural, like all abbreviated plurals...
dominoes - doms
adverts - ads
perpetrators - perps
mathematics...?

erm...back to the challenge
All said in good humour, please don't take offence I live in Yorkshire, where our accent is so broad most of the UK don't understand a word we say.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2019-05-22 04:59:55
Your offset time is: 2019-05-22 04:59:55