This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Messages - Munchor
Pages: 1 ... 28 29 [30] 31 32 ... 424
436
« on: August 05, 2011, 11:25:20 am »
ephan, I'll give you a tip: Lua starts with 1, python with 0 (/me waits for the beating)
@Levak, lol
Jim, I did not understand your algorithm, I just copied so I don't know where it is wrong. def increment(x): """Increments the string x""" length_of_string = len(x) if length_of_string == 0: return "a" bt = ord(x) #The problem is that ord doesn't work for strings, only characters if bt < 122: x = x[-1] + chr(bt+1) else: x = increment(x[-1] + "a") return x def main(): """Displays all possible words using alphabet a-z""" a = "a" for i in range(1000): a = increment(a) print a if __name__ == "__main__": main()
So I tried: def increment(x): """Increments the string x""" length_of_string = len(x) if length_of_string == 0: return "a" bt = x.encode("hex") if bt < 122: x = x + chr(bt+1) else: x = increment(x + "a") return x def main(): """Displays all possible words using alphabet a-z""" a = "a" for i in range(1000): a = increment(a) print a if __name__ == "__main__": main()
But I get recursion errors.
437
« on: August 05, 2011, 11:15:58 am »
By making the char array able to hold 9 chars to make the string 0 terminated.
Nicely spotted. The strcmp( is not working, when we tie, it says "You lose" Current code: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h>
int main();
int main() { char options[][9] = {"rocks", "paper", "scissors"}; //Possible options srand( time(NULL) ); //For random integer /* Define variables needed */ int user_choice_index; char user_choice[9]; int cpu_choice_index; char cpu_choice[9]; int i; while (1) { /* Get user choice and index */ fgets(user_choice, sizeof user_choice, stdin); for (i=0; i<3; i++) { if ( user_choice == options[i] ) { user_choice_index = i; //Index of user's choice break; } } /* Get computer choice */ cpu_choice_index = ( rand() %3 ); //Random number [0,3] strcpy(cpu_choice, options[cpu_choice_index]); printf("%s\n", cpu_choice); /* Check who wins */ if ( strcmp(cpu_choice, user_choice) == 0 ) { printf("Tie\n"); continue; } else if ( (cpu_choice_index + 1) % 3 == user_choice_index ) { printf("You won\n"); continue; } else { printf("You lose\n"); continue; } } return 0; }
438
« on: August 05, 2011, 10:52:30 am »
def increment(x): """Increments the string x""" length_of_string = len(x) if length_of_string == 0: return "a" bt = ord(x) if bt < 122: x = x[1:-1] + chr(bt+1) else: x = increment(x[1:-1] + "a") return x def main(): """Displays all possible words using alphabet a-z""" a = "a" for i in range(1000): a = increment(a) print a if __name__ == "__main__": main()
Heh Jim, I tried to copy cat your version to Python, but failed
439
« on: August 05, 2011, 10:43:05 am »
Change
cpu_choice = options[cpu_choice_index];
to
*cpu_choice = options[cpu_choice_index];
Could you see my edit please? And that doesn't work by the way HOMER-16, since you're making an integer from a pointer without a cast.
440
« on: August 05, 2011, 09:53:04 am »
Inspired on the Rock, Papers, Scissors topic I decided to try and make a C version: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h>
int main();
int main() { char options[][8] = {"rocks", "papers", "scissors"}; //Possible options srand( time(NULL) ); //For random integer /* Define variables needed */ int user_choice_index; char user_choice[8]; int cpu_choice_index; char cpu_choice[8]; int i; while (1) { /* Get user choice and index */ fgets(user_choice, sizeof user_choice, stdin); for (i=0; i<3; i++) { if ( user_choice == options[i] ) { user_choice_index = i; //Index of user's choice break; } } /* Get computer choice */ cpu_choice_index = ( rand() %3 ); //Random number [0,3] cpu_choice = options[cpu_choice_index]; /* Check who wins */ if ( strcmp(cpu_choice, user_choice) == 0 ) { printf("Tie\n"); } else if ( (cpu_choice_index + 1) % 3 == user_choice_index ) { printf("You won"); } else { printf("You lose"); } } return 0; }
However, when compiling I get: rock_papers_scissors.c:33:16: error: incompatible types when assigning to type ‘char[8]’ from type ‘char *’ On the line: cpu_choice = options[cpu_choice_index]; Each member of the array options is of type char[8], as you can see in the declaration: char options[][8] = {"rocks", "papers", "scissors"}; //Possible options So why does it think it is a char * instead of a char[8]? Thanks! EDITI recorded I was copying addresses and used strcpy(); but the program isn't work that well: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h>
int main();
int main() { char options[][8] = {"rocks", "paper", "scissors"}; //Possible options srand( time(NULL) ); //For random integer /* Define variables needed */ int user_choice_index; char user_choice[8]; int cpu_choice_index; char cpu_choice[8]; int i; while (1) { /* Get user choice and index */ fgets(user_choice, sizeof user_choice, stdin); for (i=0; i<3; i++) { if ( user_choice == options[i] ) { user_choice_index = i; //Index of user's choice break; } } /* Get computer choice */ cpu_choice_index = ( rand() %3 ); //Random number [0,3] strcpy(cpu_choice, options[cpu_choice_index]); printf("%s", cpu_choice); /* Check who wins */ if ( strcmp(cpu_choice, user_choice) == 0 ) { printf("Tie\n"); } else if ( (cpu_choice_index + 1) % 3 == user_choice_index ) { printf("You won\n"); } else { printf("You lose\n"); } } return 0; }
When I inputed scissors, here's what happened: scissors scissors�@You won rocksYou lose
441
« on: August 05, 2011, 09:13:04 am »
Michael Lee, I suggest using random.choice() to choose randomly from a list. With calc84maniac's implementation this can't be done though because the bot could also choose "list".
442
« on: August 05, 2011, 07:41:44 am »
Poor chemist, too bad the joke is English-only.
443
« on: August 05, 2011, 07:16:30 am »
This is cool, thus I think more news appear and more people will "Like" us
444
« on: August 04, 2011, 04:35:53 pm »
Seriously, though, I have no idea where else to put it. And I want to put it somewhere My problem is using it, having validated pages is cool, but showing it off is not so cool in my opinion. The only important website using it was python.org, but they removed it recently.
445
« on: August 04, 2011, 04:28:57 pm »
Looking awesome Deep Thought, I dislike the W3C Compliant button, it just looks bad
446
« on: August 04, 2011, 03:47:54 pm »
Some progress today: - Run File Option
- Code Improvement
The "Run File" option uses "wxwabbitemu" as default, but will soon be customizable, so that the user can also use "wabbitemu" for example I'll also be adding custom fonts soon.
447
« on: August 04, 2011, 03:06:51 pm »
Nspire-Lua environment for Gedit (Programming Editor for Ubuntu) Also, Gedit is not Ubuntu-Only, it's "Gnome-Editor". I'm just installing it by the way.
448
« on: August 04, 2011, 01:44:24 pm »
On Linux, can I save things to the Windows partition, then?
yes you can. if you want to share files, though, you can use the cloud, I think you have a server, don't you?
449
« on: August 04, 2011, 12:36:17 pm »
math.h is a default library, so it should be included with <>, #include <math.h>.
Oh wait, are you creating your own math.h? I think you should give it a new name, so it doesn't conflit with the default.
450
« on: August 04, 2011, 12:30:00 pm »
Hrm, random question (before I forget) -- if I dual boot both a Linux OS and a Windows OS on the same computer, is there a way to set it up in a way that they can both share each others' files (like my papers for school and stuff, and code I'm writing). I can easily access my Windows files from Linux, not sure if otherwise, never had to.
Pages: 1 ... 28 29 [30] 31 32 ... 424
|