Skip to content

Instantly share code, notes, and snippets.

@omas-public
Last active August 23, 2017 09:48
Show Gist options
  • Save omas-public/0963916602a341e98dca98008df02ec0 to your computer and use it in GitHub Desktop.
Save omas-public/0963916602a341e98dca98008df02ec0 to your computer and use it in GitHub Desktop.
POH 恋するハッカソン for JavaScript

あなたもアンドロイドアイドルに好きな芸名をつけてプロデュースしてみましょう!

プログラミング問題を解いて着せ替えアイテムをゲットすれば、アイドルからの信頼度が高まります。

アイドルを着せ替えたら、さまざまなお仕事先へ行きアイドル経験値を貯めましょう。お仕事ストーリー内にあらわれる選択肢のうち、あなたがどれを選ぶかによってアイドルの成長度が変わります!

あなたのプログラミング力とプロデュース力で、この子をトップアイドルに育ててくださいね♪

JavaScript Template

(stdin => {
  // Define Function

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');

  // Main Procedure
  const result = ((lines) => {

    return lines;

  })(inputs);

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

一行だけを取ってくる

line = inputs[0];

一行を分割

cols = inputs[0].split(' ');

一行を数値で分割

cols = inputs[0].split(' ').map(Number);
cols = Array.from(inputs[0].split(' '), Number);

数値変換

let n = parseInt(s, 10);

「Cute衣装」ゲットチャレンジ!

(stdin => {

  // Define Function
  const isDiviser  = (n, m) => m % n === 0;
  const getMessage = (pred) => ({true: 'ok', false: 'ng'}[pred]);
  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const cols    = Array.from(inputs[0].split(' '), Number);

  // Main Procedure
  const result = (([n, m]) => {
    return getMessage(isDiviser(n, m));
  })(cols);

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「Sexy衣装」ゲットチャレンジ!

(stdin => {

  // Define Function
  const isPositive = n => n >= 0;
  const diff = (a, b) => a - b;
  const proceed = (value, checkfn) => {
    return checkfn(value) ? value : 0;
  };

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const cols    = Array.from(inputs[0].split(' '), Number);

  // Main Procedure
  const result = (([M, N]) => {
    return proceed(diff(M, N), isPositive);

  })(cols);

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「おさげ」ゲットチャレンジ!

(stdin => {

  // Define Function
  const RestTime = (initialsize) => {
    let rest = initialsize;
    return time => (rest -= time);
  };
  const isPositiveIntegerOrZero = (n) => n >= 0;
  const getMessage = (pred) => ({true:() => 'ok', false:(count) => count}[pred]);
  // Declare Variab
  const inputs  = stdin.toString().trim().split('\n');
  const ninputs = Array.from(inputs, Number);

  // Main Procedure
  const result = ((cdlen, songs) => {
    const rest  = RestTime(cdlen * 60);
    const count = Array.from(songs, rest)
      .filter(isPositiveIntegerOrZero).length;

    return getMessage(count === songs.length)(count);

  })(ninputs[0], ninputs.slice(2, ninputs[1] + 2));

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「たれ目」ゲットチャレンジ!

(stdin => {

  // Define Function
  const lessOrEqual = (a, b) => a <= b;
  const getMessage  = (pred) => ({
    true: 'OK', false: 'NG'}[pred]);

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const cols    = Array.from(inputs[0].split(' '), Number);

  // Main Procedure
  const result = (([s, n]) => {
    return getMessage(lessOrEqual(s, n));

  })(cols);

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「つり目」ゲットチャレンジ!

(stdin => {

  // Define Function
  const bonus = p => (p >= 1000) ? 10 : 0;
  const point = p => Math.floor(p / 100);

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');

  // Main Procedure
  const result = ((p) => {
    return bonus(p) + point(p);

  })(parseInt(inputs[0], 10));

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「めがね」ゲットチャレンジ!

(stdin => {

  // Define Function
  const decendByNum = (a, b) => b - a;
  const median = (n) => Math.floor(n / 2);

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const cols    = inputs[1].split(' ', parseInt(inputs[0], 10));
  const result = ((alist) => {
    let clone = [].concat(alist);
    return clone.sort(decendByNum)[median(alist.length)];

  })(Array.from(cols, Number));
  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「ゆかた」ゲットチャレンジ! JavaScript Closure Pattern

(function(stdin) {
  // Define Function
  const Temperature = () => {
    let temp = 0;
    return function(t) {
      temp = (temp > 0) ? temp - 1 : temp;
      temp += t;
      return temp;
    };
  };

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const map = new Map(Array.from(inputs.slice(0, inputs.shift()),
    l => l.split(' ')));

  // Main Procedure
  const result = (function(log) {
    const temp = Temperature();

    return Array.from(Array(24).fill(0),
      (v, key) => ({in : 5, out : 3})[log.get(key.toString())] || v
    )
    .map(temp)
    .map(v => (v > 0) ? 2 : 1)
    .reduce((a, b) => a + b);

  }(map));

  // Display
  console.log(result);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

JavaScript Object Pattern

(stdin => {

  // Define Function

  const Thermometer = (settings) => {
    let temperature = 0;
    return (action) => {
      if (temperature > 0) temperature += settings.default;
      return (temperature += (settings[action] || 0));
    };
  };

  class Refrigerator {

    constructor(actions, settings) {
      this.log = this.create(new Map(actions), Thermometer(settings));
    }

    create(actions, thermometer) {
      return new Map(
        Array.from([...Array(24).keys()], key =>
          [key, thermometer(actions.get(key.toString()))])
      );
    }

    getCharges() {
      return Array.from(this.log.values(), v =>
        (v === 0) ? 1 : 2)
        .reduce((a, b) => a + b);
    }

  }
  // Declare Variable
  const inputs = stdin.toString().trim().split('\n');
  const matrix = Array.from(inputs.slice(0, inputs.shift()),
    l => l.split(' '));

  // Main Procedure
  const result = (lines => {
    let settings = {in: 5, out: 3, default: -1};
    return new Refrigerator(lines, settings).getCharges();
  })(matrix);

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「カチューシャ」ゲットチャレンジ!

(stdin => {

  // Define Function
  const ItemTotalPrice = (price) => (amount) => price * amount;

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const matrix = Array.from(inputs, l => Array.from(l.split(' '), Number));

  // Main Procedure
  const result = (([[n, p], [m, q]]) => {
    const paperTotal = ItemTotalPrice(p);
    const penTotal   = ItemTotalPrice(q);
    return paperTotal(n) + penTotal(Math.ceil(n / m));

  })(matrics);

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「ショートヘア」ゲットチャレンジ!

(stdin => {

  // Define Function

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');

  // Main Procedure
  const result = (([N, S]) => {

    return Array(parseInt(N, 10)).fill(S);

  })(inputs);

  // Display
  console.log(result.join('\n'));

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「ツインテール」ゲットチャレンジ!

(stdin => {
  // Define Function

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');

  // Main Procedure
  const result = (([s, t]) => {

    return Array(s).fill('-').map((c, i) => {
        return (i === t - 1) ? '+' : c;
    });

  })(Array.from(inputs, Number));

  // Display
  console.log(result.join(''));

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「ポニーテール」ゲットチャレンジ!

(stdin => {
  // Define Function
  const isSame = ([a, b]) => a === b;
  const getMessage = (pred) => ({
    true: 'OK', false: 'NG'
  }[pred]);
  // Declare Variable
  const inputs = stdin.toString().trim().split('\n');
  const matrix = Array.from(inputs, (v) => v.split(' '));

  // Main Procedure
  const result = ((lines) => {
    return getMessage(
      lines.filter(isSame).length > 2);

  })(matrix);

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「マイク」ゲットチャレンジ!

(stdin => {

  // Define Function

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const ninputs = Array.from(inputs, Number);

  // Main Procedure
  const result = (([n, m]) => {
    return Math.ceil(m / (n * 2));

  })(Array.from(inputs, Number));

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「ロングヘア」ゲットチャレンジ!

(stdin => {
  // Define Function
  const isMultipleOfSeven = (v) => v % 7 === 0;
  const getMessage = (pred) => (
    {true:'lucky', false: 'unlucky'}[pred]);

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');

  // Main Procedure
  const result = ((N) => {
    return getMessage(isMultipleOfSeven(N));

  })(parseInt(inputs[0], 10));

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

「水着」ゲットチャレンジ!

(stdin => {
  // Define Function
  const countMap = (s) => {
    return Array.from(s)
      .reduce((acc, key) => {
        acc[key] = acc[key] + 1 || 1;
        return acc;
      }, {});
  };
  const positiveInteger = (v) => v > 0;
  const sum = (a, b) => a + b;
  const diff = (aMap, bMap) => Array.from(Object.keys(aMap),
      key => aMap[key] - (bMap[key]) || 0);

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  const [n, m]  = Array.from(inputs[0].split(' ', 2), Number);

  // Main Procedure
  const result = ((s, t) => {
    return diff(countMap(t), countMap(s))
        .filter(positiveInteger)
        .reduce(sum);

  })(inputs[1].slice(0, n), inputs[2].slice(0, m));

  // Display
  console.log(result);

})(require('fs').readFileSync('/dev/stdin', 'utf8'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment