0

Hey guys can you help me convert this code into java... i started a little...

def  minEditDistR(target, source):
   """ Minimum edit distance. Straight from the recurrence. """
 
   i = len(target); j = len(source)
 
   if i == 0:  return j
   elif j == 0: return i
 
   return(min(minEditDistR(target[:i-1],source)+1,
              minEditDistR(target, source[:j-1])+1,
              minEditDistR(target[:i-1], source[:j-1])+substCost(source[j-1], target[i-1])))
 
def substCost(x,y):
    if x == y: return 0
    else: return 2

Here is me trying

public static int distance (String s1, String s2){
		int a = s1.length(); 
		int b = s2.length();
 
		if ( a == 0) return b;
		if ( b == 0) return a;

Thank YOU!

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by DarkLightning7
0

Most of the people on this form don't know java and python so explain what your code is supposed to do then I will be able to help you.

There is also a java library called Jython for using java and python together if you don't have to convert your code for what you are doing but this is a simple piece of code you have posted so it will be simpler to convert it.

Edited by DarkLightning7: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.