Re: convert to python code

2015-12-23 Thread Steven D'Aprano
On Wed, 23 Dec 2015 03:14 pm, Rodrick Brown wrote:

> Tried a few things but can't seem to get it right any help ?
> 
> let times = (...matrices) =>
> 
>   matrices.reduce(
> 
> ([a,b,c], [d,e,f]) => [a*d + b*e, a*e + b*f, b*e + c*f]
> 
>   );


Are you expecting us to guess what language this is written in, decipher
what it does, and write Python code to do the same thing?

How about if you tell us the language and explain what it does?


-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


convert to python code

2015-12-22 Thread Rodrick Brown
Tried a few things but can't seem to get it right any help ?

let times = (...matrices) =>

  matrices.reduce(

([a,b,c], [d,e,f]) => [a*d + b*e, a*e + b*f, b*e + c*f]

  );
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: convert to python code

2015-12-22 Thread Ben Finney
Rodrick Brown <rodrick.br...@gmail.com> writes:

> Tried a few things but can't seem to get it right any help ?

To convert it to Python code, you'll need to actually write some code.

Please show here in this forum the actual Python code which is not
behaving how you want, and say *exactly* what it's doing different from
what you expect (and, preferably, explain why you expect it to behave
differently).

-- 
 \  “Do I believe in God? … without clarification of a kind I have |
  `\never seen, I don’t know whether I believe or don’t believe in |
_o__)whatever a questioner has in mind.” —Noam Chomsky |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Convert some Python code to C++

2007-11-14 Thread Loic Mahe
[EMAIL PROTECTED] a écrit :
 For those that understand algorithms and can talk Python, I want to
 convert the Python code in the section Reading out all LCSs into C++
 code but I don't understand some of the syntax.  Can anyone give me a
 hand?
 
 def backTrackAll(C, X, Y, i, j):
 if i == 0 or j == 0:
 return set([])
 elif X[i-1] == Y[j-1]:
 return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
 j-1)])
 else:
 R = set()
 if C[i][j-1] = C[i-1][j]:
 R.update(backTrackAll(C, X, Y, i, j-1))
 if C[i-1][j] = C[i][j-1]:
 R.update(backTrackAll(C, X, Y, i-1, j))
 return R
 
 Thanks!
 

just have a look at this tutorial: and look for Lists and Sets
http://docs.python.org/tut/tut.html

and look in the reference index for set() and list() in
http://docs.python.org/lib/genindex.html


or just pick the algo in another language in the url you give

or tell us precisely what part of the python algo you do not understant!
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert some Python code to C++

2007-11-13 Thread meyousikmann
I am working on an implementation of the Longest Common Subsequence
problem (as I understand it, this problem can be used in spell
checking type activities) and have used this site to understand the
problem and its solution:

http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest_common_subsequence


For those that understand algorithms and can talk Python, I want to
convert the Python code in the section Reading out all LCSs into C++
code but I don't understand some of the syntax.  Can anyone give me a
hand?

Here is the code from that section, but is probably of little use
without understanding the entire problem setup given at the site
above:

def backTrackAll(C, X, Y, i, j):
if i == 0 or j == 0:
return set([])
elif X[i-1] == Y[j-1]:
return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
j-1)])
else:
R = set()
if C[i][j-1] = C[i-1][j]:
R.update(backTrackAll(C, X, Y, i, j-1))
if C[i-1][j] = C[i][j-1]:
R.update(backTrackAll(C, X, Y, i-1, j))
return R

Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert some Python code to C++

2007-11-13 Thread kyosohma
On Nov 13, 9:28 am, [EMAIL PROTECTED] wrote:
 I am working on an implementation of the Longest Common Subsequence
 problem (as I understand it, this problem can be used in spell
 checking type activities) and have used this site to understand the
 problem and its solution:

 http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest...

 For those that understand algorithms and can talk Python, I want to
 convert the Python code in the section Reading out all LCSs into C++
 code but I don't understand some of the syntax.  Can anyone give me a
 hand?

 Here is the code from that section, but is probably of little use
 without understanding the entire problem setup given at the site
 above:

 def backTrackAll(C, X, Y, i, j):
 if i == 0 or j == 0:
 return set([])
 elif X[i-1] == Y[j-1]:
 return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
 j-1)])
 else:
 R = set()
 if C[i][j-1] = C[i-1][j]:
 R.update(backTrackAll(C, X, Y, i, j-1))
 if C[i-1][j] = C[i][j-1]:
 R.update(backTrackAll(C, X, Y, i-1, j))
 return R

 Thanks!

You might try Shed Skin:

http://sourceforge.net/projects/shedskin/

It's been a while since I did C++. I would recommend going through a
basic C++ tutorial. I'm pretty sure the equivalence operators are
almost the same. You'll likely need to declare the types for the
arguments passed into the function as well.

I think lists are called arrays in C++. I don't know what the set
equivalent is though.

Mike

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert some Python code to C++

2007-11-13 Thread Neil Cerutti
On 2007-11-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Nov 13, 9:28 am, [EMAIL PROTECTED] wrote:
 I am working on an implementation of the Longest Common
 Subsequence problem (as I understand it, this problem can be
 used in spell checking type activities) and have used this
 site to understand the problem and its solution:

 http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest...

 For those that understand algorithms and can talk Python, I
 want to convert the Python code in the section Reading out
 all LCSs into C++ code but I don't understand some of the
 syntax.  Can anyone give me a hand?

 Here is the code from that section, but is probably of little
 use without understanding the entire problem setup given at
 the site above:

 def backTrackAll(C, X, Y, i, j):
 if i == 0 or j == 0:
 return set([])
 elif X[i-1] == Y[j-1]:
 return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
 j-1)])
 else:
 R = set()
 if C[i][j-1] = C[i-1][j]:
 R.update(backTrackAll(C, X, Y, i, j-1))
 if C[i-1][j] = C[i][j-1]:
 R.update(backTrackAll(C, X, Y, i-1, j))
 return R

 Thanks!

 You might try Shed Skin:

 http://sourceforge.net/projects/shedskin/

 It's been a while since I did C++. I would recommend going
 through a basic C++ tutorial. I'm pretty sure the equivalence
 operators are almost the same. You'll likely need to declare
 the types for the arguments passed into the function as well.

 I think lists are called arrays in C++. I don't know what the
 set equivalent is though.

It is called set, oddly enough. ;)

There's an overload of the set::insert function that takes a
couple of iterators that will serve for Python's update method.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert some Python code to C++

2007-11-13 Thread kyosohma
On Nov 13, 12:51 pm, Neil Cerutti [EMAIL PROTECTED] wrote:
 On 2007-11-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:



  On Nov 13, 9:28 am, [EMAIL PROTECTED] wrote:
  I am working on an implementation of the Longest Common
  Subsequence problem (as I understand it, this problem can be
  used in spell checking type activities) and have used this
  site to understand the problem and its solution:

 http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest...

  For those that understand algorithms and can talk Python, I
  want to convert the Python code in the section Reading out
  all LCSs into C++ code but I don't understand some of the
  syntax.  Can anyone give me a hand?

  Here is the code from that section, but is probably of little
  use without understanding the entire problem setup given at
  the site above:

  def backTrackAll(C, X, Y, i, j):
  if i == 0 or j == 0:
  return set([])
  elif X[i-1] == Y[j-1]:
  return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
  j-1)])
  else:
  R = set()
  if C[i][j-1] = C[i-1][j]:
  R.update(backTrackAll(C, X, Y, i, j-1))
  if C[i-1][j] = C[i][j-1]:
  R.update(backTrackAll(C, X, Y, i-1, j))
  return R

  Thanks!

  You might try Shed Skin:

 http://sourceforge.net/projects/shedskin/

  It's been a while since I did C++. I would recommend going
  through a basic C++ tutorial. I'm pretty sure the equivalence
  operators are almost the same. You'll likely need to declare
  the types for the arguments passed into the function as well.

  I think lists are called arrays in C++. I don't know what the
  set equivalent is though.

 It is called set, oddly enough. ;)

 There's an overload of the set::insert function that takes a
 couple of iterators that will serve for Python's update method.

 --
 Neil Cerutti

I suspected as much, but I don't think they ever got that far into C++
in the classes I took. I'll have to file that little nugget for future
reference. Hopefully the OP is getting something out of this as well.

Mike

-- 
http://mail.python.org/mailman/listinfo/python-list