Created
June 24, 2015 20:28
-
-
Save ungalcrys/9081cf5fa88717767a2d to your computer and use it in GitHub Desktop.
Simple loop for Ackermann function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class LiniarAckermann { | |
static ArrayList<Long> mList = new ArrayList<Long>(); | |
public static long ackermann(long m, long n) { | |
while (true) { | |
if (m == 0) { | |
n += 1; | |
if (mList.isEmpty()) { | |
return n; | |
} else { | |
int index = mList.size() - 1; | |
m = mList.get(index); | |
mList.remove(index); | |
} | |
} else if (n == 0) { | |
m -= 1; | |
n = 1; | |
} else { | |
mList.add(m - 1); | |
n -= 1; | |
} | |
} | |
} | |
public static void main(String[] args) { | |
System.out.println(ackermann(4, 1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment