Computer Science Canada String to binary |
Author: | zero-impact [ Sat Oct 18, 2008 12:26 pm ] | ||||
Post subject: | String to binary | ||||
Hi I'm making a program just for experimentation that takes a string and converts it into binary. This is what I have so far.
Before I go on to make a function to decode the binary I would like to know if there is any easy way to get around the string length limit in Turing. And if there isn't any ideas on how to do it? It has never really bothered me before but with this function converting each character into eight characters it severely limits the string length. This question also applies to another problem I'm working on Project Euler problem 25http://projecteuler.net/index.php?section=problems&id=25 The function lrgAdd is a function I made for an assignment in my ICS3M course.
[/url] |
Author: | The_Bean [ Sat Oct 18, 2008 2:59 pm ] | ||||
Post subject: | Re: String to binary | ||||
Pass each letter through the function individually, and output
or save to an array.
|
Author: | zero-impact [ Sat Oct 18, 2008 3:39 pm ] |
Post subject: | Re: String to binary |
Thanks! Wow I can't believe I didn't think of something that simple, DOH! Unfortunately that doesn't help me with the second problem |
Author: | The_Bean [ Sat Oct 18, 2008 4:04 pm ] |
Post subject: | Re: String to binary |
There is an easier way to convert to binary and then you just have to reverse it to decode. I think I've solved Project Euler problem 25, my answer is F at 4782. I used a complex array var fib : array 1 .. 3, 1 .. 1000 of int so fib(3,i)=fib(1,i)+fib(2,i) the 1..1000 represents each column in the number, so 189283 would be fib(1,1)=3 fib(1,2)=8 fib(1,3)=2 fib(1,4)=9 fib(1,5)=8 fib(1,6)=1 reading from right to left if the sum is greater than 10 then add the corresponding amount to the next column over Although my algorithm takes 22 - 25 seconds to solve the problem |