Skip to content

Instantly share code, notes, and snippets.

@shadeglare
Created December 3, 2013 11:49
Show Gist options
  • Save shadeglare/7767899 to your computer and use it in GitHub Desktop.
Save shadeglare/7767899 to your computer and use it in GitHub Desktop.
for PHP-man
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrainSelector
{
class Program
{
static void Main(string[] args)
{
var seatToCoupes = new Dictionary<Int32, Int32>();
var mainCoupeSize = 4;
var leftCoupeSize = 2;
var coupeCount = 9;
var totalMainSeatsOffset = coupeCount * mainCoupeSize;
for (var currentCoupe = 1; currentCoupe <= coupeCount; currentCoupe++)
{
for (var offsetMainSeatNumber = 1; offsetMainSeatNumber <= mainCoupeSize; offsetMainSeatNumber++)
{
var currentMainSeatNumber = (currentCoupe - 1) * mainCoupeSize + offsetMainSeatNumber;
seatToCoupes.Add(currentMainSeatNumber, currentCoupe);
}
for (var offsetLeftSeatNumber = 1; offsetLeftSeatNumber <= leftCoupeSize; offsetLeftSeatNumber++)
{
var currentLeftSeatNumber = (coupeCount - currentCoupe) * leftCoupeSize + offsetLeftSeatNumber + totalMainSeatsOffset;
seatToCoupes.Add(currentLeftSeatNumber, currentCoupe);
}
}
Console.WriteLine(seatToCoupes[54]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment