Programming challenges related to chemistry [closed] - c

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm looking for interesting programming puzzles, problems or challenges suitable for a class of chemistry majors learning C as their first programming language. Do you have any recommendations?

Project Euler is pretty good. They have some simple challenges that may be suitable.
These won't really do much to teach them C, though. Text books are much better for that.
Additionally, you could have them write a program to balance chemical reaction equations. That would be good for I/O and simple math.

Given a text file with a whole bunch of pressure/temperature/mole count as input, and using the ideal gas law equation, output the values of the volume for the gases and output the entire set of data (P,V,T and n) into a nicely formatted output file.
Should cover file i/o, basic function usage, and string formatting. Has the potential to cover arrays and stucts as well.

David, tasks that come to my mind would be:
calculation of the number/topology of isomers of hydrocarbons (cyclic and acyclic, saturated and unsturated)
numerical integration of optical spectra (absorption and fluorescence)
kinetical models
deconvolution of experimental data
modelling of thermodynamical cycles and their efficiencies

This seems a really vague question but assuming I'm a chemistry student that is learning C I would like to write programs that allows me to define molecules and compounds starting from simple elements.
I really don't know how to explain it, but maybe define your struct for a nitrogen atom, one for oxigen atom and have a way to bind it to produce water.. or maybe mixing to different substances too see what will come out programmatically..

You can try pex4fun. It allows you to learn algorithms in C# (which is close enough to C). pex4fun provides read-to-use classes and also engaging coding duels that turn learning into a game.

Related

Tutorials for Code Obfuscation in C [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am fascinated by the way people obfuscate their code (mostly, C) (examples here : http://ioccc.org/) and would like to learn the various techniques for the same. I have been told of a book, "Obfuscated C and other Mysteries", but I am not able to get that book.
Are there any tutorials or books that give hints on this topic?
Thank you.
The best you can do is read the comments of the author of the programs on IOCCC. They describe how they manage to obfuscate their code. Here are a few pointers:
Short and meaningless identifiers
Because a=aaa*aa; will always be more obfuscated than result = value * factor;
In order to have short identifiers, obfuscators tend to even #define many things.
Reversed array indexing
You just have to remember that var[3] and 3[var] are equivalent.
Digraphs and trigraphs
if(a< <:b+aa??))??<f();%>
should be less readable than:
if (a < (b+aa)) { f(); }
Look-alike characters
Sometimes, it's hard to tell appart l, 1 and I or o, 0 and O. For example, if you write 10l, I bet everyone will read 101 instead.
Coding style guidelines
Generally speaking, just try to find good coding guidelines and to try to violate them all. Those documents that you could find anywhere on the web could help you more than most things and would allow you not to buy anything.
Here are some links:
How to write unmaintainable code.
Morwenn's answer nicely covers obfuscation of syntax. But there is another level, and that is semantic obfuscation. Consider that the oft-mentioned Turing Machine has the same computational power as any other programming language (ignoring considerations of input and output). In fact all of the various models of computation have sibling models with equivalent power.
For example, a string char s[N] can be considered a mapping from indices to characters, so any string can be represented instead by a function which always delivers the appropriate character when called with a specified index char f(int i). Now read this. Crazy, right?

Is there any major programming language that doesn't support any form of reflection? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Wikipedia defines reflection as follows:
In computer science, reflection is the process by which a computer
program can observe (do type introspection) and modify its own
structure and behavior at runtime.[1]
Is there any major programming language (widely used in Academia or Industry) that doesn't support any form of reflection? All the examples I'm currently thinking of have at least limited support. But for C I'm for example not sure.
C, C++ dont have any forms of reflection. What can be done is embed debugging symbol in the executable with the compiler, and then process the symbol table from within the executable. However, this process must be implemented by the code (i.e. write code in c to break down and process the symbol table in the executable). Therefore, it isn't inherent in the language.
COBOL is a major language that does not. Nor any of the HDLs (VHDL, Verilog, ...).
I think a more interesting question is, what languages have complete access to their structure by "reflection"? (e.g, "what in this expression?" "What's the type of that expression?" "Build me a new class.", etc.) AFAIK, only LISP meets this requirement. Other languages provide some reflection at best but cannot entirely manipulate those langauges.
That leaves the question as to why one would add only partial reflection to a language. We make our languages Turing capable so that if we want to code something, we're pretty sure we can code it in our language. Why aren't our languages correspondingly "full reflection" capable?
One way out of this is to use program transformation systems (PTS), which are tools designed to manipulate code. A truly generic PTS (such as Stratego, DMS or TXL) can manipulate arbitrary programs in arbitrary way, providing what amounts to "full reflection". This allows one to do metaprogramming on arbitrary languages; you don't have to depend on your language committee or your compiler vendor to add bits and pieces of reflection capability.

Is "K&R C" still applicable [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I relearning C; it's been years and whilst familiar the nuances are lost in time.
I originally learned C from K&R. However, I now see many people levelling criticism at K&R.
A chief example is http://c.learncodethehardway.org/book/learn-c-the-hard-waych55.html#x61-27200055
Top reasons seem to be that it's code style is overly terse, practises aren't applicable in larger programs and lead to memory leaks or are subject to attack in shared network accessible systems.
Do people feel these criticisms are fair? Do they matter to somebody learning C? If so, could people recommend a "modern" C book, preferably available for Kindle?
As long as you're talking about the 2nd Edition, K&R is still very relevant.
In fact, I would say it's still the very best single book on C, both for learning, and for reference.
That said, you should also get a copy of Harbison & Steele's "C: A Reference Manual". It's the best current reference on C, and the Fifth Edition covers C99, which you should use if you can.
Also, once you've got a bit of C behind you, I'd strongly recommend reading "Expert C Programming", by Peter van der Linden.
It is still relevant and still very useful with regards to learning the language. Learning the language doesn't require you to implement new practices or styles that assist in code readability, etc.
For example, the idea of self documenting code is that you use verbose variable and function names to help explain the purpose of a function or a variable. K&R is clearly opposed to this. That doesn't mean you can't learn the C language from K&R, it just means that your style will need to be adjusted/updated based on whatever naming convention you decide upon in the future.
I cannot recommend "Expert C Programming" enough (as stated by gregj).

Compiler C to Brainfuck (for harassing a professor)? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
A professor of mine has said he'll accept homework assignments in any language we'd care to use. I'm on good enough terms that I'd like to mess with him a bit and submit a valid homework assignment using brainfuck, whitespace, or some equally "useful" language.
I have the C-sources for a few simple numerical analysis routines as well as the compiled output and the assembly files they generate.
Does anyone know of a decompiler (or a C->brainfuck translator) that could give me something akin to the "brainfuck source code"?
Just use APL or J.
Unlike BF, they were actually designed to serve a "useful" (and not a "useful as in BF" sense) purpose - and yet can easily make Perl code-golf entries look like novels. (The dedication and mental training to enjoy these languages is currently more than my skill/effort levels.)
If the goal is using a purely esoteric language, I have always enjoyed the look of Piet programs. It looks prettier and is actually able to solve common CS homework problems. Following the links will reveal "Piet assemblers" and other tools. Win.
Happy coding.
For what it's worth, I just wrote a very simple Brainfuck Assembler (inspired by this SO post actually), which assembles readable source code (not C, just something simple and nameless) to BrainFuck. The source-code and compilation/usage instructions can be found here: BrainFuck Assembler.
Edit: The project has recently been updated under a new name: BrainFix.
Edit 2: I redid the entire project. The new and improved version has quite a lot of features and is available on Github.
A quick Google search brings up the (a?) Brainfuck site, which links to an archive with "all things Brainfuck". I doubt there's a C->brainfuck translator anywhere, I wouldn't think anyone would invest that much time.

Interview questions on CUDA Programming? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I have an interview coming up in a week's time for an entry level position that involves programming in CUDA (hopefully with C).
I was wondering if anybody can suggest some interview questions that I can expect during the interview.
I have gone through the official programming guide but I'm not all that convenient right now.
Thanks.
Some questions I think you should prepare are:
How many different kind of memories are in a GPU ?
What means coalesced / uncoalesced?
Can you implement a matrix transpose kernel?
What is a warp ?
How many warps can run simultaneously inside a multiprocessor?
What is the difference between a block and a thread ?
Can thread communicate between them? and blocks ?
Can you describe how works a cache?
What is the difference between shared memory and registers?
Which algorithms perform better on the gpu? data bound or cpu bound?
Which steps will you perform to port of an application to cuda ?
What is a barrier ?
What is a Stream ?
Can you describe what means occupancy of a kernel?
What means structure of array vs array of structures?
"You have N vectors of length M (N>>M). Tell me how you would go about designing a kernel to evaluate the distance matrix. Pay special attention to the way the problem is sub-divided and to the way the thread co-operation can be used to improve occupancy.
How would your answer to this question change if M>>N?"
The idea here is not to get you writing code, but to get you thinking out loud. This shows that you really know how to use GPGPU technology and are not merely regurgitating the user guide.
If it's a scientific role then expect questions on floating point and numerical accuracy, in particular you should look at the reduction sample in the NVIDIA SDK since that illustrates a whole load of the points in Fabrizio's post too.

Resources