Skip to main content
Adding `pace` as an optional parameter allows for an expression-valued mathod, saving some bytes
Source Link
Rik
  • 751
  • 4
  • 7

C# method (137137 122 bytes)

Requires using System.Linq adding 19 bytes, included in the 137122:

bool C(float t,string r){var p=0f;return,float -p>rp=0)=>r.Split('=').Aggregate(t,(f,s)=>f-(s==""?p:p=1/float.Parse(s)));<-p;

Expanded version:

bool Check(float time, string road)
{
   , varfloat pacepace=0) ==> 0f;
    return -pace > road.Split('=')
        .Aggregate(time, (f, s) => f - (
            s == "" 
            ? pace 
            : pace = 1 / float.Parse(s))); 
}        < -pace;

The road string is split on the = character. Depending on whether a string is the resulting array is empty, the aggregate function sets the pace variable for the segment (denoting the time it takes to travel a single =) and subtracts it from the time supplied. This will do one too many substractions (for the final road segment), so instead of comparing to 0, we compare to -pace

C# method (137 bytes)

Requires using System.Linq adding 19 bytes, included in the 137:

bool C(float t,string r){var p=0f;return -p>r.Split('=').Aggregate(t,(f,s)=>f-(s==""?p:p=1/float.Parse(s)));

Expanded version:

bool Check(float time, string road)
{
    var pace = 0f;
    return -pace > road.Split('=').Aggregate(time, (f, s) => f - (s == "" ? pace : pace = 1 / float.Parse(s)));
}

The road string is split on the = character. Depending on whether a string is the resulting array is empty, the aggregate function sets the pace variable for the segment (denoting the time it takes to travel a single =) and subtracts it from the time supplied. This will do one too many substractions (for the final road segment), so instead of comparing to 0, we compare to -pace

C# method (137 122 bytes)

Requires using System.Linq adding 19 bytes, included in the 122:

bool C(float t,string r,float p=0)=>r.Split('=').Aggregate(t,(f,s)=>f-(s==""?p:p=1/float.Parse(s)))<-p;

Expanded version:

bool Check(float time, string road, float pace=0) => 
    road.Split('=')
        .Aggregate(time, (f, s) => f - (
            s == "" 
            ? pace 
            : pace = 1 / float.Parse(s))) 
        < -pace;

The road string is split on the = character. Depending on whether a string is the resulting array is empty, the aggregate function sets the pace variable for the segment (denoting the time it takes to travel a single =) and subtracts it from the time supplied. This will do one too many substractions (for the final road segment), so instead of comparing to 0, we compare to -pace

Source Link
Rik
  • 751
  • 4
  • 7

C# method (137 bytes)

Requires using System.Linq adding 19 bytes, included in the 137:

bool C(float t,string r){var p=0f;return -p>r.Split('=').Aggregate(t,(f,s)=>f-(s==""?p:p=1/float.Parse(s)));

Expanded version:

bool Check(float time, string road)
{
    var pace = 0f;
    return -pace > road.Split('=').Aggregate(time, (f, s) => f - (s == "" ? pace : pace = 1 / float.Parse(s)));
}

The road string is split on the = character. Depending on whether a string is the resulting array is empty, the aggregate function sets the pace variable for the segment (denoting the time it takes to travel a single =) and subtracts it from the time supplied. This will do one too many substractions (for the final road segment), so instead of comparing to 0, we compare to -pace