"Basic" Challenge help
"Basic" Challenge help
Can someone please give me a hint to convert 28679718602997181072337614380936720482949 into base 7. I've tried doing it in binary code but the answer was wrong. Please help
Do you know what "base 7" means? If not, look it up and get a good understanding of the concept. It should be fairly clear how to convert mathematically at that point, but you'll need a decent calculator for a number that large.
I'd generally recommend using Python for performing arithmetic on arbitrarily large integers. There also exist calculators that support arbitrary output bases, but I won't tell you the name of the one I used as it makes this problem rather easy. It bears a strong resemblence to HVM, though.
I'd generally recommend using Python for performing arithmetic on arbitrarily large integers. There also exist calculators that support arbitrary output bases, but I won't tell you the name of the one I used as it makes this problem rather easy. It bears a strong resemblence to HVM, though.
Wouldn't be terribly difficult to do long hand eithergfoot wrote:Do you know what "base 7" means? If not, look it up and get a good understanding of the concept. It should be fairly clear how to convert mathematically at that point, but you'll need a decent calculator for a number that large.
I'd generally recommend using Python for performing arithmetic on arbitrarily large integers. There also exist calculators that support arbitrary output bases, but I won't tell you the name of the one I used as it makes this problem rather easy. It bears a strong resemblence to HVM, though.
Mathematica is brilliant and can be rather pricey but it's used on the backend of WolframAlpha, you can use Mathematica code with it or you can try natural language which for simple things like this works. If you get Wolfram Mathematica you'll be laughing any time maths pops up. As for the "invalid value" errors you get, that's because the number is too big for JavaScript numbers (it would take 135 bits to store).
-
- Posts: 4
- Joined: Thu Dec 23, 2010 12:17 pm
Base 7 is a different way to "write" integers. For example: base 2 (or binary) is 01010001100 and so on.. it means, that you can write 2 different chars to write your number. in base 3 you can use 0, 1 and 2, in base 4 you can use 0, 1, 2 and 3. So we use base 10 (0 till 9 are 10 different integers)
Hexadecimal is with 16 different chars.. but we do only have 10 digits, so we use the first few letters from the alphabet (A, B, C .. F)
So in Base 7 you cannot have digits which are higher than 6 --> 0, 1, 2, 3, 4, 5, 6
to convert your number, you have to use the division algorithm (maybe you know '%' or 'modulo', division with remainder)
for example:
decimal 9 in base 7 is 12:
9 : 7 = 1, remains 2
1 : 7 = 0, remains 1
now you read the remainders from bottom to top 1 -- > 2
you may also write every number in base 7 down and count them (I wouldn't, because for large/long numbers, you'll become in trouble ):
dec -> base 7
0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 6
7 -> 10
8 -> 11
9 -> 12
another example:
decimal 78 in base 7 is 141:
78 : 7 = 11, remains 1
11 : 7 = 1, remains 4
1 : 7 = 0, remains 1
1 --> 4 --> 1
I have NOT finished the Challenge, because i wantet to code it on my own.. But languages like Python(I'm not very good with it) or C# and PHP only accept Int 64 (max 99999999)
I guess you don't bother now, after a year. But maybe a few other people may use it
Hexadecimal is with 16 different chars.. but we do only have 10 digits, so we use the first few letters from the alphabet (A, B, C .. F)
So in Base 7 you cannot have digits which are higher than 6 --> 0, 1, 2, 3, 4, 5, 6
to convert your number, you have to use the division algorithm (maybe you know '%' or 'modulo', division with remainder)
for example:
decimal 9 in base 7 is 12:
9 : 7 = 1, remains 2
1 : 7 = 0, remains 1
now you read the remainders from bottom to top 1 -- > 2
you may also write every number in base 7 down and count them (I wouldn't, because for large/long numbers, you'll become in trouble ):
dec -> base 7
0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 6
7 -> 10
8 -> 11
9 -> 12
another example:
decimal 78 in base 7 is 141:
78 : 7 = 11, remains 1
11 : 7 = 1, remains 4
1 : 7 = 0, remains 1
1 --> 4 --> 1
I have NOT finished the Challenge, because i wantet to code it on my own.. But languages like Python(I'm not very good with it) or C# and PHP only accept Int 64 (max 99999999)
I guess you don't bother now, after a year. But maybe a few other people may use it
Last edited by Omgaskinhead on Sun Mar 06, 2011 9:25 am, edited 1 time in total.
Strangely enough I disagree with your statement about Python being crap but opinion aside; such statements aren't very becoming On the factual side of things:
- Python uses arbitrary precision integers so the only limit on the maximum value is determined by how much memory your Python process can get from the OS
- PHP uses 32-bit signed integers unless on a 64-bit system i.e. long mode OS
- C# can also work with arbitrary precision integers by using the Bignum type which is a part of .NET
- The maximum value of 64-bit integers is 9,223,372,036,854,775,807 if signed (as Int64 is) or 18,446,744,073,709,551,615 otherwise
-
- Posts: 4
- Joined: Thu Dec 23, 2010 12:17 pm
Oh damn sorry, I forgot that a byte in binary is 2^8 right? so my 9999.. is wrong, im sorry.. And with (crap) I wanted to say that I didn't practise it for a long time. So I'm not good in coding python.CodeX wrote:Strangely enough I disagree with your statement about Python being crap but opinion aside; such statements aren't very becoming On the factual side of things:
- Python uses arbitrary precision integers so the only limit on the maximum value is determined by how much memory your Python process can get from the OS
- PHP uses 32-bit signed integers unless on a 64-bit system i.e. long mode OS
- C# can also work with arbitrary precision integers by using the Bignum type which is a part of .NET
- The maximum value of 64-bit integers is 9,223,372,036,854,775,807 if signed (as Int64 is) or 18,446,744,073,709,551,615 otherwise
I know about the Convert.ToInt64(); but thats not high enough I thought? Or how can I increase the in Python or C#? I searched a few times but couldn't find anything. But I guess it's a defined class, so I'll try BigInt a = new BigInt(whatever);
thanks a lot
.NET's Bignum style integers are dealt with by the BigInteger class which would be initialized like so:And binary types are related to powers of 2 instead of 10 e.g.
8 unsigned binary digits have 2^8 states, largest value of 2^8-1 or 25510 = 111111112
8 unsigned decimal digits have 10^8 states, largest value 10^8-1 or 9999999910.
As for Python you don't have to change anything to put integers of any size in so you can just throw a ridiculously big integer into Python and start working with it
Code: Select all
BigInteger a = BigInteger.Parse("12345678987654321");
8 unsigned binary digits have 2^8 states, largest value of 2^8-1 or 25510 = 111111112
8 unsigned decimal digits have 10^8 states, largest value 10^8-1 or 9999999910.
As for Python you don't have to change anything to put integers of any size in so you can just throw a ridiculously big integer into Python and start working with it
-
- Posts: 4
- Joined: Thu Dec 23, 2010 12:17 pm