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
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Apr 2017 05:04
well for starters, that would create an infinite loop. While 'n' is not zero continue looping. N will never reach 0 because it can be divided by 2 infinitely and will become infinitely small but will never be 0. You would have to check for some epsilon value, like 0.00001

I'd have to look up how decimal values are stored in binary as I don't remember. Unless by decimal you simply mean a base 10 integer? Or are we talking about floats?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 18th Apr 2017 05:31 Edited at: 12th Apr 2018 22:45
It does work just for only some of them its correct
for example with the following test data and showing what should be

1 gives 1........................proper answer 00000001
2 gives 10......................proper answer 00000010
3 gives 101....................proper answer 00000011
4 gives 100....................proper answer 00000100
5 gives 1101..................proper answer 00000101
6 gives 1010..................proper answer 00000110
7 gives 1001..................proper answer 00000111
8 gives 1000..................proper answer 00001000
9 gives 11001................proper answer 00001001
10 gives 11010..............proper answer 00001010

An easy method of converting decimal to binary number equivalents is to write down the decimal number and to continually divide-by-2 (two) to give a result and a remainder of either a “1” or a “0” until the final result equals zero

ok fixed it had to use the trunc command

fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 18th Apr 2017 06:51 Edited at: 12th Apr 2018 22:46
I believe this is what you asked for Phaelax as the array is integer I have no problem with infinite loops etc
fubar
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 18th Apr 2017 11:04 Edited at: 18th Apr 2017 11:05
I'm a bit unsure. I have not found anything, whether I can take the agk's native commands or not. Because if so then the task is not so difficult.

Integer in bin -> binStr = Bin (number [ i ])
Count even numbers -> countEven = FindStringCount (binStr, "0")
Count odd numbers -> countOdd = FindStringCount (binStr, "1")

and that was it.

Or did I misunderstand the task?
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 18th Apr 2017 11:48 Edited at: 12th Apr 2018 22:46
Well done Madbit wasn't aware of those commands

Quote: "Given an array of integers, determine who has the most bits; odd or even. Here's the catch, odd numbers shall only count their 1 bits and even will count the 0 bits. Even numbers will also NOT count any leading 0s in the binary."


The only thing as I understand that your code don't do is tally it up for an array and output what scored highest odds evens or a tie etc
so I believe this alteration to your code does



both my way and your way of getting a binary number get the identical results except mine would fail with large integers as I would expect the built in function would store them in a long integer prior to string conversion
fubar
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Apr 2017 13:46 Edited at: 18th Apr 2017 13:47
MadBit, does bin() create a binary string with exactly 32 digits? Or only the relevant part necessary (drops leading zeros)? Cause if it's the first, even's count will be off.
Ok smarty pants, do it without using strings!

fubarpk, I see you added trunc() in there. That would indeed resolve the infinite loop possibility I saw. What I was throwing me off was your function accepting a float as a parameter. I traversed through your function manually on paper to see how it worked. It's a unique approach unfamiliar to me, but it works; even though the binary representation it creates is an integer So theoretically, I only see it working with values up to 1023 = 1111111111.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 18th Apr 2017 13:55 Edited at: 12th Apr 2018 22:47
Quote: " I only see it working with values up to 1023 = 1111111111."


yep unfortunately we don't have long integers or doubles in AppGameKit but that's the only way I figured was possible to do the conversion
altho I think perhaps with some alteration instead of storing the number in an integer I could keep adding it to a string
which I think also might work but with the bin function not sure theres much reason to

Quote: "does bin() create a binary string with exactly 32 digits? Or only the relevant part necessary (drops leading zeros)? "

I checked the bin function and it drops leading zeros

but using a string instead of the mathematical approach just to get a binary number
fubar
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 18th Apr 2017 14:57
I really did not want to join, but now it has packed me.
In the event that I should win unexpectedly. I would like to pass the next challenge to someone since I am still busy in my project.

My entry.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
programming is ace
User Banned
Posted: 18th Apr 2017 23:07
we could do bit shifting I a while loop until reaches 0
programming is ace
User Banned
Posted: 18th Apr 2017 23:09
Seems like we already have done by bit shfts - what is that win... less code... or...
Wilf
Valued Member
17
Years of Service
User Offline
Joined: 1st Jun 2006
Location: Gone to Unity.
Posted: 18th Apr 2017 23:33 Edited at: 18th Apr 2017 23:34
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Apr 2017 02:29 Edited at: 19th Apr 2017 02:30
Here's a method I did in Java before realizing some special methods within the Integer class.

It doesn't matter what direction you travel when counting the 1's, but you have to start at the highest bit when counting 0s. Because we ignore leading zeros, we have to find that first 1 bit.





And here's a sneak preview of the new AppGameKit challenge system I started working on. Not 100% sure yet it's possible, but I'm gonna try!
http://purpletoken.com/katas.php

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
programming is ace
User Banned
Posted: 23rd Apr 2017 20:58 Edited at: 23rd Apr 2017 21:02
Not sure whats happening with this, wasn't a deadline set or winner selected...

But a nice challenge would for next one maybe using the existing 3D objects, join them altogether to make 1 object, so can make extravagant objects

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 24th Apr 2017 12:22 Edited at: 12th Apr 2018 22:47
Programming is ace I think we can achieve that with memblocks and object-meshes just not sure if you can create a mesh object with current commands
but the following comes may be useful if anyone wants to try it



An understanding of how mesh objects are stored when using memblocks would be necessary and then with knowing the max and minimum X,Y,Z of all objects
I believe this could be achieved. Sounds a bit beyond me atm as I haven't really tried the 3d commands yet
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st May 2017 11:16
been a while since we've had a challenge
any ideas? anyone?
fubar
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st May 2017 13:41
Another one banned? What are these kids doing!

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st May 2017 15:17
Quote: "Another one banned? What are these kids doing!"


Same person, multiple accounts.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 6th Jun 2017 08:03
Hey,

With the latest update providing fixes for many of the issues that we had with the file explorer challenge, how about we start that challenge again?
I was just about to give it a go when I remembered the challenge and how helpful it was to have many people working on a similar goal.
So who's up for it?
Create a file explorer using the new commands
AGK V2 user - Tier 1 (mostly)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th Jun 2017 01:43
I would be down, but I probably won't have the time. I got a million things going on over the next month or so

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 7th Jun 2017 04:04
Quote: "Create a file explorer using the new commands"


Yeah that could be fun, what's the restrictions and timeframe?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jun 2017 08:40
I would love to join in again but I am too busy with work at the moment.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 7th Jun 2017 09:58 Edited at: 7th Jun 2017 09:59
There's no need for this at all.
In my experimentation with the new commands I came across ChooseRawFile() which opens a file explorer.
Good work Paul
AGK V2 user - Tier 1 (mostly)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Jun 2017 23:28
Party pooper!

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-19 04:12:16
Your offset time is: 2024-04-19 04:12:16