I was trying to simulate the Secretary problem in JS, expecting to get a value of 1/e (~37%), but what I am getting is much less (~10%), and it was changing, increasing people would decrease it. This is what I tried, I think the error might be the let x=new Array(people).fill(0).map(e=>Math.random()) . I was expecting 37%, but got ~10% I
Tag: math
Limit dragged line to an arc / radius of a given length
I’m currently using Phaser 3, although my question isn’t technically restricted to that framework, as it’s more of a general JS/canvas/maths question, but: I have a line drawn with graphics(). It’s anchored at one end, and the other end is draggable. I made a quick demo and so far, so good – you can see what I have already on
How to know if a point is inside an arbitrary contour in Javascript?
I have some SVG arbitrary closed shapes composed of lines and curve paths. I want to check if some points are inside the shape. I have found Point in Polygon algorithm that seems to work well, but I will have to decompose my path into a multitude of lines. Is there a more direct solution to this problem? If not,
Generate random 6 characters based on input
Generate random 6 characters based on input. Like I want to turn 1028797107357892628 into j4w8p. Or 102879708974181177 into lg36k but I want it to be consistant. Like whenever I feed 1028797107357892628 in, it should always spit out j4w8p. Is this possible? (Without a database if possible.) I know how to generate random 6 characters but I dont know how to
Only half of array gets raised to power
I wanted to create binary to decimal calculator. When i tried to console log both of arrays (binary is array of 0’s and 1’s, binarypos is array of numbers that are powers of 2. Screenshot Then i created simpler version, made in console so chance of making a mistake lowered to zero. But the bug appears again! I want it
Calculate width of hexagons in a field
I am drawing a hexagonal grid using javascript and svg. The grid needs to have a fixed width (let’s say, of 1000px). The dimensions of the grid can differ, but I have that information (the columns and rows). I have written a function that given a hexagons ‘bounding box’ width (the height is a factor 0.8660254 of the width), will
Reverse Isometric Projection in Javascript
I have a function which converts some 3D coords (x, y, z) into a position in the screen (width, height), with an isometric perspective (true isometric, not dimetric). So, for better clarification, here we have the blue lines, which represents the 2D Screen, and the black lines, which represents the 3D isometric space: The above function works fine. If I
Percetange calculation wrong result
I want to calculate the percentage of a minute from a given number of hours. So let’s say I have 2 hours. That’s 2*60 minutes. And I want to know how much percent does 1 minute take from 2 hours. The value should be 0.833, because 0.833 * (2*60) = 100%. But how do I get this 0.833 number? (hours
Convert 45 to 1 and 345 to 2 [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 9 months ago. Improve this question I’m building a carousel with a swiping limit exceeding both left and right of 45px on each item has 300px width I wonder How to
MYR Currency Rounding
Looking for help in rounding the money to the nearest 0.05 in js language. Input & Expected Output: From: https://www.bnm.gov.my/misc/-/asset_publisher/2BOPbOBfILtL/content/frequently-asked-questions-faqs-on-rounding-mechanism Answer You could take an offset and take a multiple floored value. If you need zeroes at the end take .toFixed(2).