0
\$\begingroup\$

The question Find i^n, given n does not clearly state whether the solution must be a compilable program or can be an expression, neither does it identify where the input shall come from.

This leads to answers like this, which are a mixture of both and neither short nor compilable.

For verbose languages like C#, are LinqPad C# expressions encouraged in ? If so, how to get the needed input?

A solution like

"i,-1,-i,1".Split(',')[n%4]

is nice and short and can compete with several other answers. But n would need to be replaced by the actual number, which increases the length. Is that allowed and by definition we count n just as 1 character?

Edit

There are 38 LinqPad answers already, applying the rules more or less lax. From the top-voted ones:

  • This one might be ok, because it does not need input, but prints output to the LinqPad STDOUT if you like
  • That uses a string as input but does not count it as characters
  • This follows my example above
  • Another approach seems to be a function that uses LinqPad specific methods (.Dump())
  • This takes advantage of missing usingstatements in LinqPad
\$\endgroup\$
6
  • \$\begingroup\$ Related: Code Golf Input Output Methods \$\endgroup\$ Mar 5, 2015 at 22:31
  • \$\begingroup\$ You've just answered your own question with that link. The other relevant poll was this one. We've got accepted defaults on these matters, which are also listed on the code-golf tag wiki. Any answer may overrule these defaults, but if it doesn't then they apply. In particular, the current consensus is that snippets are not allowed. \$\endgroup\$ Mar 5, 2015 at 22:33
  • \$\begingroup\$ @MartinBüttner: If it is a function, I guess it does not need the access modifier like in the linked i^n answer. \$\endgroup\$ Mar 5, 2015 at 22:37
  • \$\begingroup\$ Does it not? Is it a mandatory part of a function definition in C#? \$\endgroup\$ Mar 5, 2015 at 22:40
  • \$\begingroup\$ @MartinBüttner: By default it is private, but you can still call it from within your own program. \$\endgroup\$ Mar 5, 2015 at 22:43
  • \$\begingroup\$ Yes, I'd say that's fine then. \$\endgroup\$ Mar 5, 2015 at 22:44

0

Browse other questions tagged .