Yesterday we were looking at LXD containers and how to enable static ip addressing of the containers instead of the conventional DHCP.
We said we needed to specify
and for each of the containers set the following
1) entry in the lxd_dnsmasq.conf file
2) eth0 with the static ip address as in the /etc/network/interfaces or equivalent config file with:
Remember to initialize the containers with 'lxc init' instead of 'lxc launch'.
#codingexercise
Find all distinct palindromic substrings of a given string
For example, "abaaa" should result in "a" "aa" "aaa" "aba" "b"
public static void Combine(ref String input, ref StringBuilder candidate, ref List<String> combinations, int level, int start)
{
for (int i = start; i < input.Length; i++)
{
if (candidate.contains(input[i]) == false){
candidate[level] = input[i];
if (candidate.IsPalindrome() && combinations.Contains(candidate) == false)
combinations.Add(candidate.ToString());
if (i < input.Length - 1)
Combine(ref input, ref candidate, ref combinations, level + 1, start + 1);
candidate[level] = '\0';
}
}
}
bool isPalindrome( List<int> digits, int start, int end)
{bool ret = true;
while(start < end)
{
if (digits[start] != digits[end]) return false;
start++;
end--;
}
return ret;
}
#writeup https://1drv.ms/w/s!Ashlm- Nw-wnWlkDRgzKeR5lVB1Ml
The above code works well for distinct elements of input string. if we also had a frequency table from the input string, we could generate other permutations and check for palindrome.
We said we needed to specify
LXD_CONFILE="/etc/default/lxd_dnsmasq.conf"
in /etc/default/lxd-bridgeand for each of the containers set the following
1) entry in the lxd_dnsmasq.conf file
sudo sh -c "echo 'dhcp-host=containername,ipaddress' >> /etc/default/lxd_dnsmasq.conf"
and2) eth0 with the static ip address as in the /etc/network/interfaces or equivalent config file with:
auto eth0
iface eth0 inet static
address ABC.DEF.GHI.JKL
netmask 255.255.255.252
network ABC.DEF.GHI.0
gateway www.xxx.yyy.zzz
dns-search example.com sales.example.com dev.example.com
dns-nameservers nameserver1.ip.addr.ess
The gateway is what we set in the route table as
sudo route add default gw www.xxx.yyy.zzz eth0
Remember to initialize the containers with 'lxc init' instead of 'lxc launch'.
#codingexercise
Find all distinct palindromic substrings of a given string
For example, "abaaa" should result in "a" "aa" "aaa" "aba" "b"
public static void Combine(ref String input, ref StringBuilder candidate, ref List<String> combinations, int level, int start)
{
for (int i = start; i < input.Length; i++)
{
if (candidate.contains(input[i]) == false){
candidate[level] = input[i];
if (candidate.IsPalindrome() && combinations.Contains(candidate) == false)
combinations.Add(candidate.ToString());
if (i < input.Length - 1)
Combine(ref input, ref candidate, ref combinations, level + 1, start + 1);
candidate[level] = '\0';
}
}
}
bool isPalindrome( List<int> digits, int start, int end)
{bool ret = true;
while(start < end)
{
if (digits[start] != digits[end]) return false;
start++;
end--;
}
return ret;
}
#writeup https://1drv.ms/w/s!Ashlm-
The above code works well for distinct elements of input string. if we also had a frequency table from the input string, we could generate other permutations and check for palindrome.
No comments:
Post a Comment