Jump to content

espurritado

Member
  • Posts

    178
  • Joined

  • Last visited

Everything posted by espurritado

  1. Last year I had to do a presentation about multithreading in c#, here's the first proof of concept I wrote for thread pools. Hope it helps. namespace EjemploThreadPool { class Program { static void Main(string[] args) { ThreadPool.SetMaxThreads(2,5); for (int i =0;i<10;i++) { ThreadPool.QueueUserWorkItem(ThreadProc); } Console.Read(); } static void ThreadProc(Object stateInfo) { Console.WriteLine("Empiezo a trabajar"); Thread.Sleep(1000); Console.WriteLine("Termino de trabajar"); } } } EDIT: After reading your code, you would have to make everything inside the while a process which is the task you would assign to the thread. You would have to make sure H, O and A are only accessed by one thread at any given moment. Consider using something like locks for the increment section.Since there is a limit to how many calculations you make, there's no special need to consider fairness (some process might get stuck in the lock but it's not an infinite task so eventually it will go through) Finally, the stopwatch must be stopped either by the last process, or when all the processes are done. The easiest way is to keep a done process counter (also with exclusive access) and make the check at the end of every process
  2. Not long ago I was toying with python and generating prime numbers, and I thought I could generate a file with all prime numbers up to 22048. Long story short, don't. I didn't give much thought to the code in terms of memory allocation (never had to worry about it before) and right at the moment I launched the program to see if it worked, my whole computer froze and my hdd started to sound like crazy (when ram memory is full, computers tend to use other memory as if it were ram). I had to force my computer off because it was completely unresponsive. After that, I took my calculator and found out the program I was trying to execute would need an insane amount of memory.
  3. As the people before me have said computers basically understand 1s and 0s. It depends on the programming language on how it works, but let's assume a compiled language. First you have to define the language, the syntax, the semantic, the basic words, the basic types, etc. Then you have to create somehow a compiler, something that from a text file with a piece of code that follows the rules described in the previous step creates a file with the a of instructions for an OS to do what you asked to do. And there you go, you have your programming language. There's obviously more to it, you have to determine the memory structure for variables, the organization of your reserved words, the hierarchy of your names in the different levels.
  4. var x=0; var y=0; $(document).keydown(function(e){ if(knappTryckt) { if(e.keyCode == 37) { if(x>0){ $("#spelare1").stop().animate({left: "-=" + 100 + "%"},5000); x-=100; } } you just have to limit to the border size and to 0 corresponding to each key press. There's probably an easier way with JQuerry, but I've never used it. This should work but I haven't tested it so I might have gotten the direction wrong P.D.: Sorry about the crappy tabulation, It wouldn't go right
  5. It's not that complicated, you just need to keep track of the player's position and stop it moving when it reaches a border
  6. Sometimes I've had problems, specially when using ubuntu since it comes with both python 2 and python 3. PyCharm has a gui functionality that allows to install packages from pip. It has always worked for me that way
  7. I've used Tkinter before, didn't took me more than an afternoon to figure it out.
  8. you need to use Slim. I would recommend using composer to install it
  9. lets take it step by step: you roll 2,3,3,3,5; your counts list is [0,0,0,0,0,0] you start reading your rolls read the 2; you increase the second element in your array by one; your counts list is [0,1,0,0,0,0] read the 3; you increase the third element in your array by one; your counts list is [0,1,1,0,0,0] read the 3; you increase the third element in your array by one; your counts list is [0,1,2,0,0,0] read the 3; you increase the third element in your array by one; your counts list is [0,1,3,0,0,0] read the 5; you increase the fifth element in your array by one; your counts list is [0,1,3,0,1,0] therefor [0,1,3,0,1,0]. then, you just have to ask: is the counts list [1,1,1,1,1,0] or [0,1,1,1,1,1]? if it is, you've got a straight for four of a kind is even simpler, you just ask: is there a four in counts? also = means assignment == means comparison you've got every single condition wrong
  10. actually is not that unrelated, you just don't check for the suit and just go up to 6 instead of 13
  11. The solution, as I see it, is to get an array of length 6, it will contain how many dice have rolled it's position. Lets say you roll 2,3,3,3,5 then your array would be [0,1,3,0,1,0] then you just have to define your conditions for each possible scoring condition, for example, 5 in any position of the array means Yahtzee
  12. you could consider printing the first number outside the loop, and then in the loop, coma and the next number. also PLEASE use code tags thanks
  13. normally there's some kind of button combo that forces the reset. check your manual or look for soft reset and you tablet model
  14. it's been a while since I've done PHP, but if the function parameters mean what I think (the default value for $numEndDate is NULL) then the error comes from trying to turn NULL into a string
  15. Not sure, but I think they are known by ISO. Just to be sure you can refer to them by the number of keys (105 for full and 88 for tenkeyless)
  16. Hey guys, My uncle is looking into getting his personal cloud (for redundancy and working on documents on different computers easily) and one of his options is https://nextcloud.com/box/ . From what I read I'm not completely sure I like it. However, I would like to know the opinion you guys have about the product (both hardware and software) and, if you have tried it, how did it go. Thanks!!
  17. it's just requesting the name for the drive. I believe it can be blank, or you can just call it MyDisk or whatever you want
  18. I would guess you left something enabled, or some field that was empty occupied. I would try restoring the computer to a previous point
  19. you could consider setting up the Danish keyboard in the OS. As long as the keys layout is the same (for example the Danish layout and the Spanish) you could press the key where your character is supposed to be and you will get that output
  20. my mistake, sorry, the readLine has to be inside the loop, however the control variable (rightSexAnswer/rightAdventureAnswer) has to be outside the loop. just move the readLine to right after the do{ also, another bit of common practices, variable names start with lower case and use what is called camel case (the first letter of every word after the first is uppercase). Classes names start with upper case and use camel case
  21. it's easy, for the sex question, for example it would be do{ string SEXanswer = Console.ReadLine(); bool rightAnswer = false; if (SEXanswer.ToLower() == "male") { Console.WriteLine("???: I am " + SEXanswer + "."); Console.WriteLine("The Creator: Hello young man, what is your name?"); rightAnswer = true; } else if (SEXanswer.ToLower() == "female") { Console.WriteLine("???: I am " + SEXanswer + "."); Console.WriteLine("The Creator: Hello young lady, what is your name?"); rightAnswer = true; } else { Console.WriteLine("???: I am " + SEXanswer + "."); Console.WriteLine("The Creator: Sorry, didn't catch that could you repeat whether you're a boy or girl?"); } }while(!rightAnswer)
  22. I just gave it a quick read and seems cool, however, those goto aren't really good practices, on the long run (and if you collaborate in the project with other people) is more convenient to use do{ } while(). Other than that, I look forward to see your progress
  23. there's the obvious option of creating a new list and insert the elements from the old list one by one if they are not present already in the list
  24. If you are just programming and what to see your changes faster, there's an atom extension called atom-live-server, which creates a local server where you can load your html and adds a bit of code that makes it reload every time one of the files being used changes
×