Show Posts

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 - calcdude84se

Pages: 1 ... 15 16 [17] 18 19 ... 161
241
Computer Programming / Re: char[8] to char[8] giving error
« on: August 05, 2011, 12:45:12 pm »
"A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str."
That might be your problem. If it is, you'll need to make user_choice a 10-byte array: 8 for printing characters, one for the newline, and another for the null. That'll throw of your comparisons with strcmp, though, so you could also add a newline to each element of options. Then the printf("%s\n"... line won't need that \n.

242
Computer Programming / Re: char[8] to char[8] giving error
« on: August 05, 2011, 12:09:02 pm »
Excellent! :D
One of the more difficult things about C is remembering that there are no strings with pleasant operations like '==' like in Python, only char pointers and functions on them. C's '==' is very close to (if not the same as!) Python's 'is'

243
Computer Programming / Re: char[8] to char[8] giving error
« on: August 05, 2011, 11:58:26 am »
I see a few problems:
In your for loop, you should be using strcmp, not ==
You should just be using printf("%s\n", options[cpu_choice_index]);. Don't do whatever mess you were trying with strcpy.
To check who wins, you should not be comparing strings, just use cpu_choice_index and user_choice_index.
Finally, those continue's are unnecessary.

244
News / Re: FLASHY - 83/4 series boot code modification
« on: August 05, 2011, 11:43:47 am »
We could... sorta. It wouldn't be able to just run like any OS now, which can just run from flash. The boot code would have to read the flash drive and copy code to RAM, while also making the OS able to copy more code. Because you'll just be copying to RAM anyway, it would make a lot more sense just to make a minimal OS that did the same thing. No point in risking modification of the boot code. The closest you should ever get to that is making a very small mod that runs page $3C/$6C under certain conditions, and $3C/$6C could contain that code. Since $3C/$6C is a privileged page, (as is all of its sector, because $3F/$6F is more boot code...) you wouldn't need any other OS. To be honest, I still don't see much point in "booting from a flash drive" :/

245
Computer Programming / Re: Rock Paper Scissors
« on: August 05, 2011, 09:33:32 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".
*calcdude84se
There's nothing wrong with indexing AFAIK. In fact, you want an index because it makes determining win/lose easier.

246
Humour and Jokes / Re: Drink something.
« on: August 05, 2011, 09:31:13 am »
Virtually all puns are language-specific, so there's nothing to be done about that.
I'll make the "explain the joke" spoiler:
Spoiler For Spoiler:
"H2O, too" sounds like "H2O2", or hydrogen peroxide, which, of course, is not something you should drink.
Also:
Little Johnny was a chemist,
But little Johnny is no more,
For what he thought was H2O
Was H2SO4
:D

247
Computer Programming / Re: html execution in javascript?
« on: August 05, 2011, 08:20:10 am »
PHP is server-side. It needs to be run on the server. I don't know where you're testing this from, but, if you're testing it on your computer, just viewing the page in a web browser won't work. You'll have to set up a (small, temporary) webserver of your own on your computer to test. Now, if you're uploading this every time and testing it on your website, then make sure your host has PHP enabled. (Most all do.)

248
Computer Programming / Re: Rock Paper Scissors
« on: August 05, 2011, 08:13:28 am »
Try to avoid sys.exit, since it makes it difficult to embed your programs. Still a better version:
Code: [Select]
# A list containing all your choices.
choices = ["rock", "paper", "scissors", "quit"] #make "quit" another choice

while 1: #more idiomatic, and very slightly faster than "while True:"
    #No need to set either player* variable beforehand

    # The computer will pick a number from zero up to (but not including) three.
    compchoice = random.randrange(0,3)

    # This way, it'll keep looping until you enter a valid input.
    while playerpick not in choices:
        playerpick = raw_input("choice: ") #A stylistic choice, but I like spaces after my colons

    # Searches the list 'choices' and returns which position the string was in.
    playerchoice = choices.index(playerpick)

    #Quit if the player picked 3 ("quit")
    if playerchoice == 3:
        break #This successfully leaves the main loop

    # Optimization.
    print "vs " + choices[compchoice]

    if compchoice == playerchoice:
        print "tie"
    elif (compchoice + 1) % 3 == playerchoice:
        # Also an optimization.
        print "u win"
    else:
        print "u lose"

Edit: optionally, you can set playerpick to 'raw_input("choice: ").lower()', which allows use of both upper-, lower-, and mixed-case for input.

249
Miscellaneous / Re: Maze algorithm help
« on: August 04, 2011, 10:45:29 pm »
And, to clarify further, a set of connected cells is one whose cells' values are all the same. (Edit: except the first time it's mentioned, where it actually means its literal meaning. You could have a counter that you increment every time you don't connect to the cell on the left in the first row to initially fill array OLD.)
And the code isn't very optimized; it's just TI-BASIC. I have never found a way to make TI-BASIC code easy to read for more complicated things.
Glad you like it :). Maybe I should start writing tutorials...

250
Computer Programming / Re: html execution in javascript?
« on: August 04, 2011, 10:38:52 pm »
You slightly misinterpreted what I said :P
You don't use another <script> tag. The whole script should be in a CDATA section.
And the "alert(..." line in the example I gave stood for any JS code, given that it was a stand-in for the entire JS script.
Edit: thus, the fixed version of your code is
Code: [Select]
<script language="javascript" type="text/javascript"> //<![CDATA[
document.title=("Cell's Awesome Profile! :)")
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if (is_chrome === true)
  {

    document.print("<p>i has chrome yay</p>")

  }
else
  {
     document.write("<p>get chrome!</p>");
  }
//]]>
</script>
Edit 2: also, you didn't put <p></p> around the other text. Fixed.

251
Miscellaneous / Re: Maze algorithm help
« on: August 04, 2011, 10:35:17 pm »
Nah, it'd take me a bit too to remember how it works :P
As for the general logic:
  • Create two arrays the width of the maze (in cells). Call them, say, NEW and OLD.
  • For the first row, connect each cell to the one on its left with a given probability. Each member in a set of connected cells should have the same value at its index in array OLD.
  • For each subsequent row:
    • For each set of connected cells from the previous row:
      • Choose one cell from it and connect it downwards.
      • Set that cell's value in array NEW the same as in array OLD
    • For each cell in the row:
      • Connect the same cell from the previous row with a given probability.
      • If you do, set that cell's value in array NEW the same as in array OLD.
      • If not, and if it's not already connected from earlier, set it to some new value.
      • As long as it is not in the same set of connected cells as the cell to its left (which can be checked via array NEW), connect it to the cell to its left with a given probability.
      • If you do, set all elements in arrays NEW and OLD which have the value of the current cell (including the current cell itself) to the value of the cell on its left.
      • Store array NEW to array OLD (or swap pointers. Whatever.)
  • Some special things need to be done for the last row to connect all cells:
  • Until every element of array OLD has the same value:
    • Pick two cells whose values are different and connect them.
    • Set all elements in array OLD which have the value of the second cell to the value of the first cell (still including the second cell)
Notes:
  • Don't perform steps mentioning "cell to the left" for the first cell in a row, obviously.
  • When I refer to the "value of a cell", I mean the value of the element at the corresponding index in array NEW (or OLD for a cell in the previous row).

252
Computer Programming / Re: html execution in javascript?
« on: August 04, 2011, 09:29:39 pm »
DOM stands for the Document Object Model. It describes an object-oriented interface to an HTML (or any XML) file.
As for CDATA, it is just a special section which is not parsed. The best way to do it is like this:
Code: [Select]
<script type="text/javascript">
//<![CDATA[
alert("Code goes here")
//]]>
</script>
It also makes it XHTML-compatible.
Edit: ninja'd

253
Miscellaneous / Re: Maze algorithm help
« on: August 04, 2011, 09:22:03 pm »
Here's a page full of maze generation algorithms: http://www.astrolog.org/labyrnth/algrithm.htm
Eller's algorithm is cool because it only needs to store data for one row of the maze.
Edit: If you're any good at reading BASIC code, I do have a program that implements Eller's algorithm. Lemme find its topic...
Edit 2: Found it. http://ourl.ca/8028

254
Computer Programming / Re: html execution in javascript?
« on: August 04, 2011, 09:10:14 pm »
You shouldn't be putting HTML directly in JS code. That shouldn't even work. If you want to modify the page using Javascript, you have to go through the DOM, or use document.write like you did in the else clause. What you write should also be proper HTML.
So, the two interesting lines should be like this:
document.write("<p>This is HTML</p>")
document.write("<p>Get Chrome!</p>")
The only reason that might work is because the JS code is being parsed like HTML. There are a couple ways to prevent that. Use CDATA, or make the whole thing a comment. Either should work. Note that you should do this for any JS code, just in case.

255
Other Calc-Related Projects and Ideas / Re: ZeldaKing's Projects
« on: August 03, 2011, 01:51:18 pm »
May you send it to TI and get a new one for it?
Can you please upload a video/a few photos of that?
We've had several people allege that their calcs have stopped working recently... x.x
A picture of the screen would be nice, yes. As for nothing working, not even the [ON] key works?

Pages: 1 ... 15 16 [17] 18 19 ... 161