tomuwhu

EÉ2016 okt full

Sep 25th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div id="app">
  3.     <pre>
  4.       <div v-html="x"></div>
  5.       <input v-model="text"><br>8. feladat: <a  id="ax"
  6.               v-if="text.length" download="hegylancok.txt"
  7.               :href="`data:text/plain;charset=utf-8,${ encodeURIComponent(text) }`"
  8.               >Letöltés szövegfájlként (hegylancok.txt)</a>
  9.     </pre>
  10.   </div>
  11. </template>
  12. <script>
  13.   class Hegylanc {
  14.     constructor() {
  15.       var p
  16.       this.v = Array(80).fill(0).map( (e, i) => i > 2 && i < 77
  17.           ? (p = Math.round(Math.random() * 15 + 1)) % 2 ? p : 0
  18.           : 0
  19.       )
  20.     }
  21.     f() {
  22.       return this.v.map(e => e.toString(16).toUpperCase()).join("");
  23.     }
  24.     g(p) {
  25.       let zs, hsz = 0;
  26.       zs = this.f().split('0').map( v => v.length===1?`<c>${hsz++,v}</c>`:v).join('0')
  27.       return p ? hsz : zs ;
  28.     }
  29.     h() {
  30.       return this.f().split(0).map(v=>({hl:v,hh:v.length})).sort((a,b)=>b.hh-a.hh)[0]
  31.     }
  32.   }
  33. var hegylanc = new Hegylanc(), q
  34. export default {
  35.   name: "App",
  36.   data() {
  37.     return {
  38.       text: hegylanc.f(),
  39.       x: `\n4. feladat:\n${hegylanc.f()}        
  40.           \n5. feladat: Hegyek száma: ${hegylanc.g(true)} db
  41.           \n6. feladat:\n${hegylanc.g()}
  42.           \n7. feladat: A leghosszabb hegylánc hossza: ${
  43.               hegylanc.h().hh
  44.             } Átlagos magassága ${
  45.               q=hegylanc.h().hl.split('').reduce( (acc, v) =>
  46.                   ( acc.ossz+=parseInt(v,16), acc.n++, acc ),
  47.                   {n:0, ossz:0}
  48.                 ), (q.ossz/q.n).toFixed(2)
  49.             }`
  50.     };
  51.   }
  52. };
  53. </script>
  54. <style>
  55. c { color: red; }
  56. input { display: none; width: 98%; }
  57. </style>
Advertisement
Add Comment
Please, Sign In to add comment