0
\$\begingroup\$

This question already has an answer here:

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\$

marked as duplicate by Martin Ender, ProgramFOX, Toothbrush, es1024, Doorknob Mar 19 '15 at 14:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Related: Code Golf Input Output Methods \$\endgroup\$ – Thomas Weller Mar 5 '15 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\$ – Martin Ender Mar 5 '15 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\$ – Thomas Weller Mar 5 '15 at 22:37
  • \$\begingroup\$ Does it not? Is it a mandatory part of a function definition in C#? \$\endgroup\$ – Martin Ender Mar 5 '15 at 22:40
  • \$\begingroup\$ @MartinBüttner: By default it is private, but you can still call it from within your own program. \$\endgroup\$ – Thomas Weller Mar 5 '15 at 22:43
  • \$\begingroup\$ Yes, I'd say that's fine then. \$\endgroup\$ – Martin Ender Mar 5 '15 at 22:44

Browse other questions tagged .