Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

<lilo> Fairlight: udp is the light margarine of tcp/ip transport protocols :) -- Seen on #Linux


computers / comp.os.linux.advocacy / OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

SubjectAuthor
* OT programming challenge: fastest/best/shortest C program to jumble a sentence, DFS
`* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenrbowman
 +* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenDFS
 |`* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenrbowman
 | +* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenDFS
 | |+* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenDFS
 | ||`* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenrbowman
 | || `* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenvallor
 | ||  `- Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenrbowman
 | |`* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenrbowman
 | | `* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenvallor
 | |  `- Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenrbowman
 | `* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenDFS
 |  `* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenrbowman
 |   +- Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenDFS
 |   `* Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenChris Ahlstrom
 |    `* Re: OT programming challenge:rbowman
 |     `* Re: OT programming challenge:Chris Ahlstrom
 |      `* Re: OT programming challenge:rbowman
 |       +* Re: 16-bit floating-point.rbowman
 |       |`* Re: Some examples ?rbowman
 |       | `* Re: How does your Pico "make sure everything is working" ?rbowman
 |       |  `* Re: I was burning EEPROMs for handheld devices back in 1984, Orem Utah.rbowman
 |       |   `- Re: Had any good Blutwurst lately ?rbowman
 |       +- Re: OT programming challenge:Chris Ahlstrom
 |       `- Re: 16-bit floating-point.DFS
 `- Re: OT programming challenge: fastest/best/shortest C program to jumble a sentenDFS

Pages:12
OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<65e9cad3$0$4689$882e4bbb@reader.netnews.com>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11260&group=comp.os.linux.advocacy#11260

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.netnews.com!eu1.netnews.com!eu1.netnews.com!not-for-mail
X-Trace: DXC=_iMFmX6S[DaO5da<66@17mHWonT5<]0TmdjI?Uho:XeklL51CP6LDLl95GMl]75=8a6i]c>P;b`]bXfi2cY2CcLiQUE_nj5jP;`LPH8bHEb=:j
X-Complaints-To: support@blocknews.net
Date: Thu, 7 Mar 2024 09:10:27 -0500
MIME-Version: 1.0
User-Agent: Betterbird (Windows)
Newsgroups: comp.os.linux.advocacy
Content-Language: en-US
From: nospam@dfs.com (DFS)
Subject: OT programming challenge: fastest/best/shortest C program to jumble a
sentence, then restore it
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 29
Message-ID: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
NNTP-Posting-Host: 127.0.0.1
X-Trace: 1709820627 reader.netnews.com 4689 127.0.0.1:36105
 by: DFS - Thu, 7 Mar 2024 14:10 UTC

Original sentence: "Jumble this sentence then put it back in order."

Simple coding requirements:
has to be done in a loop
parse the original sentence into words
randomly jumble the words
concatenate them with spaces to form a new sentence string
print new sentence to screen
parse the new sentence and restore it
repeat

I haven't started yet, but I figure it's about 5-8 lines in python. Too
easy. So it has to be written in C.

I'm the judge.

I'm looking for 3 winning entries (including mine):
1) the fastest
2) the best
3) the fewest lines

The best might be the simplest, or the shortest, or the most innovative
use of C, etc. It's subjective, but I'll explain why I chose the best.

Obviously, you can't use anyone else's submission for ideas or tips
before submitting your own.

If you win all 3 categories, you're cola's King Of The Jumble.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<l4ufsbF9kdnU4@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11280&group=comp.os.linux.advocacy#11280

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: 7 Mar 2024 18:38:03 GMT
Lines: 17
Message-ID: <l4ufsbF9kdnU4@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net xjKUYIyL6XAOP93IfW+hMQAkRiABXlbR2tPVhjs67yr8vHXH2H
Cancel-Lock: sha1:5bCoXanljMOhlxOBxlel58QZH+4= sha256:k4rDieROTJhi3NZDf6d0UKPyb3ivByJQd047qOkLKLE=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Thu, 7 Mar 2024 18:38 UTC

On Thu, 7 Mar 2024 09:10:27 -0500, DFS wrote:

> I haven't started yet, but I figure it's about 5-8 lines in python. Too
> easy. So it has to be written in C.

https://nostarch.com/impracticalpythonprojects

I couldn't work up too much interest in the anagrams and cryptography
chapters but one exercise is the Union route Cipher.

https://programmingpraxis.com/2012/03/06/union-route-cipher/

Spice up your challenge! A point he makes with one of the more complex
ciphers is while code can do the grunt work human intervention is needed
to sort the fly shit from the pepper since you'll get grammatically
correct sentences like Chomsky's 'Colorless green ideas sleep furiously'.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usf2m9$1n0jh$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11323&group=comp.os.linux.advocacy#11323

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Fri, 8 Mar 2024 08:09:33 -0500
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <usf2m9$1n0jh$2@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Mar 2024 13:09:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fab2b49de04fb903622181ec797b4864";
logging-data="1802865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hU9cakgSby1u2uldL4GSP"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:FCBLs1cVDZ6KS6Q9S3AkejW752U=
In-Reply-To: <l4ufsbF9kdnU4@mid.individual.net>
Content-Language: en-US
 by: DFS - Fri, 8 Mar 2024 13:09 UTC

On 3/7/2024 1:38 PM, rbowman wrote:
> On Thu, 7 Mar 2024 09:10:27 -0500, DFS wrote:
>
>> I haven't started yet, but I figure it's about 5-8 lines in python. Too
>> easy. So it has to be written in C.
>
>
> Spice up your challenge!

Once you try it, you'll see it doesn't need spice.

It's harder than you think to randomly shuffle the words in a shorter
sentence, so that each word ends up in a different position than it
started in.

Bring it!

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<l518d6FmepqU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11636&group=comp.os.linux.advocacy#11636

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: 8 Mar 2024 19:48:54 GMT
Lines: 90
Message-ID: <l518d6FmepqU1@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net A3SyFW1aeMWR7cA+eMtWEwHcj+WzFeFUfZbKjE0OfrqSa/uTQ7
Cancel-Lock: sha1:8bCwI1TOmAo/oeD8AymOlEZUBrM= sha256:AKxS/qFmOSltmeH670CDIJSid6Jo3rSL5RpKmvxO/Gw=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Fri, 8 Mar 2024 19:48 UTC

On Fri, 8 Mar 2024 08:09:33 -0500, DFS wrote:

> It's harder than you think to randomly shuffle the words in a shorter
> sentence, so that each word ends up in a different position than it
> started in.
>
> Bring it!

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

int main(int argc, char** argv)
{ char* sentence = strdup("Once you try it, you'll see it doesn't need
spice.");
char* tokens[20];
int token_count = 0;
int i;
int j;
int slots;
int candidate;
int* indices;

for (tokens[token_count] = strtok(sentence, " ");
tokens[token_count];
tokens[token_count] = strtok(NULL, " "))
{
token_count++;
}

indices = malloc(token_count * sizeof(int));
for (i=0; i<token_count; i++) {
indices[i] = -1;
}
srand((unsigned int) time(NULL));
for (i=0, slots=0; slots<token_count; i++) {
candidate = rand() % token_count;
for (j=0; j<token_count; j++) {
if (indices[j] == candidate) {
break;
}
else if (indices[j] == -1) {
indices[slots++] = candidate;
break;
}
}
}
printf("\nshuffled:\n");
for (i=0; i<slots; i++) {
printf("%s ", tokens[indices[i]]);
}
printf("\noriginal: \n");
for (i=0; i<slots; i++) {
printf("%s ", tokens[i]);
}
printf("\n");

return 0;
}

../shuffle

shuffled:
doesn't you spice. try Once it, it need see you'll
original:
Once you try it, you'll see it doesn't need spice.

../shuffle

shuffled:
need it, spice. it you you'll see Once try doesn't
original:
Once you try it, you'll see it doesn't need spice.

Get enough monkeys running it and the shuffled sentence may be the same as
the original.

For production, I'd first count the tokens and allocate the tokens array
but I'm lazy. Further enhancements, allow the string to be entered on the
command line, read strings from a file and write shuffled strings to a
file, and so on.

Of course in Python you could use split and shuffle to abstract away all
the messiness.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usfs1a$1svs6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11643&group=comp.os.linux.advocacy#11643

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Fri, 8 Mar 2024 15:22:06 -0500
Organization: A noiseless patient Spider
Lines: 133
Message-ID: <usfs1a$1svs6$1@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 8 Mar 2024 20:22:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fab2b49de04fb903622181ec797b4864";
logging-data="1998726"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BWRpJwDD7HS++WQGK7LhO"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:rNm9Q33nw5HrF/T/KjjpFnxjwbE=
In-Reply-To: <l518d6FmepqU1@mid.individual.net>
Content-Language: en-US
 by: DFS - Fri, 8 Mar 2024 20:22 UTC

On 3/8/2024 2:48 PM, rbowman wrote:
> On Fri, 8 Mar 2024 08:09:33 -0500, DFS wrote:
>
>> It's harder than you think to randomly shuffle the words in a shorter
>> sentence, so that each word ends up in a different position than it
>> started in.
>>
>> Bring it!

Thanks for doing it.

FYI:
--------------------------------------------------------------------------
~$ gcc jumble_rbowman.c -o jumble

jumble_rbowman.c: In function ‘main’:
jumble_rbowman.c:9:29: warning: missing terminating " character
9 | char* sentence = strdup("Once you try it, you'll see it
doesn't need
| ^
jumble_rbowman.c:9:29: error: missing terminating " character
9 | char* sentence = strdup("Once you try it, you'll see it
doesn't need
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jumble_rbowman.c:10:1: error: ‘spice’ undeclared (first use in this
function)
10 | spice.");
| ^~~~~
jumble_rbowman.c:10:1: note: each undeclared identifier is reported only
once for each function it appears in
jumble_rbowman.c:10:7: warning: missing terminating " character
10 | spice.");
| ^
jumble_rbowman.c:10:7: error: missing terminating " character
10 | spice.");
| ^~~
jumble_rbowman.c:11:5: error: expected identifier before ‘char’
11 | char* tokens[20];
| ^~~~
jumble_rbowman.c:54:1: error: expected ‘,’ or ‘;’ before ‘}’ token
54 | }
| ^
jumble_rbowman.c:54:1: error: expected declaration or statement at end
of input
--------------------------------------------------------------------------

> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <time.h>
>
> int main(int argc, char** argv)
> {
> char* sentence = strdup("Once you try it, you'll see it doesn't need
> spice.");
> char* tokens[20];
> int token_count = 0;
> int i;
> int j;
> int slots;
> int candidate;
> int* indices;
>
> for (tokens[token_count] = strtok(sentence, " ");
> tokens[token_count];
> tokens[token_count] = strtok(NULL, " "))
> {
> token_count++;
> }
>
> indices = malloc(token_count * sizeof(int));
> for (i=0; i<token_count; i++) {
> indices[i] = -1;
> }
> srand((unsigned int) time(NULL));
> for (i=0, slots=0; slots<token_count; i++) {
> candidate = rand() % token_count;
> for (j=0; j<token_count; j++) {
> if (indices[j] == candidate) {
> break;
> }
> else if (indices[j] == -1) {
> indices[slots++] = candidate;
> break;
> }
> }
> }
> printf("\nshuffled:\n");
> for (i=0; i<slots; i++) {
> printf("%s ", tokens[indices[i]]);
> }
> printf("\noriginal: \n");
> for (i=0; i<slots; i++) {
> printf("%s ", tokens[i]);
> }
> printf("\n");
>
> return 0;
> }
>
> ./shuffle
>
> shuffled:
> doesn't you spice. try Once it, it need see you'll
> original:
> Once you try it, you'll see it doesn't need spice.
>
> ./shuffle
>
> shuffled:
> need it, spice. it you you'll see Once try doesn't
> original:
> Once you try it, you'll see it doesn't need spice.
>
> Get enough monkeys running it and the shuffled sentence may be the same as
> the original.
>
> For production, I'd first count the tokens and allocate the tokens array
> but I'm lazy. Further enhancements, allow the string to be entered on the
> command line, read strings from a file and write shuffled strings to a
> file, and so on.
>
> Of course in Python you could use split and shuffle to abstract away all
> the messiness.
>
>
>
>

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usft59$1t70f$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11652&group=comp.os.linux.advocacy#11652

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Fri, 8 Mar 2024 15:41:13 -0500
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <usft59$1t70f$1@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usfs1a$1svs6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 8 Mar 2024 20:41:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="fab2b49de04fb903622181ec797b4864";
logging-data="2006031"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HL+HkfVdxgiRz0TM2oSon"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:swcQO4wRyGFyn9OuuaP9HUy2TFU=
In-Reply-To: <usfs1a$1svs6$1@dont-email.me>
Content-Language: en-US
 by: DFS - Fri, 8 Mar 2024 20:41 UTC

On 3/8/2024 3:22 PM, DFS wrote:
> On 3/8/2024 2:48 PM, rbowman wrote:
>> On Fri, 8 Mar 2024 08:09:33 -0500, DFS wrote:
>>
>>> It's harder than you think to randomly shuffle the words in a shorter
>>> sentence, so that each word ends up in a different position than it
>>> started in.
>>>
>>> Bring it!
>
>
> Thanks for doing it.
>
>
> FYI:
> --------------------------------------------------------------------------
> ~$ gcc jumble_rbowman.c -o jumble
>
> jumble_rbowman.c: In function ‘main’:
> jumble_rbowman.c:9:29: warning: missing terminating " character
>     9 |     char* sentence = strdup("Once you try it, you'll see it
> doesn't need
>       |                             ^
> jumble_rbowman.c:9:29: error: missing terminating " character
>     9 |     char* sentence = strdup("Once you try it, you'll see it
> doesn't need
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> jumble_rbowman.c:10:1: error: ‘spice’ undeclared (first use in this
> function)
>    10 | spice.");
>       | ^~~~~
> jumble_rbowman.c:10:1: note: each undeclared identifier is reported only
> once for each function it appears in
> jumble_rbowman.c:10:7: warning: missing terminating " character
>    10 | spice.");
>       |       ^
> jumble_rbowman.c:10:7: error: missing terminating " character
>    10 | spice.");
>       |       ^~~
> jumble_rbowman.c:11:5: error: expected identifier before ‘char’
>    11 |     char* tokens[20];
>       |     ^~~~
> jumble_rbowman.c:54:1: error: expected ‘,’ or ‘;’ before ‘}’ token
>    54 | }
>       | ^
> jumble_rbowman.c:54:1: error: expected declaration or statement at end
> of input
> --------------------------------------------------------------------------

Sorry. That's ALL from a crlf inserted by the newsreader. It compiled
cleanly after I took it out.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usgfe4$20gfq$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11669&group=comp.os.linux.advocacy#11669

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Fri, 8 Mar 2024 20:53:08 -0500
Organization: A noiseless patient Spider
Lines: 280
Message-ID: <usgfe4$20gfq$2@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Mar 2024 01:53:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bd0cd99499b1364606b6e597c9f2633e";
logging-data="2114042"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UaoCoDK6Hn1dtg/+K3CKd"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:dGItwoUfsCUbRm+thOKX51qzB44=
In-Reply-To: <l518d6FmepqU1@mid.individual.net>
Content-Language: en-US
 by: DFS - Sat, 9 Mar 2024 01:53 UTC

On 3/8/2024 2:48 PM, rbowman wrote:
> On Fri, 8 Mar 2024 08:09:33 -0500, DFS wrote:
>
>> It's harder than you think to randomly shuffle the words in a shorter
>> sentence, so that each word ends up in a different position than it
>> started in.
>>
>> Bring it!
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <time.h>
>
> int main(int argc, char** argv)
> {
> char* sentence = strdup("Once you try it, you'll see it doesn't need
> spice.");
> char* tokens[20];
> int token_count = 0;
> int i;
> int j;
> int slots;
> int candidate;
> int* indices;
>
> for (tokens[token_count] = strtok(sentence, " ");
> tokens[token_count];
> tokens[token_count] = strtok(NULL, " "))
> {
> token_count++;
> }
>
> indices = malloc(token_count * sizeof(int));
> for (i=0; i<token_count; i++) {
> indices[i] = -1;
> }
> srand((unsigned int) time(NULL));
> for (i=0, slots=0; slots<token_count; i++) {
> candidate = rand() % token_count;
> for (j=0; j<token_count; j++) {
> if (indices[j] == candidate) {
> break;
> }
> else if (indices[j] == -1) {
> indices[slots++] = candidate;
> break;
> }
> }
> }
> printf("\nshuffled:\n");
> for (i=0; i<slots; i++) {
> printf("%s ", tokens[indices[i]]);
> }
> printf("\noriginal: \n");
> for (i=0; i<slots; i++) {
> printf("%s ", tokens[i]);
> }
> printf("\n");
>
> return 0;
> }
>
> ./shuffle
>
> shuffled:
> doesn't you spice. try Once it, it need see you'll
> original:
> Once you try it, you'll see it doesn't need spice.
>
> ./shuffle
>
> shuffled:
> need it, spice. it you you'll see Once try doesn't
> original:
> Once you try it, you'll see it doesn't need spice.

------------------------------------------------------------
~$ ./shuffle
slot = 0, candidate = 1
slot = 1, candidate = 8
slot = 2, candidate = 2 (match)
slot = 3, candidate = 7
slot = 4, candidate = 9
slot = 5, candidate = 5 (match)
slot = 6, candidate = 4
slot = 7, candidate = 6
slot = 8, candidate = 0
slot = 9, candidate = 3

original: Once you try it, you'll see it doesn't need spice.
shuffled: you need try doesn't spice. see you'll it Once it,
------------------------------------------------------------

Some words weren't shuffled. Your bank acct is now hacked.

When I was writing my version yesterday (see below), I found ~8% of the
rands matched when the sentence was short.

Double the length of the sentence and the percent of matches falls to
around 5%.

> Get enough monkeys running it and the shuffled sentence may be the same as
> the original.

That would = bad programming.

> For production, I'd first count the tokens and allocate the tokens array
> but I'm lazy. Further enhancements, allow the string to be entered on the
> command line, read strings from a file and write shuffled strings to a
> file, and so on.

I usually try to take command line inputs. Makes the program easier to
test and fun to use.

> Of course in Python you could use split and shuffle to abstract away all
> the messiness.

It amazes me how productive Python can be versus C.

my code
----------------------------------------------------------------------

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>

//usage $./prog "sentence in quotes" N-jumbles

//is dest already set in the array
int found(int dest,int rarr[], int cnt) {
int match = 0;
for (int j = 0; j < cnt; j++) {
if (dest == rarr[j]) {match = 1;break;}
}
return match;
}

int main(int argc, char *argv[]) {

int i = 0, j = 0, k = 0;
char *orig = argv[1];
int loops = atoi(argv[2]);
//count words = number of spaces + 1
int wordcnt = 1;
for (int i = 0; i < strlen(orig); i++) {
if(isspace(orig[i]) && !isspace(orig[i+1])) {wordcnt++;}
}

//arrays to hold words and numbers
char **words = malloc(sizeof(char*) * wordcnt);
char **temp = malloc(sizeof(char*) * wordcnt);
int randarr[wordcnt];
for(int i = 0; i < wordcnt ; randarr[i++] = wordcnt + 1);

//split string copy on space, add words to array
char *copy = strdup(orig);
const char delimiter[] = " ";
char *token = strtok(copy, delimiter);
while (token != NULL) {
words[i++] = token;
token = strtok(NULL, delimiter);
}

//show word count
printf(" %d words\n",wordcnt);

//print original sentence
printf("---------------------------------------------------\n");
printf(" %s\n",orig);
printf("---------------------------------------------------\n");
//generate randoms until each word moves to a different position
srand(time(NULL));
int src,dest,fdest;
int totmatches = 0;
k = 1;
while (k <= loops) {
for (int src = 0; src < wordcnt; src++) {
dest = rand() % wordcnt;

//printf("src=%d,dest=%d,found=%d\n",src,dest,found(dest,randarr,wordcnt));
while (1)
{
fdest = found(dest,randarr,wordcnt);
if ((src != dest && fdest == 0) || (src == dest && src ==
(wordcnt-1) && fdest == 0))
{
randarr[src] = dest;
temp[dest] = words[src];
break;
}
else
{
dest = rand() % wordcnt;

//printf("src=%d,dest=%d,found=%d\n",src,dest,found(dest,randarr,wordcnt));
}
}
}

//print jumbled indices and values in arrays
//for(j = 0; j < wordcnt; j++) {
//printf("%d %d %10s %10s\n",j,randarr[j],words[j],temp[j]);
//}

//print jumbled sentence
printf("%2d. ",k);
int matches = 0;
for(j = 0; j < wordcnt; j++) {
printf("%s ",temp[j]);
if (temp[j] == words[j]) {matches++;totmatches++;}
}
if (matches > 0) {printf(" %d match\n",matches);} else {printf("\n");}

//reset arrays
memset(temp, 0, wordcnt * sizeof(temp));
for(int j = 0; j < wordcnt ; randarr[j++] = 999);

k++;
}
printf("---------------------------------------------------\n");
printf("Total matches = %d\n",totmatches);

free(words);
free(temp);
return(0);
}

----------------------------------------------------------------------

~$ ./jumble "Jumble this sentence then put it back in order" 10
9 words
---------------------------------------------------
Jumble this sentence then put it back in order
---------------------------------------------------
1. then put Jumble sentence in this it back order 1 match
2. order in Jumble put back sentence then it this
3. this back in order sentence Jumble it put then
4. put Jumble order it then this sentence back in
5. sentence order then Jumble in this it put back
6. back in it this Jumble sentence order then put
7. put Jumble back it in then order this sentence
8. it order back in this put then Jumble sentence
9. sentence order put Jumble back this in it then
10. it sentence back put then in Jumble this order 1 match
---------------------------------------------------
Total matches = 2

You'll note in mine the match is always the last word of the input. I'm
gonna put in a little kludge to fix that: swap the last word for a
randomly chosen earlier one. That'll make for a 'perfect' jumble.

Thanks for participating. I was about to cancel the challenge for lack
of interest. Our code isn't quite done, since one of the requirements
was to concatenate the tokens, then print. And then split the jumbled
one apart and reconstitute it. Mostly useless exercises, I now realize.

Your code is shorter than mine, but mine takes 2 command line inputs and
prints more information.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<l520v9FqgibU5@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11675&group=comp.os.linux.advocacy#11675

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: 9 Mar 2024 02:48:10 GMT
Lines: 31
Message-ID: <l520v9FqgibU5@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usfs1a$1svs6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 0+UEFEdpkHFhmyZyZwibcABSaP1zqndUMygLmQyH+YmWt0Exfg
Cancel-Lock: sha1:Kq1jjuuZ/qPulVS9MDnFuGfYcj0= sha256:bBqzxn0lfRwmRHN7tSCa/ukncMUssFfU9iq5npAbEyI=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sat, 9 Mar 2024 02:48 UTC

On Fri, 8 Mar 2024 15:22:06 -0500, DFS wrote:

> FYI:

Obviously you didn't put it back together after word wrap broke it up.

gcc -pedantic -Wall -Wcast-qual -Wmissing-prototypes -Wshadow shuffle.c -
o shuffle

runs with no errors or warnings. If you throw in -std=c99

gcc -std=c99 shuffle.c -o shuffle
shuffle.c: In function ‘main’:
shuffle.c:8:22: warning: implicit declaration of function ‘strdup’; did
you mean ‘strcmp’? [-Wimplicit-function-declaration]
8 | char* sentence = strdup("Once you try it, you'll see it
doesn't need spice.");
| ^~~~~~
| strcmp
shuffle.c:8:22: warning: initialization of ‘char *’ from ‘int’ makes
pointer from integer without a cast [-Wint-conversion]

Why? you might ask? ISO C99 doesn't include strdup although it's strange
it pulls strcmp out of its ass.

gcc -std=gnu99 shuffle.c -o shuffle

works fine.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usgjeh$1rnlb$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11676&group=comp.os.linux.advocacy#11676

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vallor@cultnix.org (vallor)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Sat, 9 Mar 2024 03:01:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <usgjeh$1rnlb$2@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usfs1a$1svs6$1@dont-email.me>
<l520v9FqgibU5@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Mar 2024 03:01:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ab4e216fb12235b831fdc816a1885311";
logging-data="1957547"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3a/i+6ntP5r0tbhfxu3sI"
User-Agent: Pan/0.155 (Kherson; c0bf34e gitlab.gnome.org/GNOME/pan.git;
x86_64-pc-linux-gnu)
Cancel-Lock: sha1:tcPmkL4y/AUwJoihEiNTYdMyZMo=
X-Face: \}2`P"_@pS86<'EM:'b.Ml}8IuMK"pV"?FReF$'c.S%u9<Q#U*4QO)$l81M`{Q/n
XL'`91kd%N::LG:=*\35JS0prp\VJN^<s"b#bff@fA7]5lJA.jn,x_d%Md$,{.EZ
 by: vallor - Sat, 9 Mar 2024 03:01 UTC

On 9 Mar 2024 02:48:10 GMT, rbowman <bowman@montana.com> wrote in
<l520v9FqgibU5@mid.individual.net>:

> On Fri, 8 Mar 2024 15:22:06 -0500, DFS wrote:
>
>> FYI:
>
> Obviously you didn't put it back together after word wrap broke it up.
>
> gcc -pedantic -Wall -Wcast-qual -Wmissing-prototypes -Wshadow shuffle.c
> - o shuffle
>
> runs with no errors or warnings. If you throw in -std=c99
>
> gcc -std=c99 shuffle.c -o shuffle shuffle.c: In function ‘main’:
> shuffle.c:8:22: warning: implicit declaration of function ‘strdup’; did
> you mean ‘strcmp’? [-Wimplicit-function-declaration]
> 8 | char* sentence = strdup("Once you try it, you'll see it
> doesn't need spice.");
> | ^~~~~~
> | strcmp
> shuffle.c:8:22: warning: initialization of ‘char *’ from ‘int’ makes
> pointer from integer without a cast [-Wint-conversion]
>
> Why? you might ask? ISO C99 doesn't include strdup although it's strange
> it pulls strcmp out of its ass.

What about:
char sentence[] = "Once you try it, you'll see it doesn't need spice.";

?

>
> gcc -std=gnu99 shuffle.c -o shuffle
>
> works fine.

--
-v

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<l522g2FqgibU6@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11677&group=comp.os.linux.advocacy#11677

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: 9 Mar 2024 03:14:10 GMT
Lines: 50
Message-ID: <l522g2FqgibU6@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usfs1a$1svs6$1@dont-email.me>
<usft59$1t70f$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 5zDGJIoBqZzfjLF2dhyzjA3vA+GU83XVLBb6r5EG5z4j+YoS61
Cancel-Lock: sha1:6ERtMwqGKocd84W/XJNxI3pp5vI= sha256:iid56JqBdV6fCFZDMKlbwENoEyH0kywKhSPlPv0oBW8=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sat, 9 Mar 2024 03:14 UTC

On Fri, 8 Mar 2024 15:41:13 -0500, DFS wrote:

> Sorry. That's ALL from a crlf inserted by the newsreader. It compiled
> cleanly after I took it out.

Yup...

In production code I'd likely do

char* sentence;

sentence = strdup("Once you try it, you'll see it doesn't need spice.");
if (sentence == NULL) {
printf("strdup() failed: %s", strerror(errno));
return -1;
}

Admittedly is the implied malloc() failed the odds of it printing anything
aren't great but might as well try. I probably would use strtok_r() in
production if there was a remote possibility that there would be another
nested strtok(). That's ruined more than one programmer's day.

It does make one appreciate Python when you're not scrambling for the last
nanosecond. I recently came across an article about MicroPython on the
Pico by someone who hung a logic analyzer on an output. The first
observation was

def Blink():
While True:
pin.on()
pin.off()

Blink()

was faster than an in-line

While True:
pin.on()
pin.off()

The second observation was if you were working with nanoseconds it was
time to move to C. No surprise on the second but apparently the generated
code is a little better optimized in a function.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usgl6d$1rnlb$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11678&group=comp.os.linux.advocacy#11678

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vallor@cultnix.org (vallor)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Sat, 9 Mar 2024 03:31:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <usgl6d$1rnlb$3@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usfs1a$1svs6$1@dont-email.me>
<usft59$1t70f$1@dont-email.me> <l522g2FqgibU6@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Mar 2024 03:31:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ab4e216fb12235b831fdc816a1885311";
logging-data="1957547"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19du2s4MaFX+DgpjIA6g5Tk"
User-Agent: Pan/0.155 (Kherson; c0bf34e gitlab.gnome.org/GNOME/pan.git;
x86_64-pc-linux-gnu)
Cancel-Lock: sha1:nIr943MUWNxzzlqerWIfgM2sk4Q=
X-Face: \}2`P"_@pS86<'EM:'b.Ml}8IuMK"pV"?FReF$'c.S%u9<Q#U*4QO)$l81M`{Q/n
XL'`91kd%N::LG:=*\35JS0prp\VJN^<s"b#bff@fA7]5lJA.jn,x_d%Md$,{.EZ
 by: vallor - Sat, 9 Mar 2024 03:31 UTC

On 9 Mar 2024 03:14:10 GMT, rbowman <bowman@montana.com> wrote in
<l522g2FqgibU6@mid.individual.net>:

> On Fri, 8 Mar 2024 15:41:13 -0500, DFS wrote:
>
>> Sorry. That's ALL from a crlf inserted by the newsreader. It compiled
>> cleanly after I took it out.
>
> Yup...
>
> In production code I'd likely do
>
> char* sentence;
>
> sentence = strdup("Once you try it, you'll see it doesn't need spice.");
> if (sentence == NULL) {
> printf("strdup() failed: %s", strerror(errno));
> return -1;
> }

Seems like a lot of work that could be handled by
char sentence[] = "initializer";

Am I missing something?

>
> Admittedly is the implied malloc() failed the odds of it printing
> anything aren't great but might as well try. I probably would use
> strtok_r() in production if there was a remote possibility that there
> would be another nested strtok(). That's ruined more than one
> programmer's day.
>

--
-v

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<l525jkFqgibU9@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11680&group=comp.os.linux.advocacy#11680

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: 9 Mar 2024 04:07:16 GMT
Lines: 22
Message-ID: <l525jkFqgibU9@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usfs1a$1svs6$1@dont-email.me>
<usft59$1t70f$1@dont-email.me> <l522g2FqgibU6@mid.individual.net>
<usgl6d$1rnlb$3@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net Vh4zpdDDrgLLvZKM0Tgr2ABKGzysbr8eD51chewDn6xEwR8Eot
Cancel-Lock: sha1:V7rpt4R8DZfUzuWUtNc48p4JxLQ= sha256:x3HnY0f1tGo93YveM5zH0IuMmnzr7de1XQnysmdNXcU=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sat, 9 Mar 2024 04:07 UTC

On Sat, 9 Mar 2024 03:31:26 -0000 (UTC), vallor wrote:

> Seems like a lot of work that could be handled by char sentence[] =
> "initializer";
>
> Am I missing something?

No, that works too. Force of habit for me. In a more complicated scenario
if you had

void jumble(char* phrase)
{ char* sentence = strdup(phrase);
....
}

you would preserve phrase. In this case after the strtoks if you

printf("%s\n", sentence);

you would get 'Once' since strtok() inserts '\0' after each token.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<l525peFqgibU10@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11681&group=comp.os.linux.advocacy#11681

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!nntp.comgw.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: 9 Mar 2024 04:10:22 GMT
Lines: 7
Message-ID: <l525peFqgibU10@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usfs1a$1svs6$1@dont-email.me>
<l520v9FqgibU5@mid.individual.net> <usgjeh$1rnlb$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net TZj6/SyS+6Lm2WaE0f6ZXgK+124XwzFsD0Frj8nbVT6LYyiWse
Cancel-Lock: sha1:didfK/59r+wU+iLX4zkDkWSchkU= sha256:LDhdU/i643VvlJyrvtEHam+QPcS4DCSeutpA7vN/ihM=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sat, 9 Mar 2024 04:10 UTC

On Sat, 9 Mar 2024 03:01:37 -0000 (UTC), vallor wrote:

> What about:
> char sentence[] = "Once you try it, you'll see it doesn't need spice.";

That would work for C99 since there isn't a strdup(). In this case, no
problem.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<l5272pFqgibU12@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11683&group=comp.os.linux.advocacy#11683

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: 9 Mar 2024 04:32:26 GMT
Lines: 9
Message-ID: <l5272pFqgibU12@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usgfe4$20gfq$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net lOi18TB3tscUkVS6V0LxgAGhSsZ8dsL9kL9c+2iMwtJps/Be+t
Cancel-Lock: sha1:bjitWs3lNAvKftrl6LbmaV1hT8c= sha256:Kiq6uKC6WBLu3GrpoYfk2t+AtLNLxZ/AW7WEDG5nU2M=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sat, 9 Mar 2024 04:32 UTC

On Fri, 8 Mar 2024 20:53:08 -0500, DFS wrote:

> Thanks for participating. I was about to cancel the challenge for lack
> of interest. Our code isn't quite done, since one of the requirements
> was to concatenate the tokens, then print. And then split the jumbled
> one apart and reconstitute it. Mostly useless exercises, I now realize.

I don't see how that would work without maintaining the original state.
You can't unscramble eggs. A cipher's output isn't random.

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usgqt4$25vul$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11684&group=comp.os.linux.advocacy#11684

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Sat, 9 Mar 2024 00:08:53 -0500
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <usgqt4$25vul$1@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usgfe4$20gfq$2@dont-email.me>
<l5272pFqgibU12@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Mar 2024 05:08:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bd0cd99499b1364606b6e597c9f2633e";
logging-data="2293717"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UJu6Ot/rDdsrQkU9o7O3m"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:60Jbew9cYH3tJV/OUa7IPNfovGk=
In-Reply-To: <l5272pFqgibU12@mid.individual.net>
Content-Language: en-US
 by: DFS - Sat, 9 Mar 2024 05:08 UTC

On 3/8/2024 11:32 PM, rbowman wrote:
> On Fri, 8 Mar 2024 20:53:08 -0500, DFS wrote:
>
>> Thanks for participating. I was about to cancel the challenge for lack
>> of interest. Our code isn't quite done, since one of the requirements
>> was to concatenate the tokens, then print. And then split the jumbled
>> one apart and reconstitute it. Mostly useless exercises, I now realize.
>
> I don't see how that would work without maintaining the original state.
> You can't unscramble eggs. A cipher's output isn't random.

Yes, you have the original. And you have the shuffled, so you can
parse them again and use strcmp's.

Or, I created an array during the scrambling, ie

int randarr[9] now holds 304618527

This tells me (0-based indexing):
word 3 in the jumble goes back to position 0
word 0 goes to position 1
word 4 goes to position 2
word 6 goes to position 3
word 1 goes to position 4
word 8 goes to position 5
word 5 goes to position 6
word 2 goes to position 7
word 7 goes to position 8

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usgrse$262lt$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11686&group=comp.os.linux.advocacy#11686

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Sat, 9 Mar 2024 00:25:35 -0500
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <usgrse$262lt$1@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Mar 2024 05:25:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bd0cd99499b1364606b6e597c9f2633e";
logging-data="2296509"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/X0HQCc6gHQjPqMbo++p85"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:eGCQglWt3YOmMvoyXdy/aVENlz0=
In-Reply-To: <l4ufsbF9kdnU4@mid.individual.net>
Content-Language: en-US
 by: DFS - Sat, 9 Mar 2024 05:25 UTC

On 3/7/2024 1:38 PM, rbowman wrote:
> On Thu, 7 Mar 2024 09:10:27 -0500, DFS wrote:
>
>> I haven't started yet, but I figure it's about 5-8 lines in python. Too
>> easy. So it has to be written in C.
>
> https://nostarch.com/impracticalpythonprojects
>
> I couldn't work up too much interest in the anagrams and cryptography
> chapters but one exercise is the Union route Cipher.
>
> https://programmingpraxis.com/2012/03/06/union-route-cipher/
>
> Spice up your challenge! A point he makes with one of the more complex
> ciphers is while code can do the grunt work human intervention is needed
> to sort the fly shit from the pepper since you'll get grammatically
> correct sentences like Chomsky's 'Colorless green ideas sleep furiously'.

I did one like this 22 years ago:
https://programmingpraxis.com/2009/08/07/adfgx/

Wrote a working VB app to demo it.
https://imgur.com/a/A4FPlOC

Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

<usi3d7$2dh6i$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11696&group=comp.os.linux.advocacy#11696

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: OFeem1987@teleworm.us (Chris Ahlstrom)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge: fastest/best/shortest C program to
jumble a sentence, then restore it
Date: Sat, 9 Mar 2024 11:40:06 -0500
Organization: None
Lines: 22
Message-ID: <usi3d7$2dh6i$2@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usgfe4$20gfq$2@dont-email.me>
<l5272pFqgibU12@mid.individual.net>
Reply-To: OFeem1987@teleworm.us
Injection-Date: Sat, 9 Mar 2024 16:40:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="10d03f4f76d4ed9c11c2d9b46110a1a9";
logging-data="2540754"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192VThemTJ192cHrBSrXv0H"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:7Kg6MBFPGzDcPCP6dF3QM+ltgeY=
X-Mutt: The most widely-used MUA
X-User-Agent: Microsoft Outl00k, Usenet K00k Editions
X-Slrn: Why use anything else?
 by: Chris Ahlstrom - Sat, 9 Mar 2024 16:40 UTC

rbowman wrote this copyrighted missive and expects royalties:

> On Fri, 8 Mar 2024 20:53:08 -0500, DFS wrote:
>
>> Thanks for participating. I was about to cancel the challenge for lack
>> of interest. Our code isn't quite done, since one of the requirements
>> was to concatenate the tokens, then print. And then split the jumbled
>> one apart and reconstitute it. Mostly useless exercises, I now realize.
>
> I don't see how that would work without maintaining the original state.
> You can't unscramble eggs. A cipher's output isn't random.

Ask the poster named "%" about that :-)

Heh heh:

--
....people came to the land; the land loved them; they worked and struggled and
had lots of children. There was a Frenchman who talked funny and a greenhorn
from England who was a fancy-pants but when it came to the crunch he was all
courage. Those novels would make you retch.
-- Canadian novelist Robertson Davies, on the generic Canadian novel.

Re: OT programming challenge:

<l53msoF4bvgU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11697&group=comp.os.linux.advocacy#11697

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge:
Date: 9 Mar 2024 18:08:26 GMT
Lines: 5
Message-ID: <l53msoF4bvgU1@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usgfe4$20gfq$2@dont-email.me>
<l5272pFqgibU12@mid.individual.net> <usi3d7$2dh6i$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net x+i3r0t54ixvpm6aFCTyJg0sZ7d+yX6spEyIeAXSxWXO2ePJUe
Cancel-Lock: sha1:koKdfjnuVUUgQeqtE9bu7KLji0M= sha256:/kPDwCBWw/HPQkLZsWOs/by8Wj+GLX9AQVCK6+skjqY=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sat, 9 Mar 2024 18:08 UTC

https://arstechnica.com/information-technology/2024/03/matrix-
multiplication-breakthrough-could-lead-to-faster-more-efficient-ai-models/

Now here's a real challenge for the mathematicians in cola... Can you
beat an ω of 2.371552?

Re: OT programming challenge:

<usiqgo$2ijlr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11722&group=comp.os.linux.advocacy#11722

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: OFeem1987@teleworm.us (Chris Ahlstrom)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge:
Date: Sat, 9 Mar 2024 18:14:32 -0500
Organization: None
Lines: 15
Message-ID: <usiqgo$2ijlr$1@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usgfe4$20gfq$2@dont-email.me>
<l5272pFqgibU12@mid.individual.net> <usi3d7$2dh6i$2@dont-email.me>
<l53msoF4bvgU1@mid.individual.net>
Reply-To: OFeem1987@teleworm.us
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Mar 2024 23:14:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ce706aab4ddfdbb84973892314b4e617";
logging-data="2707131"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dHuxHbG/ZcizB0KSqB16S"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:v1Z4BQLjo0jgmZRZjMojmBbXUwU=
X-Mutt: The most widely-used MUA
X-Slrn: Why use anything else?
X-User-Agent: Microsoft Outl00k, Usenet K00k Editions
 by: Chris Ahlstrom - Sat, 9 Mar 2024 23:14 UTC

rbowman wrote this copyrighted missive and expects royalties:

> https://arstechnica.com/information-technology/2024/03/matrix-multiplication-breakthrough-could-lead-to-faster-more-efficient-ai-models/
>
> Now here's a real challenge for the mathematicians in cola... Can you
> beat an ω of 2.371552?

Yeah, I can beat matrix experts easily... not.

I don't believe there are any COLA mathematicians in COLA. Some dilettantes,
sure.

--
Q: What do you call a boomerang that doesn't come back?
A: A stick.

Re: OT programming challenge:

<l54n8cF9619U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11726&group=comp.os.linux.advocacy#11726

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge:
Date: 10 Mar 2024 03:20:45 GMT
Lines: 52
Message-ID: <l54n8cF9619U1@mid.individual.net>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usgfe4$20gfq$2@dont-email.me>
<l5272pFqgibU12@mid.individual.net> <usi3d7$2dh6i$2@dont-email.me>
<l53msoF4bvgU1@mid.individual.net> <usiqgo$2ijlr$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net Iq0kX5sSJEAFX/F3JbNrmAr22Pu1YBRACnA6KWlDn/vX4yCjWm
Cancel-Lock: sha1:jrdivQckGTPcOZOLqaUI/oJMLUE= sha256:jv9Xcb41OUP7JbZvLKtMck5/jjaYx81bmwVubLA6j3Y=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sun, 10 Mar 2024 03:20 UTC

On Sat, 9 Mar 2024 18:14:32 -0500, Chris Ahlstrom wrote:

> rbowman wrote this copyrighted missive and expects royalties:
>
>> https://arstechnica.com/information-technology/2024/03/matrix-
multiplication-breakthrough-could-lead-to-faster-more-efficient-ai-models/
>>
>> Now here's a real challenge for the mathematicians in cola... Can you
>> beat an ω of 2.371552?
>
> Yeah, I can beat matrix experts easily... not.

https://en.wikipedia.org/wiki/Convolutional_neural_network

Gems like that are what make minute improvements important. I have a
general understanding of what goes on in a CNN. Lucky for code monkeys
like me people who really know what they're doing package it up in Torch,
TensorFlow, and so forth.

Image processing has some uses that aren't intuitive. For wake words like
'alexa' you digitize the audio signal, run STFTs over a sliding windows,
maybe throw in mel filters to emphasize human speech characteristics, and
produce a spectrogram. Image classification is a well trodden path so you
train your model with spectrograms of many different people saying
'alexa', boil it down until you can do inferences on the local device and
you're good to go. Once the device wakes up speech processing gets shipped
off to a server. One goal is to be able to do more locally and avoid the
expense and security problems.

Fortunately you can change the wake word from 'alexa'. I asked one of our
QA people who goes by 'Alex' and she said she changed it to 'echo'. The
other choices are 'amazon' or 'computer'.

Again lucky for me there are nicely packaged libraries for all this good
stuff too.

https://github.com/mborgerding/kissfft

KISS-FFT would be a sacrilege to PhysfitFreak.

"It is wonderful that free, highly optimized libraries like FFT_BRANDX
exist. But such libraries carry a huge burden of complexity necessary to
extract every last bit of performance.

Sometimes simpler is better, even if it's not better."

Microprocessors don't have a lot of SRAM/RAM and many don't have a FPU. If
simple gets the job done processing audio signals it's definitely good
enough.

Re: 16-bit floating-point.

<l554tdFae4nU3@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11736&group=comp.os.linux.advocacy#11736

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: 16-bit floating-point.
Date: 10 Mar 2024 07:13:49 GMT
Lines: 20
Message-ID: <l554tdFae4nU3@mid.individual.net>
References: <usgfe4$20gfq$2@dont-email.me>
<l5272pFqgibU12@mid.individual.net> <usi3d7$2dh6i$2@dont-email.me>
<l53msoF4bvgU1@mid.individual.net> <usiqgo$2ijlr$1@dont-email.me>
<l54n8cF9619U1@mid.individual.net> <Jeff-Relf.Me@Mar.9--9.08pm.Seattle.2024>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net ihnwX08eQIiC2FT/5/uflwxvOX8bS6/PmHYAYU7RJETihYaEMH
Cancel-Lock: sha1:Q1E1TgJC6FhPS7g1mlXfSUKKhFA= sha256:gYsWoaCSoF3UCBiZtL1W18yjeRtWQ8151fFlHWMRtGA=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sun, 10 Mar 2024 07:13 UTC

On Sat, 09 Mar 2024 21:08:32 -0800 (Seattle), Relf wrote:

> Truth is, 16-bit floating-point is gaining popularity in machine
> learning ( due to its efficiency ).

The newer microcontrollers make it feasible even in your toasted :) Even
some of the Cortex M4s have a FPU.

https://en.wikipedia.org/wiki/ARM_Cortex-M

The RPi Pico that was sitting on my deck when I got home is only a M0+ but
it's a whole different class than the Arduino Unos. So far I've only
loaded MicroPython and did the blink thing using Thonny.

Thonny is no VS Code and it does have that annoying

- Thonny 4 is dedicated to Ukraine fighting the Russian invasion. 🇺🇦
Please support Ukraine! 🇺🇦

crap but it's a quick and dirty way to make sure everything is working.

Re: OT programming challenge:

<uskef1$306ps$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11741&group=comp.os.linux.advocacy#11741

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: OFeem1987@teleworm.us (Chris Ahlstrom)
Newsgroups: comp.os.linux.advocacy
Subject: Re: OT programming challenge:
Date: Sun, 10 Mar 2024 10:01:05 -0400
Organization: None
Lines: 25
Message-ID: <uskef1$306ps$2@dont-email.me>
References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com>
<l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me>
<l518d6FmepqU1@mid.individual.net> <usgfe4$20gfq$2@dont-email.me>
<l5272pFqgibU12@mid.individual.net> <usi3d7$2dh6i$2@dont-email.me>
<l53msoF4bvgU1@mid.individual.net> <usiqgo$2ijlr$1@dont-email.me>
<l54n8cF9619U1@mid.individual.net>
Reply-To: OFeem1987@teleworm.us
Injection-Date: Sun, 10 Mar 2024 14:01:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4016958e136334c76cfc9aeb80240208";
logging-data="3152700"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zOE8gqXzvs9SyTwRXnCmu"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:A+snO+6q9oNR1HTIYkTsJHIj16g=
X-Slrn: Why use anything else?
X-User-Agent: Microsoft Outl00k, Usenet K00k Editions
X-Mutt: The most widely-used MUA
 by: Chris Ahlstrom - Sun, 10 Mar 2024 14:01 UTC

rbowman wrote this copyrighted missive and expects royalties:

> <brevsnip>
>
> Again lucky for me there are nicely packaged libraries for all this good
> stuff too.
>
> https://github.com/mborgerding/kissfft
>
> KISS-FFT would be a sacrilege to PhysfitFreak.
>
> "It is wonderful that free, highly optimized libraries like FFT_BRANDX
> exist. But such libraries carry a huge burden of complexity necessary to
> extract every last bit of performance.
>
> Sometimes simpler is better, even if it's not better."
>
> Microprocessors don't have a lot of SRAM/RAM and many don't have a FPU. If
> simple gets the job done processing audio signals it's definitely good
> enough.

The lack of an integer implementation kept Ogg from overtaking MP3, IIRC.

--
You plan things that you do not even attempt because of your extreme caution.

Re: 16-bit floating-point.

<uskh5c$30qhq$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11744&group=comp.os.linux.advocacy#11744

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: Re: 16-bit floating-point.
Date: Sun, 10 Mar 2024 10:47:11 -0400
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uskh5c$30qhq$3@dont-email.me>
References: <usgfe4$20gfq$2@dont-email.me> <l5272pFqgibU12@mid.individual.net>
<usi3d7$2dh6i$2@dont-email.me> <l53msoF4bvgU1@mid.individual.net>
<usiqgo$2ijlr$1@dont-email.me> <l54n8cF9619U1@mid.individual.net>
<Jeff-Relf.Me@Mar.9--9.08pm.Seattle.2024>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Mar 2024 14:47:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ec05b6bf3a15acd02cf034c1d7a8084f";
logging-data="3172922"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qEbdEOh4aCuq/aD6tPVw9"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:ddynyWdopG09vjhyjI1ZlwA7HLA=
Content-Language: en-US
In-Reply-To: <Jeff-Relf.Me@Mar.9--9.08pm.Seattle.2024>
 by: DFS - Sun, 10 Mar 2024 14:47 UTC

On 3/10/2024 12:08 AM, Relf wrote:

> DFS, by the way, avoids floating-point like the plague;

It's rarely a conscious decision.

> when he DARES to dip his toe into the pool, it's 64-bit.

Re: Some examples ?

<l56ikrFh9tiU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11768&group=comp.os.linux.advocacy#11768

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: Some examples ?
Date: 10 Mar 2024 20:14:19 GMT
Lines: 97
Message-ID: <l56ikrFh9tiU1@mid.individual.net>
References: <usi3d7$2dh6i$2@dont-email.me> <l53msoF4bvgU1@mid.individual.net>
<usiqgo$2ijlr$1@dont-email.me> <l54n8cF9619U1@mid.individual.net>
<Jeff-Relf.Me@Mar.9--9.08pm.Seattle.2024> <l554tdFae4nU3@mid.individual.net>
<Jeff-Relf.Me@Mar.9--11.32pm.Seattle.2024>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 96rd1ZbUm8ddCKRIybAK0AutBiXvlynkXj6H/lABmxMPigp6QT
Cancel-Lock: sha1:abfVbk9oj21USjQ+xDxbKwOGucU= sha256:5MSFqEGycCoQ2vc8rWMuN2Kn+rUlWERxrHuGD4mhIqY=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Sun, 10 Mar 2024 20:14 UTC

On Sat, 09 Mar 2024 23:32:35 -0800 (Seattle), Relf wrote:

> rBowman:
>> [ My 4 $ RPi Pico makes ] sure everything is working.
>
> Could you give us some examples ?

Of the tool chain? The first step is to download the latest MicroPython
package:

https://micropython.org/download/RPI_PICO/

When you hold down the boot seelct button while plugging the device into
the USB bus it shows up in Dolphin as a mass storage device with what I
guess is meant to be a Raspberry Pi icon. You copy the u2e file to the
device and it resets.

Next, start Thonny and make sure it sees the device. I'd never used Thonny
and that was a little different. By default is shows the Python installed
on the host machine, but clicking on the lower left corner brings up a
selection where you can pick the MicroPython on the device. There is a
REPL pane where you can run simple commands.

The device shows up as /dev/ttyACM0 and may require setting group
permissions to access. I haven't tried plugging in an Arduino or another
device but I assume that would show as ttyACM1 (ACM -- abstract control
model) and you'd have to sort out which was which.

I've got the Pico W with Wifi so that's a little different than the plain
Pico. The on board LED is associated with the Wifi chip and not a separate
pin. A lot of the online sites like

https://projects.raspberrypi.org/en/projects/getting-started-with-the-
pico/5

show

from machine import Pin
led = Pin(25, Pin.OUT)

led.toggle()

which does not work with the W. It needs to be 'led = Pin("LED", Pin.OUT).

Then you can do a simple script in the Thonny editor

from machine import Pin
from time import sleep

led = Pin("LED", Pin.OUT)
while True:
led.value(1)
sleep(0.5)
led.value(0)
sleep(0.5)

The Run button transfers the script to the device and it blinks. That's
the 'hello world' of the uP world. There's a lot of other things to check
out

https://docs.micropython.org/en/latest/rp2/quickref.html

The Pico doesn't have a lot of goodies on board so after the simple blink
you need to start wiring it up.

https://peppe8o.com/using-gyroscope-and-accelerometer-with-mpu6050-
raspberry-pi-pico-and-micropython/

The Arduino Nano 33 BLE Sense has a similar form factor and a lot more
included on the board.

https://gilberttanner.com/blog/arduino-nano-33-ble-sense-overview/

Prices are volatile since there are a lot of clones in the market but a
Nano is roughly $40 and a Pico under $10. The Core M4 is a little better
than the M0+ too. It all depends on what you want to do. For example a
remote controller with a thumb joystick and a nRF24L01 transceiver would
require external parts for both so you might as well go cheap. For a
project where you need an IMU the Nano may come out cheaper and will be
easier to package without the external boards. Same for a remote weather
station where the Nano has temperature, pressure, and humidity sensors on
board.

Programming is similar and you can use C/C++ or MicroPython with both. I
know the Nano can use the Mbed RTOS but I'm not sure about the Pico.

Re: How does your Pico "make sure everything is working" ?

<l57d30FlkreU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=11797&group=comp.os.linux.advocacy#11797

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bowman@montana.com (rbowman)
Newsgroups: comp.os.linux.advocacy
Subject: Re: How does your Pico "make sure everything is working" ?
Date: 11 Mar 2024 03:45:37 GMT
Lines: 11
Message-ID: <l57d30FlkreU1@mid.individual.net>
References: <usiqgo$2ijlr$1@dont-email.me> <l54n8cF9619U1@mid.individual.net>
<Jeff-Relf.Me@Mar.9--9.08pm.Seattle.2024> <l554tdFae4nU3@mid.individual.net>
<Jeff-Relf.Me@Mar.9--11.32pm.Seattle.2024>
<l56ikrFh9tiU1@mid.individual.net>
<Jeff-Relf.Me@Mar.10--8.03pm.Seattle.2024>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net Zyx1DzqJGuUtLJaqRpNDDACBFP8+F1ei2KCdFJt19BnqKjPmCh
Cancel-Lock: sha1:ZrFDBXPLMY6TsKRMeC2pTXlUEgc= sha256:39Pr6qIx6QSn+U+Dcyw5BSeMrjeAIJEtVMK2Rkjqe+M=
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
 by: rbowman - Mon, 11 Mar 2024 03:45 UTC

On Sun, 10 Mar 2024 20:03:44 -0700 (Seattle), Relf wrote:

> I'd hate to think that you wasted 4 $, rBowman.

Don't fucking worry your little head about it.


> How does your Pico "make sure everything is working" ?

You don't have a clue about setting up a tool chain do you?


computers / comp.os.linux.advocacy / OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor