last day (16 days later) » 

07:15
-3
Q: Irrational arrays without strings

guest271314Write a function that takes input as an integer, decimal or irrational number and outputs an array containing the integer or if a decimal number includes the last integer and decimal separator portion of input set as a single element with remaining integer and decimal portions of input set as adj...

How do we take an irrational number? Also most languages are going to simplify 100.00 to 100 unless they take input as a string
@JoKing "How do we take an irrational number?" Not sure what you mean? You write the code.
@Doorknob What specifically about the second test case does not appear to be consistent to you? The last two examples are intended to depict a plain or golfing language function or procedure within a function which converts the input or output to a string during the procedure.
A decimal representation of an irrational number is, by definition, infinite. Most languages won't be able to handle this, and those that can will have infinite output...
@PeterTaylor e used in a language such as JavaScript is an artifact of computer science and the technology of the day and is not the number e. The test cases at the question are exhaustive enough for the present inquiry. If you decide to contribute further defensive code in an answer kindly do so in an answer to the question.
@JoKing Yes, an irrational number infinite, though output can be stopped at the 20th decimal place, or the maximum output of the language used. Have written code in JavaScript which converts a number to an array without using string methods, omitted from the question body; came across this issue when passing irrational numbers or simply 1.5; considered numerous approaches, decided to post the question here to see how the users here would approach the case. Vote to close the question if you do not like the question.
The proper action for an unclear question shouldn't be for users to close the question, but for the poster to clear up the confusion.
07:15
@JoKing What is confusing to you? Should the current JavaScript code which does not return the expected result be included at the question?
I think you're confused on what irrational means. Do you mean numbers with a possible fractional parts, rather than numbers that can't be expressed as a ratio of two integers? The former is what your examples appear to be, while the latter is impossible to represent as a finite decimal number.
@JoKing e, Pi, φ are irrational numbers. As indicated at a previous comment, output can be stopped at the 20th decimal place for input that is an irrational number, which would in any case be the maximum output possible for that language or system itself. None of the examples at the question exceed 20 decimal places after the decimal. 0.5 is a decimal number that is not an irrational number which should be output as [0.5].
The confusion is that you are asking us to take an irrational number as input. I think you should remove the whole irrational number thing entirely if I'm honest
There's also my first question, how can we take 100.00 as input if not by string?
cool
@JoKing Updated question
and 100.00? And is there a reason this is tagged ?
07:27
@JoKing Updated question
07:38
@JoKing Is the question clear to you now?
07:48
I can understand it from the test cases, but the specification is pretty gibberish
@JoKing Then edit the question to suit understand of the readers of the question. "improve this question" There is a clear language barrier. This is supposed to be a coding site, not a queen's proper english and grammar site. The requirement is to expand or spread an input integer or decimal to an array without using string methods. Considered using [0, Symbol(/./), 5] to represent a decimal, though the question asks for a different solution which does not involve converting objects.
@JoKing Perhaps some code which does not return expected result will show what am trying to achieve based on https://stackoverflow.com/a/36828957/, https://stackoverflow.com/a/45666094/, https://codereview.stackexchange.com/questions/10351/

function* numberToArray(n) {
let a = n || this.valueOf();
const r = [];
if (!Number.isInteger(a))
// attempt to handle `e`; `Pi`; `φ`; `0.5`
// without using string methods
a*=1000000000000000000000;
for(;~~a;r.unshift(~~(a%10)),a/=10);
yield* r;
}

Number.prototype[Symbol.iterator] = numberToArray;
@JoKing To, in part, to assist with fine-tunely do something like this using arrays


~~(128.625*9*1.2375)
1432

(128.625*9*1.844)
2134.6605

(128.625*9*1.8513)
2143.1111625

(128.625*9*1.999)
2314.092375

(128.625*9*2.0225)
2341.2965625

though that is beyond the scope of the question.
08:58
@guest271314 While it's true that other users can improve the question by editing it, "not a queen's proper english and grammar site" is a bit snarky.
Usually, disallowing built in functions will create more confusion than it helps to make the challenge more interesting.
2
@user202729 Have never used the term "snarky". That is an entirely different language. Have no issues with direct communication. Built-in string functions are disallowed. The point of the question is to achieve the requirement without using string methods. Users are apparently trying harder to confuse themselves than actually trying to answer the coding question. Or posting an answer that states it is not possible.
But the simplest way is to use strings, right?
In languages like C, there are no string, just array of characters.
@user202729 Not in JavaScript, when the code is constantly converting to and from a string, [...''+123] or [...${123}] and back and forth could vastly be simplified; especially where numbers in arrays are used frequently within the code
@guest271314 Actually, in Javascript, using strings would be the fastest and simplest way.
(assuming you're most familiar with Javascript)
@user202729 Not from perspective here.
09:10
@guest271314 Why?
@user202729 Converting back and forth, as stated at previous comment. How is that relevant to the question?
@user202729 You might as well ask why people write golfing languages.
Ok, "why" is not very related, I agree. Just trying to tell you that don't do this in production code.
@user202729 There is no "don't do this". That too, is wholly irrelevant to the question. Again, you might as well state don't write golfing languages
@guest271314 But you don't golf your production code, right?
@user202729 Where is your line of questioning going? Motive for the question? We probably have entirely different worldviews.
09:18
Anyway. Javascript Number type cannot distinguish between 0 and 0.0 right?
@user202729 JavaScript have many limitations. That is not the question. The question is clearly printed at the question itself.
Can the challenge be solved in Javascript, given the limitation I mentioned above?
@user202729 More than likely, yes.
How do you workaround it?
Another question.
@user202729 Read the entire discussion page. Initially considered using a Symbol, to avoid have the ability to convert the decimal representation to a number type in a single expression or procedure for disambiguation. Then considered the current approach, and asked the question here.
09:22
The output for 10.01 is [1, 0.0, 1] and the output for 101 is [1, 0, 1]. Must the output for those inputs be different?
@user202729 Yes. The expected outputs are printed at your comment
But they're the same in Javascript.
@user202729 They are not the same inputs or outputs.
And Symbol uses string in their constructor anyway. Because strings are not allowed, isn't Symbol not allowed too?
@user202729 Considered using Symbol, which is not easily converted to a number and can be used as the decimal delimiter in an array. However, that would require writing a function which separated the digits on each side of the delimiter and processing them differently
09:26
Assume an answer is written in Javascript. Is it allowed to use a string to construct a Symbol in the code?
@user202729 Ideally, no strings or string methods should be used at all in the code. Technically Symbol is not String type in JavaScript. If you gather the question post the answer, including illustrating and demonstrating what is possible and not possible, deficiencies using numbers in JavaScript, or the languages you use to write the answer. Not possible is a valid answer.
Then how 0 and 0.0 be outputted as different values?
@user202729 If that is not possible state that in your answer and provide a viable alternative to represent a decimal in an array that is not easily or cannot be converted or coerced into a number by happenstance ~~(NaN) and further that array can be converted back to the original input without digits or decimals changing
@user202729 Without using any string methods
@guest271314 For example in Javascript what's a "viable alternative" to 0.0?
@user202729 Could potentially use [0, Symbol(/./), 0]. Or another approach which does not use string methods. Or, state that requirement is not possible using JavaScript.
09:44
In languages such as C, is using an array of char ok?
(C has no built in string, but has strcpy/strcmp/etc functions)
@user202729 Have not tried C, though char is essentially equivalent to String in JavaScript?, which must not be used for this requirement. The question is probably moot at this point and will be closed. Not sure what is taking so long for the needs more downvote crowd to do what they do. They are gaining as type, surely. Will wind up solving the question for self. At least you have tried to gather the gist of the question here.
@user202729 Tried to post a coherent question. Am probably so far removed as to experiences from the users at se sites that there is little common understanding, particularly as to communication, to be had.
A side note for future challenges. This site isn't really a question and answer site, like Stack Exchange. Instead, questions are challenges, and should be fully specified and clear. Answers should not be subjective and should answer the question fully. They are not meant to do anything but answer the question as specified
Posting an answer stating the requirement is not possible is not standard behaviour on this site and the answer would be deleted by mods. That stuff is usually addressed in the comments
2
For challenges where the restriction only make sense in some languages, it may work better to restrict it to those languages.
10:41
@guest271314 If loopholes exist in your challenge, then it is up to you to fix them, not the answerer.
@guest271314 Back at chat again. Yes, they're opinions, but community opinions are a good measuring stick of whether your question will be well-received. Doing all the things that the community doesn't like won't get your question closed, but it'll get it downvoted
@guest271314 A note: Answers should answer the question. If someone is trying to clear up stuff, doing so in the comments is the correct way of doing so. Please stop suggesting that people post an answer that you can define as incorrect
11:07
@guest271314 Can I just confirm that you're reading the previous 5 or 6 messages?
@JoKing Yes, have read your messages. What you define as "community" is obviously very different from how view the same term. Will suggest what decide to. The same as users suggest to edit the question for them to understand in the language they are used to reading. A "downvote" is absolutely meaningless to this user; see this stat at each se site have logged in to: "0 down"
We're usually hesitant to edit questions beyond grammer and punctuation on this site, as we don't want to change anything the asker is actually asking.
@JoKing In fact: Needs more "downvote". If only to demonstrate how the "community" you refer to expresses itself. Would prefer an answer to the question. That is not presumably forthcoming
Well, you kinda have to ask a clear question to get an answer
@JoKing This is what "Needs more "downvote"" means to this user needsmorejquery.com. It is utterly useless. The question is clear. If you cannot meet the requirement, that is not based on the question itself.
11:16
Not really. You haven't really specified how to output -0.0 without using strings.
The problem with the requirements is that they are pretty much impossible, since there are almost no languages that can represent -0.0 differently from 0
2
@JoKing The output has been specified. There, you stated a viable answer. Starred. Apparently more work has been put into composing obscure glyphs for golfing languages that outputting [0.0]
Well, most challenges don't simultaneously say that -0.0 is different from 0 while demanding that you can't use strings
@JoKing Am not "most", by far. In any event, at least you have once again tried. And provided a viable answer to the question, given no formal answer has been and will more than likely not be posted by "community". Certainly did not set out for this question to take on this legalese language lawyer litigation. Simply asked to solve a problem encountered.
I'm not really sure what you mean by a viable answer.
Well, this isn't a Q and A site. If you're looking for programming help, Stack Overflow is a better site for that
@JoKing See your language at the top starred comment. se users are always stating what their site is not, until they want to do something at the site.
11:25
Well no, answers on this site are almost always composed of a program as the answer, not straight text
@JoKing Then, as stated at first comment to you at this question, post an answer which solves the question. Make the solution possible. The question is very clear. Trivial at first glance, perhaps; trivial in actual application, perhaps not; yet clear.
@JoKing As with most every question closed by "community" at se sites, will create own solution and answer. Am definitely not reliant on the confines of some pseudo "community" which so rapidly votes to "close" what is not "clear" to them, or view as impossible or do not understand or make a concerted effort to not understand, without directly saying that. At least you did
@guest271314 I'd answer, but the only two languages I pretty much ever use on the site often can't answer it because of the restrictions.. That isn't a reason to close-vote the challenge, but very much is a reason to downvote it.
A note when making future challenges. This isn't a question and answer site. Questions aren't asked here because users need a practical answer to use in real life (except maybe questions). While it's common for challenges to be inspired by real life code, they're typically modified in a way to be answerable for a majority of languages
@dzaima "down" vote is worthless to this user. Do not take part in that emotion-driven exercise, here.
@guest271314 it tells you that the challenge is bad, and tells others that the challenge might not be worth looking at / wasting time reading.
11:37
it also hides the challenge on the front page if there's enough downvotes
@dzaima No, you are incorrect.
@guest271314 Why?
@dzaima Am not a follower. Could not care less what "community" collectively "thinks". That calls for the operation of other peoples' minds. se users circle like vultures and are quite prone to peer-pressure and wanting to be accepted by their little pseudo "community" that exists only in their own mind
@guest271314 ok, you don't care, but others would rather answer an interesting question, not one that has many problems and isn't even answerable in most languages.
@dzaima Fine. Suggested they vote to "close", "down" vote, move on, or do whatever has meaning to them emotionally. Other than that, will answer own question, in due time. There have been other questions at se which were deemed impossible by other dozens of questions, that have solved
11:41
What is your goal in asking questions here at PPCG?
@JoKing To get actual answers in the actual answer from users. Not side discussions about the laurels of se pseudo "community", etc.
@guest271314 in the comments you just asked "Do you use any strings?" You have no way of knowing besides knowing the language/asking the author. On PPCG we require an objective way to check the validity of an answer, and asking the author is very, very unobjective.
@guest271314 I'm on PPCG to have fun.
@dzaima Yes, the author should state if they are using strings. If not, will debug their glyps and find the truth. The entire se platform is subjective
Yes, PPCG is a re-creative programming site. Challenges are asked in order for users to enjoy answering them
@guest271314 PPCG isn't subjective is the thing.
PPCG is very different from the rest of SE.
11:45
@dzaima Yes, it is. Proven by the closure of several of this users' questions. No, it is not. The same culture.
Overflowing in fact, at this question
@guest271314 PPCG might have the same users as some other SE sites, but here we require objectivity while other sites don't.
@dzaima What you state is objective is subjective
@dzaima That is not to state that there are not quality and talented minds here. Though the se culture, in general, the entire platform is entirely subjective.
@dzaima Before get banned from here, will depart. You folks keep having fun! Cheers!
@guest271314 again, PPCG shouldn't really even be a part of SE. It is supposed to be as objective as possible.
if I answer with compiled bytecode, you have no way of knowing whether I used strings or not, since in the bytecode it's all numbers. Really, nothing ever really uses strings.
12:51
@dzaima machine code.
 
5 hours later…
18:09
@dzaima @JoKing @user202729 See updated question
 
3 hours later…
21:25
@guest271314 Things to avoid, inferring the challenge from test cases. For example, I don't know the rules behind whether you can output 1.9 vs 1,0.9 or 4.4,5 vs 4,0.45? The specification is still gibberish
 
2 hours later…
23:01
@JoKing Output each variation that you have perceived as possible and which you can also demonstrate conversion back to integer or decimal number. Your answer will be the answer, as you will have produced the best possible solution at that time, which could not be disputed.
23:32
@guest271314 The question doesn't say anything about converting the list of numbers back again. For example, for input 1.999, can I output [1,0.999]?
23:45
@JoKing The original question asks for each digit to be expanded at the output array [1,0.9,9,9]. If you have an answer which produces the output that you described, post an answer. Have not found a question and answer which previously had the exact requirement described at the question; therefore, there is no output to compare to at an answer which asks for the decimal to be indexed separately and to not use string methods.

  last day (16 days later) »