3
$\begingroup$
words = getWordsFromPi[200];

For[i = 0, i < Length[words], i++, 
  if[DictionaryWordQ[StringJoin[words[[i]]], 
    Insert[list, words[[i]]]]]]

words is a list of lists that contain 5-character elements. My goal with the For-loop is to check which 5-characters, when joined together in string, create a valid word recognized by DictionaryWordQ.

When I find a valid word it, I want to accumulate it in another list.

I do not know where to go from here.

getWordsFromPi[n_] := 
Map[StringJoin, 
Partition[
Map[FromCharacterCode, 
 Flatten@ToExpression@
   StringSplit[Delete[StringPartition[ToString[N[Pi, n]], 2], 1], 
    ","]], 5]];

words = getWordsFromPi[10000];
Select[words, DictionaryWordQ]

The issue I am having now is that the DictionaryWordQ built-in function isn't working how I wanted it to. When you execute the code above, you will obtain this list:

{"H-W\.00B", "\.00\.05D
G", "\.00C3\.03\"", "XX\.00NE", "\.00:L\.07:", "\.00\.1d`\.07S", "F\
\.00E\\R", "\.00\"\.0fW\.16", "\.00P\.1f7Z", "\.00%\[RawEscape]b'"}

Clearly none of these are the English words that I am looking for. In fact, I expected the list to be empty, but instead I obtained this nonsense. What am I doing wrong?

$\endgroup$
9
  • $\begingroup$ Select[words, DictionaryWordQ] should generate the subset of words that are dictionary words. $\endgroup$
    – march
    Commented Apr 16, 2019 at 22:52
  • $\begingroup$ I think you should provide part of your list. Also I would recommend you to use somathing like Select[words,DictionaryWordQ[StringJoin@#]&] . But I need this list in order to check if this works $\endgroup$
    – ZaMoC
    Commented Apr 16, 2019 at 22:53
  • $\begingroup$ imgur.com/dqOGFrk Here is my code. I changed my function to produce a list that already StringJoins ahead of time so now the list is just a list of 5 length strings $\endgroup$ Commented Apr 16, 2019 at 22:58
  • $\begingroup$ Please copy/paste this code (the getwordsFromPi function) in your question $\endgroup$
    – ZaMoC
    Commented Apr 16, 2019 at 23:16
  • 1
    $\begingroup$ Thank you! This is exactly what I was looking for. $\endgroup$ Commented Apr 16, 2019 at 23:39

2 Answers 2

2
$\begingroup$

I made a quick-fix using modulo 26 in order to get only letters

getWordsFromPi[n_] :=Map[StringJoin,Partition[Map[FromCharacterCode, 
 Mod[Flatten@ToExpression@StringSplit[Delete[StringPartition[ToString[N[Pi, n]],2], 1], ","], 
   26] + 65], 5]];

words = getWordsFromPi[10000];
Select[words, DictionaryWordQ]    

this returns

{"GRAVE"}

Here is the second filter that you asked (I prefer the first one)
This only keeps numbers from 65-90 but in order to return some words you need way more digits of Pi...
try it

getWordsFromPi[n_] := 
Map[StringJoin, 
Partition[
Map[FromCharacterCode, 
 Select[Flatten@
   ToExpression@
    StringSplit[Delete[StringPartition[ToString[N[Pi, n]], 2], 1],
      ","], 65 <= # <= 90 &]], 5]];

 words = getWordsFromPi[100000];
 Select[words, DictionaryWordQ]     

100.000 digits return...

{"ITCHY"}

$\endgroup$
1
$\begingroup$

Instead of using N[] + string trickery, it is better to just use RealDigits[] directly.

Using J42161217's two examples:

With[{n = 1*^4}, 
     Select[StringJoin /@ Partition[FromCharacterCode[Mod[FromDigits[#], 26] + 65] & /@
            Partition[Rest[First[RealDigits[Pi, 10, n + 1]]], 2], 5], DictionaryWordQ]]
   {"GRAVE"}

With[{n = 1*^5},
     Select[StringJoin /@ Partition[Map[FromCharacterCode, Select[FromDigits /@
            Partition[Rest[First[RealDigits[Pi, 10, n + 1]]], 2], Between[{65, 90}]]], 5],
            DictionaryWordQ]]
   {"ITCHY"}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.