The post Various SPOJ Solutions in Python appeared first on Dreamshire.
]]>Warning: SPOJ may prevent Python from being used for solving some problems or set time limits suitable only for archaic compiled languages.
Paraphrased: Find the volume of a tetrahedron given only the six edge-lengths.
from math import sqrt for _ in range(int(raw_input())): A, D, B, E, C, F = map(lambda x: int(x)**2, raw_input().split()) volume = sqrt((-A*B*C - A*D*E - B*D*F - C*E*F + A*C*D + B*C*D + \ A*B*E + B*C*E + B*D*E + C*D*E + A*B*F + A*C*F + \ A*D*F + C*D*F + A*E*F + B*E*F - C*C*D - C*D*D - \ B*B*E - B*E*E - A*A*F - A*F*F)/144.0) print "%.4f" % volume
Paraphrased: Calculate the Stirling number of the second kind, S(n,m).
for _ in range(int(raw_input())): n, m = map(int, raw_input().split()) print int(not((n-m) & ((m-1)/2)))
Paraphrased: Print the person who moves first. BS Problem.
for _ in range(int(raw_input())): N, p = map(int, raw_input().split()) print "Airborne wins." if p==0 else "Pagfloyd wins."
Paraphrased: (Really?) Print the last character of a string. Another BS Problem.
for _ in range(int(raw_input())): N, S = raw_input().split() print S[-1:]
Paraphrased: find the kth number (indexed from 1) whose cube ends in 888.
for _ in range(int(raw_input())): k = int(raw_input()) print 250*(k-1) + 192
Paraphrased: Find the value at an (x,y) coordinate in a stair-step pattern.
for _ in range(int(raw_input())): x, y = map(int, raw_input().split()) print (x+y if x%2==0 else x+y-1) if (x==y or (x-y)==2) else 'No Number'
Paraphrase: Output ‘TAK’ if n is a power of 2 else output ‘NIE’
n = int(raw_input()) print "TAK" if n == -n&n else "NIE"
Paraphrased: Count the number of triangles in a triangular grid (triangle tiling).
for _ in range(int(raw_input())): n = int(raw_input()) print n*(n+2)*(2*n+1) / 8
Paraphrased: Find the Maximal Quadrilateral Area for a Cyclic Quadrilateral using Brahmagupta’s formula.
from math import sqrt for _ in range(int(raw_input())): a, b, c, d = map(float, raw_input().split()) s = (a+b+c+d)/2 max_area = sqrt(((s-a)*(s-b)*(s-c)*(s-d))) print "{:.2f}".format(max_area)
Paraphrased: Minimize the Gender Regularity in a linear arrangement of boys and girls
from math import ceil while(True): G, B = map(float, raw_input().split()) if G==-1 and B==-1: break print int(ceil(max(G,B)/(1+min(G,B))))
Paraphrased: Find the second pentagonal number modulo 1,000,007.
for _ in range(int(raw_input())): n = int(raw_input()) print (n*(3*n+1)/2) % 1000007
Paraphrased: Always a right triangle, use Thales’ theorem to solve.
for I in range(int(raw_input())): r = int(raw_input()) print "Case %d: %.2f" % (I+1, 4*r*r + 0.25)
Paraphrased: Add the net transactions in wine trading. Use PYPY.
while (True): t=0; w=0 if int(raw_input()) == 0: break for a in map(int, raw_input().split()): t+= a w+= abs(t) print w
Paraphrased: Sum the two inputs.
print sum(map(int, raw_input().split()))
Paraphrased: Add 1 and divide by 2.
for _ in range(int(raw_input())): print (int(raw_input())+1) / 2
Paraphrased: Check for a common difference or common ratio. Calculate next in series.
while (True): a1, a2, a3 = map(int,raw_input().split()) if a1==0 and a2==0 and a3==0: break print "AP %d" % (a3+a2-a1) if a2-a1 == a3-a2 else "GP %d" % (a3*a2/a1)
Paraphrased: Calculate the probability for replenishing supply in simple queue based on cost of x and supply of x and 2x.
while (True): N, M = map(float, raw_input().split()) if N==0 and M==0: break p = (M-N+1)/(M+1) if M >= N else 0 print "%.6f" % p
The post Various SPOJ Solutions in Python appeared first on Dreamshire.
]]>The post Adding, removing, changing social icons in the WordPress Divi Theme 2.4+ appeared first on Dreamshire.
]]>The basic unit for each social icon presented on both the header and footer is a block of PHP code in the file:
wp-content/themes/Divi-child/includes/social_icons.php
A typical unit appears below:
<?php if ( 'on' === et_get_option( 'divi_show_instagram_icon', 'on' ) ) : ?> <li class="et-social-icon et-social-instagram"> <a href="<?php echo esc_url( et_get_option( 'divi_instagram_url', '#' ) ); ?>" class="icon"> <span><?php esc_html_e( 'Instagram', 'Divi' ); ?></span> </a> </li> <?php endif; ?>
Note: Make sure you created a child theme. In fact, make sure you always create a child theme.
To add a service, cut the code above and place it after a <?php endif; ?>
, you can move these blocks around to get the order you desire. If something other than Instagram, change it to which service you want using common sense for the name.
To remove a service simply delete its block of code or turn it 'off'
.
To change the URL of a service replace the #
with the URL of your choosing.
Also of interest may be the social follow module from ET for DIVI.
<ul class="et-social-icons"> <?php if ( 'on' === et_get_option( 'divi_show_facebook_icon', 'on' ) ) : ?> <li class="et-social-icon et-social-facebook"> <a href="<?php echo esc_url( et_get_option( 'divi_facebook_url', '//facebook.com' ) ); ?>" class="icon"> <span><?php esc_html_e( 'Facebook', 'Divi' ); ?></span> </a> </li> <?php endif; ?> <?php if ( 'on' === et_get_option( 'divi_show_twitter_icon', 'on' ) ) : ?> <li class="et-social-icon et-social-twitter"> <a href="<?php echo esc_url( et_get_option( 'divi_twitter_url', '//twitter.com' ) ); ?>" class="icon"> <span><?php esc_html_e( 'Twitter', 'Divi' ); ?></span> </a> </li> <?php endif; ?> <?php if ( 'on' === et_get_option( 'divi_show_instagram_icon', 'on' ) ) : ?> <li class="et-social-icon et-social-instagram"> <a href="<?php echo esc_url( et_get_option( 'divi_instagram_url', '//instagram.com' ) ); ?>" class="icon"> <span><?php esc_html_e( 'Instagram', 'Divi' ); ?></span> </a> </li> <?php endif; ?> <?php if ( 'on' === et_get_option( 'divi_show_rss_icon', 'off' ) ) : ?> <?php $et_rss_url = '' !== et_get_option( 'divi_rss_url' ) ? et_get_option( 'divi_rss_url' ) : get_bloginfo( 'rss2_url' ); ?> <li class="et-social-icon et-social-rss"> <a href="<?php echo esc_url( $et_rss_url ); ?>" class="icon"> <span><?php esc_html_e( 'RSS', 'Divi' ); ?></span> </a> </li> <?php endif; ?> </ul>
The post Adding, removing, changing social icons in the WordPress Divi Theme 2.4+ appeared first on Dreamshire.
]]>The post Project Euler 207 Solution appeared first on Dreamshire.
]]>For some positive integers k, there exists an integer partition of the form 4^{t} = 2^{t} + k,
where 4^{t}, 2^{t}, and k are all positive integers and t is a real number.
The first two such partitions are 4^{1} = 2^{1} + 2 and 4^{1.5849625…} = 2^{1.5849625…} + 6.
Partitions where t is also an integer are called perfect.
For any m ≥ 1 let P(m) be the proportion of such partitions that are perfect with k ≤ m.
Thus P(6) = 1/2.
In the following table are listed some values of P(m)
P(5) = 1/1
P(10) = 1/2
P(15) = 2/3
P(20) = 1/2
P(25) = 1/2
P(30) = 2/5
…
P(180) = 1/4
P(185) = 3/13
Find the smallest m for which P(m) < 1/12345
The post Project Euler 207 Solution appeared first on Dreamshire.
]]>The post Project Euler 172 Solution appeared first on Dreamshire.
]]>How many 18-digit numbers n (without leading zeros) are there such that no digit occurs more than three times in n?
from Euler import binomial
digits, base, max_r = 18, 10, 3
def nd(d,b):
if b>1:
return sum(nd(d-r, b-1)*binomial(d,r) for r in xrange(min(d+1, max_r+1)))
return d <= max_r
print "There are", nd(digits, base) * (base-1)/base,
print digits, "digit numbers such that no digit occurs more than", max_r,
print "times in base", base
Use this link to get the Project Euler 172 Solution Python source.The post Project Euler 172 Solution appeared first on Dreamshire.
]]>The post Project Euler 163 Solution appeared first on Dreamshire.
]]>Consider an equilateral triangle in which straight lines are drawn from each vertex to the middle of the opposite side, such as in the size 1 triangle in the sketch below.
Sixteen triangles of either different shape or size or orientation or location can now be observed in that triangle. Using size 1 triangles as building blocks, larger triangles can be formed, such as the size 2 triangle in the above sketch. One-hundred and four triangles of either different shape or size or orientation or location can now be observed in that size 2 triangle.
It can be observed that the size 2 triangle contains 4 size 1 triangle building blocks. A size 3 triangle would contain 9 size 1 triangle building blocks and a size n triangle would thus contain n^{2} size 1 triangle building blocks.
If we denote T(n) as the number of triangles present in a triangle of size n, then
T(1) = 16
T(2) = 104
Find T(36).
The post Project Euler 163 Solution appeared first on Dreamshire.
]]>The post Project Euler 190 Solution appeared first on Dreamshire.
]]>Let S_{m} = (x_{1}, x_{2}, … , x_{m}) be the m-tuple of positive real numbers with x_{1} + x_{2} + … + x_{m} = m for which P_{m} = x_{1} * x_{2}^{2} * … * x_{m}^{m} is maximised.
For example, it can be verified that [P_{10}] = 4112 ([ ] is the integer part function).
Find Σ[P_{m}] for 2 ≤ m ≤ 15.
The post Project Euler 190 Solution appeared first on Dreamshire.
]]>The post Project Euler 318 Solution appeared first on Dreamshire.
]]>
Consider the real number √2+√3.
When we calculate the even powers of √2+√3
we get:
(√2+√3)^{2} = 9.898979485566356…
(√2+√3)^{4} = 97.98979485566356…
(√2+√3)^{6} = 969.998969071069263…
(√2+√3)^{8} = 9601.99989585502907…
(√2+√3)^{10} = 95049.999989479221…
(√2+√3)^{12} = 940897.9999989371855…
(√2+√3)^{14} = 9313929.99999989263…
(√2+√3)^{16} = 92198401.99999998915…
It looks like that the number of consecutive nines at the beginning of the fractional part of these powers is non-decreasing.
In fact it can be proven that the fractional part of (√2+√3)^{2n} approaches 1 for large n.
Consider all real numbers of the form √p+√q with p and q positive integers and p<q, such that the fractional part
of (√p+√q)^{2n} approaches 1 for large n.
Let C(p,q,n) be the number of consecutive nines at the beginning of the fractional part of
(√p+√q)^{2n}.
Let N(p,q) be the minimal value of n such that C(p,q,n) ≥ 2011.
Find ∑N(p,q) for p+q ≤ 2011.
#Project Euler Problem 318 Solution
from math import sqrt, log10, ceil
s, L = 0, 2011
for p in xrange(1, L):
for q in xrange(p+1, L-p+1):
c = p + q - 2*sqrt(p*q)
if c < 1:
s += ceil(-L / log10(c))
print "sum of N(p,q) for p+q <=", L, "is", int(s)
Use this link to get the Project Euler 318 Solution Python 2.7 source.The post Project Euler 318 Solution appeared first on Dreamshire.
]]>The post Project Euler 317 Solution appeared first on Dreamshire.
]]>A firecracker explodes at a height of 100 m above level ground. It breaks into a large number of very small fragments, which move in every direction; all of them have the same initial velocity of 20 m/s.
We assume that the fragments move without air resistance, in a uniform gravitational field with g=9.81 m/s^{2}.
Find the volume (in m^{3}) of the region through which the fragments move before reaching the ground.
Give your answer rounded to four decimal places.
The post Project Euler 317 Solution appeared first on Dreamshire.
]]>The post Project Euler 288 Solution appeared first on Dreamshire.
]]>For any prime p the number N(p,q) is defined by
N(p,q) = ∑_{n=0 to q} T_{n}*p^{n}
with T_{n} generated by the following random number generator:
S_{0} = 290797
S_{n+1} = S_{n}^{2} mod 50515093
T_{n} = S_{n} mod p
Let Nfac(p,q) be the factorial of N(p,q).
Let NF(p,q) be the number of factors p in Nfac(p,q).
You are given that NF(3,10000) mod 3^{20}=624955285.
Find NF(61,10^{7}) mod 61^{10}
The post Project Euler 288 Solution appeared first on Dreamshire.
]]>The post Project Euler 183 Solution appeared first on Dreamshire.
]]>Let N be a positive integer and let N be split into k equal parts, r = N/k, so that N = r + r + … + r.
Let P be the product of these parts, P = r × r × … × r = r^{k}.
For example, if 11 is split into five equal parts, 11 = 2.2 + 2.2 + 2.2 + 2.2 + 2.2, then P = 2.2^{5} = 51.53632.
Let M(N) = P_{max} for a given value of N.
It turns out that the maximum for N = 11 is found by splitting eleven into four equal parts which leads to P_{max} = (11/4)^{4}; that is, M(11) = 14641/256 = 57.19140625, which is a terminating decimal.
However, for N = 8 the maximum is achieved by splitting it into three equal parts, so M(8) = 512/27, which is a non-terminating decimal.
Let D(N) = N if M(N) is a non-terminating decimal and D(N) = -N if M(N) is a terminating decimal.
For example, ΣD(N) for 5 ≤ N ≤ 100 is 2438.
Find ΣD(N) for 5 ≤ N ≤ 10000.
The post Project Euler 183 Solution appeared first on Dreamshire.
]]>