"Basic" Challenge help

damantise
Posts: 3
Joined: Wed Oct 01, 2008 3:14 am

"Basic" Challenge help

Post by damantise »

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
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post by gfoot »

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. :)
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

gfoot 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. :)
Wouldn't be terribly difficult to do long hand either ;)
Masti6
Posts: 55
Joined: Sat May 15, 2010 12:04 pm
Location: Finland, Nurmes

Post by Masti6 »

I'm also needing some help or tips on this one.
I have tried many Base 7 calculators and translators but none seems to give anything else but "invalid value".
Any hints on how to get this thing working?

28679718602997181072337614380936720482949 = OMG WTF (no, that's not the answer)
User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

There's a very good language called Mathematica out there (very expensive) - but the author of that language has created a free interpreter (that's one facet of a huge enterprise) which is REALLY useful for many of the challenges.
There is no spoon.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

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).
User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

Wolfram|Alpha was what I meant by the 'huge enterprise'. It's so useful - and it talks to you if you ask it (simple) questions like 'Do you pass the Turing test?'
There is no spoon.
Masti6
Posts: 55
Joined: Sat May 15, 2010 12:04 pm
Location: Finland, Nurmes

Post by Masti6 »

I have visited the Wolfram site(s), google'd and wikipedia'd Mathematica, but I still can't figure how it helps me solve
28679718602997181072337614380936720482949
into anything that makes sense. It just gives me some info about it in different form, etc. But none of them actually help.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

your meant to ask WolframAlpha a question, not just drop a number on it
Omgaskinhead
Posts: 4
Joined: Thu Dec 23, 2010 12:17 pm

Post by Omgaskinhead »

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 :P ):


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 :D
Last edited by Omgaskinhead on Sun Mar 06, 2011 9:25 am, edited 1 time in total.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

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:
  1. 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
  2. PHP uses 32-bit signed integers unless on a 64-bit system i.e. long mode OS
  3. C# can also work with arbitrary precision integers by using the Bignum type which is a part of .NET
  4. 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
Omgaskinhead
Posts: 4
Joined: Thu Dec 23, 2010 12:17 pm

Post by Omgaskinhead »

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:
  1. 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
  2. PHP uses 32-bit signed integers unless on a 64-bit system i.e. long mode OS
  3. C# can also work with arbitrary precision integers by using the Bignum type which is a part of .NET
  4. 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
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.

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 :)
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

.NET's Bignum style integers are dealt with by the BigInteger class which would be initialized like so:

Code: Select all

BigInteger a = BigInteger.Parse("12345678987654321");
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
Omgaskinhead
Posts: 4
Joined: Thu Dec 23, 2010 12:17 pm

Post by Omgaskinhead »

Ok Thank you CodeX, now I remember.. We had this in school last few weeks. (I'm actually learning informatican or whatever you call it in the US --> I'm swiss :P)

Btw: solved the Challenge. With BigInt it's easier than I thought :)
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

I can only guess based on the topics covered in your course, I'm from England anyway :P p.s. Thanks for Toblerones
Post Reply