Coder Social home page Coder Social logo

aocyj's People

Contributors

ocyj avatar

Watchers

 avatar

aocyj's Issues

Condense single-line methods

AOCYJ/AOC2020/Day02.cs

Lines 17 to 27 in 66bfe87

public override object SolvePart1()
{
return passwordAndPolicies.Count(p => p.min <= p.password.CountChar(p.@char)
&& p.password.CountChar(p.@char) <= p.max);
}
public override object SolvePart2()
{
return passwordAndPolicies.Count(p => p.password[p.min - 1] == p.@char
^ p.password[p.max - 1] == p.@char);
}

For single-line methods, you can use expression bodies.

Regular expressions

Try to use regular expressions when parsing text. It will make your life much easier.

AOCYJ/AOC2020/Day02.cs

Lines 35 to 40 in 66bfe87

string[] parts = line.Split(' ');
(int min, int max, char @char, string password) passwordAndPolicy;
passwordAndPolicy.min = int.Parse(parts[0].Split('-')[0]);
passwordAndPolicy.max = int.Parse(parts[0].Split('-')[1]);
passwordAndPolicy.@char = char.Parse(parts[1].Substring(0,1));
passwordAndPolicy.password = parts[2];

Interactive tutorial about regular expressions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.