This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.
private ArrayList FindAllStrings(string input)
{
ArrayList strings = new ArrayList();
for (int i = 0; i <= input.Length; i++)
AddStrings(strings, input, i, "");
return strings;
}
private void AddStrings(ArrayList strings, string input, int N, string leading = "")
{
if (N == 0)
strings.Add(leading);
else
{
for (int i = 0; i + N <= input.Length; i++)
AddStrings(strings, input.Substring(i + 1), N - 1, leading + input[i]);
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.DataSource = Variations(textBox1.Text);
}
private List<string> Variations(string input)
{
List<string> values = new List<string>();
for (int i=0; i < input.Length; i++)
{
values.Add(input.Substring(i,1));
}
List<string> results = new List<string>();
for (int i = input.Length; i >= 1; i--)
{
Facet.Combinatorics.Variations<string> vars = new Facet.Combinatorics.Variations<string>(values.AsReadOnly(), i);
foreach (IList<string> set in vars)
{
results.Add(String.Join(",", set));
}
}
return results;
}
}
}
a,b,c,d
a,b,d,c
a,c,b,d
a,d,b,c
a,c,d,b
a,d,c,b
b,a,c,d
b,a,d,c
c,a,b,d
d,a,b,c
c,a,d,b
d,a,c,b
b,c,a,d
b,d,a,c
c,b,a,d
d,b,a,c
c,d,a,b
d,c,a,b
b,c,d,a
b,d,c,a
c,b,d,a
d,b,c,a
c,d,b,a
d,c,b,a
a,b,c
a,b,d
a,c,b
a,d,b
a,c,d
a,d,c
b,a,c
b,a,d
c,a,b
d,a,b
c,a,d
d,a,c
b,c,a
b,d,a
c,b,a
d,b,a
c,d,a
d,c,a
b,c,d
b,d,c
c,b,d
d,b,c
c,d,b
d,c,b
a,b
a,c
a,d
b,a
c,a
d,a
b,c
b,d
c,b
d,b
c,d
d,c
a
b
c
d
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Then you just call it for each length.
Open in new window