I am aware of many resources all over the web. I'd like to read your explanations to undrestand better

]]>Did the creator of the chess game get a decent reward? Let's check it with some Go code.

Note: I printed out the loop results and corrected a mistake.

]]>Note that in Go a multiline string is enclosed in ` (ascii 96, whatever those are called).

]]>Note that in Go the **:=** is shorthand for assigning a type (by inference) and a value to a variable. A slice is like an array that can grow, and a map is a key indexed list. Go has only the for loop, but the syntax is very flexible and can accomplish all the usual loop duties.

`solveCubic(..)`

is called, the original implementation ignored the returned number of roots, but I changed it to `int shouldBeOne=`

so that I could look at it It is not one usually and we ignore more a root, and I don't know if that's a mistake or not. If this isn't a good place for this I'll have to head somewhere else.
```
public class Torus extends GeometricObject {
private double a;//outer circle center distance
private double b;//swept circle radius
private BBox bbox;
public Torus() {
this(2, 0.5);
}
public Torus(double a, double b) {
super();
this.a = a;
this.b = b;
bbox = new BBox(-a - b, a + b, -b, b, -a - b, a + b);
}
//...OTHER STUFF
public Normal computeNormal(Point3D p) {
Normal normal = new Normal();
double param_squared = a * a + b * b;
double x = p.x;
double y = p.y;
double z = p.z;
double sum_squared = x * x + y * y + z * z;
normal.x = 4.0 * x * (sum_squared - param_squared);
normal.y = 4.0 * y * (sum_squared - param_squared + 2.0 * a * a);
normal.z = 4.0 * z * (sum_squared - param_squared);
normal.normalize();
return (normal);
}
@Override
public boolean hit(Ray ray, ShadeRec s) {
if (!bbox.hit(ray)) {
return (false);
}
double x1 = ray.o.x;
double y1 = ray.o.y;
double z1 = ray.o.z;
double d1 = ray.d.x;
double d2 = ray.d.y;
double d3 = ray.d.z;
double[] coeffs = new double[5]; // coefficient array for the quartic equation
double[] roots = new double[4]; // solution array for the quartic equation
// define the coefficients of the quartic equation
double sum_d_sqrd = d1 * d1 + d2 * d2 + d3 * d3;
double e = x1 * x1 + y1 * y1 + z1 * z1 - a * a - b * b;
double f = x1 * d1 + y1 * d2 + z1 * d3;
double four_a_sqrd = 4.0 * a * a;
double E = e * e - four_a_sqrd * (b * b - y1 * y1); // constant term
double D = 4.0 * f * e + 2.0 * four_a_sqrd * y1 * d2;
double C = 2.0 * sum_d_sqrd * e + 4.0 * f * f + four_a_sqrd * d2 * d2;
double B = 4.0 * sum_d_sqrd * f;
double A = sum_d_sqrd * sum_d_sqrd; // coefficient of t^4
coeffs[0] = E;
coeffs[1] = D;
coeffs[2] = C;
coeffs[3] = B;
coeffs[4] = A;
boolean intersected = false;
// find roots of the quartic equation
int num_real_roots = Utility.solveQuartic(coeffs, roots);
double t = Utility.HUGE_VALUE;
if (num_real_roots == 0) {
return (false);
}
// find the smallest root greater than kEpsilon, if any
// the roots array is not sorted
for (int j = 0; j < num_real_roots; j++) {
if (roots[j] > Utility.EPSILON) {
intersected = true;
if (roots[j] < t) {
t = roots[j];
}
}
}
if (!intersected) {
return (false);
}
s.lastT = t;
s.localHitPosition.setTo(ray.o.add(ray.d.mul(t)));
s.normal.setTo(computeNormal(s.localHitPosition));
return (true);
}
//...OTHER STUFF
}
class Utility {
public static final double PI = Math.PI;
public static final double TWO_PI = 2 * PI;
public static final double PI_ON_180 = PI / 180.0;
public static final double INV_PI = 1.0 / PI;
public static final double INV_2_PI = 1.0 / TWO_PI;
public static final double EPSILON = 0.0001;
public static final double HUGE_VALUE = 1.0e10;
public static final boolean isZero(double x) {
return x > -EPSILON && x < EPSILON;
}
public static final int SolveQuadric(double c[], double s[]) {
double p, q, D;
/* normal form: x^2 + px + q = 0 */
p = c[ 1 ] / (2 * c[ 2 ]);
q = c[ 0 ] / c[ 2 ];
D = p * p - q;
if (isZero(D)) {
s[ 0 ] = - p;
return 1;
}
else if (D > 0) {
double sqrt_D = Math.sqrt(D);
s[ 0 ] = sqrt_D - p;
s[ 1 ] = - sqrt_D - p;
return 2;
}
else /* if (D < 0) */
return 0;
}
public static final int solveCubic(double c[], double s[]) {
int i, num;
double sub;
double A, B, C;
double sq_A, p, q;
double cb_p, D;
/* normal form: x^3 + Ax^2 + Bx + C = 0 */
A = c[ 2 ] / c[ 3 ];
B = c[ 1 ] / c[ 3 ];
C = c[ 0 ] / c[ 3 ];
/* substitute x = y - A/3 to eliminate quadric term:
x^3 +px + q = 0 */
sq_A = A * A;
p = 1.0/3 * (- 1.0/3 * sq_A + B);
q = 1.0/2 * (2.0/27 * A * sq_A - 1.0/3 * A * B + C);
/* use Cardano's formula */
cb_p = p * p * p;
D = q * q + cb_p;
if (isZero(D)) {
if (isZero(q)) { /* one triple solution */
s[ 0 ] = 0;
num = 1;
}
else { /* one single and one double solution */
double u = Math.cbrt(-q);
s[ 0 ] = 2 * u;
s[ 1 ] = - u;
num = 2;
}
}
else if (D < 0) { /* Casus irreducibilis: three real solutions */
double phi = 1.0/3 * Math.acos(-q / Math.sqrt(-cb_p));
double t = 2 * Math.sqrt(-p);
s[ 0 ] = t * Math.cos(phi);
s[ 1 ] = - t * Math.cos(phi + PI / 3);
s[ 2 ] = - t * Math.cos(phi - PI / 3);
num = 3;
}
else { /* one real solution */
double sqrt_D = Math.sqrt(D);
double u = Math.cbrt(sqrt_D - q);
double v = - Math.cbrt(sqrt_D + q);
s[ 0 ] = u + v;
num = 1;
}
/* resubstitute */
sub = 1.0/3 * A;
for (i = 0; i < num; ++i)
s[ i ] -= sub;
return num;
}
public static final int solveQuartic(double c[], double s[]) {
double[] coeffs=new double[4];
double z, u, v, sub;
double A, B, C, D;
double sq_A, p, q, r;
int i, num;
/* normal form: x^4 + Ax^3 + Bx^2 + Cx + D = 0 */
A = c[ 3 ] / c[ 4 ];
B = c[ 2 ] / c[ 4 ];
C = c[ 1 ] / c[ 4 ];
D = c[ 0 ] / c[ 4 ];
/* substitute x = y - A/4 to eliminate cubic term:
x^4 + px^2 + qx + r = 0 */
sq_A = A * A;
p = - 3.0/8 * sq_A + B;
q = 1.0/8 * sq_A * A - 1.0/2 * A * B + C;
r = - 3.0/256*sq_A*sq_A + 1.0/16*sq_A*B - 1.0/4*A*C + D;
if (isZero(r)) {
/* no absolute term: y(y^3 + py + q) = 0 */
coeffs[ 0 ] = q;
coeffs[ 1 ] = p;
coeffs[ 2 ] = 0;
coeffs[ 3 ] = 1;
num = solveCubic(coeffs, s);
s[ num++ ] = 0;
}
else {
/* solve the resolvent cubic ... */
coeffs[ 0 ] = 1.0/2 * r * p - 1.0/8 * q * q;
coeffs[ 1 ] = - r;
coeffs[ 2 ] = - 1.0/2 * p;
coeffs[ 3 ] = 1;
int shouldBeOne = solveCubic(coeffs, s);
/* ... and take the one real solution ... */
z = s[ 0 ];
/* ... to build two quadric equations */
u = z * z - r;
v = 2 * z - p;
if (isZero(u))
u = 0;
else if (u > 0)
u = Math.sqrt(u);
else
return 0;
if (isZero(v))
v = 0;
else if (v > 0)
v = Math.sqrt(v);
else
return 0;
coeffs[ 0 ] = z - u;
coeffs[ 1 ] = q < 0 ? -v : v;
coeffs[ 2 ] = 1;
num = SolveQuadric(coeffs, s);
coeffs[ 0 ]= z + u;
coeffs[ 1 ] = q < 0 ? v : -v;
coeffs[ 2 ] = 1;
int tempNum = 0;
double[] tempSols = new double[2];
tempNum = SolveQuadric(coeffs, tempSols);
for(int in =0; in<tempNum; in++){
s[in+num]=tempSols[in];
}
num+=tempNum;
}
/* resubstitute */
sub = 1.0/4 * A;
for (i = 0; i < num; ++i)
s[ i ] -= sub;
return num;
}
}
```

]]>##

#

```
<xs:simpleType name="nameType">
<xs:restriction base="string">
<xs:minLength value="1" />
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
<xs:element name="information">
<xs:complexType>
<xs:sequence>
<xs:element name="personal" maxOccurs="10">
<xs:complexType>
<xs:sequence>
<xs:element type="nameType" name="name"/>
<xs:element type="nameType" name="surname"/>
<xs:element type="nameType" name="age"/>
<xs:element type="nameType" name="postcode"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="school" maxOccurs="10">
<xs:complexType>
<xs:sequence>
<xs:element type="nameType" name="maths"/>
<xs:element type="nameType" name="english"/>
<xs:element type="nameType" name="physics"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
```

]]>I have learnt HTML,C,C++. But there are so many things out there....it's confusing what to learn and where.

I wanna learn more and achieve more. Like really get good at it..but I lack motivation and lose confidence in myself.

I need help and I am ready to learn things.

But where do I start?

Thankyou for your help.

]]>What is the time complixity of the following code:

Can you please give rules to follow , I couldn't figure it out!

```
func(n)
sÃ¢Â†Â0;
for iÃ¢Â†Ân to n^3
do
jÃ¢Â†Â1;
while j < i^2
do
jÃ¢Â†ÂjÃƒÂ—2;
sÃ¢Â†Âs+jÃ¢ÂˆÂ’i;
return(s);
```

Thanks

]]>Ok, so I have an assignement due for next week. It's fairly straight forward.

**Task 1**

A school keeps records of the weights of each pupil. The weight, in kilograms, of each pupil is recorded on the first day of term. Input and store the weights and names recorded for a class of 30 pupils you must store the weights in a one-dimensional array and the names in another one-dimensional array. All the weights must be validated on entry and any invalid weights rejected. You must decide your own validation rules. You may assume that the pupilsÃ¢Â€Â™ names are unique. Out put the names and weights of the pupils in the class.**Task 2**

The weights, in kilograms, of each pupil are recorded again on the last day of term. Calculate and store the difference in weights for each pupil.**Task 3**

For those pupils who have a difference in weight of more than 2.5 kilograms, output, with a suitable message, the pupilÃ¢Â€Â™s name, the difference in weight and whether this is a rise of a fall.

My pathetic attempt. (Please note that the syntax doesn't matter that much, this is pre-highschool stuff, some elements of my code are slightly VB-like)

Task 1

```
dim Studentnames[1:30] as string
dim Studentweights[1:30] as integer
For count=1 to 30
Input name
name = studentname[count]
Input weight
If weight>100 OR weight<20
THEN PRINT "ERROR: Weight not within range"
Else weight1 = studentweight[count]
Output studentweight[count], studentnames[count]
next
endfor
```

Task 2

```
dim weightdiff[1:30] as integer
dim diff as integer= 0
For count= 1 to 30
Input studentweights[count], finalweight
diff= studentweights[count] - finalweight
diff= weightdiff[count]
next
end for
```

Task 3

```
dim loss as integer= 0
dim gain as integer=0
For count = 1 to 30
Input studentname[count], weightdiff[count]
If weightdiff[count] >2.5
THEN gain= weightdiff[count]
PRINT studentname[count], "has lost", loss, "kilograms of weight"
Else if weightdiff[count] <2.5
THEN loss= 0 - weightdiff[count]
PRINT studentname[count], "has gained", gain, "kilograms of weight"
next
endfor
```

Since a negative weightdiff means a gain in weight, I subtracted the weightdiff from 0 (to make it positive) and then stored it in a variable called gain.

]]>My plan is to generate a graph at random keeping track of the number of components until I only have d edges to add and the generated graph so far has (d + 1) components. Then add the remaining edges ensureing that each edge added joins two unconnected components of the graph. The difficulty is that now each time I generate a new edge at random I must discard it if both of its endpoints are on the same component of the graph. I have no idea how many edges I can be expected to discard by this approach and have not found anything in the literature on my approach or any other approach.

Is there a result that states how many edges I need to generate before the graph becomes connected?

Is there another approach that guarentees termination in a reasonable time (O(nlog n) or better)?

I rarely visit here so emailing me at rpboland@gmail.com might be useful. ]]>

I have designed a website on the java and now I am facing many problems of designing and setting the layout. So suggest me the language to be used to designe a website which is more flexible and easyly modification can be done. I selected java on the basis of having more secure languge but its need more time and i am unble to modify it. So suggest me the best language to be used. And also to gain more traffice towards my website.

Thanks

```
#include<stdio.h>
int main(){
char str[100];
int i=0,j=-1,flag=0;
printf("Enter a string: ");
scanf("%s",str);
while(str[++j]!='\0');
j--;
while(i<j)
if(str[i++] != str[j--]){
flag=1;
break;
}
if(flag == 0)
printf("The string is a palindrome");
else
printf("The string is not a palindrome");
return 0;
}
```

]]>Device ID (input) / (key)

Device ID Lease Code 1 2 3 4 5 6 7 8

MI110800017 703 95be 73cb 416f 3155 14a8 e976 5750 703

MI110500013 8b97 1d6f 94cf 51f1 dd0c 7a0e d7e2 b1d3 8b97

MI110600013 5956 4c11 f56c 1a53 f0be 3a92 9da8 72eb 5956

MI110100001 acc2 8d17 16f9 20b0 4983 2bfb fb37 f16e acc2

MI110200002 1392 0efb e0f3 8b8a 4b6c 71d1 394f 9.70E+01 1392

MI1120800026 5331 070c 453d 9156 7cae 143d 595b 8c23 5331

MI110800012 ? ? ? ? ? ? ? ? ? ]]>

1. Write basic statement to assign two values 400 and 200, reading a data list to the identifier L and W

2. Write a program to point the value of a box with dimension 3 by 4 by 6, print out the 3 side with the volume. ]]>