c# - Recursion and return a function -
i have following code in javascript , write same in c#. don't know how recursion , returning function together.
function findsequence(goal) { function find(start, history) { if (start == goal) return history; else if (start > goal) return null; else return find(start + 5, "(" + history + " + 5)") || find(start * 3, "(" + history + " * 3)"); } return find(1, "1"); }
i thought work isn't.
public static func<int, string, string> findsequence(int goal) { var find = new func<int, string, string>(start, history => { if (start == goal) return history; else if (start > goal) return null; else return (find(start + 5, "(" + history + " + 5)") || find(start * 3, "(" + history + " * 3)")); }); return find; }
Comments
Post a Comment