/// <summary> /// /// </summary> /// <param name="writer"></param> public void Serialize(BinaryWriter writer) { writer.Write(VertexCount); writer.Write(Vertices.ToArray()); writer.Write(TriangleCount); writer.Write(Triangles.ToArray()); writer.Write(Subsets.Count); writer.Write(Subsets.ToArray()); }
public void Compute4_1() { var result = Subsets.Compute(4, 1).ToArray(); Assert.That(result.Length, Is.EqualTo(4)); Assert.That(result[0], Is.EquivalentTo(new[] { 0 })); Assert.That(result[1], Is.EquivalentTo(new[] { 1 })); Assert.That(result[2], Is.EquivalentTo(new[] { 2 })); Assert.That(result[3], Is.EquivalentTo(new[] { 3 })); }
public void Compute4_3() { var result = Subsets.Compute(4, 3).ToArray(); Assert.That(result.Length, Is.EqualTo(4)); Assert.That(result[0], Is.EquivalentTo(new[] { 0, 1, 2 })); Assert.That(result[1], Is.EquivalentTo(new[] { 0, 1, 3 })); Assert.That(result[2], Is.EquivalentTo(new[] { 0, 2, 3 })); Assert.That(result[3], Is.EquivalentTo(new[] { 1, 2, 3 })); }
public void Compute5_4() { var result = Subsets.Compute(5, 4).ToArray(); Assert.That(result.Length, Is.EqualTo(5)); Assert.That(result[0], Is.EquivalentTo(new[] { 0, 1, 2, 3 })); Assert.That(result[1], Is.EquivalentTo(new[] { 0, 1, 2, 4 })); Assert.That(result[2], Is.EquivalentTo(new[] { 0, 1, 3, 4 })); Assert.That(result[3], Is.EquivalentTo(new[] { 0, 2, 3, 4 })); Assert.That(result[4], Is.EquivalentTo(new[] { 1, 2, 3, 4 })); }
public void Compute5_1() { var result = Subsets.Compute(5, 1).ToArray(); Assert.That(result.Length, Is.EqualTo(5)); var i = 0; Assert.That(result[i++], Is.EquivalentTo(new[] { 0 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 1 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 2 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 3 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 4 })); }
static void Main(string[] args) { Console.WriteLine("Binary Search: Bitonic Array Maximum"); Console.WriteLine(FindMax(new int[] { 1, 3, 8, 12, 4, 2 })); Console.WriteLine(FindMax(new int[] { 3, 8, 3, 1 })); Console.WriteLine(FindMax(new int[] { 1, 3, 8, 12 })); Console.WriteLine(FindMax(new int[] { 10, 9, 8 })); Console.WriteLine("\nTwo Pointers: Pair with Target Sum"); int[] result = Search(new int[] { 1, 2, 3, 4, 6 }, 6); Console.WriteLine("Pair with target sum: [" + result[0] + ", " + result[1] + "]"); result = Search(new int[] { 2, 5, 9, 11 }, 11); Console.WriteLine("Pair with target sum: [" + result[0] + ", " + result[1] + "]"); Console.WriteLine("\n‘K’ Closest Points to the Origin"); Point[] points = new Point[] { new Point(1, 3), new Point(3, 4), new Point(2, -1), new Point(1, -1), new Point(-1, -1) }; List <Point> result2 = FindClosestPoints(points, 2); Console.WriteLine("Here are the k points closest the origin: "); foreach (Point p in result2) { Console.WriteLine("[" + p.x + " , " + p.y + "] "); } Console.WriteLine("\n‘K’ Closest Points to the Origin(0,0)"); Point result3 = ClosestToOrigin(points, 2); Console.WriteLine("[" + result3.x + " , " + result3.y + "] "); Console.WriteLine("\n Subsets"); List <List <int> > result4 = Subsets.FindSubsets(new int[] { 1, 3 }); Console.WriteLine("Here is the list of subsets: " + Subsets.ToString(result4)); result4 = Subsets.FindSubsets(new int[] { 1, 5, 3 }); Console.WriteLine("Here is the list of subsets: " + Subsets.ToString(result4)); Console.WriteLine("\n Binary Tree Path Sum"); TreeNode root = new TreeNode(12); root.left = new TreeNode(7); root.right = new TreeNode(1); root.left.left = new TreeNode(9); root.right.left = new TreeNode(10); root.right.right = new TreeNode(5); Console.WriteLine("Tree has path: " + TreePathSum.hasPath(root, 23)); Console.WriteLine("Tree has path: " + TreePathSum.hasPath(root, 16)); Console.ReadKey(); }
bool _CompareElement(Subsets Src1, Subsets Src2) { if (Src1.Length() != Src2.Length()) { return(false); } if (Src1.numList[0] != Src2.numList[0]) { return(false); } if (Src1.numList[1] != Src2.numList[1]) { return(false); } if (Src1.numList[2] != Src2.numList[2]) { return(false); } if (Src1.Length() > 3) { if (Src1.numList[3] != Src2.numList[3]) { return(false); } if (Src1.Length() > 4) { if (Src1.numList[4] != Src2.numList[4]) { return(false); } if (Src1.Length() > 5) { if (Src1.numList[5] != Src2.numList[5]) { return(false); } } } } return(true); }
public List <List <Verse> > Find(int number_of_verses, int number_of_words) { m_subsets = new List <List <Verse> >(); long[] verse_word_counts = new long[m_items.Count]; for (int i = 0; i < m_items.Count; i++) { verse_word_counts[i] = m_items[i].Words.Count; } Subsets subsets = new Subsets(verse_word_counts); subsets.Find(number_of_verses, number_of_words, OnFound); return(m_subsets); }
public List <List <Chapter> > Find(int number_of_chapters, int number_of_verses) { m_subsets = new List <List <Chapter> >(); long[] chapter_verse_counts = new long[m_items.Count]; for (int i = 0; i < m_items.Count; i++) { chapter_verse_counts[i] = m_items[i].Verses.Count; } Subsets subsets = new Subsets(chapter_verse_counts); subsets.Find(number_of_chapters, number_of_verses, OnFound); return(m_subsets); }
private Subset CreateSubset(List <State> statesList) { foreach (Subset item in Subsets) { if (!item.States.Except(statesList).Any()) { findState = true; return(item); } } Subset subset = new Subset("S" + indexState, statesList.OrderBy(or => or.StateName).ToList()); Subsets.Add(subset); indexState++; findState = false; return(subset); }
public void Compute5_2() { var result = Subsets.Compute(5, 2).ToArray(); Assert.That(result.Length, Is.EqualTo(10)); var i = 0; Assert.That(result[i++], Is.EquivalentTo(new[] { 0, 1 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 0, 2 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 0, 3 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 0, 4 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 1, 2 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 1, 3 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 1, 4 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 2, 3 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 2, 4 })); Assert.That(result[i++], Is.EquivalentTo(new[] { 3, 4 })); }
public ModelSection(CacheBase Cache, int Address) { EndianReader Reader = Cache.Reader; Reader.SeekTo(Address); #region Submesh Block int iCount = Reader.ReadInt32(); int iOffset = Reader.ReadInt32() - Cache.Magic; for (int i = 0; i < iCount; i++) { Submeshes.Add(new Submesh(Cache, iOffset + 24 * i)); } #endregion #region Subset Block Reader.SeekTo(Address + 12); iCount = Reader.ReadInt32(); iOffset = Reader.ReadInt32() - Cache.Magic; for (int i = 0; i < iCount; i++) { Subsets.Add(new Subset(Cache, iOffset + 16 * i)); } #endregion #region Other Reader.SeekTo(Address + 24); VertsIndex = Reader.ReadInt16(); Reader.ReadInt32(); UnknownIndex = Reader.ReadInt16(); Reader.SeekTo(Address + 40); FacesIndex = Reader.ReadInt16(); Reader.SeekTo(Address + 45); TransparentNodesPerVertex = Reader.ReadByte(); NodeIndex = Reader.ReadByte(); VertexFormat = Reader.ReadByte(); OpaqueNodesPerVertex = Reader.ReadByte(); #endregion }
public List <List <Word> > Find(int number_of_words, int number_of_letters) { m_subsets = new List <List <Word> >(); long[] word_lengths = new long[m_items.Count]; for (int i = 0; i < m_items.Count; i++) { string simplified_word_text = m_items[i].Text; if (m_items[i].Text.IsArabicWithDiacritics()) { simplified_word_text = simplified_word_text.Simplify29(); } word_lengths[i] = simplified_word_text.Length; } Subsets subsets = new Subsets(word_lengths); subsets.Find(number_of_words, number_of_letters, OnFound); return(m_subsets); }
private static void Main(string[] args) { long[] numbers = new long[] { 7, 286, 200, 176, 120, 165, 206, 75, 129, 109, 123, 111, 43, 52, 99, 128, 111, 110, 98, 135, 112, 78, 118, 64, 77, 227, 93, 88, 69, 60, 34, 30, 73, 54, 45, 83, 182, 88, 75, 85, 54, 53, 89, 59, 37, 35, 38, 29, 18, 45, 60, 49, 62, 55, 78, 96, 29, 22, 24, 13, 14, 11, 11, 18, 12, 12, 30, 52, 52, 44, 28, 28, 20, 56, 40, 31, 50, 40, 46, 42, 29, 19, 36, 25, 22, 17, 19, 26, 30, 20, 15, 21, 11, 8, 8, 19, 5, 8, 8, 11, 11, 8, 3, 9, 5, 4, 7, 3, 6, 3, 5, 4, 5, 6 }; Subsets subsets = new Subsets(numbers); int count = 7; long sum = 313; if (args.Length == 2) { int.TryParse(args[0], out count); long.TryParse(args[1], out sum); } Stopwatch stopwatch = Stopwatch.StartNew(); m_subset_count = 0L; subsets.Find(count, sum, OnSubsetFound); stopwatch.Stop(); Console.WriteLine("Subsets found: " + m_subset_count); Console.WriteLine(stopwatch.Elapsed); Console.ReadKey(); }
protected override void InitFromMeshData(Device device, GeometryGenerator.MeshData mesh) { var subset = new MeshSubset() { FaceCount = mesh.Indices.Count / 3, FaceStart = 0, VertexCount = mesh.Vertices.Count, VertexStart = 0 }; Subsets.Add(subset); var max = new Vector3(float.MinValue); var min = new Vector3(float.MaxValue); foreach (var vertex in mesh.Vertices) { max = MathF.Maximize(max, vertex.Position); min = MathF.Minimize(min, vertex.Position); } BoundingBox = new BoundingBox(min, max); Vertices = mesh.Vertices.Select(v => new VertPosNormTexTan(v.Position, v.Normal, v.TexCoords, v.TangentU)).ToList(); Indices = mesh.Indices.Select(i => i).ToList(); Materials.Add(new Noire.Common.Material { Ambient = Color.Gray, Diffuse = Color.White, Specular = new Color(1f, 1f, 1f, 16f) }); DiffuseMapSRV.Add(null); NormalMapSRV.Add(null); ModelMesh.SetSubsetTable(Subsets); ModelMesh.SetVertices(device, Vertices); ModelMesh.SetIndices(device, Indices); }
private void DrawBitmap(Graphics graphics, int height) { long nChar, nNextChar, nCheckDigit; _currentXDrawPosition = 0; // calculate the check digit nCheckDigit = CheckDigit; // draw start character for current subset if (_currentSubset == Subsets.SUBSETA) { DrawPattern(graphics, RetrievePattern(103), height); } else if (_currentSubset == Subsets.SUBSETB) { DrawPattern(graphics, RetrievePattern(104), height); } else if (_currentSubset == Subsets.SUBSETC) { DrawPattern(graphics, RetrievePattern(105), height); } // initialize position in message int nCharacterPosition = 0; while (nCharacterPosition < _message.Length) { if (_currentSubset == Subsets.SUBSETC) { // if it's a switch to subsetA - same character (103) for all subsets if (ASCIItoCode128SubsetAB[(int)Subsets.SUBSETA, _message[nCharacterPosition]] == 101) { // draw the startA code DrawPattern(graphics, RetrievePattern(101), height); // we've moved one message character nCharacterPosition++; // actually change the subset _currentSubset = Subsets.SUBSETA; } // if it's a switch to subsetB - same character (104) for all subsets else if (ASCIItoCode128SubsetAB[(int)Subsets.SUBSETA, _message[nCharacterPosition]] == 100) { // draw the startB code DrawPattern(graphics, RetrievePattern(100), height); // we've moved one message character nCharacterPosition++; // actually change the subset _currentSubset = Subsets.SUBSETB; } // it's FNC1 - just print it out else if (ASCIItoCode128SubsetAB[(int)Subsets.SUBSETA, _message[nCharacterPosition]] == 102) { // draw the FNC1 DrawPattern(graphics, RetrievePattern(100), height); // we've moved one message character nCharacterPosition++; } // it's a digit - pull two at a time else { string csTemp; // get the next two characters csTemp = _message.Substring(nCharacterPosition, 2); //m_csMessage.Mid(nCharacterPosition,2); // convert them to longs nChar = long.Parse(csTemp); // atol((const char *)csTemp); // draw the code 128 character DrawPattern(graphics, RetrievePattern(nChar), height); // we've moved two message characters nCharacterPosition += 2; } } // we're in SUBSETA or SUBSETB else { // handle upper ASCII characters if necessary long nTemp2 = _message[nCharacterPosition]; if (nTemp2 < -1) { nTemp2 = nTemp2 & 255; } // retrieve the message character nChar = ASCIItoCode128SubsetAB[(int)_currentSubset, nTemp2]; // draw the char DrawPattern(graphics, RetrievePattern(nChar), height); // we've moved one character position nCharacterPosition++; // if switch in SUBSETA if (_currentSubset == Subsets.SUBSETA) { if (nChar == 100) { _currentSubset = Subsets.SUBSETB; } else if (nChar == 99) { _currentSubset = Subsets.SUBSETC; } } // if switch in SUBSETB else if (_currentSubset == Subsets.SUBSETB) { if (nChar == 101) { _currentSubset = Subsets.SUBSETA; } else if (nChar == 99) { _currentSubset = Subsets.SUBSETC; } } // if a shift character else if (nChar == 98) { // shift subsets for the next character only if (_currentSubset == Subsets.SUBSETA) { nNextChar = ASCIItoCode128SubsetAB[(int)Subsets.SUBSETB, _message[nCharacterPosition]]; } else { nNextChar = ASCIItoCode128SubsetAB[(int)Subsets.SUBSETA, _message[nCharacterPosition]]; } // draw the shifted character DrawPattern(graphics, RetrievePattern(nChar), height); // since we've handled two characters advance character position again nCharacterPosition++; } } } // draw check digit DrawPattern(graphics, RetrievePattern(nCheckDigit), height); // draw stop character DrawPattern(graphics, RetrievePattern(106), height); return; }
/// <summary> /// Fills a constant signature object from an XML fragment. /// </summary> /// <param name="reader">The XML reader containing the fragment to read.</param> /// <exception cref="LSLInvalidSymbolNameException"> /// Thrown if the constants name does not abide by LSL symbol naming /// conventions. /// </exception> /// <exception cref="LSLInvalidSubsetNameException"> /// Thrown if any of the given subset names in the CSV 'Subsets' string do /// not match the pattern ([a-zA-Z]+[a-zA-Z_0-9\\-]*). /// </exception> /// <exception cref="LSLInvalidConstantTypeException">if 'Type' is <see cref="LSLType.Void" />.</exception> /// <exception cref="LSLLibraryDataXmlSyntaxException"> /// On missing or unknown attributes. /// If the constant 'Type' is <see cref="LSLType.Void" />. /// If the constant 'Type' does not correspond to an <see cref="LSLType" /> enumeration member. /// If a 'Properties' node 'Name' is <c>null</c> or whitespace. /// If a 'Properties' node 'Name' is used more than once. /// If a 'Properties' node 'Value' is <c>null</c> or whitespace. /// </exception> /// <exception cref="LSLInvalidConstantValueStringException"> /// If 'Value' is an invalid value for a float and <see cref="LSLConstantSignature.Type" /> is set to <see cref="LSLType.Float" /> /// or /// If 'Value' is an invalid value for an integer and <see cref="LSLConstantSignature.Type" /> is set to <see cref="LSLType.Integer" /> /// or /// If 'Value' is an invalid value for a vector and <see cref="LSLConstantSignature.Type" /> is set to <see cref="LSLType.Vector" /> /// or /// If 'Value' is an invalid value for a rotation and <see cref="LSLConstantSignature.Type" /> is set to <see cref="LSLType.Rotation" /> /// </exception> /// <exception cref="XmlException">Incorrect XML encountered in the input stream. </exception> /// <exception cref="ArgumentNullException"><paramref name="reader" /> is <c>null</c>.</exception> void IXmlSerializable.ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } reader.MoveToContent(); var hasSubsets = false; var hasType = false; var hasName = false; var hasValue = false; string valueString = null; var lineNumberInfo = (IXmlLineInfo)reader; while (reader.MoveToNextAttribute()) { if (reader.Name == "Value") { var val = reader.Value; //The value is only truly missing if its entirely devoid of character data //some LSL constants like EOF are nothing but whitespace characters if (val.Length != 0) { hasValue = true; } //need to set the type first, defer this until later. valueString = val; } else if (reader.Name == "Subsets") { Subsets.SetSubsets(reader.Value); hasSubsets = true; } else if (reader.Name == "Type") { LSLType type; if (Enum.TryParse(reader.Value, out type)) { Type = type; hasType = true; } else { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryConstantSignature{0}: Type attribute invalid.", hasName ? (" '" + Name + "'") : "")); } } else if (reader.Name == "Name") { Name = reader.Value; hasName = true; } else { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryConstantSignature{0}: Unknown attribute '{1}'.", hasName ? (" '" + Name + "'") : "", reader.Name)); } } if (!hasName) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, "LibraryConstantSignature: Missing Name attribute."); } if (!hasType) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryConstantSignature '{0}': Missing Type attribute.", Name)); } if (!hasValue) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryConstantSignature '{0}': Missing Value attribute.", Name)); } if (!hasSubsets) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryConstantSignature '{0}': Missing Subsets attribute.", Name)); } //Set the value string, this can possibly throw an LSLInvalidConstantValueStringException //The Type property needs to be set first above for validation to occur. ValueString = valueString; var canRead = reader.Read(); while (canRead) { if ((reader.Name == "DocumentationString") && reader.IsStartElement()) { DocumentationString = reader.ReadElementContentAsString(); canRead = reader.Read(); } else if ((reader.Name == "Property") && reader.IsStartElement()) { var pName = reader.GetAttribute("Name"); if (string.IsNullOrWhiteSpace(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "LibraryConstantSignature '{0}': Property element's Name attribute cannot be empty.", Name)); } var value = reader.GetAttribute("Value"); if (string.IsNullOrWhiteSpace(value)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "LibraryConstantSignature '{0}': Property element's Value attribute cannot be empty.", Name)); } if (_properties.ContainsKey(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "LibraryConstantSignature '{0}': Property name '{1}' has already been used.", Name, pName)); } _properties.Add(pName, value); canRead = reader.Read(); } else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "LibraryConstant") { break; } else { canRead = reader.Read(); } } }
public BasicModel(Device device, TextureManager texMgr, string filename, string texturePath, bool flipUV = false) { var importer = new AssimpImporter(); if (!importer.IsImportFormatSupported(Path.GetExtension(filename))) { throw new ArgumentException("Model format " + Path.GetExtension(filename) + " is not supported! Cannot load {1}", "filename"); } #if DEBUG importer.AttachLogStream(new ConsoleLogStream()); importer.VerboseLoggingEnabled = true; #endif var postProcessFlags = PostProcessSteps.GenerateSmoothNormals | PostProcessSteps.CalculateTangentSpace; if (flipUV) { postProcessFlags |= PostProcessSteps.FlipUVs; } var model = importer.ImportFile(filename, postProcessFlags); var min = new Vector3(float.MaxValue); var max = new Vector3(float.MinValue); foreach (var mesh in model.Meshes) { var verts = new List <PosNormalTexTan>(); var subset = new MeshGeometry.Subset { VertexCount = mesh.VertexCount, VertexStart = Vertices.Count, FaceStart = Indices.Count / 3, FaceCount = mesh.FaceCount }; Subsets.Add(subset); // bounding box corners for (var i = 0; i < mesh.VertexCount; i++) { var pos = mesh.HasVertices ? mesh.Vertices[i].ToVector3() : new Vector3(); min = Vector3.Minimize(min, pos); max = Vector3.Maximize(max, pos); var norm = mesh.HasNormals ? mesh.Normals[i] : new Vector3D(); var texC = mesh.HasTextureCoords(0) ? mesh.GetTextureCoords(0)[i] : new Vector3D(); var tan = mesh.HasTangentBasis ? mesh.Tangents[i] : new Vector3D(); var v = new PosNormalTexTan(pos, norm.ToVector3(), texC.ToVector2(), tan.ToVector3()); verts.Add(v); } Vertices.AddRange(verts); var indices = mesh.GetIndices().Select(i => (short)(i + (uint)subset.VertexStart)).ToList(); Indices.AddRange(indices); var mat = model.Materials[mesh.MaterialIndex]; var material = mat.ToMaterial(); Materials.Add(material); var diffusePath = mat.GetTexture(TextureType.Diffuse, 0).FilePath; if (Path.GetExtension(diffusePath) == ".tga") { // DirectX doesn't like to load tgas, so you will need to convert them to pngs yourself with an image editor diffusePath = diffusePath.Replace(".tga", ".png"); } if (!string.IsNullOrEmpty(diffusePath)) { DiffuseMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, diffusePath))); } var normalPath = mat.GetTexture(TextureType.Normals, 0).FilePath; if (!string.IsNullOrEmpty(normalPath)) { NormalMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, normalPath))); } else { var normalExt = Path.GetExtension(diffusePath); normalPath = Path.GetFileNameWithoutExtension(diffusePath) + "_nmap" + normalExt; NormalMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, normalPath))); } } BoundingBox = new BoundingBox(min, max); ModelMesh.SetSubsetTable(Subsets); ModelMesh.SetVertices(device, Vertices); ModelMesh.SetIndices(device, Indices); }
public static Image DrawBarcode(string message, Subsets subset, int height) { Barcode128 barcode = new Barcode128(message, subset); return(barcode.DrawImage(height)); }
public override bool Deserialize(object data) { if (data is BinaryReader) { BinaryReader br = data as BinaryReader; int vc = br.ReadInt32(); for (int i = 0; i < vc; ++i) { CVertex v = new CVertex(); if (v.Deserialize(br) == true) { Vertices.Add(v); } } int ic = br.ReadInt32(); for (int i = 0; i < ic; ++i) { int index = br.ReadInt32(); Indices.Add(index); } int sc = br.ReadInt32(); for (int i = 0; i < sc; ++i) { CSubset subset = new CSubset(); if (subset.Deserialize(br) == true) { Subsets.Add(subset); } } } else if (data is JObject) { JObject jmesh = data as JObject; foreach (JObject jv in jmesh["Vertices"]) { CVertex v = new CVertex(); v.Deserialize(jv); Vertices.Add(v); } foreach (int index in jmesh["Indices"]) { Indices.Add(index); } foreach (JObject js in jmesh["Subsets"]) { CSubset subset = new CSubset(); subset.Deserialize(js); Subsets.Add(subset); } } else { return(false); } return(true); }
/// <summary> /// Fills a function signature object from an XML fragment. /// </summary> /// <param name="reader">The XML reader containing the fragment to read.</param> /// <exception cref="ArgumentNullException">If <paramref name="reader" /> is <c>null</c>.</exception> /// <exception cref="LSLLibraryDataXmlSyntaxException"> /// On missing or unknown attributes. /// If a parameter 'Name' is used more than once. /// If a parameter 'Name' is whitespace. /// If a parameter 'Type' is <see cref="LSLType.Void" /> and not Variadic. /// If a parameter 'Type' does not correspond to an <see cref="LSLType" /> enumeration member. /// If a 'Properties' node 'Name' is <c>null</c> or whitespace. /// If a 'Properties' node 'Name' is used more than once. /// If a 'Properties' node 'Value' is <c>null</c> or whitespace. /// </exception> /// <exception cref="LSLInvalidSymbolNameException"> /// Thrown if the function signatures name or any of its parameters names /// do not abide by LSL symbol naming conventions. /// </exception> /// <exception cref="XmlException">Incorrect XML encountered in the input stream. </exception> /// <exception cref="LSLInvalidSubsetNameException"> /// Thrown if any of the given subset names in the 'Subsets' CSV string do /// not match the pattern ([a-zA-Z]+[a-zA-Z_0-9\\-]*). /// </exception> void IXmlSerializable.ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } var parameterNames = new HashSet <string>(); var lineNumberInfo = (IXmlLineInfo)reader; reader.MoveToContent(); var hasReturnType = false; var hasSubsets = false; var hasName = false; while (reader.MoveToNextAttribute()) { if (reader.Name == "Subsets") { Subsets.SetSubsets(reader.Value); hasSubsets = true; } else if (reader.Name == "ReturnType") { LSLType type; if (Enum.TryParse(reader.Value, out type)) { ReturnType = type; hasReturnType = true; } else { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction{0}: ReturnType attribute Value '{1}' invalid.", hasName ? (" '" + Name + "'") : "", reader.Value)); } } else if (reader.Name == "Name") { hasName = true; Name = reader.Value; } else { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction{0}: Unknown attribute '{1}'.", hasName ? (" '" + Name + "'") : "", reader.Name)); } } if (!hasName) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, "LibraryFunction: Missing Name attribute."); } if (!hasReturnType) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction '{0}': Missing ReturnType attribute.", Name)); } if (!hasSubsets) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction '{0}': Missing Subsets attribute.", Name)); } var isVariadic = false; var canRead = reader.Read(); while (canRead) { if ((reader.Name == "Parameter") && reader.IsStartElement()) { if (isVariadic) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction '{0}': More than one variadic parameter was defined.", Name)); } var pName = reader.GetAttribute("Name"); if (string.IsNullOrWhiteSpace(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "LibraryFunction '{0}': Parameter Name attribute invalid, cannot be empty or whitespace.", Name)); } LSLType pType; if (!Enum.TryParse(reader.GetAttribute("Type"), out pType)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "LibraryFunction '{0}': Parameter named '{1}' has an invalid Type attribute.", Name, pName)); } if (parameterNames.Contains(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction '{0}': Parameter Name '{1}' already used.", Name, pName)); } var variadic = reader.GetAttribute("Variadic"); if (!string.IsNullOrWhiteSpace(variadic)) { if (variadic.ToLower() == "true") { isVariadic = true; } else if (variadic.ToLower() != "false") { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "LibraryFunction '{0}': Variadic attribute in parameter #{1} of Function '{2}' must equal True or False (Case Insensitive).", Name, pName, Name)); } } if (pType == LSLType.Void && !isVariadic) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "LibraryFunction '{0}': Parameter Type invalid, function parameters cannot be Void unless they are declared variadic.", Name)); } parameterNames.Add(pName); AddParameter(new LSLParameterSignature(pType, pName, isVariadic)); canRead = reader.Read(); } else if ((reader.Name == "DocumentationString") && reader.IsStartElement()) { DocumentationString = reader.ReadElementContentAsString(); canRead = reader.Read(); } else if ((reader.Name == "Property") && reader.IsStartElement()) { var pName = reader.GetAttribute("Name"); if (string.IsNullOrWhiteSpace(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction '{0}': Property element's Name attribute cannot be empty.", Name)); } var value = reader.GetAttribute("Value"); if (string.IsNullOrWhiteSpace(value)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction '{0}': Property element's Value attribute cannot be empty.", Name)); } if (_properties.ContainsKey(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("LibraryFunction '{0}': Property name '{1}' has already been used.", Name, pName)); } _properties.Add(pName, value); canRead = reader.Read(); } else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "LibraryFunction") { break; } else { canRead = reader.Read(); } } }
public SkinnedModel(Device device, TextureManager texMgr, string filename, string texturePath, bool flipTexY = false) { var importer = new AssimpImporter(); #if DEBUG importer.AttachLogStream(new ConsoleLogStream()); importer.VerboseLoggingEnabled = true; #endif var model = importer.ImportFile(filename, PostProcessSteps.GenerateSmoothNormals | PostProcessSteps.CalculateTangentSpace); // Load animation data Animator = new SceneAnimator(); Animator.Init(model); // create our vertex-to-boneweights lookup var vertToBoneWeight = new Dictionary <uint, List <VertexWeight> >(); // create bounding box extents _min = new Vector3(float.MaxValue); _max = new Vector3(float.MinValue); foreach (var mesh in model.Meshes) { ExtractBoneWeightsFromMesh(mesh, vertToBoneWeight); var subset = new MeshGeometry.Subset { VertexCount = mesh.VertexCount, VertexStart = Vertices.Count, FaceStart = Indices.Count / 3, FaceCount = mesh.FaceCount }; Subsets.Add(subset); var verts = ExtractVertices(mesh, vertToBoneWeight, flipTexY); Vertices.AddRange(verts); // extract indices and shift them to the proper offset into the combined vertex buffer var indices = mesh.GetIndices().Select(i => (short)(i + (uint)subset.VertexStart)).ToList(); Indices.AddRange(indices); // extract materials var mat = model.Materials[mesh.MaterialIndex]; var material = mat.ToMaterial(); Materials.Add(material); // extract material textures var diffusePath = mat.GetTexture(TextureType.Diffuse, 0).FilePath; if (!string.IsNullOrEmpty(diffusePath)) { DiffuseMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, diffusePath))); } var normalPath = mat.GetTexture(TextureType.Normals, 0).FilePath; if (!string.IsNullOrEmpty(normalPath)) { NormalMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, normalPath))); } else { // for models created without a normal map baked, we'll check for a texture with the same // filename as the diffure texture, and _nmap suffixed // this lets us add our own normal maps easily var normalExt = Path.GetExtension(diffusePath); normalPath = Path.GetFileNameWithoutExtension(diffusePath) + "_nmap" + normalExt; if (File.Exists(Path.Combine(texturePath, normalPath))) { NormalMapSRV.Add(texMgr.CreateTexture(Path.Combine(texturePath, normalPath))); } } } BoundingBox = new BoundingBox(_min, _max); ModelMesh.SetSubsetTable(Subsets); ModelMesh.SetVertices(device, Vertices); ModelMesh.SetIndices(device, Indices); }
private IEnumerable <IEnumerable <Star> > AllSubsets() { return(Subsets.Select(p => p.AllStars())); }
/// <summary> /// Fills an event signature object from an XML fragment. /// </summary> /// <param name="reader">The XML reader containing the fragment to read.</param> /// <exception cref="ArgumentNullException">If <paramref name="reader" /> is <c>null</c>.</exception> /// <exception cref="LSLLibraryDataXmlSyntaxException"> /// On missing or unknown attributes. /// If a parameter 'Name' is used more than once. /// If a parameter 'Name' is whitespace. /// If a parameter 'Type' is <see cref="LSLType.Void" />. /// If a parameter 'Type' does not correspond to an <see cref="LSLType" /> enumeration member. /// If a 'Properties' node 'Name' is <c>null</c> or whitespace. /// If a 'Properties' node 'Name' is used more than once. /// If a 'Properties' node 'Value' is <c>null</c> or whitespace. /// </exception> /// <exception cref="LSLInvalidSymbolNameException"> /// Thrown if the event signatures name or any of its parameters names do /// not abide by LSL symbol naming conventions. /// </exception> /// <exception cref="XmlException">Incorrect XML encountered in the input stream. </exception> /// <exception cref="LSLInvalidSubsetNameException"> /// Thrown if any of the given subset names in the 'Subsets' CSV string do /// not match the pattern ([a-zA-Z]+[a-zA-Z_0-9\\-]*). /// </exception> void IXmlSerializable.ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } var parameterNames = new HashSet <string>(); reader.MoveToContent(); var hasSubsets = false; var hasName = false; var lineNumberInfo = (IXmlLineInfo)reader; while (reader.MoveToNextAttribute()) { if (reader.Name == "Subsets") { Subsets.SetSubsets(reader.Value); hasSubsets = true; } else if (reader.Name == "Name") { hasName = true; Name = reader.Value; } else { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("EventHandler{0}: Unknown attribute '{1}'.", hasName ? (" '" + Name + "'") : "", reader.Name)); } } if (!hasName) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, "EventHandler: Missing Name attribute."); } if (!hasSubsets) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("EventHandler '{0}': Missing Subsets attribute.", Name)); } var canRead = reader.Read(); while (canRead) { if ((reader.Name == "Parameter") && reader.IsStartElement()) { var pName = reader.GetAttribute("Name"); if (string.IsNullOrWhiteSpace(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "EventHandler '{0}': Parameter Name attribute invalid, cannot be empty or whitespace.", Name)); } LSLType pType; if (!Enum.TryParse(reader.GetAttribute("Type"), out pType)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("EventHandler '{0}': Parameter named '{1}' has an invalid Type attribute.", pName, Name)); } if (pType == LSLType.Void) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "EventHandler '{0}': Parameter named '{1}' has an invalid Type, event parameters cannot be Void.", Name, pName)); } if (parameterNames.Contains(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("EventHandler '{0}': Parameter Name '{1}' already used.", Name, pName)); } parameterNames.Add(pName); AddParameter(new LSLParameterSignature(pType, pName, false)); canRead = reader.Read(); } else if ((reader.Name == "DocumentationString") && reader.IsStartElement()) { DocumentationString = reader.ReadElementContentAsString(); canRead = reader.Read(); } else if ((reader.Name == "Property") && reader.IsStartElement()) { var pName = reader.GetAttribute("Name"); if (string.IsNullOrWhiteSpace(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("EventHandler '{0}': Property element's Name attribute cannot be empty.", pName)); } var value = reader.GetAttribute("Value"); if (string.IsNullOrWhiteSpace(value)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format("EventHandler '{0}': Property element's Value attribute cannot be empty.", pName)); } if (_properties.ContainsKey(pName)) { throw new LSLLibraryDataXmlSyntaxException(lineNumberInfo.LineNumber, string.Format( "EventHandler '{0}': Property name '{1}' has already been used.", Name, pName)); } _properties.Add(pName, value); canRead = reader.Read(); } else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "EventHandler") { break; } else { canRead = reader.Read(); } } }
public static void Test(){ char[] a = {'a','b','c','d'}; Subsets s = new Subsets(a); }
/// <summary> /// 添加子集 /// </summary> /// <param name="subset">子集</param> public Tree <T> AddSubset(Tree <T> subset) { Subsets.AddNoNull(subset); return(this); }
//searches for words in the dictionary that match unique permutations of all subsets //of the user input. private void searchForWords() { string input = txtLetters.Text; //check for bad input if (input.Length == 0) { MessageBox.Show("You must enter letters in the textbox to get results."); return; } else if (input.Length > 8) { MessageBox.Show("A maximum of eight characters is allowed due to the time-complexity of this algorithm."); return; } //tree to hold words if (!my_dictionary_loaded) { my_dictionary_loaded = true; addDictionary(); } //get characters char[] letters = input.ToLower().ToCharArray(); //get unique permutations Subsets s = new Subsets(); s.addObserver(this); lblInfo.Text = "Getting letter permutations..."; List <List <DSInteger> > permutation_indices = s.getUniquePermutationIndices <DSInteger>(letters.Length); lblInfo.Text = "Building possible words..."; pbrProgress.Value = 0; pbrProgress.Maximum = permutation_indices.size(); //get word candidates from the permutation indices Set <DSString> word_candidates = new HashSet <DSString>(); for (int i = 0; i < permutation_indices.size(); i++) { StringBuilder builder = new StringBuilder(); List <DSInteger> permutation = permutation_indices.get(i); for (int j = 0; j < permutation.size(); j++) { builder.Append(letters[permutation.get(j).value]); } DSString possible = new DSString(builder.ToString()); if (!word_candidates.contains(possible)) { word_candidates.add(possible); } //show progress updateProgress(); } pbrProgress.Value = 0; pbrProgress.Maximum = word_candidates.size(); lblInfo.Text = "Check Search Tree for words..."; //sort candidates according to length and then alphabetically DSString[] sorted = word_candidates.toArray(); Sorting <DSString> .Sort(Sorts.QuickSort, ref sorted, new StringLengthComparator()); //clear old lookups lstWords.Items.Clear(); //lookup each word in the bst for (int i = sorted.Length - 1; i >= 0; i--) { DSString current = sorted[i]; if (my_bst.contains(current)) { lstWords.Items.Add(current.value); } //show progress updateProgress(); } //show words found lblInfo.Text = "Words found: " + lstWords.Items.Count; }
private BasicModel(Device device, TextureManager11 textureManager, string filename, string texturePath, bool autoLoadTextures, bool flipUv, bool tex1By1) { var importer = new AssimpContext(); if (!importer.IsImportFormatSupported(Path.GetExtension(filename))) { throw new ArgumentException($"Model format {Path.GetExtension(filename)} is not supported. Cannot load {filename}.", nameof(filename)); } #if DEBUG var logStream = new ConsoleLogStream(); logStream.Attach(); #endif var postProcessFlags = PostProcessSteps.GenerateSmoothNormals | PostProcessSteps.CalculateTangentSpace; if (flipUv) { postProcessFlags |= PostProcessSteps.FlipUVs; } var model = importer.ImportFile(filename, postProcessFlags); var min = new Vector3(float.MaxValue); var max = new Vector3(float.MinValue); _meshCount = model.Meshes.Count; foreach (var mesh in model.Meshes) { var verts = new List <VertPosNormTexTan>(); var subset = new MeshSubset() { VertexCount = mesh.VertexCount, VertexStart = Vertices.Count, FaceStart = Indices.Count / 3, FaceCount = mesh.FaceCount }; Subsets.Add(subset); // bounding box corners for (var i = 0; i < mesh.VertexCount; i++) { var pos = mesh.HasVertices ? mesh.Vertices[i].ToVector3() : new Vector3(); min = MathF.Minimize(min, pos); max = MathF.Maximize(max, pos); var norm = mesh.HasNormals ? mesh.Normals[i] : new Vector3D(); var texC = mesh.HasTextureCoords(0) ? mesh.TextureCoordinateChannels[0][i] : (tex1By1 ? new Vector3D(1, 1, 0) : new Vector3D()); var tan = mesh.HasTangentBasis ? mesh.Tangents[i] : new Vector3D(); var v = new VertPosNormTexTan(pos, norm.ToVector3(), texC.ToVector2(), tan.ToVector3()); verts.Add(v); } Vertices.AddRange(verts); var indices = mesh.GetIndices().Select(i => i + subset.VertexStart).ToList(); Indices.AddRange(indices); var mat = model.Materials[mesh.MaterialIndex]; var material = mat.ToMaterial(); Materials.Add(material); if (autoLoadTextures) { TextureSlot diffuseSlot; mat.GetMaterialTexture(TextureType.Diffuse, 0, out diffuseSlot); var diffusePath = diffuseSlot.FilePath; if (Path.GetExtension(diffusePath) == ".tga") { // DirectX doesn't like to load tgas, so you will need to convert them to pngs yourself with an image editor diffusePath = diffusePath.Replace(".tga", ".png"); } var fullDiffusePath = diffusePath == null ? null : Path.Combine(texturePath, diffusePath); if (File.Exists(fullDiffusePath)) { DiffuseMapSRV.Add(textureManager.CreateTexture(fullDiffusePath)); } else { DiffuseMapSRV.Add(textureManager.CreateColor1By1(material.Diffuse.ToColor())); } TextureSlot normalSlot; mat.GetMaterialTexture(TextureType.Normals, 0, out normalSlot); var normalPath = normalSlot.FilePath; var fullNormalPath = normalPath == null ? null : Path.Combine(texturePath, normalPath); string textureName; if (File.Exists(fullNormalPath)) { textureName = fullNormalPath; } else { if (File.Exists(fullDiffusePath)) { var normalExt = Path.GetExtension(fullDiffusePath); normalPath = Path.GetFileNameWithoutExtension(diffusePath) + "_nmap" + normalExt; fullNormalPath = Path.Combine(texturePath, normalPath); if (File.Exists(fullNormalPath)) { textureName = fullNormalPath; } else { textureName = TextureManager11.TexDefaultNorm; } } else { textureName = TextureManager11.TexDefaultNorm; } } NormalMapSRV.Add(textureManager.CreateTexture(textureName)); } } BoundingBox = new BoundingBox(min, max); ModelMesh.SetSubsetTable(Subsets); ModelMesh.SetVertices(device, Vertices); ModelMesh.SetIndices(device, Indices); }
static void Main(string[] args) { Mine mine = new Mine(); int[][] twoD = new int[2][]; twoD[0] = new int[] { 0, 0 }; twoD[1] = new int[] { 0, 1 }; int[,] field = mine.Minesweeper(twoD, 3, 4); int mRow = field.GetUpperBound(0); int mCol = field.GetUpperBound(1); for (int r = 0; r <= mRow; r++) { for (int c = 0; c <= mCol; c++) { Console.Write(field[r, c] + " "); } Console.WriteLine(""); } int[] bst = { 2, 3, 4, 10, 40 }; BinarySearch binarySearch = new BinarySearch(); int n = bst.Length; int x = 10; Console.WriteLine("Recurcive: The index is " + binarySearch.BinarySearchRecursive(bst, 0, n - 1, x)); Console.WriteLine("Itirative: The index is " + binarySearch.BinarySearchItirative(bst, x)); var path = new List <int>(); var Prev = new Dictionary <int, int>(); Console.WriteLine(string.Join(", ", search.DFS(unDirectedgraph, 1))); Console.WriteLine(string.Join(", ", search.BFS(unDirectedgraph, 1, ref Prev, v => path.Add(v)))); Console.WriteLine("Trace Path..."); Console.WriteLine(string.Join(", ", path)); foreach (var vertex in vertices) { Console.WriteLine("shortest path to {0,2}: {1}", vertex, string.Join(", ", search.ShortestPathFromPrev(Prev, 1, vertex))); } Console.WriteLine("Topological Sort...."); Console.WriteLine(string.Join(", ", TopSort())); Console.WriteLine("Is 'create' anagram of 'eaterc'? : " + anagram.isAnagram("create", "eaterc")); void checkPalindrome(string str) { Palindrome p = new Palindrome(); Console.WriteLine("Is this word a palindrome? " + str); Console.WriteLine(p.isPalidrome(str, false)); }; checkPalindrome("hello"); checkPalindrome("motor"); checkPalindrome("rotor"); Misc misc = new Misc(); int[] arr1 = { 5, 6, 1, 2, 3, 4 }; int n1 = arr1.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr1, 0, n1 - 1)); int[] arr2 = { 1, 2, 3, 4 }; int n2 = arr2.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr2, 0, n2 - 1)); int[] arr3 = { 1 }; int n3 = arr3.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr3, 0, n3 - 1)); int[] arr4 = { 1, 2 }; int n4 = arr4.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr4, 0, n4 - 1)); int[] arr5 = { 2, 1 }; int n5 = arr5.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr5, 0, n5 - 1)); int[] arr6 = { 5, 6, 7, 1, 2, 3, 4 }; int n6 = arr6.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr6, 0, n1 - 1)); int[] arr7 = { 1, 2, 3, 4, 5, 6, 7 }; int n7 = arr7.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr7, 0, n7 - 1)); int[] arr8 = { 2, 3, 4, 5, 6, 7, 8, 1 }; int n8 = arr8.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr8, 0, n8 - 1)); int[] arr9 = { 3, 4, 5, 1, 2 }; int n9 = arr9.Length; Console.WriteLine("The minimum element is " + misc.FindMinInSortedRotated(arr9, 0, n9 - 1)); int[] arr = { 64, 34, 25, 12, 22, 11, 90 }; BubbleSort bSort = new BubbleSort(); bSort.Sort(arr); Console.Write("arr = { 64, 34, 25, 12, 22, 11, 90 } => Sorted array = "); printArray(arr); int[] ar = { 99, 44, 6, 2, 1, 5, 63, 87, 283, 4, 0 }; QuickSort qs = new QuickSort(); qs.Quick_Sort(ar); Console.Write("arr = { 99, 44, 6, 2, 1, 5, 63, 87, 283, 4, 0} => Insertion Sorted array = "); printArray(ar); int[] arr_1 = { 64, 34, 25, 12, 22, 11, 90 }; SelectionSort sSort = new SelectionSort(); sSort.Sort(arr_1); Console.Write("arr_1 = { 64, 34, 25, 12, 22, 11, 90 } => Sorted array = "); printArray(arr_1); WordLadder wordLadder = new WordLadder(); string strpath = ""; int i = wordLadder.LadderLength("hit", "cog", ref strpath); Console.WriteLine(strpath); HammingWeight hw = new HammingWeight(); int[] hw_1 = { 31, 51 }; Console.WriteLine("Hamming Weight of hw_1 = { 31,51} = " + hw.GetHammingWeightbyPreprocessing(hw_1)); Fibonacci fib = new Fibonacci(); Console.WriteLine("6th Fibonacci number by rec is : " + fib.FibRecursive(6)); Console.WriteLine("6th Fibonacci number by DP is : " + fib.FibDP(6)); Console.WriteLine("6th Fibonacci number by Bottomup is : " + fib.FibBottomUp(6)); Subsets subsets = new Subsets(); int[] arrSS = new int[] { 2, 4, 6, 10 }; Console.WriteLine("No. of subsets whose sum is 16 in { 2, 4, 6, 10 } : " + subsets.CountSubsetsDP(arrSS, 16)); HasPairWithSum obj = new HasPairWithSum(); Console.WriteLine("Does the array { 2, 4, 6, 10 } has a pair whose sum is 12: " + obj.isPairWithSumExists(arrSS, 12)); MergeArrays ma = new MergeArrays(); int[] arrSorted2 = new int[] { 0, 3, 4 }; int[] arrSorted1 = new int[] { 2, 4, 6, 10 }; Console.WriteLine("Merged Sorted array for the sorted arrays { 0, 3, 4} and { 2, 4, 6, 10 } : "); printArray(ma.MergeSortedArrays(arrSorted1, arrSorted2)); MoveZeros mz = new MoveZeros(); Console.WriteLine("Move Zeros from {0,0,1} "); int[] mzA = new int[] { 0, 0, 1 }; mz.MoveZeroes(mzA); printArray(mzA); FirstRecurring fr = new FirstRecurring(); int[] fra = new int[] { 2, 5, 1, 2, 3, 5, 1, 2, 4 }; Console.WriteLine("First recurring element in { 2, 5, 1, 2, 3, 5, 1, 2, 4 } is: " + fr.GetFirstRecurringElement <int>(fra)); Islands il = new Islands(); int[,] M = new int[, ] { { 1, 1, 0, 0, 0 }, { 0, 1, 0, 0, 1 }, { 1, 0, 0, 1, 1 }, { 0, 0, 0, 0, 0 }, { 1, 0, 1, 0, 1 } }; Console.Write("Number of islands is: " + il.countIslands(M)); LongestPalindromicSubstring lss = new LongestPalindromicSubstring(); Console.Write("LongestPalindrome in 'babad' : " + lss.LongestPalindrome("cbbd")); BinaryTree tree = new BinaryTree(); tree.root = new TreeNode(1); tree.root.left = new TreeNode(2); tree.root.right = new TreeNode(3); tree.root.left.left = new TreeNode(4); tree.root.left.right = new TreeNode(5); Console.WriteLine(""); Traversals trav = new Traversals(); trav.printInorder(tree.root); Console.WriteLine(""); trav.printPreorder(tree.root); Console.WriteLine(""); trav.printPostOrder(tree.root); Console.WriteLine(""); Console.Write("The height of the tree is : " + trav.GetTreeHeight(tree.root)); Console.WriteLine("Level Order:"); trav.LevelOrderTraversal(tree.root); }
public void Compute0_1() { var act = new TestDelegate(() => Subsets.Compute(0, 1).ToArray()); Assert.That(act, Throws.Exception); }