# OK. LETS START REAL PROGRAMMING IN C FOR PROBLEMS!!!

Discussion in 'C Programming' started by 88888 Dihedral, Nov 20, 2011.

1. ### 88888 DihedralGuest

PROBLEM 1: COMPUTE THE EULER'S NUMBER UP TO 30 DIGITS AFTER 1.
THE DIGIT REQUIRED SHOULD BE PARAMETER BY THE CALLER!

PROBLEM 2: COMPUTE PI AS IN THE ABOVE!

PROBLEM 3: LIST ALL PERMUTATIONS OF A STRING WITHOUT ANY REPEATED STRING IN THE LIST!

PROBLEM 4: IMPLEMENT A HASH THAT COULD BE AS FAST AS POSSIBLE AND VERY STABLE AND ROBUST TO BE USED EVERYWHERE TO BEAT OTHER LANGUAGES WITH A HASH BUILT IN.

88888 Dihedral, Nov 20, 2011

2. ### Ian CollinsGuest

On 11/21/11 08:12 AM, 88888 Dihedral wrote:
> PROBLEM 1: COMPUTE THE EULER'S NUMBER UP TO 30 DIGITS AFTER 1.
> THE DIGIT REQUIRED SHOULD BE PARAMETER BY THE CALLER!
>
> PROBLEM 2: COMPUTE PI AS IN THE ABOVE!
>
> PROBLEM 3: LIST ALL PERMUTATIONS OF A STRING WITHOUT ANY REPEATED STRING IN THE LIST!
>
> PROBLEM 4: IMPLEMENT A HASH THAT COULD BE AS FAST AS POSSIBLE AND VERY STABLE AND ROBUST TO BE USED EVERYWHERE TO BEAT OTHER LANGUAGES WITH A HASH BUILT IN.

Problem 5: Locate and turn off caps-lock.

--
Ian Collins

Ian Collins, Nov 20, 2011

3. ### 88888 DihedralGuest

I solved those long time ago in C.

88888 Dihedral, Nov 20, 2011
4. ### Eric SosmanGuest

On 11/20/2011 2:23 PM, 88888 Dihedral wrote:
> I solved those long time ago in C.

Glad to hear it. Just to verify, please post the output of
your Problem 3 solution for the string

I solved those long time ago in C

.... and state whether you are considering or ignoring letter case,

--
Eric Sosman
d

Eric Sosman, Nov 20, 2011
5. ### Kaz KylhekuGuest

On 2011-11-20, Eric Sosman <> wrote:
> On 11/20/2011 2:23 PM, 88888 Dihedral wrote:
>> I solved those long time ago in C.

>
> Glad to hear it. Just to verify, please post the output of
> your Problem 3 solution for the string

I like problem 4, because of its well-quantified and concretely targettable
requirement: "as fast as possible".

Kaz Kylheku, Nov 20, 2011
6. ### 88888 DihedralGuest

1. Define an order in the symbol set of the string by a sort.
2. Start from the smallest mapped by the ordered defined which will yield the maximum if reversed.
3. From the smallest string by the order defined, just generate the next until the maximum is reached.

I hate to answer trivial questions!

88888 Dihedral, Nov 20, 2011
7. ### Ian CollinsGuest

On 11/21/11 09:13 AM, 88888 Dihedral wrote:
> 1. Define an order in the symbol set of the string by a sort.
> 2. Start from the smallest mapped by the ordered defined which will yield the maximum if reversed.
> 3. From the smallest string by the order defined, just generate the next until the maximum is reached.
>
> I hate to answer trivial questions!

Like you hate quoting context?

--
Ian Collins

Ian Collins, Nov 20, 2011
8. ### Eric SosmanGuest

On 11/20/2011 3:13 PM, 88888 Dihedral wrote:
> 1. Define an order in the symbol set of the string by a sort.
> 2. Start from the smallest mapped by the ordered defined which will yield the maximum if reversed.
> 3. From the smallest string by the order defined, just generate the next until the maximum is reached.
>
> I hate to answer trivial questions!

I'm sure you'll be happy to learn that you're tied for third
place in my fastest-to-PLONK list.

--
Eric Sosman
d

Eric Sosman, Nov 20, 2011
9. ### Joe PfeifferGuest

88888 Dihedral <> writes:

> PROBLEM 1: COMPUTE THE EULER'S NUMBER UP TO 30 DIGITS AFTER 1.
> THE DIGIT REQUIRED SHOULD BE PARAMETER BY THE CALLER!
>
> PROBLEM 2: COMPUTE PI AS IN THE ABOVE!
>
> PROBLEM 3: LIST ALL PERMUTATIONS OF A STRING WITHOUT ANY REPEATED STRING IN THE LIST!
>
> PROBLEM 4: IMPLEMENT A HASH THAT COULD BE AS FAST AS POSSIBLE AND VERY STABLE AND ROBUST TO BE USED EVERYWHERE TO BEAT OTHER LANGUAGES WITH A HASH BUILT IN.

our homework directly.

Joe Pfeiffer, Nov 20, 2011
10. ### Lew PitcherGuest

On Nov 20, 2:12 pm, 88888 Dihedral <>
wrote:
> PROBLEM 1: COMPUTE THE EULER'S NUMBER UP TO 30 DIGITS AFTER 1.
> THE DIGIT REQUIRED SHOULD BE PARAMETER BY THE CALLER!

"Euler's Number"? Do you mean "the mathematical constant e"? Or
perhaps "a sequence En of integers defined by a specific Taylor series
expansion"?

If you mean /e/, then
a) the number starts with a /2/, not a /1/ (as in 2.718281828...),
b) Steve Wozniak published a solution to 116000 places, in 1981, and
c) /I/ wrote and published a C-language solution to 5000 places in the
1990s
What's so difficult about a /30 place/ solution?

> PROBLEM 2: COMPUTE PI AS IN THE ABOVE!

It's been done. Many times over.

> PROBLEM 3: LIST ALL PERMUTATIONS OF A STRING WITHOUT ANY REPEATED STRING IN THE
> LIST!

A little more difficult, but again, it's been done many times over.

> PROBLEM 4: IMPLEMENT A HASH THAT COULD BE AS FAST AS POSSIBLE AND VERY STABLE AND
> ROBUST TO BE USED EVERYWHERE  TO BEAT OTHER LANGUAGES WITH A HASH BUILTIN.

Again, it's been done, many times. And it's simpler than e or pi.

So, what's your point? Or is this a sad attempt to get others to do

Lew Pitcher, Nov 20, 2011
11. ### Martin AmbuhlGuest

On 11/20/2011 2:12 PM, 88888 Dihedral wrote:
> PROBLEM 1: COMPUTE THE EULER'S NUMBER UP TO 30 DIGITS AFTER 1.
> THE DIGIT REQUIRED SHOULD BE PARAMETER BY THE CALLER!
>
> PROBLEM 2: COMPUTE PI AS IN THE ABOVE!
>
> PROBLEM 3: LIST ALL PERMUTATIONS OF A STRING WITHOUT ANY REPEATED STRING IN THE LIST!
>
> PROBLEM 4: IMPLEMENT A HASH THAT COULD BE AS FAST AS POSSIBLE AND VERY STABLE AND ROBUST TO BE USED EVERYWHERE TO BEAT OTHER LANGUAGES WITH A HASH BUILT IN.

The subject line "OK. LETS START REAL PROGRAMMING IN C FOR PROBLEMS!!!"
is a lie. It should read: "a cretin who can't turn off his shift lock
and engages in childish multiple exclamation marks wants someone else to
do his homework." Or just "Dihedral is a troll, please ignore."

Martin Ambuhl, Nov 20, 2011
12. ### Keith ThompsonGuest

Martin Ambuhl <> writes:
> On 11/20/2011 2:12 PM, 88888 Dihedral wrote:
>> PROBLEM 1: COMPUTE THE EULER'S NUMBER UP TO 30 DIGITS AFTER 1.
>> THE DIGIT REQUIRED SHOULD BE PARAMETER BY THE CALLER!
>>
>> PROBLEM 2: COMPUTE PI AS IN THE ABOVE!
>>
>> PROBLEM 3: LIST ALL PERMUTATIONS OF A STRING WITHOUT ANY REPEATED STRING IN THE LIST!
>>
>> PROBLEM 4: IMPLEMENT A HASH THAT COULD BE AS FAST AS POSSIBLE AND VERY STABLE AND ROBUST TO BE USED EVERYWHERE TO BEAT OTHER LANGUAGES WITH A HASH BUILT IN.

>
> The subject line "OK. LETS START REAL PROGRAMMING IN C FOR PROBLEMS!!!"
> is a lie. It should read: "a cretin who can't turn off his shift lock
> and engages in childish multiple exclamation marks wants someone else to
> do his homework." Or just "Dihedral is a troll, please ignore."

Quite possibly, but it's also possible that the OP has seen the
recent spate of off-topic flaming and is making a clumsy attempt
to encourage actual discussion of C programming.

Perhaps we should consider following his example, if not his
typography.

1. Don't post in all-caps. It's considered equivalent to shouting, and
is generally seen as rude. Same for exclamation points.

2. Questions about actual problems you've encountered are more likely to
generate good answers than contrived puzzles (unless the puzzles are
particularly interesting, but frankly these aren't).

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson, Nov 20, 2011
13. ### 88888 DihedralGuest

There was some library for big numbers written C. Of course, printing the big numbers won't be the same as printing native types. With other languages supporting big numbers C with some libraries seems not attractive to novices.

88888 Dihedral, Nov 21, 2011
14. ### Keith ThompsonGuest

88888 Dihedral <> writes:
> There was some library for big numbers written C. Of course, printing
> the big numbers won't be the same as printing native types. With other
> languages supporting big numbers C with some libraries seems not
> attractive to novices.

If you're actually interested in particating here, then please
(a) format your text in lines shorter than 80 columns, preferably
around 72 and (b) quote some context from the article to which you're
can make this difficult, but the "old" interface isn't as bad as
the new one).

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson, Nov 21, 2011
15. ### Malcolm McLeanGuest

On Nov 20, 11:45 pm, Lew Pitcher <> wrote:
>
> "Euler's Number"? Do you mean "the mathematical constant e"?
>

That is Euler's number.

The confusion arises because e doesn't stand for "Euler". He chose it
because other mathematicians had already bagged a, b, c, and d for
other uses. The C programming language was named on the same system.
--
Brand new: seqlogo generator
http://www.malcolmmclean.site11.com/www

Malcolm McLean, Nov 21, 2011
16. ### 88888 DihedralGuest

On Monday, November 21, 2011 5:45:22 AM UTC+8, Lew Pitcher wrote:
> On Nov 20, 2:12 pm, 88888 Dihedral <>
> wrote:
> > PROBLEM 1: COMPUTE THE EULER'S NUMBER UP TO 30 DIGITS AFTER 1.
> > THE DIGIT REQUIRED SHOULD BE PARAMETER BY THE CALLER!

>
> "Euler's Number"? Do you mean "the mathematical constant e"? Or
> perhaps "a sequence En of integers defined by a specific Taylor series
> expansion"?
>
> If you mean /e/, then
> a) the number starts with a /2/, not a /1/ (as in 2.718281828...),
> b) Steve Wozniak published a solution to 116000 places, in 1981, and
> c) /I/ wrote and published a C-language solution to 5000 places in the
> 1990s
> What's so difficult about a /30 place/ solution?

>
> > PROBLEM 2: COMPUTE PI AS IN THE ABOVE!

>
> It's been done. Many times over.
>
> > PROBLEM 3: LIST ALL PERMUTATIONS OF A STRING WITHOUT ANY REPEATED STRING IN THE
> > LIST!

>
> A little more difficult, but again, it's been done many times over.
>
> > PROBLEM 4: IMPLEMENT A HASH THAT COULD BE AS FAST AS POSSIBLE AND VERY STABLE AND
> > ROBUST TO BE USED EVERYWHERE  TO BEAT OTHER LANGUAGES WITH A HASH BUILT IN.

>
> Again, it's been done, many times. And it's simpler than e or pi.
>
> So, what's your point? Or is this a sad attempt to get others to do

I am talking about language features to be checked to be used as a tool to solve problems.

88888 Dihedral, Nov 21, 2011
17. ### Phil CarmodyGuest

Malcolm McLean <> writes:
> On Nov 20, 11:45 pm, Lew Pitcher <> wrote:
> >
> > "Euler's Number"? Do you mean "the mathematical constant e"?
> >

> That is Euler's number.

Except when one of them's ~2.781828 and the other one's ~0.577215665.
Better to include either the e or the gamma in the name to reduce
ambiguity.

Phil
--
Unix is simple. It just takes a genius to understand its simplicity
-- Dennis Ritchie (1941-2011), Unix Co-Creator

Phil Carmody, Nov 21, 2011
18. ### jacob naviaGuest

Re: Euler's constant

Le 20/11/11 20:12, 88888 Dihedral a Ã©crit :
> PROBLEM 1: COMPUTE THE EULER'S NUMBER UP TO 30 DIGITS AFTER 1.
> THE DIGIT REQUIRED SHOULD BE PARAMETER BY THE CALLER!

Euler's constant is the limit of the sum when N goes to infinity of:

1 + 1/2 + 1/3 + 1/4 + ... 1/N - ln(n)

This is related to the PSI function (digamma) by

Euler constant = -psi(1)

ï»¿ï»¿This can be calculated in C with this program:
(Using lcc-win. Other compilers will be able to do this too
but in a different way)

d:\lcc\mc79\test>type teuler.c
#include <qfloat.h>
#include <specialfns.h>
#include <stdio.h>
int main(void)
{
qfloat e=psiq(1.0q);
printf("Euler constant is:\n%.95qf\n",-e);
}

OUTPUT:
Euler constant is:
+0.577215664901532860606512090082402431042159335939923598805767234884867726777664670936947063291747

Thanks to this poster I have uncovered a bug in that function, that I
could correct.

lcc-win uses the Cephes Mathematical library of Stephen L Moshier. He uses:

*
* d +-
* psi(x) = -- ln | (x)
* dx
*
* is the logarithmic derivative of the gamma function.
* For general positive x, the argument is made greater than 16
* using the recurrence psi(x+1) = psi(x) + 1/x.
* Then the following asymptotic expansion is applied:
*
* inf. B
* - 2k
* psi(x) = log(x) - 1/2x - > -------
* - 2k
* k=1 2k x
*
* where the B2k are Bernoulli numbers.
*
* psi(-x) = psi(x+1) + pi/tan(pi(x+1))

jacob navia, Nov 21, 2011
19. ### 88888 DihedralGuest

I suggest 2 or 3 new built in types added to C that will certainly beat other computer languages. I don't think after 10 years C is still not evolved.

88888 Dihedral, Nov 21, 2011
20. ### Kleuskes & MoosGuest

On Mon, 21 Nov 2011 04:00:21 -0800, 88888 Dihedral wrote:

> I suggest 2 or 3 new built in types added to C that will certainly beat
> other computer languages.

Such as?

> I don't think after 10 years C is still not evolved.

Me neither. In fact i think it's evolved quite a bit.

-------------------------------------------------------------------------------
___________________________________
/ I'm DESPONDENT ... I hope there's \
| something DEEP-FRIED under this |
\ miniature DOMED STADIUM ... /
-----------------------------------
\
\
___
{~._.~}
( Y )
()~*~()
(_)-(_)
-------------------------------------------------------------------------------

Kleuskes & Moos, Nov 21, 2011