Size of code


#1

Hello everybody,
Does anyone have an example where C# can compete with another language on the criterion of the size of code ?
I imagine it involves regular expressions ?


#2

when we talk about small size Clashes… well, C# looses to Python 2-3 times usually because
using… Console.ReadLine… Console.WriteLine… int.Parse… class… static… void Main()…
sometimes u can use
using C=System.Console; // and win few chars for many C.ReadLine
C.Write( “true” ); // last output u can use only Write not WriteLine
use SQL-like syntax of LINQ not function style.
and u can to see code of other players in any language for looking perls. many of them share their code after finishing clash


#3

sometimes u can use
using C=System.Console; // and win few chars for many C.ReadLine
C.Write( “true” ); // last output u can use only Write not WriteLine


Hum, good idea, thanks.
Well, for the line return at the end … Not sure, I think my output once was not visible because the line return was missing.


Maybe I have to review Linq to distinguish both.

Hum, I also have the possibility to learn Python :slight_smile:


#4

Well, I tried that today, and got a type error.
Perhaps it was a bad idea to put brackets after it ?


#5

brackets are needed :slight_smile: probably my typo


#6

Well, next time I keep a copy.
I have to do it when I have some time left, in order to come back to something that works even if it is long. Yesterday I could have done it, I did not have the idea of the copy at the good moment.


#7

Got an example of Thillman575 to convert a number to a given base and see whether the results is a palindrome.
The idea was the same, using static System.Console;
In the code you do not need to prefix, and just say ReadLine() or Write(). There are two times ReadLine(), I could see the results with a function R() that calls ReadLine().
He wrote a code of 277 characters, that treated all the required bases. With 1606 characters I only went unto base 40.
In Python, Pavelchadnov did the same as Thillman with 77 characters. He did not share his code.

shall see whether the link will be valid :
https://www.codingame.com/clashofcode/clash/report/8973471cc511ee25be427464884d0587bed134


#8

using C=System.Console;
class M{
const string D=“0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”;
static string c(long v,long b)=>(v>=b?c(v/b,b):"")+D[(int)(v%b)];
static long R()=>long.Parse(C.ReadLine());
public static void Main(){
C.Write(c(R(),R()));
}}


#9

if use int instead long then -11chars more


#10

with int 233 chars

using C=System.Console;class M{
static string c(int v,int b)=>(v>=b?c(v/b,b):"")+“0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”[v%b];
static void Main(){C.Write(c(int.Parse(C.ReadLine()),int.Parse(C.ReadLine())));}}


#11

Bingo !
In size of code I beated Python, of a short hand, at Sudoku.
The Python code was not shared.
That being said the best code, from far, is Java.
https://www.codingame.com/clashofcode/clash/report/90024366db982b05b6a70f28c9a9784b9e9af9


#12

oops! I forgot palindrome.
code below contains 252chars for max base=62. (0-9A-Za-z)
?“true”:“false” adds 15chars for “true/false” results not “True/False” (imo checking is case sensitive)

using static System.Console;using System.Linq;class M{
static string c(long v,int b)=>(v<b?"":c(v/b,b))+(char)((v%=b)+(v<10?48:v<36?55:61));
static void Main(){var r=c(long.Parse(ReadLine()),int.Parse(ReadLine()));Write(r.SequenceEqual(r.Reverse()));}}


#13

Well, brackets are needed when you say
__
using(StreamWriter sw = new StreamWriter(path){sw.Write("...");}
__
But for references in header of a module, no. You just put a column.

You know, when I published links to clashes, the shared codes were available. I do not know how much time it is shared really, now there are only the scores. Happily, I remember the problem, we received two numbers in decimal, the second one was a base to which convert the first one, and we had to say whether the results was a palindrome, i.e. identical if read from the end to the beginning (as AKA, for instance).
Are you able to say next year what your code does ?


#14

I didnt see any shared code from links (no such buttons, maybe nobody shared code at all from begining).
you also did not give a full description of the problem - what input, what output.
so, my code read 10-base number as long N from one line, number for base conversion B from next line, convert N to base B as string and check this string for palindrom with “True/False” as output .
remark says that in case we want “true”/“false” then we should add 15chars.

1393753996031259953
16
< True (1357 9BDF FDB9 7531)


#15

using static System.Console
is better… “C.” are useless with it and you save one char