sed help

Fermat’s Last Theorem is solved! Now I really feel like Rip Van Wrinkle. :smiley:

I see what you’re saying. You trade speed and simplicity for other options. To everything, there is a purpose.

Have a good day,

Yeah. That is the tool-theory, a tool should do one thing and do it well, and you’d choose the right tool for the job.

This is a good approach, as long as the tool-chain is fast enough, and only then do you rewrite in a higher level language, you can also view tools as functional objects. That using tool is indeed object oriented, sort of.

here is the Wikipedia article about Fermat’s last theorem

I also think you’d like to have a look at the Chinese remainder theorem as well; the calculation is the proof.
If you detested it at school, you may find it intriguing now!

And you have a good day as well kel. -Always a pleasure!


Here is a free book for you: Aho/Ullman: Foundations of Computer Science


In 1995, amazing:

Where have you been??? :slight_smile:

Just kidding, but I remember it as it was today. I was reading it in internet explorer, on Windows 95, I had an annoying friend at the time, who had a Mac, to every problem I had he just said, why don’t you just do it like that, or Ah, I just do that to accompish it. :slight_smile: AppleTalk and sharing documents. No such thing on Windows 95!

The book about Fermat’s last theorem, is by the way a very good one, with lots of interesting math in it.

Actually, I got too obsessive with computers in the past. So, I had to go fishing, or hiking, or gardening, or guitars or etc. When I get too obsessive, I go cold turkey. Then, I know that I don’t have to do something all the time. Computers can be addicting. Who would ignore another brain. :slight_smile:

Edited: forgot golf. :smiley:

I would lie if said I didn’t know what you were talking about. :wink:

Things got much easier after I started having laptops, less to carry around. :smiley:

By the way, if there is too much sunshine outside, there is a keyboard shortcut: ctrl-opt-cmd 8, that inverts the screen!

It works most of the time.

I hear you!

We just got wifi and I’m in the garage listening to music and realized that I could go on the internet also. It’s a distraction (or option) that needs to be tamed.

Well, enjoy your wifi, I have been reading something insanely boring today, now I go out, and enjoy the rest of the evening. Have a still good day.

This is good for up to 999 lines:

set cmd to "<~/Desktop/WolfandCrane.txt  sed -En '
1 {
	# Before editing the first line, create a counter and put it in the hold space. The 30 digits are notionally the three rotating wheels of a three-digit meter, the first, eleventh, and twenty-first digits being the “visible” ones. The initial reading is 001.
# Append each line in turn to the meter in the hold space and copy the result into the pattern space.
# Lose the non-visible digits in the pattern space and substitute a dot and a tab for the linefeed between the meter and the line. (We know the first 30 characters are digits, so we can use “.” rather than “[0-9]” in the regex.)
# Lose any leading zeros and print.
# Get the original meter/line combination again from the hold space.
# Rotate the “units wheel” by one digit and lose the line text.
/^.{20}0/ {
	# If the units have returned to zero, advance the “tens wheel”.
	# And if the tens return to zero, advance the “hundreds wheel”.
	/^.{10}0/ s/^(.)(.{9})/\\2\\1/
# Put the advanced meter back in the hold space.
do shell script cmd

Text encoding for smart double-quotes corrected 2022-12-01.


I must say i am glad I didn’t try to write a proof or something, late last night, when I realized, I might have used the ‘y’ command to shift the numbers one place to the right, but I had trouble with the 100’s and 10’s.

Wery well done Nigel!

Don’t be put off that there aren’t much room in your sed script for doing any other text transforms. it was really instructive to read, and see a clever solution. :slight_smile:

Actually, this one will be plastered up on the wall!

Hi Nigel,

Wow! :cool: Great idea using the counter also! Who said sed can’t count, huh? :smiley:

Thanks a lot,

I did :slight_smile:

And it doesn’t, but who cares, as the effect is the same anyway!

It is going up on the wall.Nigel’s Fame, my Shame. :smiley:

I actually got some of the same idea last night, but I couldn’t get longer than to 9 lines.

I don’t remember you saying that. I was just using a bit of irony. :slight_smile: Yes, it is a great script!

BTW, does anyone know the maximum number of bytes ‘do shell script’ can handle?

Edited: I should say, from a file for processing.


It is really great! :slight_smile:

Should give you the maximum length of a command line a shell can handle, as for a do shell script command line, I’d guess that if there is a limit as to the size of the command line, that limit would be 2^14 characters (not bytes).

I guess stream input to a do shell script would be pretty much unlimited.

Thanks, guys. :slight_smile:

It turns out that one of the ‘h’ commands can be cut from my script and two of the 's’s combined if the meter reading starts at 001 instead of 000 and is incremented after each line is printed instead of before it. I’ve updated the script accordingly.

Eliminating the anomalies, I get 0.009999990463 secs… I have a feeling that this is good for four ling lines.

Agent Smith? :wink: