public Question load(int id) { QuestionLoader questionLoader = new QuestionLoader(unswerManipalator, queryConfigurator); return(questionLoader.load(id)); }
private (Vector3 bot, int radius) LoadNanobots() { var input = QuestionLoader.Load(23).Split(Environment.NewLine); var maxRadius = int.MinValue; var maxBot = new Vector3(); foreach (var line in input) { var parts = line.Split(", "); var posData = parts[0].Substring(parts[0].IndexOf('<') + 1, parts[0].Length - 6).Split(',').Select(int.Parse).ToList(); var point = new Vector3(posData[0], posData[1], posData[2]); var radius = int.Parse(parts[1].Substring(2)); this._nanobots.Add(point, radius); if (radius > maxRadius) { maxRadius = radius; maxBot = point; } } return(maxBot, maxRadius); }
private IDictionary <char, Node> InitialiseNodes() { var nodes = new Dictionary <char, Node>(); foreach (var line in QuestionLoader.Load(7).Split(Environment.NewLine)) { var lineData = line.Split(' '); var source = lineData[1][0]; var target = lineData[7][0]; if (nodes.ContainsKey(target)) { nodes[target].IncomingNodes.Add(source); } else { var node = new Node(target); node.IncomingNodes.Add(source); nodes.Add(target, node); } if (!nodes.ContainsKey(source)) { nodes.Add(source, new Node(source)); } } return(nodes); }
private void LoadClay() { var data = QuestionLoader.Load(17).Split(Environment.NewLine); foreach (var line in data) { var parts = line.Split(", "); var range = parts[1].Substring(2).Split(".."); int startX, endX, startY, endY; if (parts[0][0] == 'x') { startX = int.Parse(parts[0].Substring(2)); endX = startX; startY = int.Parse(range[0]); endY = int.Parse(range[1]); } else { startY = int.Parse(parts[0].Substring(2)); endY = startY; startX = int.Parse(range[0]); endX = int.Parse(range[1]); } this.AddLine(startX, endX, startY, endY); } }
public Day6() { var pointData = QuestionLoader.Load(6).Split(Environment.NewLine); foreach (var pointStr in pointData) { var pointArray = pointStr.Split(", "); var point = new Point(int.Parse(pointArray[0]), int.Parse(pointArray[1])); if (point.X < this._minX) { this._minX = point.X; } if (point.X > this._maxX) { this._maxX = point.X; } if (point.Y < this._minY) { this._minY = point.Y; } if (point.Y > this._maxY) { this._maxY = point.Y; } this._points.Add(point); } }
private void InitialiseMap() { this._emptySquares.Clear(); this._people.Clear(); var lines = QuestionLoader.Load(15).Split(Environment.NewLine); for (byte y = 0; y < lines.Length; y++) { var line = lines[y]; for (byte x = 0; x < line.Length; x++) { var point = new Point(x, y); switch (line[x]) { case '.': this._emptySquares.Add(point); break; case 'G': this._people.Add(point, new Goblin()); this._emptySquares.Add(point); break; case 'E': this._people.Add(point, new Elf()); this._emptySquares.Add(point); break; } } } }
private void ReadProgram() { var lines = QuestionLoader.Load(21).Split(Environment.NewLine); this._program = new List <Instruction>(lines.Length); foreach (var line in lines) { var data = line.Split(' '); var opcode = data[0]; var a = int.Parse(data[1]); if (opcode == "#ip") { this._ip = (byte)a; } else { var b = int.Parse(data[2]); var c = int.Parse(data[3]); this._program.Add(new Instruction(opcode, a, b, c)); } } }
// Start is called before the first frame update void Awake() { qLoader = new QuestionLoader(); foreach (Question q in qLoader.questions) { Debug.Log(string.Format("Title: {0}, Text: {1}, player count: {2}", q.title, q.text, q.playerCount)); } }
protected override void DoPart1() { var examples = QuestionLoader.Load(16).Split(Environment.NewLine + Environment.NewLine); var numThreesomes = 0; foreach (var example in examples) { var data = example.Split(Environment.NewLine); var initialRegisters = data[0].Substring(9, 10).Split(',').Select(int.Parse).ToList(); var targetRegisters = data[2].Substring(9, 10).Split(',').Select(int.Parse).ToList(); var instData = data[1].Split(' '); var opCode = byte.Parse(instData[0]); var a = byte.Parse(instData[1]); var b = byte.Parse(instData[2]); var c = byte.Parse(instData[3]); var numMatches = 0; var currentMatches = new HashSet <string>(); foreach (var instructionEntry in Instructions) { var registers = new List <int>(initialRegisters); registers[c] = instructionEntry.Value(registers, a, b); if (!registers.SequenceEqual(targetRegisters)) { continue; } numMatches++; currentMatches.Add(instructionEntry.Key); } if (!this._possibleMatches.ContainsKey(opCode)) { this._possibleMatches.Add(opCode, currentMatches); } else { this._possibleMatches[opCode].IntersectWith(currentMatches); } if (numMatches >= 3) { numThreesomes++; } } ConsoleUtils.WriteColouredLine($"Got {numThreesomes} 3+ opcode examples", ConsoleColor.Cyan); }
/// COSTRUTTORE: carica dallo xml una lista di id e crea i livelli in base all'id public LivelliVM() { singleton = QuestionLoader.Instance; listaLiv = new ObservableCollection <Livello>(); /// assegna una lista di id di livelli int livelli = singleton.caricaLivelli(); /// oer ogni id nella lista caricata, crea un livello nuovo ed assegnalo al campo for (int i = 1; i < livelli + 1; i++) { listaLiv.Add(new Livello(i)); } }
void Start() { foreach (var topic in _topicList) { _topicToQuestion[topic] = new QuestionLoader($"Questions/{topic}"); } checkAnswerButton.onClick.AddListener(OnCheckAnswerClick); questionUiText.alignment = TextAlignmentOptions.Center; panel.SetActive(false); SetCurrentQuestions("Kinematics"); }
/// COSTRUTTORE: carica dallo xml una lista di id e crea i livelli in base all'id public LivelliVM() { ql = new QuestionLoader(); listaLiv = new ObservableCollection <Livello>(); /// assegna una lista di id di livelli int livelli = ql.caricaLivelli(); /// oer ogni id nella lista caricata, crea un livello nuovo ed assegnalo al campo for (int i = 1; i < livelli + 1; i++) { listaLiv.Add(new Livello(i)); } goToGame = new DelegateCommand(_goToGame); }
protected override void DoPart2() { var opcodeMap = new Dictionary <byte, string>(); while (this._possibleMatches.Any()) { var entry = this._possibleMatches.First(match => match.Value.Count == 1); var opcodeStr = entry.Value.Single(); opcodeMap.Add(entry.Key, opcodeStr); this._possibleMatches.Remove(entry.Key); foreach (var otherMatch in this._possibleMatches) { otherMatch.Value.Remove(opcodeStr); } } var program = QuestionLoader.Load(16, true).Split(Environment.NewLine); var registers = new List <int> { 0, 0, 0, 0 }; foreach (var line in program) { var instructionData = line.Split(' ').Select(byte.Parse).ToList(); var opInt = instructionData[0]; var a = instructionData[1]; var b = instructionData[2]; var c = instructionData[3]; var instruction = Instructions[opcodeMap[opInt]]; registers[c] = instruction(registers, a, b); } var colour = ConsoleColor.Cyan; if (registers[0] <= 144) { colour = ConsoleColor.Red; } ConsoleUtils.WriteColouredLine($"Register 0 has value {registers[0]}", colour); }
private void InitialiseTransforms() { var transformData = QuestionLoader.Load(12).Split(Environment.NewLine); foreach (var transform in transformData) { var node = this._transforms.Root; var transformParts = transform.Split(' '); foreach (var plant in transformParts[0]) { node = plant == '#' ? node.GetRight() : node.GetLeft(); } node.Value = transformParts[2] != "."; } }
public void SaveQuestionDataToFile(String path) { try { QuestionLoader.Save(path, questions); isDataDirty = false; view.ShowFileSavedSuccesfully(path); filePath = path; } catch (ArgumentException ex) { view.ShowError("Invalid question set: " + ex.Message); } catch (IOException ex) { view.ShowError("Problem while saving question set: " + ex.Message); } }
public static void Main(string[] args) { SetUpcontainerAndContext(); questionRepository = Container.GetInstance <IQuestionRepository>(); answerRepository = Container.GetInstance <IAnswerRepository>(); searchTermRepository = Container.GetInstance <ISearchTermRepository>(); Console.WriteLine("Mongo document samples manager"); var remove = false; CheckArgs(args, out remove); if (remove) { Console.WriteLine("Removing sample documents..."); var questionRemover = new QuestionRemover(questionRepository); questionRemover.Remove(); var answerRemover = new AnswerRemover(answerRepository); answerRemover.Remove(); var searchTermRemover = new SearchTermRemover(searchTermRepository); searchTermRemover.Remove(); } else { // TODO make the load dependent on an empty database to prevent duplicate id exceptions var questionLoader = new QuestionLoader(questionRepository); questionLoader.SetUpQuestions(); var answerLoader = new AnswerLoader(answerRepository, questionRepository); answerLoader.SetUpAnswers(); var searchTermLoader = new SearchTermLoader(searchTermRepository); searchTermLoader.SetUpSearchTerms(); } Console.WriteLine("finished, press any key to close..."); Console.ReadKey(); }
/// <summary> /// Loads exercise from specified file path. /// </summary> /// <param name="fileName">path to exercise</param> public void LoadExercise(string path) { try { List <Question> questions = QuestionLoader.Load(path); if (questions.Count == 0) { view.ShowError("Selected exercise is empty"); return; } view.NavigateToExercise(path, new Exercise(questions, DateTime.Now)); } catch (IOException ex) { view.ShowError(ex.Message); } catch (FileFormatException ex) { view.ShowError(ex.Message); } }
private static HashSet <SkyPoint> GetPoints() { var data = QuestionLoader.Load(10).Split(Environment.NewLine); var points = new HashSet <SkyPoint>(); foreach (var entry in data) { var point = entry.Substring(10, 14).Split(','); var vel = entry.Substring(36, 6).Split(','); var x = int.Parse(point[0].Trim()); var y = int.Parse(point[1].Trim()); var dx = int.Parse(vel[0].Trim()); var dy = int.Parse(vel[1].Trim()); points.Add(new SkyPoint(x, y, dx, dy)); } return(points); }
private void LoadConstellations() { var points = QuestionLoader.Load(25).Split(Environment.NewLine); foreach (var point in points) { var coordinates = point.Split(',').Select(float.Parse).ToList(); var star = new Vector4(coordinates[0], coordinates[1], coordinates[2], coordinates[3]); var otherConstellations = this.LoadNeighbouringConstellations(star); if (otherConstellations.Any()) { this._constellations.RemoveWhere(otherConstellations.Contains); var newConstellation = new List <Vector4>(); foreach (var constellation in otherConstellations) { newConstellation.AddRange(constellation); } newConstellation.Add(star); this._constellations.Add(newConstellation); } else { var constellation = new List <Vector4> { star }; this._constellations.Add(constellation); } } }
private void LoadLandscape() { var data = QuestionLoader.Load(18).Split(Environment.NewLine); for (var y = 0; y < data.Length; y++) { var line = data[y]; for (var x = 0; x < line.Length; x++) { var p = new Point(x, y); Acre feature; switch (line[x]) { case '.': feature = Acre.Open; break; case '#': feature = Acre.Lumberyard; break; case '|': feature = Acre.Trees; break; default: throw new ArgumentOutOfRangeException(); } this._landscape.Add(p, feature); } } }
public Day1() { this._steps = QuestionLoader.Load(1).Split(Environment.NewLine).Select(int.Parse).ToList(); }
public Day2() { this._ids = QuestionLoader.Load(2).Split(Environment.NewLine).ToList(); }
public Day4() { this._logs = QuestionLoader.Load(4).Split(Environment.NewLine).OrderBy(l => l).ToList(); this._guards = new Dictionary <int, Guard>(); }
private void StartQuiz(object obj) { QuestionService = new QuestionLoader(NumberOfQuestions); questions = QuestionService.LoadQuestions(Include901, Include902, Include1001, Include1002); ParentWindow.LoadQuestionVM(questions); }
private void LoadArmies() { this._immuneSystem.Clear(); this._infection.Clear(); var questionData = QuestionLoader.Load(24).Split(Environment.NewLine + Environment.NewLine); var regexWithImmunity = new Regex("^([0-9]+) units each with ([0-9]+) hit points ((.*) )with an attack that does ([0-9]+) ([a-z]+) damage at initiative ([0-9]+)$"); var regexWithoutImmunity = new Regex("^([0-9]+) units each with ([0-9]+) hit points with an attack that does ([0-9]+) ([a-z]+) damage at initiative ([0-9]+)$"); foreach (var armyData in questionData) { var armies = armyData.Split(Environment.NewLine).ToList(); var armySet = armies[0] == "Immune System:" ? this._immuneSystem : this._infection; armies.RemoveAt(0); var armyNum = 1; foreach (var armyLine in armies) { var matches = regexWithImmunity.Match(armyLine); if (matches.Length == 0) { matches = regexWithoutImmunity.Match(armyLine); } var army = new Army { NumUnits = int.Parse(matches.Groups[1].Value), HitPoints = int.Parse(matches.Groups[2].Value), ArmyNum = armyNum++, IsInfection = armySet == this._infection }; if (matches.Groups.Count == 8) { var immunityData = matches.Groups[3].Value; immunityData = immunityData.Substring(1, immunityData.Length - 3); var immunityParts = immunityData.Split("; ").ToList(); foreach (var immunityPart in immunityParts) { var immunities = immunityPart.Split(' ').ToList(); var immunitySet = immunities[0] == "immune" ? army.Immunities : army.Weaknesses; immunities.RemoveAt(0); immunities.RemoveAt(0); foreach (var immunity in immunities) { immunitySet.Add(immunity.EndsWith(',') ? Enum.Parse <AttackType>( StringUtils.UpperFirst(immunity.Substring(0, immunity.Length - 1))) : Enum.Parse <AttackType>(StringUtils.UpperFirst(immunity))); } } army.AttackPower = int.Parse(matches.Groups[5].Value); army.AttackType = Enum.Parse <AttackType>(StringUtils.UpperFirst(matches.Groups[6].Value)); army.Initiative = int.Parse(matches.Groups[7].Value); } else { army.AttackPower = int.Parse(matches.Groups[3].Value); army.AttackType = Enum.Parse <AttackType>(StringUtils.UpperFirst(matches.Groups[4].Value)); army.Initiative = int.Parse(matches.Groups[5].Value); } armySet.Add(army); } } }
public Day3() { this._claims = QuestionLoader.Load(3).Split(Environment.NewLine); }
private List <Cart> InitialiseMapAndCarts() { var lines = QuestionLoader.Load(13).Split(Environment.NewLine); var carts = new List <Cart>(); for (var y = 0; y < lines.Length; y++) { var line = lines[y]; char?lastPiece = null; for (var x = 0; x < line.Length; x++) { if (!this._map.ContainsKey(x)) { this._map.Add(x, new Dictionary <int, MapFeature>()); } var mapPiece = line[x]; var curPos = new Point(x, y); switch (mapPiece) { case '/': if (lastPiece.HasValue && (lastPiece == '-' || lastPiece == '+' || lastPiece == '/' || lastPiece == '\\')) { this._map[x].Add(y, new Corner { Left = true, Top = true }); } else { this._map[x].Add(y, new Corner { Right = true, Bottom = true }); } break; case '\\': if (lastPiece.HasValue && (lastPiece == '-' || lastPiece == '+' || lastPiece == '/' || lastPiece == '\\')) { this._map[x].Add(y, new Corner { Left = true, Bottom = true }); } else { this._map[x].Add(y, new Corner { Right = true, Top = true }); } break; case '+': this._map[x].Add(y, new Intersection()); break; case '^': carts.Add(new Cart(curPos, new Point(0, -1))); break; case 'v': carts.Add(new Cart(curPos, new Point(0, 1))); break; case '>': carts.Add(new Cart(curPos, new Point(1, 0))); break; case '<': carts.Add(new Cart(curPos, new Point(-1, 0))); break; } lastPiece = mapPiece; } } return(carts); }