public override void Puzzle1() { //cups.ForEach(x => Console.WriteLine(x)); int currrentMove = 0; for (int move = 1; move <= 100; move++) { Console.WriteLine($"-- move {move} --"); if (currrentMove >= cups.Count) { currrentMove = 0; } Cups.MakeMove(cups, currrentMove); currrentMove++; } Console.WriteLine($"-- Final --"); Cups.PrintCups(cups, -1); StringBuilder sbFinale = new StringBuilder(); while (1 != cups[cups.Count() - 1]) { cups.Add(cups[0]); cups.RemoveAt(0); } cups.ForEach(x => sbFinale.Append(x)); Console.WriteLine($"Cuplabels = {sbFinale.ToString().Replace("1","")}"); }
private IEnumerator ShuffleRoutine() //دالة لانتظار بضع ثوانى { yield return(new WaitForSeconds(1f)); //يستنى ثانية بعدين الكابس تطلع foreach (Cups cup in cups) //عشان تتعمل على ال 3 كابس { cup.MoveUp(); } yield return(new WaitForSeconds(0.5f)); Cups targetCup = cups[Random.Range(0, cups.Length)]; //for taking random cup targetCup.ball = ball; ball.transform.position = new Vector3( //make ball go to the random cup in x,z and the same y targetCup.transform.position.x, ball.transform.position.y, targetCup.transform.position.z ); yield return(new WaitForSeconds(1f)); foreach (Cups cup in cups) //تنزل الكابس { cup.MoveDown(); } }
public override void Puzzle2() { for (int i = cups.Count + 1; i <= 1000000; i++) { cups.Add(i); } int currrentMove = 0; Console.WriteLine($"{DateTime.Now.ToString("hh:mm:ss")}: -- move {currrentMove} --"); for (int move = 1; move <= 10000000; move++) { if (move % 100000 == 0) { Console.WriteLine($"{DateTime.Now.ToString("hh:mm:ss")}: -- move {move} --"); } if (currrentMove >= cups.Count) { currrentMove = 0; } Cups.MakeMove(cups, currrentMove); currrentMove++; } //Console.WriteLine($"-- Final --"); int temp = cups.IndexOf(1); long temp2 = cups[temp + 1] * cups[temp + 2]; //Console.WriteLine($"Cuplabels = {cups[temp+1] * cups[temp+2]}"); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Jan\Desktop\OuputD23P2.txt")) { file.WriteLine(cups[temp + 1]); file.WriteLine(cups[temp + 2]); } }
private static void PlayIt(Cups cups, int loopLimit) { var maxValue = cups.Map.Values.Select(x => x.Value).Max(); var currentNode = cups.First; for (var i = 1; i <= loopLimit; i++) { var pickupStart = currentNode.Next; var pickupEnd = pickupStart.Next.Next; var handValues = new HashSet <int> { currentNode.Next.Value, currentNode.Next.Next.Value, currentNode.Next.Next.Next.Value }; var nextLabel = currentNode.Value; do { nextLabel--; nextLabel = nextLabel == 0 ? maxValue : nextLabel; }while (handValues.Contains(nextLabel)); var destination = cups.Map[nextLabel]; MoveCups(currentNode, destination, pickupStart, pickupEnd); currentNode = currentNode.Next; } }
public void Test(string input, string expected) { Cups c = new Cups(input); string s = c.OneHundred(); Assert.Equal(expected, s); }
protected int SelectDestinationCup(int currentCupValue) { // not the currenc cup! var cupsToSearchIn = Cups.Where(c => c != currentCupValue).ToList(); // if not found, then go up and search from the highest var minValue = cupsToSearchIn.Min(); var maxValue = cupsToSearchIn.Max(); var valueToSearchFor = currentCupValue - 1; valueToSearchFor = valueToSearchFor < minValue ? maxValue : valueToSearchFor; var itemFoundIndex = cupsToSearchIn.FindIndex(c => c == valueToSearchFor); while (itemFoundIndex == -1) { valueToSearchFor--; itemFoundIndex = cupsToSearchIn.FindIndex(c => c == valueToSearchFor); } var itemFound = cupsToSearchIn[itemFoundIndex]; if (PRINT) { Console.WriteLine($"destination: {itemFound}"); } return(itemFound); }
void Start() { cupLeft = GameObject.Find("Cup_Left").GetComponent <Cups>(); cupRight = GameObject.Find("Cup_Right").GetComponent <Cups>(); audioManager = GameObject.Find("Main Camera").GetComponent <AudioManager>(); triggerAudioSource = GetComponent <AudioSource>(); }
public static Cups Create(IEnumerable <int> values, int size = 9) { var cups = new Cups(size); var done = 1; var first = new Cup(values.First()); cups.search[first.Value] = first; var prev = first; foreach (var val in values.Skip(1)) { var curr = new Cup(val); cups.search[val] = curr; prev.Next = curr; prev = curr; done++; } while (++done <= size) { var curr = new Cup(done); cups.search[done] = curr; prev.Next = curr; prev = curr; } prev.Next = first; cups.Curr = first; return(cups); }
public void TestMethod10() { Cups cups = new Cups(); double expectedResult = .10; Assert.AreEqual(expectedResult, cups.price); }
public Inventory() { lemons = new Lemons(); ice = new Ice(); sugar = new Sugar(); pitcher = new Pitcher(); cups = new Cups(); }
public string Part1(string input) { var numbers = new LinkedList <int>(input.ToCharArray().Select(x => int.Parse(x.ToString()))); var cups = new Cups(numbers); PlayIt(cups, 100); return(string.Join("", cups.OrderFromCupOne().Select(x => x.Value))); }
public CrabCupsGame(string data, bool fill = false) { Original = data; Cups = Original.ToCharArray().Select(ch => int.Parse(new string(ch, 1))).ToList(); if (fill) { Cups.AddRange(Enumerable.Range(10, 999991)); } CurrentCup = Cups[0]; }
public long part_two(string input) { var cups = Cups.Create(input.ToCharArray().Select(ch => ch - '0'), 1_000_000); while (cups.Turn < 10_000_000) { cups.Next(); } return((long)cups.Search(1).Next.Value *cups.Search(1).Next.Next.Value); }
public string part_one(string input) { var cups = Cups.Create(input.ToCharArray().Select(ch => ch - '0')); while (cups.Turn < 100) { cups.Next(); } return(cups.Answer()); }
public long RightMultiply(string input, int goes) { var cups = new Cups(input, 1000000); for (var i = 0; i < goes; i++) { cups.Move(); } return(cups.RightMultiply); }
public override Day Run() { dayOfMonth = 23; stopwatch.Start(); Cups cups = new Cups("389547612", 9); answer_part1 = cups.LabelAfterMoves(100); cups = new Cups("389547612", 1000000); answer_part2 = cups.ProductOfFirstCups(10000000).ToString(); return(this); }
/// <summary> /// 检查两个杯子的状态是否是已就绪 /// </summary> /// <param name="checkTran"></param> void CheckReady(Cups checkCup) { if (checkCup.myHandState == Cups.myHand.Left) { isLeftReady = true; } else { isRightReady = true; } }
public string TextFrom1(string input, int goes) { var cups = new Cups(input, input.Length); for (var i = 0; i < goes; i++) { cups.Move(); } return(cups.TextFrom1); }
public int GetNextCupIndex(int currcentCupIndex) { var totalCups = Cups.Count(); currcentCupIndex++; if (currcentCupIndex >= totalCups) { currcentCupIndex -= totalCups; } return(currcentCupIndex); }
protected void PrintCups() { var strings = new List <string>(); for (int i = 0; i < Cups.Count(); i++) { var cup = CurrcentCupIndex == i ? $"({Cups[i]})" : $"{Cups[i]}"; strings.Add(cup); } Console.WriteLine($"cups: {String.Join(" ", strings)}"); }
private static string MoveCups(string initialPosition, int moves) { var cups = new Cups(initialPosition.Select(c => (long)int.Parse(c.ToString()))); for (var i = 0; i < moves; i++) { var removed = cups.RemoveThreeClockwiseOfCurrent(); cups.InsertCups(removed); } return(cups.CurrentState); }
public Box(int uid, Door door, Slider slider, List <Panel> panels, List <Traverse> traverse, Cups cups) { this.Uid = uid; this.Door = door; this.Slider = slider; this.Panels = panels; this.Traverse = traverse; this.Cups = cups; this.Height = ComputeHeight(); this.Width = ComputeWidth(); this.Depth = ComputeDepth(); }
public CrabCups(string cups, bool reachMillion) { Cups = cups.Select(c => c.ToString()).Select(Int32.Parse).ToList(); CurrcentCupIndex = 0; var maxValue = Cups.Max(); for (int i = maxValue + 1; i <= 1000000; i++) { Cups.Add(i); } }
private void Collect() { var groups = Cups.Where(c => !c.IsScore).GroupBy(c => c.Owner); foreach (var group in groups) { Score(group.Key).Stones += CupCount(group.Key); foreach (var cup in group) { cup.Stones = 0; } } }
public string GetResult() { var res = ""; var oneIndex = Cups.FindIndex(c => c == 1); var lookIndex = GetNextCupIndex(oneIndex); while (lookIndex != oneIndex) { res += Cups[lookIndex]; lookIndex = GetNextCupIndex(lookIndex); } return(res); }
public int FindDestination(int maxValue) { int destCup = CurrentCup; do { destCup--; if (destCup < 1) { destCup = maxValue; } } while (Cups.IndexOf(destCup) == -1); return(destCup); }
public string CupsAfterOne() { int[] list = new int[8]; var iOne = Cups.IndexOf(1) + 1; for (int i = 0; i < list.Length; i++) { int idx = (iOne + i) % 9; list[i] = Cups[idx]; } string val = string.Join("", list.Select(i => i.ToString()).ToArray()); return(val); }
public string Part2(string input) { var inputNumbers = input.ToCharArray().Select(x => int.Parse(x.ToString())).ToList(); var allNumbers = inputNumbers.Union(Enumerable.Range(inputNumbers.Max() + 1, 1000000 - inputNumbers.Max())); var numbers = new LinkedList <int>(allNumbers); var cups = new Cups(numbers); PlayIt(cups, 10000000); var part2Order = cups.OrderFromCupOne().Take(2).Select(x => Convert.ToInt64(x.Value)).ToList(); return(part2Order.Aggregate((a, b) => a * b).ToString()); }
public BaseCupsFactory CreateCups(Cups cups) { BaseCupsFactory baseCupsFactory = null; if (cups.CupsSize == (int)CupsSize.smallCupSize) { baseCupsFactory = new SmallCupsConcreteFactory(cups); } else if (cups.CupsSize == (int)CupsSize.mediumCupSize) { baseCupsFactory = new MeduimCupConcreteFactory(cups); } return(baseCupsFactory); }
static void Main(string[] args) { var smallCup = new Cups { CupsSize = (int)CupsSize.smallCupSize }; var meduimCup = new Cups { CupsSize = (int)CupsSize.mediumCupSize }; var decoratorPatternService = new DecoratorPattenService(); var expressWithDoubleShortSmallCup = decoratorPatternService.ExpressWithDoubleShort(smallCup); Console.WriteLine("Cost of ExpressWithDoubleShortSmallCup {0}", expressWithDoubleShortSmallCup); var expressWithDoubleShortLargeCup = decoratorPatternService.ExpressWithDoubleShort(meduimCup, (int)CupsSize.mediumCupSize); Console.WriteLine("Cost of ExpressWithDoubleMeduimCup {0}", expressWithDoubleShortLargeCup); var expressWithCaramelSmallCup = decoratorPatternService.ExpressWithCaramel(smallCup); Console.WriteLine("Cost of ExpressWithCaramelSmallCup {0}", expressWithCaramelSmallCup); var expressWithCaramelMeduimCup = decoratorPatternService.ExpressWithCaramel(meduimCup, (int)CupsSize.mediumCupSize); Console.WriteLine("Cost of ExpressWithCaramelMeduimCup {0}", expressWithCaramelMeduimCup); var expressWithCaramelAndDoubleShortSmallCup = decoratorPatternService.ExpressWithCaramelAndDoubleShort(smallCup); Console.WriteLine("Cost of ExpressWithCaramelAndDoubleShortSmallCup {0}", expressWithCaramelAndDoubleShortSmallCup); var expressWithCaramelAndDoubleShortMeduimCup = decoratorPatternService.ExpressWithCaramelAndDoubleShort(meduimCup, (int)CupsSize.mediumCupSize); Console.WriteLine("Cost of ExpressWithCaramelAndDoubleShortMeduimCup {0}", expressWithCaramelAndDoubleShortMeduimCup); var oberserPatternService = new ObseverPatternService(); for (int i = 1; i < 5; i++) { oberserPatternService.Execute(i); } var employee = new Employee(); employee.CreateEmployee(); employee.CalculateEmployeeBonus(); Console.ReadLine(); }
public CupsAndGallons(Cups cups) { CalcCupsAndGallons(cups.Value); }