Advertisement
dabidabidesh

radioCrystals

Jun 15th, 2020
3,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //15 EXERCISE = FUNCTIONS/More Exercise/04. Radio Crystals.js
  2. radioCrystals = (input) => {
  3.   'use strict'
  4.  
  5.   const cut = (x) => x / 4
  6.   const lap = (x) => x * 0.8
  7.   const grind = (x) => x - 20
  8.   const etch = (x) => x - 2
  9.   const xRay = (x) => x + 1
  10.  
  11.   const print = (operation, thickness) => {
  12.     if (thickness > 0)
  13.       console.log(`${operation} x${thickness}\nTransporting and washing`)
  14.   }
  15.  
  16.   let cuts = 0,
  17.     laps = 0,
  18.     grinds = 0,
  19.     etchs = 0
  20.  
  21.   for (let i = 1; i < input.length; i++) {
  22.     let currentThickness = input[i]
  23.     let targetThickness = input[0]
  24.  
  25.     console.log(`Processing chunk ${currentThickness} microns`)
  26.  
  27.     while (currentThickness / 4 >= targetThickness - 1) {
  28.       currentThickness = Math.floor(cut(currentThickness))
  29.       cuts++
  30.     }
  31.     print('Cut', cuts)
  32.  
  33.     while (currentThickness * 0.8 >= targetThickness - 1) {
  34.       currentThickness = Math.floor(lap(currentThickness))
  35.       laps++;
  36.     }
  37.     print('Lap', laps)
  38.  
  39.     while (currentThickness - 20 >= targetThickness - 1) {
  40.       currentThickness = grind(currentThickness)
  41.       grinds++
  42.     }
  43.     print('Grind', grinds)
  44.  
  45.     while (currentThickness - 2 >= targetThickness - 1) {
  46.       currentThickness = etch(currentThickness)
  47.       etchs++
  48.     }
  49.     print('Etch', etchs)
  50.  
  51.     if (currentThickness === targetThickness - 1) {
  52.       currentThickness = xRay(currentThickness)
  53.       console.log(`X-ray x1`)
  54.       console.log(`Finished crystal ${currentThickness} microns`)
  55.     }
  56.     else
  57.       console.log(`Finished crystal ${currentThickness} microns`)
  58.   }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement