Hello I am new user. I am giving presentation on cobra tomorrow morning. Of course just I am giving an out line and little description about cobra. Its interesting. But due to less time I could not able to learn much. I have many doubts. But no time. From now on words I will regularly visit this site and even I love to work. Ok coming to my problem please send me TPK algorithm in cobra. How to execute this Trabb Pardo - Knuth algorith in cobra. Please send me now. From morning I am trying. Please help. Can any one send me now. please mail to my Email id sundeep325@gmail.com
Forums
Is any one online..plz help me
11 posts
• Page 1 of 2 • 1, 2
Re: Is any one online..plz help me
sundeep325 wrote:Ok coming to my problem please send me TPK algorithm in cobra.
I couldn't find a Python version online, which would be easier to port to Cobra. The closest I've found is a Java version,I recommend you start there. It's a short algorithm so it shouldn't be difficult to translate to Cobra.
sundeep325 wrote:From morning I am trying
Then maybe it would be easier if you send us what you've got so far, and we can correct it.
- jonathandavid
- Posts: 159
Re: Is any one online..plz help me
Theres a Ruby version on the wikipedia entry for TPK algorithm which is pretty easy to convert to Cobra
( modulo a coupla things that may be bugs which I'll raise some tickets/questions for tomorrow)
( modulo a coupla things that may be bugs which I'll raise some tickets/questions for tomorrow)
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
Re: Is any one online..plz help me
sundeep325, you may feel free to use the slides from my Feb 2008 presentation at http://cobra-language.com/docs/papers-etc/Cobra-Socal-Piggies-2008-02-Slides.pdf. The first 19 slides are fairly accurate. The slides after that are somewhat out of date. If I had known about your presentation earlier, I would have updated them for you.
Interestingly, I have sometimes found it easier to port C# code to Cobra than Python or Ruby simply because C# comes with all the types and uses the .NET libraries. Also, the strongly typed version is also quite snappy. I'll have an LZW compression example soon based on such a port.
Interestingly, I have sometimes found it easier to port C# code to Cobra than Python or Ruby simply because C# comes with all the types and uses the .NET libraries. Also, the strongly typed version is also quite snappy. I'll have an LZW compression example soon based on such a port.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Is any one online..plz help me
As i told u, im new, i dont have idea about this cobra. Just started 3 days before. I don't know what kind syntax use for what. So help me in giving an appropriate pgm. I am pasting here python program. please change it to cobra lang.
1 # tpk.py: Knuth's TPK program in Python
2
3 import sys,math
4
5 def f(x):
6 return math.sqrt(abs(x)) + 5.0*(x**3.0)
7
8 A = [] # declare a mutable sequence
9
10 # Read in the values of the array "A"
11 for i in range(11):
12 A.append (float(sys.stdin.readline()));
13
14 # In reverse order, apply "f" to each element of "A" and print
15 for i in range(10,-1,-1):
16 y = f (A[i])
17 if y<400.0:
18 sys.stdout.write ("%d %f\n" % (i,y))
19 else:
20 sys.stdout.write ("%d TOO LARGE\n" % i)
1 # tpk.py: Knuth's TPK program in Python
2
3 import sys,math
4
5 def f(x):
6 return math.sqrt(abs(x)) + 5.0*(x**3.0)
7
8 A = [] # declare a mutable sequence
9
10 # Read in the values of the array "A"
11 for i in range(11):
12 A.append (float(sys.stdin.readline()));
13
14 # In reverse order, apply "f" to each element of "A" and print
15 for i in range(10,-1,-1):
16 y = f (A[i])
17 if y<400.0:
18 sys.stdout.write ("%d %f\n" % (i,y))
19 else:
20 sys.stdout.write ("%d TOO LARGE\n" % i)
- sundeep325
- Posts: 5
Re: Is any one online..plz help me
Here is the python program. And if possible try to not use magic numbers in the program. Like y<400, every thing we shld give at the run time. Please help me. thank for the replies.
Last edited by sundeep325 on Sat Dec 20, 2008 8:31 pm, edited 1 time in total.
- sundeep325
- Posts: 5
Re: Is any one online..plz help me
And also is there any chance to get BNF notation for our cobra language, like <digit>--> {0|1|.....|9}.
- sundeep325
- Posts: 5
Re: Is any one online..plz help me
There is currently no BNF, but here is some help:
(1) Check out the existing How-To's and Samples which you can present directly
http://cobra-language.com/how-to/
http://cobra-language.com/samples/
(2) Check out wiki docs which give some grammatical forms:
http://cobra-language.com/trac/cobra/wiki/AdditionalDoc
(1) Check out the existing How-To's and Samples which you can present directly
http://cobra-language.com/how-to/
http://cobra-language.com/samples/
(2) Check out wiki docs which give some grammatical forms:
http://cobra-language.com/trac/cobra/wiki/AdditionalDoc
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Is any one online..plz help me
Before I forget heres a stab at the algorithm in Cobra,
- Code: Select all
# use float (float64) not .Net Double, use Math.pow not **
class TPK
def f(x as float) as float is shared
# return Math.sqrt(Math.abs(x)) + 5.0f*x ** 3.0f # shld work but does not
return Math.sqrt(Math.abs(x)) + 5.0f * Math.pow(x, 3.0f)
def main is shared
ray = []
for i in 11 # or for i in 0 : 11
ray.add(float.parse(Console.readLine))
ray.reverse
for x in ray
y = .f(x)
print "[x] [if(y>400f, 'TOO LARGE', y)]"
#Use this loop instead of above loop and ray.reverse to insert items in reverse order
#for i in 11
# ray.insert(0, float.parse(Console.readLine))
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 73 guests