ChatGPT

Started by Slim, January 25, 2023, 02:57:10 PM

Previous topic - Next topic

Slim

I was going to write a brief BASH script to display random musical notes, for a fretboard learning exercise - I've always approached playing the guitar in terms of intervals and shapes. I want to be able to hit the nearest (say) Db without having to think about it too much.

So I decided to write a quick and dirty BASH script that would display the notes at random, every 5 seconds. Then I thought - why not just get ChatGPT to write it?

"Could you please write a BASH script for me to display musical notes randomly, at an interval of 5 seconds?" I asked.

It came back with this in two seconds:

#!/bin/bash

# Array of musical notes
notes=("C" "D" "E" "F" "G" "A" "B")

# Function to generate a random note
function get_random_note() {
  local note_index=$((RANDOM % ${#notes[@]}))
  echo "${notes[$note_index]}"
}

# Main loop
while true; do
  random_note=$(get_random_note)
  echo "Current note: $random_note"
  sleep 5
done

"That's very good, but please include flats and sharps", I replied.

About a second later:

#!/bin/bash

# Array of musical notes
notes=("C" "C#" "Db" "D" "D#" "Eb" "E" "F" "F#" "Gb" "G" "G#" "Ab" "A" "A#" "Bb" "B")

# Function to generate a random note
function get_random_note() {
  local note_index=$((RANDOM % ${#notes[@]}))
  echo "${notes[$note_index]}"
}

# Main loop
while true; do
  random_note=$(get_random_note)
  echo "Current note: $random_note"
  sleep 5
done

"Save the script, run it using the steps mentioned in the previous response, and you will now see random musical notes displayed, including flats (♭) and sharps (♯)", it said.

I ran it and although it did exactly what I'd asked for, it didn't do exactly what I wanted. I realised I didn't want it to repeat a note until it had been through the whole set of notes at random.

It came back with this, a second later:

#!/bin/bash

# Array of musical notes
notes=("C" "C#" "Db" "D" "D#" "Eb" "E" "F" "F#" "Gb" "G" "G#" "Ab" "A" "A#" "Bb" "B")

# Function to shuffle the notes array
function shuffle_notes() {
  local i=$(( ${#notes[@]} - 1 ))
  while [[ $i -gt 0 ]]; do
    local j=$(( RANDOM % (i+1) ))
    local temp=${notes[i]}
    notes[i]=${notes[j]}
    notes[j]=$temp
    ((i--))
  done
}

# Shuffle the notes array
shuffle_notes

# Function to get and remove the next note
function get_next_note() {
  local note=${notes[0]}
  notes=("${notes[@]:1}")
  echo "$note"
}

# Main loop
while [[ ${#notes[@]} -gt 0 ]]; do
  random_note=$(get_next_note)
  echo "Current note: $random_note"
  sleep 5
done

My first thought on looking through the code was that it was using a cumbersome method, but I assumed it would work. It didn't. It repeated the same note ad nauseam.

I pasted the output from the script and asked if it could see the problem. It apologised. "It seems that the notes array is not being shuffled correctly before retrieving the next note", it remarked.

And it came back with a modified version:

#!/bin/bash

# Array of musical notes
notes=("C" "C#" "Db" "D" "D#" "Eb" "E" "F" "F#" "Gb" "G" "G#" "Ab" "A" "A#" "Bb" "B")

# Function to shuffle the notes array
function shuffle_notes() {
  local num_notes=${#notes[@]}
  for ((i = num_notes - 1; i > 0; i--)); do
    local j=$((RANDOM % (i + 1)))
    local temp=${notes[i]}
    notes[i]=${notes[j]}
    notes[j]=$temp
  done
}

# Shuffle the notes array
shuffle_notes

# Function to get and remove the next note
function get_next_note() {
  local note=${notes[0]}
  notes=("${notes[@]:1}")
  echo "$note"
}

# Main loop
while [[ ${#notes[@]} -gt 0 ]]; do
  random_note=$(get_next_note)
  echo "Current note: $random_note"
  sleep 5
done

Unfortunately, it was still repeating notes.

I posted the output. It was smart enough to notice the error, and attempted another fix:

#!/bin/bash

# Array of musical notes
notes=("C" "C#" "Db" "D" "D#" "Eb" "E" "F" "F#" "Gb" "G" "G#" "Ab" "A" "A#" "Bb" "B")

# Function to shuffle the notes array
function shuffle_notes() {
  local num_notes=${#notes[@]}
  for ((i = num_notes - 1; i > 0; i--)); do
    local j=$((RANDOM % (i + 1)))
    local temp=${notes[i]}
    notes[i]=${notes[j]}
    notes[j]=$temp
  done
}

# Function to get and remove the next note
function get_next_note() {
  local note=${notes[0]}
  notes=("${notes[@]:1}")
  echo "$note"
}

# Main loop
while [[ ${#notes[@]} -gt 0 ]]; do
  shuffle_notes
  random_note=$(get_next_note)
  echo "Current note: $random_note"
  sleep 5
done

This time it worked perfectly. But I gave it a bit of education (not sure why, because it won't remember anything I teach it outside the conversation but hey).  "Here's a tip - there is a utility called 'shuf' that would make the task simpler", I typed.

"Thank you for the tip! You're absolutely right. The 'shuf' utility in Linux can simplify the task of shuffling the array. Here's an updated version of the script that utilizes shuf:"

It came back with a new version of the script, but although it worked it had retained a step from its previous effort which was now unnecessary.

"You don't need to remove the next note - just loop through the shuffled array", I explained.

"Apologies for the confusion. You're right, we don't need to remove the next note from the shuffled array. We can simply loop through the shuffled array. Here's the corrected version of the script:"

#!/bin/bash

# Array of musical notes
notes=("C" "C#" "Db" "D" "D#" "Eb" "E" "F" "F#" "Gb" "G" "G#" "Ab" "A" "A#" "Bb" "B")

# Shuffle the notes array
shuffled_notes=($(shuf -e "${notes[@]}"))

# Main loop
for note in "${shuffled_notes[@]}"; do
  echo "Current note: $note"
  sleep 5
done


Finally, this was very close to what I would have written in the first place. But it only took a couple of minutes to get there and to be fair, it had already produced an inefficient version that worked perfectly.
H5N1 kIlled a wild swan

The Picnic Wasp

Yeah, my thoughts exactly, James.😁

Slim

I asked ChatGPT to rewrite my most recent cycling post in the style of the LBC pseudo-journalist James O'Brien - hoping that James' innate cuntiness might lend it a certain sharpness. Well - this is what happened.

Whilst I find myself bound to the confines of my on-call duties, a remarkable tale unfolds, my dear readers. I confess, the lure of a captivating bike ride beckoned, undeterred by the challenges that lay in its path. Alas, the sweltering temperatures, reaching unprecedented heights in the late 20s, coupled with the ominous threat of impending rain, compelled me to postpone my cycling escapade. Patience became my companion as I awaited the arrival of the late afternoon, which, as fate would have it, proved to be fortuitous.

At the stroke of 2 pm, an unforeseen turn of events materialized. A high-priority incident, demanding my immediate attention, disrupted the tranquil flow of my day. How many times have I found myself miles away from home on a Saturday afternoon, enveloped in the serenity of a biking expedition, only to face the daunting prospect of explaining such circumstances? Today, however, the benevolence of a guardian angel graced my presence, steering me away from such predicaments. Truly, fortune smiled upon me.

Emboldened by the passage of time and the dissipation of the scorching sun's ultraviolet rays, I commenced my journey at precisely 16:42. A modicum of Dutch courage coursed through my veins as I indulged in a San Miguel, for the road ahead beckoned with both trepidation and excitement.

Initially, my intention was to traverse the path leading to Melbourne, veer right towards Isley Walton, and return via Top Brand. Yet, an audacious spirit gripped me as I pressed onward, traversing Swarkestone Bridge and venturing eastward through Weston and Aston, until Shardlow beckoned. Finally, the route guided me down to Isley Walton, passing through Castle Donington. Although reminiscent of previous rides, this endeavor proved significantly extended towards the northern territories.

Remarkably, the annual Download Festival enveloped Donington Park in its sonic embrace, yet the spectacle of revelers remained conspicuously absent from the town's streets and pubs. Typically, such occasions inundate the local establishments with a plethora of stoner-looking denizens and youths clad in Motorhead t-shirts. However, this day revealed no such scene.

By way of digression, it came to my attention that Metallica, renowned for their sonic prowess, allegedly caused a noise disturbance, resonating as far as fifteen miles away on Thursday night. A mere eight miles south of the venue, my better half claimed to have faintly heard their melodic strains while tending to the garden. Curiously, as I ventured outside earlier this evening, the resounding echoes of their performance remained elusive to my ears.

A serendipitous sight graced my vision as I witnessed a Sunwing passenger jet gracefully taking flight from the nearby airport. Previously unbeknownst to me, Sunwing emerged as a low-cost airline hailing from the far reaches of Toronto. Mere moments later, a Lear Jet descended with poise, preparing for a gentle landing. Rarely do I bear witness to such aviation spectacles during my cycling endeavors, making this occurrence a welcome deviation from the norm.

As the clock struck 7 pm, a thin veil of clouds gracefully enshrouded the skies, providing a modest respite from the sweltering heat that had permeated the day. Gratitude welled within me for this ephemeral relief.

However, with a mere two miles remaining, a disquieting suspicion took hold—my rear tire seemed to have succumbed to the inevitable fate of deflation. It had grown undeniably soft, a precursor to the forthcoming inconvenience. Although I had detected a slight anomaly in its pressure prior to embarking on this sojourn, I elected to inflate it to 100 PSI, assuring myself of its resilience. Alas, my optimism faltered as the tire gradually lost its firmness, necessitating a series of makeshift attempts to restore its tautness within the final mile. Miraculously, I arrived home unscathed, my rim unblemished, and the tire displaying no visible signs of distress.

Ah, well. Another task to undertake on the morrow, as it appears the repair of my tire now awaits my attention. As I conclude this recounting of my day's endeavors, my mileage stands at an admirable 31.02, contributing to a grand total of 224 miles conquered this month.

Until the next pedal stroke, I bid you adieu.
H5N1 kIlled a wild swan

The Picnic Wasp

The last sentence made me laugh out loud. I can only hear Rowan Atkinson's voice saying that, as Blackadder takes an obsequious bow.

dom

Good choice Slim! Love James O'Brien

Slim

I've been invited, by virtue as my role as a "local guide" - a title awarded by Google to people who have submitted a number of reviews to establishments on Google Maps - to take part in a trial of Google's competitor to ChatGPT, Bard.



I've just given it a spin and it got confused very quickly unfortunately. I asked if it was able to assist in the composition of fiction, it said yes (in essence); I asked if it had any limitations and it said it would be unable to help as it was text-based.

I replied that its response didn't make sense, as I was referring to text. Then it came back with some nonsense about making text bold.

Ah well I'll perservere with it for a bit, to help out if nothing else.

H5N1 kIlled a wild swan

Fishy

Trying ChatGPT for the first time.. asked for sing lyrics in the style of Dpinal Tap

(Verse 1)
We're the loudest band in town, we turn it up to eleven,
Our amps are massive, our hair's a gift from rock 'n' heaven,
We're not sure where we're going, but we're on a wild ride,
With our spandex and leather, we're the kings of rock 'n' pride.

(Chorus)
We're Spinal Tap, and we're here to rock,
Our drummer's always exploding, and that's a shock,
We're lost backstage, can't find the way out,
But we'll keep on playing, without a doubt!

(Verse 2)
Our backstage riders are crazy, we demand only green M&M's,
We're searching for the stage, but it's like a labyrinth in the den,
Our Stonehenge prop was way too small, it was a little absurd,
But we'll still rock this town, and be the loudest you've ever heard.

(Chorus)
We're Spinal Tap, and we're here to rock,
Our drummer's always exploding, and that's a shock,
We're lost backstage, can't find the way out,
But we'll keep on playing, without a doubt!

(Guitar Solo)

(Verse 3)
We've had our ups and downs, and our drummers have met their fate,
But we'll keep on going, 'cause we're the loudest, mate,
Our amps are on fire, the volume's cranked to max,
We're Spinal Tap, and we'll never relax!

(Chorus)
We're Spinal Tap, and we're here to rock,
Our drummer's always exploding, and that's a shock,
We're lost backstage, can't find the way out,
But we'll keep on playing, without a doubt!

(Outro)
So turn it up to eleven, and join our crazy show,
We're Spinal Tap, and we'll never let go,
In the world of rock 'n' roll, we're the kings of the block,
Spinal Tap forever, we'll never stop!
From The Land of Honest Men

David L

"But we'll keep on going, 'cause we're the loudest, mate,"

That's lame. Needs some development IMHO  ;)