Sutekh's C++ +More Thread

LennyLenard_sl

shitlord
195
1
'=' is assignment e.g. int x = 1;

'==' is evaluation (equal) e.g. if(x == 1)

Though inforloop, you've got three parts (they probably have different technical terms btw)

So when reading the condition, you can read it as (I know I do) "while counter is less than 21". So for it to be

"while counter is equal to 20", and counter is equal to 1 in the first iteration of the loop, and thus, it'll never work. Even though it's technically grammatically sound.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,408
73,478
Either is fine. It's one of those code formatting debates that really doesn't matter.
 

Noodleface

A Mod Real Quick
37,961
14,508
Yeah at work they actually prefer separate lines because it is easier to debug code that is separated and over a few million lines/files
 

Tuco

I got Tuco'd!
<Gold Donor>
45,408
73,478
That class I took 15 years ago sure paid off, or not ;o I'm lost.. some fuckery is present. What's wrong boss?

So this was a very good response to the problem. There's three big things it does that are critical:
1. It uses a source-based search for finding the rotated point. Rather than iterating over the source and rotating each point to find the destination it's better to iterate over the destination and find its source. This removes the hole problem completely without adding any more 'holy filling' processing.
2. You avoid the double for loops over height/width by just iterating from 0 - totalSize. Another thing that I've found really speeds up iterating over data is to forgo all index operations and to avoid the for loop entirely. Ex:

actually runs faster with:
Like many improvements in efficiency this, of course, reduces readability, maintainability and can be easier to add bugs in code. But when performance is needed you can really speed things up. The codebase I'm working on would simply not work fast enough with the processing payload we use if I didn't do this in a lot of areas.

3. You were careful with casting from double to int and made sure to round the numbers by adding 0.5 before the cast. This is very important with this operation because if you don't cast properly the displayed map will be jittery and jump around a lot.


As for the fuckery, I can only assume you mean the values at the corners. This is completely unavoidable for this problem because you're effectively changing the size of the array without being able to add new information. There's nothing you can do about this and you either need to have the output be a subset of the initial array, change the shape of the data to a circle or hide it in some other way (In my case I'm not displayed rows of data, I'm displaying obstacles that can pop in and out as you drive, so the fact that you are changing the shape is somewhat mitigated unless you're very clever or know the system more than a user should).
 

Tuco

I got Tuco'd!
<Gold Donor>
45,408
73,478
What about me? What about Adebisi's beginner challenges?
I don't really know what you're learning or doing with C++ but the problem I listed is actually pretty good if you're learning C++. It uses very basic constructs that any programmer will learn, is a real world problem (as in, I got paid to solve it and will get to use it on a robot tomorrow!!!) and is part of a pretty expansive field of computer science. Doing more complex problems that use constructs you've learned and done very basic programs in is good because it allows you to go past just knowing how to use the tools and into using the tools to create something. Once you get used to doing that you begin to master the tools.

For C++ it's also good because if you tried to you could really do some impressive things with the raw memory that would be difficult or impossible in other languages, and it really shows off one of the advantages of C/C++ over say, python or java (Which are excellent languages on their own, just not built with accessing memory in mind)
 

sole

Molten Core Raider
338
1,203
After a semester of trying to code I gave up on it, just not for me. Anyway, I'm a linguist that focuses on forensics (suicide/ransom/written confessions etc), and average sentence and word length come in to play heavily. Manually calculating this can be a pretty long process sometimes. Would there be a simple way of programming this for my own personal use, i.e., I transcribe a ransom and run a program that tells me the average sentence length and word length of the transcription that I can compare to my manual calculations? If it's doable and if I ever use it in the field I'll give due credit if that's a concern. Wasn't quite sure where to put this but any help would be appreciated.
 

LennyLenard_sl

shitlord
195
1
After a semester of trying to code I gave up on it, just not for me. Anyway, I'm a linguist that focuses on forensics (suicide/ransom/written confessions etc), and average sentence and word length come in to play heavily. Manually calculating this can be a pretty long process sometimes. Would there be a simple way of programming this for my own personal use, i.e., I transcribe a ransom and run a program that tells me the average sentence length and word length of the transcription that I can compare to my manual calculations? If it's doable and if I ever use it in the field I'll give due credit if that's a concern. Wasn't quite sure where to put this but any help would be appreciated.
Short answer is: yes.

If you don't have other requirements that make you need C/C++ you're probably also better off with an easier language. If you want to stick with a C family language, C# has great built in string handling. Python should be able to do it too no problem. Could even use php and have it hosted on a website.

EDIT: Those are just some of your options, I'm sure people here can suggest oodles more.
 

Chris

Potato del Grande
18,170
-382
Here is a challenge: Output the Mandlebrot Set using ASCII. Bonus points for how detailed you get it.
 

sole

Molten Core Raider
338
1,203
Short answer is: yes.

If you don't have other requirements that make you need C/C++ you're probably also better off with an easier language. If you want to stick with a C family language, C# has great built in string handling. Python should be able to do it too no problem. Could even use php and have it hosted on a website.

EDIT: Those are just some of your options, I'm sure people here can suggest oodles more.
Thanks, and yeah I would just want something extremely efficient... open the program, load the .docx file and let the program scan it. The only variables I would need would be # of sentences, words per sentence, # of words, word length, average sentence length and average word length.

I wouldn't even know what language would be best suited for this type of analysis. Tuco or AMOD, it might be a better idea to move these posts to a separate thread, as I'd actually be willing to commission the project. It would be cool to see the difference (if any) in veracity and conclusions between "synthetic" and "manual" calculations.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,408
73,478
If your format is .docx I can only imagine that's a nightmare to read already. You'd probably have to use some kind of proprietary API to read it and I'd use whatever Microsoft wants you to use to read it:
Manipulating Word 2007 Files with the Open XML Format API (Part 1 of 3)

If your format is just straight text you can implement an average word length and average in virtually any language pretty easily.

At some point you'll might want to go a step further and do some analysis on the words (To measure the correlation of swear words and successful suicides, for example) and you'd probably want to combine Regular Expressions (regex) with some kind of database to store the word dictionaries (Flat file would probably work for you, no need to involve a SQL or oracle db unless the total number of words in all your different word sets goes over tens of thousands).

Once you get that sophisticated you'll want to run your routines over and over again and get output near-instantly, so you'll want something reasonably fast at string comparisons. I have to imagine that C/C++ probably has the fastest, but I wouldn't be surprised if Java or C# approaches the C speeds.

Here's a fun little app I just made that gives the avg word size and total word count of whatever text you shove into the text box. This is all in C#, which I chose just because I bet that MS docx api uses .NET.

I didn't verify it was correct, or even review the code because that'd kill the buzz I have going on now. Let me know if you want the full project. I'll talk more about this later when I'm not drunk.

rrr_img_59923.png


 

Tuco

I got Tuco'd!
<Gold Donor>
45,408
73,478
You should be able to unzip this, open the WordCounter.sln file and your VS2013 express will attempt to convert it. Just let it have its way with it and you should be able to build it. If you can't let me know.

Getting an average of the words and total count of the words with a very simple method like I used is easy and only takes a few minutes. Making it foolproof and finding corner cases and handling them is what is challenging. This is true for almost any kind of programming. One corner case is what happens when you have two spaces in a word? Does it handle it properly or does it count a " " as a word, lowering the average size and increasing the number of words in a sentence. What about if you're counting sentences and use something like:

What if someone has "Farewell cruel world..." Is that one sentence? Because it might count it as three....

Like I said before this should be enough to help you do what you said you wanted and I have no idea about forensics much less your focus of research. I just think it'd be a fun project to model a person's followup of their written threats by analyzing their letter and its characteristics in an automated way. And that'd be a very involved programming task.