This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"/> | |
| <title>nested ternary or hash?</title> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
| <script src="./suite.js"></script> | |
| </head> | |
| <body> | |
| <h1>Open the console to view the results</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const storage = require("Storage") | |
| const appDesc = "+activit"; | |
| storage.write(appDesc, { "name": "activities", "src": "-activit" }); | |
| const chunkCount = storage.list().filter(n => n.startsWith("activi")).length | |
| for (let i = 1; i <= chunkCount; i++) { | |
| storage.erase("activi" + i) | |
| } | |
| storage.write("-activit", `var e=require("activi1");var r=require("activi2");var t=require("activi3");var i="Start";function a(){var t=g.getWidth();var a=g.getHeight();var n=r.buildMetric();var o=e.initLayout({draw:function(){g.clear();var r=.2*a;g.setColor.apply(g,e.green);var o=.17*a;var s=.32*t;var c=.87*t;var l=.5*a-o;var v=.5*a+o;g.drawCircle(s,.5*a,o);g.drawCircle(c,.5*a,o);g.clearRect(s,l,c,v);g.drawLine(s,l,c,l);g.drawLine(s,v,c,v);g.drawPoly([.86*t,.44*a,.92*t,.5*a,.86*t,.56*a],1);g.setColor.apply(g,e.white);e.drawCenteredString(i,r,t,a);r=.1*a;e.drawCenteredString(n.curr(),r,t,a,.5*r);var u=e.positionService.value.hasFix?e.green:e.white;g.setColor.apply(g,u);g.drawCircle(.5*t,.85*a,10);if(e.positionService.value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const storage = require("Storage") | |
| const appDesc = "+activit"; | |
| storage.write(appDesc, { "name": "activities", "src": "-activit" }); | |
| const chunkCount = storage.list().filter(n => n.startsWith("activi")).length | |
| for (let i = 1; i <= chunkCount; i++) { | |
| storage.erase("activi" + i) | |
| } | |
| storage.write("-activit", `var e=require("activi1");var r=require("activi2");var t=require("activi3");var i="Start";function a(){var t=g.getWidth();var a=g.getHeight();var n=r.buildMetric();var o=e.initLayout({draw:function(){g.clear();var r=.2*a;g.setColor.apply(g,e.green);var o=.17*a;var s=.32*t;var l=.87*t;var c=.5*a-o;var v=.5*a+o;g.drawCircle(s,.5*a,o);g.drawCircle(l,.5*a,o);g.clearRect(s,c,l,v);g.drawLine(s,c,l,c);g.drawLine(s,v,l,v);g.drawPoly([.86*t,.44*a,.92*t,.5*a,.86*t,.56*a],1);g.setColor.apply(g,e.white);e.drawCenteredString(i,r,t,a);r=.1*a;e.drawCenteredString(n.curr(),r,t,a,.5*r);var u=e.positionService.value.hasFix?e.green:e.white;g.setColor.apply(g,u);g.drawCircle(.5*t,.85*a,10);if(e.positionService.value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const [trainCars, numTickets, numRoutes] = readline().split(' ').map(n => +n) | |
| const colors = ['red', 'yellow', 'green', 'blue', 'white', 'black', 'orange', 'pink', 'engine'] | |
| // Player's hand: for each color type, a number of cards | |
| const hand = {} | |
| readline().split(' ').forEach((num, i) => { | |
| hand[colors[i]] = +num | |
| }) | |
| // Player's tickets: two cities and a number of earned points |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let [symbols, length, head] = readline().split(' ').map(n => +n) | |
| // current state | |
| let current = readline() | |
| // current tape, filled with 0 | |
| const tape = Array.from({length}, () => 0) | |
| // All states stored by name. | |
| // Contains array of actions; each match symbol of the same rank, and contains: | |
| // - symbol [Integer] to write | |
| // - isLeft [Boolean] to move tape on left or right side |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const [floors, up, down, start, target] = readline().split(' ').map(n => +n) | |
| const move = (start, target, up, down, floors) => { | |
| if (target === start) { | |
| return 0 | |
| } | |
| let count = 0 | |
| let current = start | |
| const stack = [] | |
| while(current !== target) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const code = [...readline()] | |
| if (code.length % 3) { | |
| print('ERROR') | |
| } else { | |
| const chars = [] | |
| for (let i = 0; i< code.length; i += 3) { | |
| chars.push(String.fromCharCode(code[i] + code[i + 1] + code[i + 2])) | |
| } | |
| print(chars.join('')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Freely inspired by http://www.geeksforgeeks.org/find-longest-path-directed-acyclic-graph/ | |
| // get the building maps, considering that exist's ids are -1 | |
| let n = +readline() | |
| const rooms = [] | |
| while(n--) { | |
| const [i, money, next1, next2] = readline().split(' ').map(n => n === 'E' ? -1 : +n) | |
| rooms[i] = { | |
| id: i, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let [width, height] = [+readline(), +readline()] | |
| let n = height | |
| let grid = [] | |
| // use a boolean grid to make comparison faster | |
| while(n--) { | |
| // O is water and thus true. false is land | |
| grid.push(readline().split('').map(c => c === 'O')) | |
| } | |
| n = +readline() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Return a stop by its id | |
| * @param {String} id - stop's id | |
| * @return {Object} the full stop object | |
| */ | |
| const getById = id => stops.find(n => n.id === id) | |
| /** | |
| * Compute distance between two nodes | |
| * @param {Object} a - first node, with `lat` and `lng` attributes |
NewerOlder