0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

英単語になるカラーコードを総当たりで探す

Last updated at Posted at 2024-08-11

やりたかったこと

カラーコードで使用するアルファベット6種類6文字で、英単語になるものがいくつあるのか知りたい。
検索したところ総当たりで調べた結果は見つけられなかった。
→ せっかくなのでプログラムを書いて調べてみることにしました。

※先行記事:

追記

  • 準備として記載していたnode.jsのアプリ作成部分を省略しました
  • いただいたコメントをもとにコードを修正しました

やったこと

パブリックドメインの英和辞書を取得

こちらからJSON形式のものをお借りしました。

JS

最初のコード
import { readFile } from 'fs/promises'

const json = JSON.parse(await readFile('./ejdict.json'))
const chars = ['a', 'b', 'c', 'd', 'e', 'f'];
const codes = [];

//文字列生成して存在チェック
for (let i=0; i<6; i++){
    for (let j=0; j<6; j++){
        for (let k=0; k<6; k++){
            for (let l=0; l<6; l++){
                for (let m=0; m<6; m++){
                    for (let n=0; n<6; n++){
                        let code = chars[i] + chars[j] + chars[k] + chars[l] + chars[m] + chars[n];
                        if (code in json){
                            codes.push(code);
                        }
                    }
                }
            }
        }
    }
}

for (let i=0; i<codes.length; i++){
    console.log('#' + codes[i] + ' : ' + json[codes[i]]);
}

修正版

import { readFile } from 'fs/promises'

const json = JSON.parse(await readFile('./ejdict.json'))
const codes = [];

for (let i=0xaaaaaa; i<=0xffffff; i++){
    const hex = i.toString(16);
    if(/\d/.test(hex)) continue;
    const colorCode = `#${hex}`;
    if(hex in json){
        codes.push(`${colorCode} : ${json[hex]}`);
    }
}

for (let i=0; i<codes.length; i++){
    console.log(codes[i]);
}

結果

#accede : (要求・提案などに)同意する,承認する(agree)《+『to』+『名』》 / (王位・財産などを)継承する;(公職などに)就任する《+『to』+『名』》
#decade : 『10年間』
#deface : 表面を傷つける[摩滅する]; 読めなくする, わからなくする・〈外観〉'を'醜くする・…'を'摩損する,すり消す,読みにくくする
#efface : (…から)〈文字・記憶など〉‘を'消す,ぬぐい去る《+『名』+『from』+『名』》
#facade : (建物の)正面(front) / (物の)外観;見せかけ

5つだけヒットしました。
#accede (要求・提案などに)同意する,承認する
#decade 10年間
#deface 表面を傷つける
#efface (…から)〈文字・記憶など〉を消す
#facade (建物の)正面

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?