Telephone?

node v4.9.1
version: 2.0.0
endpointsharetweet
You probably played the game of telephone as a kid, but it's kind of boring as an adult. But what if we get the computer to play for us instead? First, let's require some utilities from other notebooks, and define a few of our own.
// translations, powered by yandex. // To use, make sure you set process.env.YANDEX_API_KEY to your own API key! // You can sign up here: https://tech.yandex.com/keys/get/?service=trnsl var yandex = require('notebook')('tonic/yandex-translation-api/1.1.0'); // Some common english phrases var sayings = require('notebook')('capicue/sayings/2.0.0'); // Just a few niceties around Math.random() var rand = require('notebook')('tonic/random/5.0.0'); function randomLanguage() { var languageKeys = Object.keys(languages); return languageKeys[rand(languageKeys.length)]; } // Grab a random language from the supported languages. var languages = await yandex.languages();
Alright, now we're ready. The basic idea is to start with a phrase and run it through a translation API a whole bunch of times, finally translating it back into the original language to see what we get.
// The core game async function telephone(text, language = "en", steps = 10) { return await step([{lang: language, text: text}]); async function step(history) { var last = history[history.length - 1]; var toLanguage = (history.length === steps) ? history[0].lang : randomLanguage(); var result = await yandex.translate(last.lang, toLanguage, last.text); var results = history.concat([{text: result, lang: toLanguage}]); if (history.length === steps) return results.map(function(step){ return [step.text, languages[step.lang]]; }); return step(results); } } var sentence = sayings.random(); await telephone(sentence);
Time stretch!
Loading…

12 comments

  • posted 4 years ago by joshmiddlebrooks
    4042935573
  • posted 4 years ago by joshmiddlebrooks
    joshmiddlebrooks9@gmail.com
  • posted 3 years ago by pattanawichiwong
    3802675250ถอนเงินโบนัส
  • posted 3 years ago by pattanawichiwong
    0930865880เบอร์3802675250เลขบัญชีทีเอ็มบี
  • posted 3 years ago by dirtysocks
    kek kek kek
  • posted a year ago by hummer-3
    AR
  • posted 9 months ago by 6264832108
    6264832108
  • posted 9 months ago by 6264832108
    Chhatar Singh
  • posted 9 months ago by 6264832108
    Nagaaj
  • posted 9 months ago by 6264832108
    109700150090141
  • posted 9 months ago by 6264832108
    654321
  • posted 9 months ago by 6264832108
    *

sign in to comment