The programming thread.

I did run freebsd for about 12 years - and it was kind of a pia (and costly since they were so anti-eide - this was in the mid 90's to mid 2000's - around the time Apple purchased Jordan. I was working for a company that did stuff in linux (2000-2020); so at some point i got tired of dealing with freebsd package manager and switched to linux - well specicifically ubuntu - after trying 5 or 6 different distributions (fedora, and a few others) and that is where i've been since - of course when ubuntu added zfs ready packages that sealed the cake as i was tired of building custom kernels with zfs. ZFS is really fantastic - not as good as netapp's top secret filesystem but close but this is another topic (and of course fantastic, good, ... are based off of my critera which might be contradictory to yours; but either way even today brts is a pile of horse radish waiting for you to skinny dip esp if you run raid of any sort).
The important thing is to be comfortable with a distro, I think.

I've tried a few again these last few weeks, including FreeBSD for comparison to Linux. It doesn't feel as mature, despite being rooted in the first Unix making it out of the post-Bell Labs business world. But it's normal, since Linux must have a lot more contributors. His current package manager is OK, but I haven't had to live with it for a long time.

My favourite distribution remains Manjaro, but other distributions also based on Arch come close (I'll have to test CachyOS on hardware to see if its optimized scheduling really pays off). Fedora caused me a lot of headaches, especially during the installation, and later, when I had to circumvent some issues with desktop environments. I've messed with Alpine, too, and it wasn't always easy, but I think it's more a niche distribution for containers and embedded systems anyway. Definitely more lightweight, but you have to post-install a lot of basic stuff.

I suppose you meant BTRFS? It has its uses, but I wouldn't use it without a good reason. ZFS seems great, but I heard it's a memory hog, and its legitimacy in the context of Canonical's Ubuntu is contested, I think.
 
Joined
Aug 29, 2020
Messages
12,482
Location
Good old Europe
The revenge of C++:


pibbuR who currently lets his enthusiasm be safely borrowed from the Rust fanbois.
 
Joined
Nov 11, 2019
Messages
2,698
Location
beRgen@noRway
Will they call it C+=2? *quickly runs away*
Or C+++. Or Crust. Or Really Modern C++. Or Smart C++. Or C<>. Or C&& (move semantics).

pibbuR who observes that there are a lot of options. Like the language itself. Which haters claim is part of the problem. Hah!
 
Joined
Nov 11, 2019
Messages
2,698
Location
beRgen@noRway
:ROFLMAO:


[…] the code has been forked at least 2,600 times as of this writing. In forking and examining the source when first released, coders have noticed some, shall we say, anomalies:
 
Joined
Aug 29, 2020
Messages
12,482
Location
Good old Europe
More CUDA programming :

//parallel printing of 128 random integers
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <time.h>

__global__ void kernel_proc(int *input)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
printf("block id: %d, thread id: %d, i: %d, value: %d\n", blockIdx.x, threadIdx.x, i, input);

}

int main()
{
int size = 128;
int byte_size = size * sizeof(int);


int* h_input;
time_t t;
h_input= (int *)malloc(byte_size);
srand((unsigned)time(&t));
for (int i{ 0 }; i < size; i++)
{
h_input = (int)(rand() & 0xff);
}

int* d_input;
cudaMalloc((void**)&d_input, byte_size); //allocate d_input memory on GPU
cudaMemcpy(d_input, h_input, byte_size, cudaMemcpyHostToDevice);

dim3 blockthreads(size/2); //GPU thread organization parameters. 2 blocks with 64 threads
dim3 blocks(2);

kernel_proc << <blocks, blockthreads >> > (d_input);
cudaDeviceSynchronize(); //wait until GPU is finished

cudaFree(d_input);
free(h_input);

cudaDeviceReset();
return 0;
}

Yay!
 
Last edited:
Joined
Nov 11, 2019
Messages
2,698
Location
beRgen@noRway
Python Pi's in alpha (sorry, it was too tempting).


Heh, they've only just released 3.13; someone's in a hurry.
No reason to be sorry. But now they have to adapt their versioning. So I expect the next version will be 3.141, then 3.1415, 3.14159.....

pibbuR who refuses to use Python if they don't follow these principles. (Probably also if they do).
 
Joined
Nov 11, 2019
Messages
2,698
Location
beRgen@noRway
No reason to be sorry. But now they have to adapt their versioning. So I expect the next version will be 3.141, then 3.1415, 3.14159.....

pibbuR who refuses to use Python if they don't follow these principles. (Probably also if they do).
You can submit a PEP (Python Enhancement Proposal). Who knows; they're a playful bunch. ;)

 
Joined
Aug 29, 2020
Messages
12,482
Location
Good old Europe
A (not very difficult) programming task, from the Matlab course I'm following:

Find 3 integers, such that
  1. a<b<c
  2. a+b+c=1000
  3. a^2+b^2=c^2
If you want to cheat, you could of course ask ChatGpt, which according to a friend of mind gives (in C):

for (a = 1; a < 1000; a++) {
for (b = a + 1; b < 1000; b++) {
c = 1000 - a - b; // since a + b + c = 1000
// test if a^2 + b^2 = c^2
if (a * a + b * b == c * c) {
printf("Solution: a = %d, b = %d, c = %d\n", a, b, c);
printf("a * b * c = %d\n", a * b * c);
return 0;
}
}
}

This will give the correct answer: 200,375,425. But it's highly unoptimized, requiring 179275 iterations.

First of all, if a<b<c, a cannot exceed 333, and b cannot exceed (1000-a)/2 which will reduce the number of iterations to 69775.

But actually, only one loop is required, giving no more than 333 iterations. By solving the two equations (for each iteration a is known)
  1. a+b+c=1000
  2. a^2+b^2=c^2
we get:
  1. b=-(a^2-(1000-a)^2)/(2*(1000-a));
  2. c=(1000-a)-b;
Then we only have to test if b and c are integers (we already know a is integer).

So the program becomes (here written in Matlab), where N is the sum of the integers.

N=1000 ;
for a=1:N/3
% solve equations a+b+c=N, a^2+b^2=c^2, a is known for each iteration
b=-(a^2-(N-a)^2)/(2*(N-a));
c=(N-a)-b;
% test if b and c are integers
if b==floor(b) && c==floor(c)
fprintf('Solution a: %d b:%d c:%d\n',a,b,c);
% omit return to catch more than one solution (if for instance N=9000)
end;
end;

For N=1000 there is only one solution. For other values there may be more (N=9000 gives 7).

Conclusion: ChatGpt provides an algorithm, but definitely not the one you should use.

pibbuR

PS. ChatGPT was asked for the solution in Norwegian, and I don't know the exact question given to it. Other variants of the question, in English may for all I know provide a better solution.
DS.
 
Last edited:
Joined
Nov 11, 2019
Messages
2,698
Location
beRgen@noRway
A (not very difficult) programming task, from the Matlab course I'm following:

Find 3 integers, such that
  1. a<b<c
  2. a+b+c=1000
  3. a^2+b^2=c^2
If you want to cheat, you could of course ask ChatGpt, which according to a friend of mind gives (in C):

for (a = 1; a < 1000; a++) {
for (b = a + 1; b < 1000; b++) {
c = 1000 - a - b; // since a + b + c = 1000
// test if a^2 + b^2 = c^2
if (a * a + b * b == c * c) {
printf("Solution: a = %d, b = %d, c = %d\n", a, b, c);
printf("a * b * c = %d\n", a * b * c);
return 0;
}
}
}

This will give the correct answer: 200,375,425. But it's highly unoptimized, requiring 179275 iterations.

First of all, if a<b<c, a cannot exceed 333, and b cannot exceed (1000-a)/2 which will reduce the number of iterations to 69775.

But actually, only one loop is required, giving no more than 333 iterations. By solving the two equations (for each iteration a is known)
  1. a+b+c=1000
  2. a^2+b^2=c^2
we get:
  1. b=-(a^2-(1000-a)^2)/(2*(1000-a));
  2. c=(1000-a)-b;
Then we only have to test if b and c are integers (we already know a is integer).

So the program becomes (here written in Matlab), where N is the sum of the integers.

N=1000 ;
for a=1:N/3
% solve equations a+b+c=N, a^2+b^2=c^2, a is known for each iteration
b=-(a^2-(N-a)^2)/(2*(N-a));
c=(N-a)-b;
% test if b and c are integers
if b==floor(b) && c==floor(c)
fprintf('Solution a: %d b:%d c:%d\n',a,b,c);
% omit return to catch more than one solution (if for instance N=9000)
end;
end;

For N=1000 there is only one solution. For other values there may be more (N=9000 gives 7).

Conclusion: ChatGpt provides an algorithm, but definitely not the one you should use.

pibbuR

PS. ChatGPT was asked for the solution in Norwegian, and I don't know the exact question given to it. Other variants of the question, in English may for all I know provide a better solution.
DS.
You raise an interesting point about efficiency as you reduce the complexity from N^2 to N. Now we visit a real world problem. We had a bunch of customers to sort and the code did it using an N^2 algorithm. This worked fine with 5 customers. But then over time we had 1,000,000 customers and it became a bit of a problem. My friend fix this in his code as was his job not once, nor twice but three times because the person who wrote the code was quite insistent that his code was fine and it did not matter that it took several days to get the results instead of a few seconds as the data could actually be processed without sorting at all but that is another story. To make matters worse the configuration had to be updated every 15 minutes or new customers could not access the system so while the system was busy processing the data from the previous update a new update would arrive. To make the entire situation intolerable the person who loved his N^2 solution that would never finished was very likeable so the big boss made him a team leader and primary contact for technical issues.

Moral of story: Slow is fine - for no matter how slow you are if you are likeable it matters not.
 
Joined
Jun 26, 2021
Messages
791
python.png
 
Joined
Nov 11, 2019
Messages
2,698
Location
beRgen@noRway
A (not very difficult) programming task, from the Matlab course I'm following:

Find 3 integers, such that
  1. a<b<c
  2. a+b+c=1000
  3. a^2+b^2=c^2
A small nitpick (I didn't see your post earlier): You need to require that a, b, c are positive. Your programs also all assume a > 0 implicitly. If I calculated correctly, a = -1500, b = 800, c = 1700 would be a solution otherwise.
 
Joined
Dec 26, 2007
Messages
2,195
There could be more trouble with the "b==floor(b) && c==floor(c)" statement, depending on the types and language being used. The division could end up with b being 123.00000000002 or some such. Unless your language and/or types are set up for it, you need to worry any time you try to get an integer out of division.
 
Joined
Aug 3, 2008
Messages
8,532
Location
Kansas City
I read the last few posts of this thread and now i have headache. Will I get a headache everytime i read the last few posts in this thread ?
 
Joined
Jun 26, 2021
Messages
791
Joined
Nov 11, 2019
Messages
2,698
Location
beRgen@noRway
Joined
Nov 11, 2019
Messages
2,698
Location
beRgen@noRway
Back
Top Bottom