Skip to content

Instantly share code, notes, and snippets.

@mattwarren
Last active May 14, 2021 14:58
Show Gist options
  • Save mattwarren/3c7cfaa245effc0a318b87f1ee5dc153 to your computer and use it in GitHub Desktop.
Save mattwarren/3c7cfaa245effc0a318b87f1ee5dc153 to your computer and use it in GitHub Desktop.

Rules

  1. You can have as many lines as you want within method M()
  2. No single line can be longer than 100 chars
  3. To get your score, divide the '# of expanded lines' by the '# of original line(s)'
    1. Based on the default output formatting of https://sharplab.io, no re-formatting allowed!!
    2. But you can format the intput however you want, i.e. make use of the full 100 chars
  4. Must compile with no warnings on https://sharplab.io (allows C# 7 features)
    1. But doesn't have to do anything sensible when run
  5. You cannot modify the code that is already there, i.e. public class C {} and public void M()
    1. Cannot just add async to public void M(), that's too easy!!
  6. You can add new using ... declarations, these do not count towards the line count
using System;
public class C {
    public void M() {
        // Only allowed to change the code in here
        // CAN'T make M() async, that's too easy!!
    }
}

If you want to, paste your sharplab.io links below along with the score


Example - Score = 23

Available on sharplab.io

using System;
public class C {
    public void M() {
        Func<string> test = () => "blah"?.ToString();
    }
}

This counts as 1 line of original code (only code inside method M() is counted)

This expands to 23 lines (again only lines of code inside the braces ({, }) of class C are counted, as formatted by sharplab.io)

Giving a score of 23 / 1 = 23

public class C 
{
    [CompilerGenerated]  // <-- START counting from this line
    [Serializable]
    private sealed class <>c
    {
        public static readonly C.<>c <>9;
        public static Func<string> <>9__0_0;
        static <>c()
        {
            // Note: this type is marked as 'beforefieldinit'.
            C.<>c.<>9 = new C.<>c();
        }
        internal string <M>b__0_0()
        {
            return "blah";
        }
    }
    public void M()
    {
        if (C.<>c.<>9__0_0 == null)
        {
            C.<>c.<>9__0_0 = new Func<string>(C.<>c.<>9.<M>b__0_0);
        }    
    }  // <-- STOP counting at this line
}
@EamonNerbonne
Copy link

https://sharplab.io/#b:master/K4Zwlgdg5gBAYjAvDAygTxAFwKYFsB0cwEAxgDwAmaEAhrmCQDSoY4EAqAFgE7Y0WQo+djRABrEMNFjK1OgwB8CgNwBYAFAAHYACMANgxgk9okDADCMAN4aYdmNv2GAbgHswFGAFkAFAEprDQQAM0RRahIYAA9EBSiAMniAPxTUtPSMzKzsnIyaAHcaMEwkgqKSsuLSwuKNavL6qsqKmpaG5sa2ptbO3o7+noGGpKi1dXsYAF8NafUgA

using F = System.Func<dynamic, System.Threading.Tasks.Task<dynamic>>;
public class C {
    public void M() {
F f=async x=>x&&~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~await~await~await~await
~await~await~await~await~await~await~await~await~await~await~await~await~await~await~await~await~~x;
    }
}

2510 output / 2 input => 1255

@mattwarren
Copy link
Author

@EamonNerbonne I'm so sorry, I've only just noticed your entry (GitHub doesn't give notifications for gists),

WOW, you win, no doubts about it, that's pretty cool using the bitwise operator like that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment