|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
Yay, I made what might be the most simple FFT ever
public static void FFTInplace (final Complex[] v, final double sign) { // check whether the array length is power of two final int n = v.length; if( (n & (n - 1)) != 0 ){ throw new IllegalArgumentException("Not power of two"); } // main loop for( int m = n; m > 1; m /= 2 ){ Complex root = Complex.cis(sign * 2.0 * Math.PI / m); Complex twiddle = new Complex(1.0, 0.0); for( int i = 0; i < m / 2; i++ ){ for( int x2 = i + m / 2; x2 < n; x2 += m ){ int x1 = x2 - m / 2; Complex e = v[x1]; Complex f = v[x2]; v[x1] = e.add(f); v[x2] = e.sub(f).mul(twiddle); } twiddle = twiddle.mul(root); } } // bit reversal int p = Integer.numberOfLeadingZeros(n - 1); for( int i = 0; i < n; i++ ){ int j = Integer.reverse(i) >>> p; if( i < j ){ Complex t = v[i]; v[i] = v[j]; v[j] = t; } } }
Edit: Optimized code a bit by swapping the nested loops and adjusting the indexing accordingly.
|
I'm just posting here as a tribute to Dennis Ritchie. Sad month for great computer visionaries (Steve Jobs and Ritchie), and it's terrible to see them go. I don't do much stuff in C, mainly dealing with C++, but I know that Ritchie played a huuuge role in the development of technology, programming, and pretty much everything else we see on our computers (he was also co-developer of Unix, essentially the heart that all modern operating systems have utilized/replicated). I'm just hoping we won't have to see anybody else go so soon (Bjarne, Gates, etc.).
C hwaiting!
|
On October 14 2011 16:17 shinarit wrote:Hey guys! I have a Python question. What is the nicest/shortest/wittiest code to create something iterable (order is not important) of tuples of integer coordinates with the format of ([0 - MaxX-1], [0 - MaxY-1])? I tried some generators, but all have some issues, and now im working with a one liner, but not sure its the best. What i tired: >>> [((x, y) for x in range(n)) for y in range(n)] [<generator object <genexpr> at 0x7f1318670f50>, <generator object <genexpr> at 0x7f13168c4050>] >>> ([(x, y) for x in range(n)] for y in range(n)) <generator object <genexpr> at 0x7f13168c40a0> >>> [[(x, y) for x in range(n)] for y in range(n)] [[(0, 0), (1, 0)], [(0, 1), (1, 1)]]
And i went with the third one, connected with the itertools library. itertools.chain.from_iterable([[(x, y) for x in range(sizex)] for y in range(sizey)])
But there must be some nicer, more effective way, i know it.
Think you might be looking for itertools.product().
>>> coordTuples = [] >>> for i in itertools.product(range(0, MaxX-1), range(0, MaxY-1)): >>> coordTuples.append(i)
You don't need to append everything into a list if you don't want, and can just put your code in that for loop.
Sample Output: + Show Spoiler + >>> import itertools >>> MaxX = 3 >>> MaxY = 4 >>> for i in itertools.product(range(0, MaxX-1), range(0, MaxY-1)): ... print repr(i) ... (0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2)
|
Hyrule18969 Posts
I knew you weren't dead. Get back to work!
|
Quick question, why is the following code throwing a syntax error?
+ Show Spoiler +File file = new File(fileName); Scanner scan = new Scanner(file); String thisLine = scan.nextLine(); StringTokenizer token = new StringTokenizer(thisLine); int alphabet; int states; int acceptNum; //Parses first line of text file states = Integer.parseInt(token.nextToken()); alphabet = Integer.parseInt(token.nextToken()); acceptNum = Integer.parseInt(token.nextToken()); //Parses second line of text file int[acceptNum] tempArray; accepting = tempArray; Spoilered cause it's large, but the syntax error is right here according to my IDE: int[acceptNum] tempArray;
All I'm trying to do is have an array with a variable size. I don't mean variable in that it grows as the program runs, I mean variable as in I don't hardcode a size, it's defined based on the file I read.
Edit: NVM, it was a stupid mistake, I solved it on my own. Thanks anyways TL.
|
Hey, I'm looking for a programmer that would make a pretty rudimentary program for me. What I want it to do is to be a larvae inject learning tool. Most larvae inject tools just have a timer that goes off every 40 seconds. What I think would be cool is if someone made a program that after every time someone performed a certain keystroke pattern it would reset the timer. This keystroke pattern could be customized per user and would correspond to his/her's inject keystrokes. This way about every 40 seconds the player would be reminded that all his larvae popped. Will pay $5 for this to be done. Pm me please!
|
Does anyone know of a way to generate a square wave in Python? I'm trying to make a tuner, for lack of a better description. I've already got a square wave generator (that I made using PyGame), but the quality is horrible and every time it loops, there's a clicking sound that can be heard immediately when it starts playing. Since it only generates a second or so, there's this constant *click click click* sound that's driving me insane.
@Easytouch: Couldn't such a thing get you in trouble for cheating?
|
On October 18 2011 14:54 ArcticVanguard wrote: Does anyone know of a way to generate a square wave in Python? I'm trying to make a tuner, for lack of a better description. I've already got a square wave generator (that I made using PyGame), but the quality is horrible and every time it loops, there's a clicking sound that can be heard immediately when it starts playing. Since it only generates a second or so, there's this constant *click click click* sound that's driving me insane.
@Easytouch: Couldn't such a thing get you in trouble for cheating? It's not cheating, and Blizzard doesn't own his computer.
|
On October 18 2011 06:10 Zeke50100 wrote: I'm just posting here as a tribute to Dennis Ritchie. Sad month for great computer visionaries (Steve Jobs and Ritchie), and it's terrible to see them go. I don't do much stuff in C, mainly dealing with C++, but I know that Ritchie played a huuuge role in the development of technology, programming, and pretty much everything else we see on our computers (he was also co-developer of Unix, essentially the heart that all modern operating systems have utilized/replicated). I'm just hoping we won't have to see anybody else go so soon (Bjarne, Gates, etc.).
C hwaiting! From NYT.
October 13, 2011 Dennis Ritchie, Trailblazer in Digital Era, Dies at 70 By STEVE LOHR Dennis M. Ritchie, who helped shape the modern digital era by creating software tools that power things as diverse as search engines like Google and smartphones, was found dead on Wednesday at his home in Berkeley Heights, N.J. He was 70.
Mr. Ritchie, who lived alone, was in frail health in recent years after treatment for prostate cancer and heart disease, said his brother Bill.
In the late 1960s and early ’70s, working at Bell Labs, Mr. Ritchie made a pair of lasting contributions to computer science. He was the principal designer of the C programming language and co-developer of the Unix operating system, working closely with Ken Thompson, his longtime Bell Labs collaborator.
The C programming language, a shorthand of words, numbers and punctuation, is still widely used today, and successors like C++ and Java build on the ideas, rules and grammar that Mr. Ritchie designed. The Unix operating system has similarly had a rich and enduring impact. Its free, open-source variant, Linux, powers many of the world’s data centers, like those at Google and Amazon, and its technology serves as the foundation of operating systems, like Apple’s iOS, in consumer computing devices.
“The tools that Dennis built — and their direct descendants — run pretty much everything today,” said Brian Kernighan, a computer scientist at Princeton University who worked with Mr. Ritchie at Bell Labs.
Those tools were more than inventive bundles of computer code. The C language and Unix reflected a point of view, a different philosophy of computing than what had come before. In the late ’60s and early ’70s, minicomputers were moving into companies and universities — smaller and at a fraction of the price of hulking mainframes.
Minicomputers represented a step in the democratization of computing, and Unix and C were designed to open up computing to more people and collaborative working styles. Mr. Ritchie, Mr. Thompson and their Bell Labs colleagues were making not merely software but, as Mr. Ritchie once put it, “a system around which fellowship can form.”
C was designed for systems programmers who wanted to get the fastest performance from operating systems, compilers and other programs. “C is not a big language — it’s clean, simple, elegant,” Mr. Kernighan said. “It lets you get close to the machine, without getting tied up in the machine.”
Such higher-level languages had earlier been intended mainly to let people without a lot of programming skill write programs that could run on mainframes. Fortran was for scientists and engineers, while Cobol was for business managers.
C, like Unix, was designed mainly to let the growing ranks of professional programmers work more productively. And it steadily gained popularity. With Mr. Kernighan, Mr. Ritchie wrote a classic text, “The C Programming Language,” also known as “K. & R.” after the authors’ initials, whose two editions, in 1978 and 1988, have sold millions of copies and been translated into 25 languages.
Dennis MacAlistair Ritchie was born on Sept. 9, 1941, in Bronxville, N.Y. His father, Alistair, was an engineer at Bell Labs, and his mother, Jean McGee Ritchie, was a homemaker. When he was a child, the family moved to Summit, N.J., where Mr. Ritchie grew up and attended high school. He then went to Harvard, where he majored in applied mathematics.
While a graduate student at Harvard, Mr. Ritchie worked at the computer center at the Massachusetts Institute of Technology, and became more interested in computing than math. He was recruited by the Sandia National Laboratories, which conducted weapons research and testing. “But it was nearly 1968,” Mr. Ritchie recalled in an interview in 2001, “and somehow making A-bombs for the government didn’t seem in tune with the times.”
Mr. Ritchie joined Bell Labs in 1967, and soon began his fruitful collaboration with Mr. Thompson on both Unix and the C programming language. The pair represented the two different strands of the nascent discipline of computer science. Mr. Ritchie came to computing from math, while Mr. Thompson came from electrical engineering.
“We were very complementary,” said Mr. Thompson, who is now an engineer at Google. “Sometimes personalities clash, and sometimes they meld. It was just good with Dennis.”
Besides his brother Bill, of Alexandria, Va., Mr. Ritchie is survived by another brother, John, of Newton, Mass., and a sister, Lynn Ritchie of Hexham, England.
Mr. Ritchie traveled widely and read voraciously, but friends and family members say his main passion was his work. He remained at Bell Labs, working on various research projects, until he retired in 2007.
Colleagues who worked with Mr. Ritchie were struck by his code — meticulous, clean and concise. His writing, according to Mr. Kernighan, was similar. “There was a remarkable precision to his writing,” Mr. Kernighan said, “no extra words, elegant and spare, much like his code.”
Can any of us mere coders aspire to greater praise than "elegant and spare?"
|
On October 18 2011 15:10 mmp wrote:Show nested quote +On October 18 2011 14:54 ArcticVanguard wrote: Does anyone know of a way to generate a square wave in Python? I'm trying to make a tuner, for lack of a better description. I've already got a square wave generator (that I made using PyGame), but the quality is horrible and every time it loops, there's a clicking sound that can be heard immediately when it starts playing. Since it only generates a second or so, there's this constant *click click click* sound that's driving me insane.
@Easytouch: Couldn't such a thing get you in trouble for cheating? It's not cheating, and Blizzard doesn't own his computer. Easy, it was just a question. I didn't mean to suggest that they did, I was just concerned such a program could get him in trouble on the ladder.
|
I'm not sure if blizzard would consider it a third party program because it doesn't interact with the game itself, only your keystrokes and such. I'm not really sure though, haven't looked into it too indepth. Just really want to use it as a practice tool on my smurf account anyways.
|
On October 18 2011 23:00 Easytouch wrote: I'm not sure if blizzard would consider it a third party program because it doesn't interact with the game itself, only your keystrokes and such. I'm not really sure though, haven't looked into it too indepth. Just really want to use it as a practice tool on my smurf account anyways. *shrugs* Might make for a good exercise. I'll give it a shot, though no promises. Picky on language? It might be easier on Python, but I'm not sure.
|
Today I saw a compilation with 26000 warnings. My eyes still hurt.
|
On October 20 2011 05:26 Frigo wrote: Today I saw a compilation with 26000 warnings. My eyes still hurt.
Compiles with warnings and no run-time issues related? Work done. :D
|
pfft, 26k warnings? I can do that with only 25 lines of code:
#ifndef WRECURSE #define WRECURSE 10 #endif
//compile with -Wall -DWRECURSE=<some number>
template<int depth, int id> struct lots_of_warnings { lots_of_warnings<depth-1,id> a; lots_of_warnings<depth-1,id+1<<depth-1> b; void operator()() { 1; a(); b(); } };
template<int id> struct lots_of_warnings<0, id> { void operator()() { 1; } };
int main(int argc, char *argv[]) { lots_of_warnings<WRECURSE,0> foo; foo(); return 0; }
gives metric craptons of warnings for large enough values of WRECURSE (anyone an idea what kind of warning i could use to get around requiring "-Wall"?)
Edit: I guess something like "unsigned x = -1;" would be better to produce warnings than just "1;"...
|
Hey guys I'm having some trouble trying to do some simple beginner coding in C. I'm trying to write a program to do a little subtraction program. It seems like the output comes out with the correct answer to the subtraction problem but the character string comes out all jumbled. I can't seem to get it to come out without and issues.
Here's the code:
#include <stdio.h>
int main() { int value1,value2,sum;
value1 = 87; value2 = 15; sum = value1 - value2;
printf ("The difference between i% and i% is i%\n", value1, value2, sum);
return 0; }
The output program would come out as:
The difference between i 0x0.0000f0p-1022nd i 72s i
Process returned 0 (0x0) execution time : 0.007 s Press any key to continue.
What I want to have as an output is something more like this:
+ Show Spoiler +The difference between 87 and 15 is 72.
Press any key to continue.
yeah... what did I do wrong?
|
You are using the wrong printf flag: replace i% with %d.
Notice that the flag indicator '%' comes before the letter. so make sure you do %d and not d%. You can see the result of reversing them in your current output.
|
Thanks that fixed it. What's the difference between '%' coming before or after the letter? The book I'm reading so far has only taught me about 'i%' for this kind of program. It works fine for addition problems but not so much for subtraction.
|
When you put a '%' in your input string, printf looks for the next character to pair with it. This is the behavior I've always known with printf, so I don't know why your book has it before.
Btw, you might learn something by trying to understand why your first attempt's output came out exactly the way it did.
|
I'm having trouble with a line of code. I cannot get the program to correctly calculate current balance for all 4 lines in the txt file, instead it only calculates the current balance for the first line, and then gives me random numbers for the next 3 lines, I'm confused as to why this is....
The Source Code + Show Spoiler + #include <iostream> #include <fstream> #include <string> #include <cstdlib> using namespace std;
int main() { string filename = "inventory.txt"; ifstream inFile; string partnum; double intialamnt; double qntysold; double minamnt; double currentbalance = 0; double minlevel;
inFile.open(filename.c_str()); //opens the file if (inFile.fail()) { cout << "The file was not successfuly opened" << endl; exit(1); } inFile >> partnum >> intialamnt >> qntysold >> minamnt; while (inFile.good()) { currentbalance = (intialamnt - qntysold); cout << partnum << " " << currentbalance << " " << qntysold << " " << minamnt << endl; inFile >> partnum >> currentbalance >> qntysold >> minamnt; } inFile.close(); return 0; }
The txt file + Show Spoiler + QA310 95 47 50 CM145 320 162 200 MS514 34 20 25 EN212 163 150 160
The current output of the program + Show Spoiler + QA310 48 47 50 CM145 -67 162 200 MS514 75 20 25 EN212 -55 150 160
|
|
|
|