Wikipedia:Reference desk/Archives/Computing/2016 June 19
Computing desk | ||
---|---|---|
< June 18 | << May | June | Jul >> | June 20 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
June 19
[edit]QBASIC programs for finding n prime numbers
[edit]After I saw an article Prime numbers in wikipedia, I got that there is no formula for prime numbers. But in the QBASIC there are some programs for finding n prime numbers. Can't we use modified form of it in finding general term(formula) of prime numbers in real life mathematics? sahil shrestha 14:45, 19 June 2016 (UTC) — Preceding unsigned comment added by Sahil shrestha (talk • contribs)
- @Sahil shrestha: I've moved your two questions down to the bottom of this page - this page, like other Wikipedia discussions, has the newest subjects at the bottom. Where you put them, at the top, they'd likely be missed by other user and not answered. -- Finlay McWalter··–·Talk 17:44, 19 June 2016 (UTC)
- There are many algorithms for generating prime numbers. Some one of those algorithms is used by the QBASIC program you saw. When we say there is "no formula" for prime numbers, this means there is no way of directly computing, say, the 1000th prime number. The only thing you can do is run a prime number generation algorithm and throw away the first 999 numbers it generates. (You will find that the 1000th is 7919.) --Steve Summit (talk) 19:30, 19 June 2016 (UTC)
- @Sahil shrestha:@Sahil shrestha:, Check out this -
FOR n = 2 TO 100
FOR k = 2 TO n / 2
flag = 0
r = n MOD k
IF r = 0 THEN
flag = 1
EXIT FOR
END IF
NEXT k
IF flag = 0 THEN PRINT n,
NEXT n
- — Preceding unsigned comment added by Aryan hindustan (talk • contribs)
- There are actually faster algorithms to find the nth prime for large n than to compute all the smaller primes but the basic point stands: There is no known efficient way to do it. The faster algorithms only means it becomes feasible (with a lot of computing power) for primes below 1026 instead of 1019 or something like that. PrimeHunter (talk) 13:32, 20 June 2016 (UTC)
Games in scientific calculators
[edit]Is there any method for playing video games like stuffs in scientific calculators of Casio brand? sahil shrestha 14:36, 19 June 2016 (UTC) — Preceding unsigned comment added by Sahil shrestha (talk • contribs)
- I am not sure what your question is. --Hofhof (talk) 23:54, 19 June 2016 (UTC)
- Hofhof, he is asking if she can play games on old calculators ,Sahil shrestha -I think NO!--Aryan ( है?) 06:13, 20 June 2016 (UTC)
- That is an urban legend, but some people claim that there were secret codes that would activate a game in a scientific calculator. It's kind of like an eastern egg.--Hofhof (talk) 09:02, 20 June 2016 (UTC)
- Not true! There WERE games for the HP 65 and the TI SR 51, and probably other calculators of similar vintage. You had to key the codes in but it was still a game. Lunar lander was one game I remember. It even had sound effects, courtesy of a small transistor radio placed against the top of the calculator. --TrogWoolley (talk) 09:53, 20 June 2016 (UTC)
- I think you mean Easter Egg. RedLinkJ (talk) 17:39, 20 June 2016 (UTC)
- That is an urban legend, but some people claim that there were secret codes that would activate a game in a scientific calculator. It's kind of like an eastern egg.--Hofhof (talk) 09:02, 20 June 2016 (UTC)
- Hofhof, he is asking if she can play games on old calculators ,Sahil shrestha -I think NO!--Aryan ( है?) 06:13, 20 June 2016 (UTC)
- Stop hanging around and finish your homework.--Hofhof (talk) 09:03, 20 June 2016 (UTC)
- Yes, simple games can be programmed, like training the Einmaleins (training children easy muliplcations) or guess a random number. Modells I know does not support INKEY or test a pixel of the graphic screen. When newer do so, videogames might be possible. A Gorilla.bas clone should be possible. --Hans Haase (有问题吗) 11:02, 20 June 2016 (UTC) Btw. would You upload the deleted picture to finish our last conversation?
- oh! Thanks for reminding me Hans Haase. I am done uploading the file and u can see it in ur talk page.sahil shrestha 14:49, 20 June 2016 (UTC) — Preceding unsigned comment added by Sahil shrestha (talk • contribs)
- I assume you are all talking about programmable calculators, not the plain scientific ones that have no RAM. Dbfirs 07:22, 21 June 2016 (UTC)
- See Casio graphic calculators, I am talking about the fx-7700G and similar. --Hans Haase (有问题吗) 14:06, 21 June 2016 (UTC)
- Yes, programmable. I used to have one. The plain scientific calculators don't have either games or Easter eggs. Dbfirs 07:43, 24 June 2016 (UTC)
- See Casio graphic calculators, I am talking about the fx-7700G and similar. --Hans Haase (有问题吗) 14:06, 21 June 2016 (UTC)
- I assume you are all talking about programmable calculators, not the plain scientific ones that have no RAM. Dbfirs 07:22, 21 June 2016 (UTC)
HTML form entry for money amount
[edit]I have the following code:
<p>Payment amount (USD): $<input type="number" size=10 maxlength=17 min="0.01" step="0.01" value = "1.00" name="amount"><br>
It works, but is a bit ugly, because while $1.23 shows up correctly, $1.20 shows up as $1.2 and $1.00 shows up as $1. How can I fix this ? StuRat (talk) 15:50, 19 June 2016 (UTC)
- The quick answer is "with JavaScript" - you can't do it with the HTML alone. See, for example, this Stack Overflow thread. Tevildo (talk) 17:34, 19 June 2016 (UTC)
- Well, that sucks, doesn't it ? I will just leave it poorly formatted rather than complicating things with more Javascript. Thanks for the answer. StuRat (talk) 15:11, 20 June 2016 (UTC)
HTML form entry for hidden numbers ?
[edit]Similar to the above, the type can be "number", in which case it is forced to be numeric, or "password", in which case it is not displayed, but replaced by asterisks. Is there a way to have both attributes, say for credit card numbers, which should both be forced to be numeric and hidden ? Or must we again use Javascript to do so ? StuRat (talk) 15:14, 20 June 2016 (UTC)
- This is probably easier to do at the server end - leave the input type as "password", and check that the value is numeric as part of the form validation. But, yes, if you want to do it in the client, you'll need JavaScript. Tevildo (talk) 19:11, 20 June 2016 (UTC)
- Thanks again. Looks like they need lots more capabilities in plain old HTML, to me. I wonder why it is still so basic, after all these years. StuRat (talk) 04:13, 21 June 2016 (UTC)
Apple phone software for Windows
[edit]Is there anything like BlueStacks, for Apple phone software apps? -- Apostle (talk) 19:18, 19 June 2016 (UTC)
- iPadian. Ruslik_Zero 20:16, 19 June 2016 (UTC)
- Okay thanks. -- Apostle (talk) 18:58, 20 June 2016 (UTC)
- It's more of an ersatz simulator which recreates popular iOS apps instead of actually emulating iOS hardware at all. Blake Gripling (talk) 00:19, 25 June 2016 (UTC)
- Okay thanks. -- Apostle (talk) 18:58, 20 June 2016 (UTC)
Pattern matching in functional languages
[edit]What makes this so special (according to FP adherents)? Couldn't this functionality be implemented in other languages easily? Like parsing an XML structure? There must be libraries for this in any language. --Hofhof (talk) 23:54, 19 June 2016 (UTC)
- Well, in most languages (with the notable exception of the LISP family), libraries are very limited in what syntax they can use.
- Here's a concrete example of a case where pattern matching is useful to make this clearer. In Python (and many other languages) if you look up a value in a map/dictionary and it isn't present, you get an exception (KeyError in Python's case). Python encourages you to use exception handling for this ("EAFP"). You can write
try:
... # do something with d[k]
except KeyError:
... # do something if k isn't in d
- But that code is wrong if the thing you do with d[k] might also raise a KeyError. And even if it can't do that now, it might change in the future, so this pattern is fragile. You can't just move the code out of the try block, because code after the try block is run after the KeyError handler also. The only universally correct approach is
try:
x = d[k]
except KeyError:
... # do something if k isn't in d
else:
... # do something with x
- This is now long and confusing, and still has the problem that if the except code throws an exception, Python will confusingly report the KeyError as the context for it, even though conceptually this is an if statement, and it doesn't do that for if statements. For all of these reasons, I often just write if k in d: ...d[k]... else: ... instead, despite its problems (code duplication and a potential race condition in threaded code).
- In Haskell, you write
case lookup k d of
Nothing ->
... -- do something if k isn't in d
Just x ->
... -- do something with x
- This is the right syntactic structure for what I'm trying to do: it looks like an if statement, but it avoids a duplicate lookup by putting the result in x at the same time. The Nothing and Just clauses can be in either order (like the Python if statement, but unlike Python try, where except must precede else).
- Introducing this kind of control-flow construct in a library would be difficult in most languages (except the LISP family). You would likely have to pass the patterns as strings (which would be parsed inefficiently at run time), and the code in the two clauses as anonymous in-line functions (if the language supports that). To bind x, you would probably have to name it in the function arguments and put the same name, or its numerical position, in the quoted pattern. You would need significant runtime reflection support in the language to make it all work. The patterns, being quoted, would not be correctly syntax highlighted. Since readability is a major advantage of this approach in the first place, it probably wouldn't be worth it.
- For more complicated patterns, a library could be useful, even if it's string-based, as it could save writing a lot of code. Regexes are an example of that. I think the value of ML-style pattern matching is mostly in the simpler cases. -- BenRG (talk) 01:43, 20 June 2016 (UTC)