Programming Thread

Started by the-pi-guy, Mar 13, 2016, 10:39 PM

0 Members and 2 Guests are viewing this topic.

the-pi-guy

Quote from: Legend on Jan 07, 2025, 12:44 AMWhat do you mean? Like the app auto updates but doesn't restart?
I want to be able to make updates to my personal application on one computer, and just dump it on the server, and have it know what to do with it. 

Legend

I love getting to work on fun challenging problems.

I asked OpenAI's premium model to do something and it said "This is, frankly, one of the most challenging tasks I've seen." It went a bit crazy trying to write the code and gave up and "faked" it (it directly said this in a comment rant). It also hallucinated quotes of mine.

kitler53

so what is actually challenging or did it just choke?
         

Featured Artist: Emily Rudd

Legend

Quote from: kitler53 on Jan 17, 2025, 06:58 PMso what is actually challenging or did it just choke?
The AI is normally arrogant like a stack overflow user. It'll completely ignore the finer details of even easy problems and just throw out code that does something else.

This is the first time it's done something like the above. I think it's just because I finally got it to understand the requirements.



In this case it's actually challenging though. My current code works for my needs but it uses a massive lookup table and a lot of enumeration. Would be nice to improve so I tried passing the challenge off to AI  ::)

the-pi-guy

Spoiler for Hidden:
<div class="codeheader"><span class="code floatleft">Code</span> <a class="codeoperation smf_select_text">Select</a> <a class="codeoperation smf_expand_code hidden" data-shrink-txt="Shrink" data-expand-txt="Expand">Expand</a></div><code class="bbc_code">using System;<br>using System.IO;<br>using NAudio.Wave;<br><br>class Program<br>{<br>&nbsp; &nbsp; static void Main(string&#91;] args)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; // Load the original audio file<br>&nbsp; &nbsp; &nbsp; &nbsp; string originalFilePath = &quot;original_audio.wav&quot;;<br>&nbsp; &nbsp; &nbsp; &nbsp; string replacementFilePath = &quot;replacement_audio.wav&quot;;<br>&nbsp; &nbsp; &nbsp; &nbsp; string outputFilePath = &quot;updated_audio.wav&quot;;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; using (var reader = new WaveFileReader(originalFilePath))<br>&nbsp; &nbsp; &nbsp; &nbsp; using (var replacement = new WaveFileReader(replacementFilePath))<br>&nbsp; &nbsp; &nbsp; &nbsp; using (var writer = new WaveFileWriter(outputFilePath, reader.WaveFormat))<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int segmentStartTime = 5000; // Start time in milliseconds<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int segmentEndTime = 10000; // End time in milliseconds<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Copy audio before the replacement<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int bytesPerMillisecond = reader.WaveFormat.AverageBytesPerSecond / 1000;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long segmentStartBytes = segmentStartTime * bytesPerMillisecond;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long segmentEndBytes = segmentEndTime * bytesPerMillisecond;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write the audio before the segment to replace<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CopyAudio(reader, writer, segmentStartBytes);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write the replacement audio<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CopyAudio(replacement, writer, replacement.Length);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Skip the replaced segment in the original audio<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reader.Position = segmentEndBytes;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write the audio after the replaced segment<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CopyAudio(reader, writer, reader.Length - segmentEndBytes);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Audio replacement completed!&quot;);<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; private static void CopyAudio(WaveFileReader reader, WaveFileWriter writer, long bytesToCopy)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; byte&#91;] buffer = new byte[1024];<br>&nbsp; &nbsp; &nbsp; &nbsp; while (bytesToCopy &gt; 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int bytesRead = reader.Read(buffer, 0, (int)Math.Min(buffer.Length, bytesToCopy));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (bytesRead == 0) break;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.Write(buffer, 0, bytesRead);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytesToCopy -= bytesRead;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></code><br><br>

Saving this for later.