There's more than one way to do things PerlMonks

### BrowserUk

by BrowserUk (Pope)
 on Jun 04, 2002 at 18:12 UTC ( #171588=user: print w/ replies, xml ) Need Help??

Posts by BrowserUk
[OT] Forces. in Seekers of Perl Wisdom
2 direct replies — Read more / Contribute
by BrowserUk
on Feb 14, 2016 at 04:43

I'm trying to solve a problem to do with forces as represented by this freebody diagram.

The large circle represents a body, that is free to rotate about axis A, that has a complex of external, non-contact forces acting upon it represented by the wiggly red arrows. The composite of these forces is calculated (by a library call using Stress Tensor integration), and the combined result is returned as (ex.) X: 335.123 N Y: -74.2858 N.

In addition to the body being free to rotate about A, the short (10 units) link arm it is attached to can rotate about the axis B.

The problem is to work out what position the combined mechanism will end up in as a result of the forces acting upon it.

For now, I'm ignoring the possibility that forces acting may change as the assembly rotates. This is part of a complex simulation and the basic idea is that from a known starting point, I use the library to calculate the net force acting at some instance in time; from that work out the position the assembly moves to; adjust the model to reflect that movement, and then re-calculate the stress tensor integration for the next instance. If the time-step is small enough and the iteration count high enough, then it should give a reasonable approximation of the affects of the forces over time.

In keeping with the "what have you got so far" ethic, the second (lower) state diagram in the image shows what I think will happen.

• The short link A-B will rotate anticlockwise about B by an angle (to the horizontal) represented by the purple line that connects B to a point F, which is a point on the periphery of the circle through which the resultant of the X/Y force acts through A in the original position.
• The body will rotate clockwise around A such that the position of the point F on its periphery will end up in the same place(ish) as it was in before the movement takes place.

I realise that the position of F in the resultant is slight displaced from its original position in space, but as shown, the angles involved are greatly exaggerated. The actual actual angles will be very small at each iteration, so the inaccuracy at each step will also be small. In the end, it is the position of the body in space that is important, not its rotation, nor the exact position of any point on it.

I'm fairly sure I can handle coding the trig to resolve the two rotations; what I'm looking for here is any kind of argument for or against my assessment of what will happen?

My thanks to anyone with enough math to tackle the problem and bored enough to bother :)

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
Context, pedantry and appropriate response. in Meditations
6 direct replies — Read more / Contribute
by BrowserUk
on Jan 02, 2016 at 05:51

Nit-picking pedantry is the bane of productive discourse.

A not uncommon question in life is: "How much do you weigh"? To which we generally respond with something like: "nn pounds" or "nn kilos".

Of course, if we last weighed ourselves naked having just stepped out of the shower, and we are currently wearing a full set of skiing gear; or if a holiday weekend or half a year has intervened, then our responses may be slightly or even wildly inaccurate. Which may or may not be okay depending on who is asking and why; but we generally know how much thought we should give to the accuracy and qualification of our responses from the context of the question.

Of course, we don't really "weigh" what we weigh. We have a mass of a certain number of Newtons that only becomes a weight in the presence of a particular value of gravity.

Ie. we 'weigh' differently on the surface of the Earth than we would on the Moon or in the ISS. And we would 'weigh' differently again if we were bridge of the Enterprise at Warp factor 10 and the inertial stabilizers failed.

But no one ever responds to the target question with "nn Newtons"; or qualifies their "nn pounds/kilos" with "whilst naked, at a distance of nn miles/meters from the center of the Earth, whilst traveling at sub-relativistic speeds, and after a week or more of nominally average calorific intake and expenditure".

And thank Dog they don't! Without we tailor and truncate our answers to the contexts in which the questions are asked, life would become quagmired in a treacle of inferable verbiage. And intolerable.

Which is why mealy-mouthed, oneupmanship, pedantry posts like this deserve the response it got.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
Mixed Unicode and ANSI string comparisons? in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by BrowserUk
on Dec 14, 2015 at 17:04

What happens if you pass a list containing a mix of Unicode and non-Unicode scalars to sort?

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
Tri state string compare? (Solved! see update2) in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by BrowserUk
on Dec 13, 2015 at 13:22

I have two strings to compare.

1. String 1 consists of a mix of 3 characters, a, b & c. Eg. AABCBAABCCCCAB
2. String 2 consists of a mix pf 2 characters; a & b.   Eg. AABABAABABABAB

I need to determine if string 2 contains As everywhere there is an A in string 1; and Bs wherever string 1 contains Bs. I don't care what string 2 contains where string 1 contains Cs.

All I need is a boolean result whether string 2 'matches' string 1. (The above example is a 'match'.)

If it helps, the choice of the 3 characters used is open to change.

The strings can be quite long and there are lots of string 2s to be compared against each string 1; so I'd rather avoid a byte by byte (at the Perl level) comparison.

I think it ought to be possible to get my boolean using some combination of byte-wise boolean string ops; but I haven't hit on which?

Update: The above two samples match because:

```AABCBAABCCCCAB
AABABAABABABAB
AAB BAAB    AB  ## I don't care what's in string 2 where there is a C
+in string 1.

#### Update2: Solution

Solved it with:

```\$ab  = "AABABAABABABAB";;

\$abmatch = "AABABAABABABAB";;
print +(( \$abc & \$abmatch ) eq \$abmatch) ? 'yes' : 'no';;
yes

\$abnomatch = "ABBABAABABABAB";;
print +(( \$abc & \$abnomatch ) eq \$abmatch) ? 'yes' : 'no';;
no

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
Pideonholes revisited. in Seekers of Perl Wisdom
2 direct replies — Read more / Contribute
by BrowserUk
on Dec 12, 2015 at 09:04

In Combinatorics problem. (Updated with more info.) I asked how to efficiently distribute N cards amongst M pigeon holes where each hole must contain at least one card.

I've now realised that for some variations of the problem I dealing with, I need to allow for the situation where the first or last pigeon hole, or both, can be zero.

I thought this would be a simple tweak to the answers I already received; but once again I've come unstuck for an efficient solution. Is there one?

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
10 direct replies — Read more / Contribute
by BrowserUk
on Dec 11, 2015 at 01:47

Given a number of postcards (say 5) and a number of pigeon holes (say 3); how many ways are there to distribute the cards into the holes such that each hole contains at least 1?

For the 5/3 case above, the following possibilities exist:

```3 1 1
2 2 1
2 1 2
1 2 2
1 1 3
1 3 1 // added per GrandFather's post below

How to efficiently generate that sequence? The order of generation is immaterial.

### Update: Need a better way

One way to do it, is to filter Algorithm::Combionatorics::variations_with_repetition() for the sum of values.

Ie. Generate the 27 variations:

And then filter on the sum() of the subsets to reduce it to the 6 I need:

```1 1 3
1 2 2
1 3 1
2 1 2
2 2 1
3 1 1

Which doesn't seem too bad until you consider a realistic set, rather than my simple example.

For instance, with 12 postcards and 7 pigeon holes, there are 35,831,808 variations_with_repetition() each of which must be summed and compared in order to discard 99.9% to arrive at the 462 I need. That's horribly inefficient :(

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
[OT] A C-language parser test file? in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by BrowserUk
on Aug 27, 2015 at 08:54

Does anyone know of a publicly available C source file specifically constructed for testing the edge cases of C-language parsers?

I'm writing a parser for the C-language (and yes; I need to write my own), and I sat down to think of a good way to test it.

My conclusion is that rather than just feeding it it reams and reams of C sources; most of which will simply be re-exercising the same paths; it would be better to try and construct a single, preferably relatively small, C-source that doesn't necessarily have to do anything useful, but simply uses all the constructs and language features that I need to support. (Which isn't the full standard; any of them.)

I started to try and write notes on everything I think need to be in this file -- and I will continue that -- but then I thought maybe such a file already exists. I've done a few half-hearted searches for something that might fit the bill; but its proven to be a difficult thing to construct a discriminative search criteria for.

So, this is just a hope that maybe someone here has knowledge of something that might lend itself to my purpose.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
XS: The equivalent of perl's ... in Seekers of Perl Wisdom
2 direct replies — Read more / Contribute
by BrowserUk
on Aug 14, 2015 at 06:43
PerlApi: hashes in Seekers of Perl Wisdom
by BrowserUk
on Aug 11, 2015 at 22:12

in Re: Perl Hashes in C?, I construct a hash using the perlapi from Inline::C.

Two of the apis, hv_fetch() and hv_store() optionally take a numeric hash value which if supplied is used directly rather than the key string and length being (re)hashed.

I assume that idea is that once you've hashed a key once, it saves rehashing it; but the fly in that ointment is that there does not seem to be any api to obtain the hash value?

Also, there does not appear to be an equivalent option to supply the hash value to hv_exists()?

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
IBM Cloud Challenge. in Meditations
4 direct replies — Read more / Contribute
by BrowserUk
on Jul 21, 2015 at 18:07

I just read about an IBM programming challenge to try and entice developers to IBMs Bluemix Cloud development environment.

(Don't bother if you're outside the UK; or if you want to use Perl (it ain't supported :(); or if stupid sign-up processes that don't work annoy you; or ... )

What struck me was that the three programming tasks are, at least notionally, so trivial. It took me less than 5 minutes to write (working, but probably not best) solutions to all three.

(Whether they would pass their test criteria I guess we'll probably never know)

I was also struck by this part of the description:

that you can put together a programme that can run within a time limit or on limited resources rather than just lashing together a hideous brute-force monstrosity. And that you can actually read the questions properly in the first place (a useful start, but one that's often forgotten).

I think it would be interesting to see how the best Perlish solutions we can come up with compare with those other languages that get entered to the competition; when and if they are actually made public.

So have at them. (Don't forget to add <spoiler></spoiler> tags around your attempts.)

I'd post the questions here but I'm not sure it wouldn't be a problem copyright wise?

I'll post my solutions here in a few days.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2016-02-14 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?