Skip to content

Instantly share code, notes, and snippets.

View Ni55aN's full-sized avatar

Vitaliy Stoliarov Ni55aN

View GitHub Profile
function queueTime(customers, n) {
var sorted = customers.sort((a,b)=>b-a);
var max = Math.max(...sorted);
var tills = Array(n).fill(0);
while(sorted.length>0){
for(var i=0;i<n && i<sorted.length;i++)
{
tills[i] += sorted.shift();
}
function primeFactors(n){
var list = [];
var maxi=9999999;
var maxk=99;
for(var i=2;n>1;i++){
var m = null;
for(var k=1;;k++){
var d = n/Math.pow(i,k);
class Perceptron {
constructor(layers, inputs) {
if (layers[0] !== inputs.length)
throw new Error("Invalid number of inputs");
this.l = layers;
this.activation = val => (val >= 0.5 ? 1 : 0);
this.learningRate = 0.1;
this.initWeights();
const fs = require('fs');
const draco3d = require('draco3d');
const js2obj = require('./js2obj');
const decoderModule = draco3d.createDecoderModule({});
const encoderModule = draco3d.createEncoderModule({});
var data = fs.readFileSync('./testdata/bunny.drc');
function optimizeGeometry(geometry) {
var saveVerts = [];
geometry.vertices.forEach((vert, i) => {
var present = geometry.faces.some(face => {
return face[0] === i || face[1] === i || face[2] === i
});
if (present)
saveVerts.push(i);
@Ni55aN
Ni55aN / computeVertexNormals-angle.js
Last active November 7, 2021 22:58
three.js smooth normals with crease angle
function calcNormal( normals, normal, angle ){
let allowed = normals.filter( n => n.angleTo( normal ) < angle * Math.PI / 180 );
return allowed.reduce( (a, b) => a.clone().add( b ) ).normalize();
}
THREE.GeometryUtils.computeVertexNormals = function(geometry, angle){
geometry.computeFaceNormals();
var vertices = geometry.vertices.map( () => [] ); // vertices with normals array
import * as THREE from 'three';
export class RealZoom {
constructor({ width, height }, diag) {
var diagPX = Math.sqrt(width ** 2 + height ** 2);
var screenWidthInch = width / diagPX * diag;
var screenWidthCM = 2.54 * screenWidthInch;
var viewWidthPX = window.innerWidth;
this.viewWidthCM = viewWidthPX / width * screenWidthCM;
}
snail = function(array) {
var side = 'top';
var result = [];
while(array.length > 0){
switch(side){
case 'top':
result.push(...cutRow(0, array));
side = 'right';
.alert {
position: absolute;
left: 0;
top: 0;
width: 100%;
background: rgba(255, 30,3, 0.7);
color: white;
padding: 1%;
font-size: 120%;
font-family: monospace;
const LabMath = {
"маточікування": function avarage(arr) {
return arr.reduce((a, b) => a + b, 0) / arr.length;
},
"медіана": function(arr) {
return arr.sort((a, b) => a - b)[Math.floor(arr.length / 2)];
},
"напівсума «крайніх» спостережень": function(arr) {
return (Math.min(...arr) + Math.max(...arr)) / 2;
},