Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Twice as old [Difficulty: 0]:
Answer 1:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
return Math.Abs(dadYears - sonYears * 2);
}
}
}
Answer 2:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
return Math.Abs(dadYears - sonYears * 2);
}
}
}
Answer 3:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
return Math.Abs(dadYears - (sonYears * 2));
}
}
}
Answer 4:
namespace Solution
{
using System;
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
return Math.Abs(dadYears-sonYears*2);
}
}
}
Answer 5:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
// Add you code here.
return Math.Abs(dadYears - (sonYears * 2));
}
}
}
A6:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
// Add you code here.
return Math.Abs(dadYears - sonYears * 2);
}
}
}
A7:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears) => Math.Abs(dadYears - (sonYears * 2));
}
}
A8:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears) => Math.Abs(dadYears - sonYears * 2);
}
}
A9:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears) => Math.Abs(2 * sonYears - dadYears);
}
}
Answers 10:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)=>Math.Abs((2*sonYears)-dadYears);
}
}
Solution 11:
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
int yearCalc = 0;
yearCalc = (dadYears - 2*sonYears);
if(yearCalc < 0)
{
yearCalc = yearCalc * -1;
}
return yearCalc;
// Add you code here.
}
}
}
The answer 12:
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int f, int s)
{
return (f > s * 2)? f - s * 2: s * 2 - f;
return f;
}
}
}
Solution 13:
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
int doubleSon = (sonYears*2);
if (dadYears > (sonYears*2))
{
int yearsAgo = dadYears - doubleSon;
return yearsAgo;
}
else
{
int yearsLeft = doubleSon - dadYears;
return yearsLeft;
}
}
}
}
The answer 14:
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears) =>
(dadYears - sonYears*2)>0 ? (dadYears - sonYears*2) : -(dadYears-sonYears*2);
}
}
The answer 15:
using System;
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dadYears, int sonYears)
{
return Math.Abs(dadYears - sonYears - sonYears);
}
}
}
The answer 16:
namespace Solution
{
public class TwiceAsOldSolution
{
public static int TwiceAsOld(int dad, int son)
{
int temp=0;
if(son*2>dad){
while(son*2!=dad){son--;dad--;temp++;}
}else if(son*2<dad){
while(son*2!=dad){son++;dad++;temp++;}
}else if(son==0){
return dad;
}
return temp;
// Add you code here.
}
}
}