I'm pretty sure this is cheating, but... #!/bin/sh grep -e "g\(()\)*('al')" $0 | sed 's/()/o/g' | sed "s/('al')/al/" exit g()('al') On its own, g()('al') is valid but g()()('al') is a syntax error. Also, bash and sh don't have non-numeric return values, so regardless of the solution you're stuck with printing.
This is a great incomplete solution. Can you submit a pull-request for it?
G()('al')
31–40 of 49 posts
Re: G()('al')
#32Earlier quoted context omitted.
This is a great incomplete solution. Can you submit a pull-request for it?
Just to clarify, I think it's a non-solution because the g()('al') is never actually executed - grep does all the work. You can add as many parenthesis as you want. The "exit" is there because you'll get a syntax error if you try to execute g()()('al'). g()('al') by itself does nothing (I'm not even sure why it's not flagged as a syntax error).
Re: G()('al')
#33Not too difficult in Common Lisp (the parser is fully exposed to user code, so I just changed the meaning of "g").
Can you submit a solution then?
Re: G()('al')
#34Re: G()('al')
#35 using System;
using System.Text;
namespace Goal
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(G("al"));
Console.WriteLine(G()("al"));
Console.WriteLine(G()()()()()("al"));
}
static StringBuilder accumulator = new StringBuilder();
delegate dynamic GoalDelegate(string s = "o");
static dynamic G(string s = "o")
{
switch (s)
{
case "o":
accumulator.Append("o");
return (GoalDelegate)G;
case "al":
string result = "G" + accumulator.ToString() + "al";
accumulator.Clear();
return result;
default:
return null;
}
}
}
}Re: G()('al')
#36 def g(a='', n=0):
return 'g '+ 'o'*n + a if a else lambda a='': g(a, n+1)Re: G()('al')
#37[deleted]
Re: G()('al')
#38C# using System; using System.Text; namespace Goal { class Program { static void Main(string[] args) { Console.WriteLine(G("al")); Console.WriteLine(G()("al")); Console.WriteLine(G()()()()()("al")); } static StringBuilder accumulator = new StringBuilder(); delegate dynamic GoalDelegate(string s = "o"); static dynamic G(string s = "o") { switch (s) { case "o": accumulator.Append("o"); return (GoalDelegate)G; case "al"…