public int ModifLikeProduit(List<string> aData) { DataSet DsJson = new DataSet(); MyCo NewCo = new MyCo(); NewCo.UpdateLikeProduit(aData.IndexOf(aData.Last()).ToString(),aData.Last(),ref DsJson); return aData.IndexOf(aData.Last()); }
public static long Jump(Dictionary<int, List<int>> cluspos, long currentpos, List<int> peaks, int[] peakclus, ref int nextvalue, ref int currentposs) { long startpos = currentpos / 2; int pos = (int)startpos / 512; if (nextvalue < peaks[currentposs]) nextvalue = peaks[currentposs]; if(nextvalue - pos > 0) { if(nextvalue - pos < 50)//pretty close { pos = nextvalue; } } else { currentposs++; } int index = peaks.IndexOf(pos); if (index != -1) { index = peakclus[index]; Random r = new Random(); if (r.Next(0, 100) > 25)//25% jump { int random = r.Next(0, cluspos[index].Count); int loc = cluspos[index][random]; currentposs = peaks.IndexOf(loc); return (long)(loc * 512 * 2); } } return currentpos; }
public static List<Scraper> GetScrapers(bool allowIgnored = false) { loadScrapers(); List<string> scraperPriorities = new List<string>(EmulatorsCore.Options.ReadOption(o => o.ScraperPriorities).Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); List<string> ignoredScraperIds = new List<string>(); if (!allowIgnored) { ignoredScraperIds.AddRange(EmulatorsCore.Options.ReadOption(o => o.IgnoredScrapers).Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); } List<Scraper> scrapers = new List<Scraper>(); foreach (Scraper scraper in allScrapers) { if (allowIgnored || !ignoredScraperIds.Contains(scraper.IdString)) { if (!scraperPriorities.Contains(scraper.IdString)) scraperPriorities.Add(scraper.IdString); scrapers.Add(scraper); } } scrapers.Sort((Scraper s, Scraper t) => { return scraperPriorities.IndexOf(s.IdString).CompareTo(scraperPriorities.IndexOf(t.IdString)); }); return scrapers; }
public bool IsValid(string s) { List<char> lefts = new List<char>() { '(', '[', '{' }; List<char> rights = new List<char>() { ')', ']', '}' }; Stack<char> charStack = new Stack<char>(); foreach (char c in s) { if (lefts.IndexOf(c) > -1) { charStack.Push(c); } else { if (charStack.Count == 0) { return false; } char pop = charStack.Pop(); if (lefts.IndexOf(pop) == rights.IndexOf(c)) { continue; } return false; } } if (charStack.Count != 0) return false; return true; }
public List<float> AssignWidthToPoints(List<Vertex> path, float minWidth) { List<float> sumOfPointNeighb = new List<float>(); float totalSum = 0; float maxSum = 0; foreach (Vertex v in path) { sumOfPointNeighb.Add(ftm.GetSumFromNeighbourhood(v.x, v.z, 2 * (int)minWidth)); totalSum += sumOfPointNeighb[path.IndexOf(v)]; if(sumOfPointNeighb[path.IndexOf(v)] > maxSum){ maxSum = sumOfPointNeighb[path.IndexOf(v)]; } } float averageSum = totalSum / sumOfPointNeighb.Count; List<float> finalWidthValues = new List<float>(); //Debug.Log("-------------"); foreach (float f in sumOfPointNeighb) { float value = minWidth + minWidth/2 * (maxSum - f) / maxSum; finalWidthValues.Add(value); //Debug.Log(value); //finalWidthValues.Add(minWidth); } return finalWidthValues; }
public static void Main() { List <int> ll = new List<int>(); string t1; int idx1; int idx2; int ent1; int ent2; for(int i = 1; i <= 10; i++) { ll.Add(i); } foreach(int i in ll) Console.Write("{0} ", i); Console.WriteLine(); while(true) { t1 = Console.ReadLine(); if(t1 == "-999") break; string[] t2 = t1.Split(' '); ent1 = Convert.ToInt32(t2[0]); ent2 = Convert.ToInt32(t2[1]); idx1 = ll.IndexOf(ent1); idx2 = ll.IndexOf(ent2); ll.RemoveAt(idx1); ll.Insert(idx1, ent2); ll.RemoveAt(idx2); ll.Insert(idx2, ent1); foreach(int i in ll) Console.Write("{0} ", i); Console.WriteLine(); } }
//Plays an animation from a given list of Texture2D's public void Animate(List<Texture2D> textures, float time, float animationRate) { //Keep track of the elapsed time if (animationTime == null) { animationTime = time; } else { animationTime += time; } //The given animation rate determines when we switch to the next texture in the list if (animationTime > animationRate / textures.Count) { //Switch to the next texture in the list, or the first texture if we're at the end. if (textures.IndexOf(texture) < textures.Count - 1) { texture = textures[textures.IndexOf(texture) + 1]; } else { texture = textures[0]; } //Reset the elapsed time animationTime = 0; } }
public static List<Notices> GetAllNotices(string link) { string htmlPage = ""; List<string> NoticeTitles = new List<string>(); List<string> NoticeDates = new List<string>(); List<string> NoticeUrl = new List<string>(); List<Notices> Notices = new List<Notices>(); using(var client = new WebClient()) { Uri weblink = new Uri(link, UriKind.Absolute); htmlPage = client.DownloadString(weblink); } NoticeTitles = PatternHelper.GetNoticeTitle(htmlPage); NoticeDates = PatternHelper.GetNoticeDate(htmlPage); NoticeUrl = PatternHelper.GetNoticeLink(htmlPage); foreach(var item in NoticeTitles) { Notices.Add(new Notices { Title = item, Date = NoticeDates[NoticeTitles.IndexOf(item)], Url = NoticeUrl[NoticeTitles.IndexOf(item)] }); } return Notices; }
internal static List<Block> CheckPostImport(List<Block> ret) { if (ret == null) return null; var lastImport = ret.LastOrDefault(r => r is Model.Import); var firstNonImport = ret.FirstOrDefault(r => !(r is Model.Import)); if (lastImport == null || firstNonImport == null) { return ret; } var lix = ret.IndexOf(lastImport); var fnix = ret.IndexOf(firstNonImport); if (lix != -1 && fnix != -1) { if (fnix < lix) { for (int i = fnix; i < ret.Count; i++) { if (ret[i] is Model.Import) { Current.RecordWarning(ErrorType.Parser, ret[i], "@import should appear before any other statements. Statement will be moved."); } } } } return ret; }
static void Main() { Console.WriteLine("Enter some text to see how many times each word appears:"); string text = Console.ReadLine(); string[] textSplitted = text.Split(',', ' '); List<string> words = new List<string>(); List<int> counter = new List<int>(); for (int i = 0; i < textSplitted.Length; i++) { string currentWord = textSplitted[i]; if (currentWord != "") { if (words.IndexOf(currentWord) == -1) { words.Add(currentWord); counter.Add(1); } else { int index = words.IndexOf(currentWord); counter[index]++; } } } Console.WriteLine("Letters : Appearances"); for (int i = 0; i < words.Count; i++) { Console.WriteLine("{0} - {1}", words[i], counter[i]); } }
static void Main() { Console.WriteLine("Enter some text to see how many times each letter appears:"); string text = Console.ReadLine(); List<char> letters = new List<char>(); List<int> counter = new List<int>(); for (int i = 0; i < text.Length; i++) { char currentLetter = text[i]; if (currentLetter != ' ') { if (letters.IndexOf(currentLetter) == -1) { letters.Add(currentLetter); counter.Add(1); } else { int index = letters.IndexOf(currentLetter); counter[index]++; } } } Console.WriteLine("Letters : Appearances"); for (int i = 0; i < letters.Count; i++) { Console.WriteLine("{0} - {1}", letters[i], counter[i]); } }
static void Main() { string number = Console.ReadLine(); List<string> digits = new List<string>(); for (char i = 'A'; i <= 'Z'; i++) digits.Add(i.ToString()); for (char i = 'a'; i <= 'f'; i++) for (char j = 'A'; j <= 'Z'; j++) digits.Add(i.ToString() + j.ToString()); if (number.Length == 1) { Console.WriteLine(digits.IndexOf(number[0].ToString())); return; } long result = 0, pow = 0; for (int i = number.Length - 1; i >= 0; i--) { // Example with number aFG... string left = number[i - 1].ToString(); // Found: F string right = number[i].ToString(); // Found: G if (i - 2 >= 0 && char.IsLower(number[i - 2])) // Check: aFG { left = number[i - 2] + "" + number[i - 1]; // Correct numbers: aF and G i--; } int index = digits.IndexOf(left + right); // Finds only numbers from type aF, bG, pL, etc... if (index != -1) { // Found one number result += index * (long)Math.Pow(168, pow++); } else { // There are two numbers, example: FG => calculates its values result += digits.IndexOf(right) * (long)Math.Pow(168, pow++) + digits.IndexOf(left) * (long)Math.Pow(168, pow++); } i--; if (i - 1 == 0) { // Only one number left result += digits.IndexOf(number[0].ToString()) * (long)Math.Pow(168, pow); break; } } Console.WriteLine(result); }
public EditCustomerInformationModel(Customer customer, IEnumerable<Country> countries) { Firstname = customer.Firstname; Lastname = customer.Lastname; Email = customer.Email; //Birthday = customer.Birthday ?? DateTime.MinValue; SelectedGenderType = (int) customer.Gender; AvailableCountries = countries.Select(x => new SelectListItem { Selected = x.Name.Trim() == customer.Country.Trim(), Text = x.Name.Trim(), Value = x.Name.Trim() }).ToList(); AvailableCountries.Insert(0, new SelectListItem { Selected = false, Text = "I'd rather not say", Value = string.Empty }); Genders = new List<SelectListItem>(); Genders.Add(new SelectListItem { Selected = false, Text = "I'd rather not say", Value = "0" }); Genders.Add(new SelectListItem { Selected = false, Text = GenderTypeEnum.Male.ToString(), Value = ((int)GenderTypeEnum.Male).ToString() }); Genders.Add(new SelectListItem { Selected = false, Text = GenderTypeEnum.Female.ToString(), Value = ((int)GenderTypeEnum.Female).ToString() }); SelectedBirthDate = (customer.Birthday.HasValue) ? customer.Birthday.Value.Day : 0; SelectedBirthMonth = (customer.Birthday.HasValue) ? customer.Birthday.Value.Month : 0; SelectedBirthYear = (customer.Birthday.HasValue) ? customer.Birthday.Value.Year : 1970; BirthDate = new List<SelectListItem>{ new SelectListItem { Selected = false, Text = "Day", Value = "0" } }; BirthDate.AddRange(Enumerable.Range(1, 31).Select(x => new SelectListItem { Selected = x == SelectedBirthDate, Text = x.ToString(), Value = x.ToString() }).ToList()); var months = new List<string> { "Month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; BirthMonth = new List<SelectListItem>(); months.ForEach(x => BirthMonth.Add(new SelectListItem { Selected = months.IndexOf(x) == SelectedBirthMonth, Text = x, Value = months.IndexOf(x).ToString() })); }
public void HandleInput(List<Keys> input) { if (input.IndexOf(Keys.Left) > -1) { MoveLeftIfPossible(); } if (input.IndexOf(Keys.Right) > -1) { MoveRightIfPossible(); } if (input.IndexOf(Keys.PageDown) > -1) { field.RotateBlockRight(); } if (input.IndexOf(Keys.PageUp) > -1) { field.RotateBlockLeft(); } if (input.IndexOf(Keys.Space) > -1) { field.FixBlock(); } }
void Start() { if (instance != null) throw new Exception("Error: multiple LocationGraphs present"); instance = this; locations = new List<Location>(); Component[] components = this.gameObject.GetComponents(typeof(Edge)); Edge[] edges = new Edge[components.Length]; for (int i = 0; i < components.Length; i++) { edges[i] = (Edge) components[i]; if (!locations.Contains(edges[i].one)) locations.Add(edges[i].one); if (!locations.Contains(edges[i].two)) locations.Add(edges[i].two); } graph = new bool[locations.Count, locations.Count]; for (int i = 0; i < graph.GetLength(0); i++) { for (int j = 0; j < graph.GetLength(1); j++) { graph[i,j] = inverse; } } foreach (Edge edge in edges) { int indexOne = locations.IndexOf(edge.one); int indexTwo = locations.IndexOf(edge.two); graph[indexOne, indexTwo] = !inverse; graph[indexTwo, indexOne] = !inverse; } }
static void ComputeDistinctStrands(string[] strands, ref int cDistinctStrands, ref string concatenatedDistinctStrands, ref int[] permuation) { List<string> distinct = new List<string>(); foreach (string strand in strands) { if (distinct.IndexOf(strand) < 0) distinct.Add(strand); } // StringBuilder builder = new StringBuilder(); foreach (string s in distinct) { if (builder.Length > 0) builder.Append('+'); builder.Append(s); } concatenatedDistinctStrands = builder.ToString(); cDistinctStrands = distinct.Count; // permuation = new int[strands.Length]; for (int i = 0; i < strands.Length; i++) { permuation[i] = distinct.IndexOf(strands[i]) + 1; } }
public void HandleInput(List<Keys> input) { if (input.IndexOf(Keys.Left) > -1) { MoveLeftIfPossible(); } if (input.IndexOf(Keys.Right) > -1) { MoveRightIfPossible(); } if (input.IndexOf(Keys.Space) > -1) { field.FixBlock(); } if (input.IndexOf(Keys.A) > -1) { currentBlock.RotateLeft(); } if (input.IndexOf(Keys.D) > -1) { currentBlock.RotateRight(); } }
static void Main() { Console.WriteLine("Enter a word:"); string word = Console.ReadLine(); List<string> words = new List<string> { ".NET", "CLR", "namespace" }; List<string> explanations = new List<string> { "platform for applications from Microsoft", "managed execution environment for .NET", "hierarchical organization of classes" }; if (words.IndexOf(word) != -1) { Console.WriteLine("{0} - {1}", word, explanations[words.IndexOf(word)]); } else { Console.WriteLine("Sorry, but there is no description of this word!"); } }
public void Update(List<Hearthstone.Card> cards, bool reset) { try { if(reset) { _animatedCards.Clear(); ItemsControl.Items.Clear(); } var newCards = new List<Hearthstone.Card>(); foreach(var card in cards) { var existing = _animatedCards.FirstOrDefault(x => AreEqualForList(x.Card, card)); if(existing == null) newCards.Add(card); else if(existing.Card.Count != card.Count || existing.Card.HighlightInHand != card.HighlightInHand) { var highlight = existing.Card.Count != card.Count; existing.Card.Count = card.Count; existing.Card.HighlightInHand = card.HighlightInHand; existing.Update(highlight).Forget(); } else if(existing.Card.IsCreated != card.IsCreated) existing.Update(false).Forget(); } var toUpdate = new List<AnimatedCard>(); foreach(var aCard in _animatedCards) { if(!cards.Any(x => AreEqualForList(x, aCard.Card))) toUpdate.Add(aCard); } var toRemove = new List<Tuple<AnimatedCard, bool>>(); foreach(var card in toUpdate) { var newCard = newCards.FirstOrDefault(x => x.Id == card.Card.Id); toRemove.Add(new Tuple<AnimatedCard, bool>(card, newCard == null)); if(newCard != null) { var newAnimated = new AnimatedCard(newCard); _animatedCards.Insert(_animatedCards.IndexOf(card), newAnimated); ItemsControl.Items.Insert(_animatedCards.IndexOf(card), newAnimated); newAnimated.Update(true).Forget(); newCards.Remove(newCard); } } foreach(var card in toRemove) RemoveCard(card.Item1, card.Item2); foreach(var card in newCards) { var newCard = new AnimatedCard(card); _animatedCards.Insert(cards.IndexOf(card), newCard); ItemsControl.Items.Insert(cards.IndexOf(card), newCard); newCard.FadeIn(!reset).Forget(); } } catch(Exception e) { Log.Error(e); } }
//We currently don't clean White Text, Small Text, Hidden Columns, Rows private List<ContentType> RemoveUnsupportedElements(List<ContentType> elementsToClean) { int index = elementsToClean.IndexOf(ContentType.WhiteText); if (index != -1) { elementsToClean.Remove(elementsToClean[index]); } index = elementsToClean.IndexOf(ContentType.SmallText); if (index != -1) { elementsToClean.Remove(elementsToClean[index]); } index = elementsToClean.IndexOf(ContentType.HiddenColumn); if (index != -1) { elementsToClean.Remove(elementsToClean[index]); } index = elementsToClean.IndexOf(ContentType.HiddenRow); if (index != -1) { elementsToClean.Remove(elementsToClean[index]); } index = elementsToClean.IndexOf(ContentType.HiddenSheet); if (index != -1) { elementsToClean.Remove(elementsToClean[index]); } return elementsToClean; }
List<byte> CreateInputBytes(List<byte> messageBytes) { var bytes = new List<byte>(); var previousByte = new byte(); messageBytes.RemoveRange(0, messageBytes.IndexOf(0x7E) + 1); messageBytes.RemoveRange(messageBytes.IndexOf(0x3E), messageBytes.Count - messageBytes.IndexOf(0x3E)); foreach (var b in messageBytes) { if ((b == 0x7D) || (b == 0x3D)) { previousByte = b; continue; } if (previousByte == 0x7D) { previousByte = new byte(); if (b == 0x5E) { bytes.Add(0x7E); continue; } if (b == 0x5D) { bytes.Add(0x7D); continue; } } if (previousByte == 0x3D) { previousByte = new byte(); if (b == 0x1E) { bytes.Add(0x3E); continue; } if (b == 0x1D) { bytes.Add(0x3D); continue; } } bytes.Add(b); } return bytes; }
/// <summary> /// Tries to implement the Get [] semantics, but it cuts corners like crazy. /// Specifically, it relies on the knowledge that the only Gets used are /// keyed on PrincipalID, Email, and FirstName+LastName. /// </summary> /// <param name="fields"></param> /// <param name="values"></param> /// <returns></returns> public UserAccountData[] Get(string[] fields, string[] values) { List<string> fieldsLst = new List<string>(fields); if (fieldsLst.Contains("PrincipalID")) { int i = fieldsLst.IndexOf("PrincipalID"); UUID id = UUID.Zero; if (UUID.TryParse(values[i], out id)) if (m_DataByUUID.ContainsKey(id)) return new UserAccountData[] { m_DataByUUID[id] }; } if (fieldsLst.Contains("FirstName") && fieldsLst.Contains("LastName")) { int findex = fieldsLst.IndexOf("FirstName"); int lindex = fieldsLst.IndexOf("LastName"); if (m_DataByName.ContainsKey(values[findex] + " " + values[lindex])) return new UserAccountData[] { m_DataByName[values[findex] + " " + values[lindex]] }; } if (fieldsLst.Contains("Email")) { int i = fieldsLst.IndexOf("Email"); if (m_DataByEmail.ContainsKey(values[i])) return new UserAccountData[] { m_DataByEmail[values[i]] }; } // Fail return new UserAccountData[0]; }
public void HandleInput(List<Keys> input) { if (input.IndexOf(Keys.Left) > -1) { field.Move(Movement.Left); } if (input.IndexOf(Keys.Right) > -1) { field.Move(Movement.Right); } if (input.IndexOf(Keys.Space) > -1) { //field.FixBlock(); } if (input.IndexOf(Keys.PageDown) > -1) { field.Move(Movement.RotateClockwise); } if (input.IndexOf(Keys.Delete) > -1) { field.Move(Movement.RotateCounterClockwise); } }
//public PlayerSprite testRemotePlayer = new PlayerSprite(); public GameContentManager(string localPlayer, List<string> allPlayers, BomberGame game) { Game = game; isGameEnded = false; Sprites = new List<Sprite>(); RemotePlayers = new List<PlayerSprite>(); LocalPlayer = new PlayerSprite(); LocalPlayer.GameContentManager = this; LocalPlayer.PlayerID = localPlayer; int localPlayerNumber = allPlayers.IndexOf(localPlayer); LocalPlayer.PlayerIndex = localPlayerNumber; LocalPlayer.Controller = new PlayerController(); LocalPlayer.Controller.Player = LocalPlayer; Sprites.Add(LocalPlayer); foreach (string s in allPlayers) { if (s != localPlayer) { PlayerSprite player = new PlayerSprite(); player.GameContentManager = this; player.PlayerID = s; int playerNumber = allPlayers.IndexOf(s); player.PlayerIndex = playerNumber; Sprites.Add(player); RemotePlayers.Add(player); } } }
public int ambiguous(string[] dictionary) { List<string> list = new List<string>(); List<int> count = new List<int>(); int res = 0; for (int a = 0; a < dictionary.Length; a++) { if (!list.Contains(dictionary[a])) { list.Add(dictionary[a]); count.Add(1); } else count[list.IndexOf(dictionary[a])]++; for (int b = 0; b < dictionary.Length; b++) { string temp = dictionary[a] + dictionary[b]; if (a == b) continue; if (!list.Contains(temp)) { list.Add(temp); count.Add(1); } else count[list.IndexOf(temp)]++; } } for (int c = 0; c < count.Count; c++) { if (count[c] > 1) res++; } return res; }
static bool count(int currentSum, int targetSum, int amountNums, int currentNumber, int prevNumber, List<int> subSetSum0, List<int> set, bool isFristPass) { if (currentSum + currentNumber == targetSum) { set[set.IndexOf(currentNumber)] = 0; subSetSum0.Add(currentNumber); return true; } else { for (int i = amountNums; i > 0; i--) { if (count(currentSum + currentNumber, targetSum, i - 1, set[i - 1], currentNumber, subSetSum0, set, false) == true) { try { set[set.IndexOf(currentNumber)] = 0; } catch (ArgumentOutOfRangeException) { return false; } subSetSum0.Add(currentNumber); if (isFristPass == false) return true; } } } return false; }
public static void Main (string[] args) { var list = new List<Enum1> { Enum1.Value0, Enum1.Value1, Enum1.Value0, (Enum1)3 }; Console.WriteLine(list.IndexOf(Enum1.Value0)); Console.WriteLine(list.IndexOf(Enum1.Value1)); Console.WriteLine(list.IndexOf((Enum1)2)); // Other overloads not implemented yet }
static void Main(string[] args) { string text = Console.ReadLine(); List<string> letters = new List<string>(); for (char i = 'A'; i <= 'Z'; i++) { letters.Add(i.ToString()); } for (char j = 'a'; j <= 'f'; j++) { for (char i = 'A'; i <= 'Z'; i++) { letters.Add(j.ToString() + i); } } int power = 0; BigInteger result = 0; string concatenation = ""; int index = 0; for (int i = text.Length - 1; i >= 0; i--) { if (i > 0) { if (char.IsUpper(text[i]) && char.IsLower(text[i - 1])) { concatenation = text[i - 1].ToString() + text[i]; index = letters.IndexOf(concatenation); if (index >= 0) { result = Power(power) * index + result; power++; concatenation = ""; i--; } } else { index = letters.IndexOf(text[i].ToString()); result = Power(power) * index + result; power++; } } else if (i == 0) { index = letters.IndexOf(text[i].ToString()); result = Power(power) * index + result; power++; } } Console.WriteLine(result); }
public int GetGameScore(List<Frame> frames) { AddTwoSinteticRolls(frames); var gameFrames = frames.Take(10).ToList(); var simpeRollsSum = gameFrames.Where(frame => frame.IsSimple).Sum(frame => frame.FrameSum); var spareRollsSum = gameFrames.Where(frame => frame.IsSpare).Sum(frame => frame.FrameSum + frames[frames.IndexOf(frame) + 1].FirstRoll); var strikeRollsSum = gameFrames.Where(frame => frame.IsStrike).SelectMany(frame => frames.Skip(frames.IndexOf(frame)).Take(3)).Sum(frame => frame.FrameSum); return simpeRollsSum + spareRollsSum + strikeRollsSum; }
private static void AddResult(List<int> numbers, List<int> result, int i) { if (numbers.IndexOf(i) > -1) { result.Add(i); numbers.RemoveRange(0, numbers.IndexOf(i) + 1); AddResult(numbers, result, i); } }