The programming thread!
Posted: Wed Mar 30, 2011 10:38 pm
I've heard many, many people saying that there's no "bad way" to program as long as you get the desired results.
This is, of course, complete and utter bullshit.
Let us take a look at a simple exercise, the likes of which you could find anywhere on the Internet:
EXAMPLE 37:
There are mathematical tools that allow us to determine whether a certain number is composed of the cubes of two others or not. For example, 35 is such a number, because it can be divided into 8 and 27, the cubes of 2 and 3, respectively.
Write a program that allows you to determine whether a number is a cube composite or not.
Sounds pretty simple, doesn't it?
Here, let's see what I did to solve the problem:
Now compare it to what some other guy did:
The question here being, is one of those answers wrong?
Of course one is.
Jesuschrist, don't be stupid.
Just look at that disgusting, convoluted, irregular, unstable piece of crap up there.
Of course it's wrong, and of course there is such a thing as bad programming.
Perhaps not impartially, objectively wrong, but wrong in the sense that answering an equation with a duck would be.
Anyway.
Does anyone feel like writing some code?
I think we could pull off a Berserk Quiz program, or something similar.
Hell, I think I could pull off something like that.
As a matter of fact, I'm starting right (well, tomorrow, I'm gonna study today) now.
Anyone, please, feel free to ridicule the code as I post it in this thread.
I encourage you to do so.
I'd particularly appreciate verbal abuse, that always pumps me up.
We have to start by thinking up the questions, I suppose.
Okay, first one:
1- Is the Idea of Evil canon?
A) No, of course not. The author requested that it be removed from the volumes, how much clearer can it be?
B) No, I don't think so. While consistent with the rest of the story, it has never been brought up since then, not even tangentially.
C) It is certainly a possibility, but I find it unlikely, as much I'd like it to be true. It had a very interesting implications, especially regarding the analogies that could have been drawn with the platonic theory of forms, but it just isn't canon.
D) DUR! Yes! Durdurdurdur! I like poop and approve of Nikita Khrushchev! Dadaism is a completely valid art movement! Oops, just soiled myself! Mmmm, just the way I like it!
And the correct answer would be B.
This is, of course, complete and utter bullshit.
Let us take a look at a simple exercise, the likes of which you could find anywhere on the Internet:
EXAMPLE 37:
There are mathematical tools that allow us to determine whether a certain number is composed of the cubes of two others or not. For example, 35 is such a number, because it can be divided into 8 and 27, the cubes of 2 and 3, respectively.
Write a program that allows you to determine whether a number is a cube composite or not.
Sounds pretty simple, doesn't it?
Here, let's see what I did to solve the problem:
Code: Select all
import IIC1103Package.Usuario;
class Pruebas {
public static void main(String[] args) {
double n= Usuario.entero("Ingrese el numero que desee analyzar");
double cube1=1;
double cube2;
double half= n/2;
double root1;
double root2;
double integer_1;
double integer_2;
if(n%2==0){
while (n!= cube1){
cube1= half +1;
cube2= half-1;
root1= Math.cbrt(cube1);
integer_1=root1*10%10;
root2= Math.cbrt(cube2);
integer_2=root2*10%10;
if(integer_1==0 && integer_2==0){
System.out.print("yes, it can.");
n=cube1;}
cube1++;
cube2++;}}
else{
n= n-1;
cube1= (n/2)+1;
cube2= (n/2);
while (n!=cube1){
root1= Math.cbrt(cube1);
integer_1=root1*10%10;
root2= Math.cbrt(cube2);
integer_2=root2*10%10;
if(integer_1==0 && integer_2==0){
System.out.print("yes, it can.");
n=cube1;}
else {cube1++;
cube2= 1+n-cube1;}}}
}}
Code: Select all
public static boolean test(int n){
for(int i=1; i*i*i<=n; i++){
int j;
for(j=i+1; i*i*i+j*j*j<n; j++)
if (i*i*i + j*j*j == n)
return true;
}
return false;
}
Of course one is.
Jesuschrist, don't be stupid.
Just look at that disgusting, convoluted, irregular, unstable piece of crap up there.
Of course it's wrong, and of course there is such a thing as bad programming.
Perhaps not impartially, objectively wrong, but wrong in the sense that answering an equation with a duck would be.
Anyway.
Does anyone feel like writing some code?
I think we could pull off a Berserk Quiz program, or something similar.
Hell, I think I could pull off something like that.
As a matter of fact, I'm starting right (well, tomorrow, I'm gonna study today) now.
Anyone, please, feel free to ridicule the code as I post it in this thread.
I encourage you to do so.
I'd particularly appreciate verbal abuse, that always pumps me up.
We have to start by thinking up the questions, I suppose.
Okay, first one:
1- Is the Idea of Evil canon?
A) No, of course not. The author requested that it be removed from the volumes, how much clearer can it be?
B) No, I don't think so. While consistent with the rest of the story, it has never been brought up since then, not even tangentially.
C) It is certainly a possibility, but I find it unlikely, as much I'd like it to be true. It had a very interesting implications, especially regarding the analogies that could have been drawn with the platonic theory of forms, but it just isn't canon.
D) DUR! Yes! Durdurdurdur! I like poop and approve of Nikita Khrushchev! Dadaism is a completely valid art movement! Oops, just soiled myself! Mmmm, just the way I like it!
And the correct answer would be B.