Words from neighbour ones: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|J}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 29:
{{trans|Python}}
<
V filteredWords = wordList.filter(chosenWord -> chosenWord.len >= 9)
Line 37:
V newWord = (0..8).map(i -> :filteredWords[@position + i][i]).join(‘’)
I newWord C filteredWords
print(newWord)</
{{out}}
Line 76:
=={{header|AppleScript}}==
===Core language===
<
-- Since the task specifically involves unixdict.txt, this code's written in
-- the knowlege that the words are on individual lines and in dictionary order.
Line 116:
end task
task()</
{{output}}
<
===AppleScriptObjC===
Same output as above.
<
use framework "Foundation"
use scripting additions
Line 159:
end task
task()</
=={{header|Arturo}}==
{{trans|Nim}}
<
wordset: select wordset 'word -> 9 =< size word
Line 177:
lastWord: new newWord
]
]</
{{out}}
Line 207:
=={{header|AutoHotkey}}==
<
for word in neighbour(wList)
result .= word (Mod(A_Index, 6) ? "`t" : "`n")
Line 232:
}
return oRes
}</
{{out}}
<pre>applicate architect astronomy christine christoph committee
Line 240:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f WORDS_FROM_NEIGHBOUR_ONES.AWK unixdict.txt
{ if (length($0) < 9) { next }
Line 260:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 289:
</pre>
=={{header|C}}==
<
#include <stdlib.h>
#include <string.h>
Line 358:
free(words);
return EXIT_SUCCESS;
}</
{{out}}
Line 389:
=={{header|C++}}==
<
#include <cstdlib>
#include <fstream>
Line 427:
}
return EXIT_SUCCESS;
}</
{{out}}
Line 460:
{{libheader| System.Classes}}
{{Trans|Java}}
<syntaxhighlight lang="delphi">
program Words_from_neighbour_ones;
Line 512:
Words.Free;
readln;
end.</
{{out}}
<pre> 1. applicate
Line 540:
=={{header|F_Sharp|F#}}==
<
// Words from neighbour ones. Nigel Galloway: February 11th., 2021.
let g=[|use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()|]|>Array.filter(fun n->n.Length>8)
g|>Array.windowed 9|>Array.map(fun n->n|>Array.mapi(fun n g->g.[n])|>System.String)|>Array.filter(fun n-> Array.contains n g)|>Array.distinct|>Array.iter(printfn "%s")
</syntaxhighlight>
{{out}}
<pre>
Line 578:
<code><clumps></code> is the same idea except it doesn't actually store all that redundant information in memory; it's a generator that generates clumps on demand. Notice that clumps are matrices, so we can take their diagonal with <code>main-diagonal</code>.
{{works with|Factor|0.99 2020-08-14}}
<
kernel literals math math.matrices sequences sequences.extras
sets strings ;
Line 592:
[ wordset in? ] map-filter ! filter diagonals that are words
members ! remove duplicates
[ 1 + swap "%2d. %s\n" printf ] each-index ! print words formatted nicely</
{{out}}
<pre style="height:17em">
Line 624:
=={{header|FreeBASIC}}==
{{trans|Ring}}
<
Open "unixdict.txt" For Input As #1
Dim As String cStr, wordList()
Line 674:
Print !"\nterminado..."
Sleep
</syntaxhighlight>
{{out}}
<pre>
Line 714:
=={{header|Go}}==
<
import (
Line 760:
}
}
}</
{{out}}
Line 791:
=={{header|J}}==
<
applicate
architect
Line 815:
transcend
transport
transpose</
In other words: find the set intersection (<code>([-.-.)</code>) between words and the sequences of 9 ascending position characters (<code>9 <@((=i.9)#&,])\</code> ...) from extracting the first 9 characters (<code>9{.&></code> ...) of words with more than 8 characters (<code>(#~ 8<#@>)</code>) for words from unixdict.txt (( ... )<code>cutLF fread 'unixdict.txt'</code>)
=={{header|Java}}==
<
import java.util.*;
Line 853:
}
}
}</
{{out}}
Line 884:
=={{header|JavaScript}}==
<
document.write(`
<p>Choose dictionary: <input id="dict" type="file"></p>
Line 913:
fr.readAsText(f);
}
</syntaxhighlight>
{{out}}
<pre>
Line 921:
=={{header|jq}}==
For speed, this solution constructs a JSON object as a dictionary ($hash):<
# input: the dictionary
# $n: starting point (starting at 0)
Line 931:
| . as $dict
| (reduce.[] as $x ({}; .[$x]=true)) as $hash
| range(0; length-9) as $i | form_word($i) | select($hash[.])</
{{out}}
<pre>["applicate","architect","astronomy","christine","christoph","committee","committee","committee","committee","committee","composite","constrict","constrict","construct","different","extensive","greenwood","implement","improvise","intercept","interpret","interrupt","interrupt","philosoph","prescript","receptive","telephone","transcend","transcend","transport","transpose"]
Line 938:
====Removing duplicates efficiently====
Using `def form_word`, we have only to modify the last line above:
<
| . as $dict
| (reduce.[] as $x ({}; .[$x]=true)) as $hash
Line 944:
($dict | form_word($i)) as $w
| if .hash[$w] then .hash[$w] = null | .words += [$w] else . end)
| .words</
=={{header|Julia}}==
<
println("Word source: $wordfile\n")
words = filter(w -> length(w) >= len, split(read(wordfile, String), r"\s+"))
Line 961:
wordsfromneighbourones("unixdict.txt")
</
<pre>
Word source: unixdict.txt
Line 971:
=={{header|Ksh}}==
<
#!/bin/ksh
Line 1,027:
fi
fi
done</
{{out}}<pre>
1 applicate
Line 1,055:
=={{header|Lua}}==
<
for word in io.open("unixdict.txt", "r"):lines() do
if #word >= 9 then
Line 1,073:
print(word)
end
end</
{{out}}
<pre>applicate
Line 1,108:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
dict //= StringSplit[#,"\n"]&;
dict //= Select[StringLength/*GreaterEqualThan[9]];
firsts9 = Characters[dict][[All,;;9]];
words = StringJoin[Diagonal[firsts9,-#]]&/@Range[0,Length[firsts9]-9];
Intersection[words,dict]</
{{out}}
<pre>{"applicate", "architect", "astronomy", "christine", "christoph", "committee", "composite", "constrict", "construct", "different", "extensive", "greenwood", "implement", "improvise", "intercept", "interpret", "interrupt", "philosoph", "prescript", "receptive", "telephone", "transcend", "transport", "transpose"}</pre>
=={{header|Nim}}==
<
# Build list and set of words with length >= 9.
Line 1,135:
inc count
echo ($count).align(2), ' ', newWord
lastWord = newWord</
{{out}}
Line 1,164:
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Words_from_neighbour_ones
Line 1,178:
my $new = join '', @{^CAPTURE}, "\n";
$dict{$new} and !$seen{$new}++ and print $new;
}</
{{out}}
applicate
Line 1,206:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">over9</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">word</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">word</span><span style="color: #0000FF;">)>=</span><span style="color: #000000;">9</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
Line 1,213:
<span style="color: #004080;">sequence</span> <span style="color: #000000;">neighwords</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">unique</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">9</span><span style="color: #0000FF;">),</span><span style="color: #000000;">slicen</span><span style="color: #0000FF;">)),</span><span style="color: #008000;">"in"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">words</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d words: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">neighwords</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">neighwords</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">))})</span>
<!--</
{{out}}
<pre>
Line 1,220:
=={{header|Processing}}==
<
for (String str : loadStrings("unixdict.txt")) {
if (str.length() >= 9) {
Line 1,237:
for (String word : found) {
println(word);
}</
{{out}}
<pre style="height: 18em;">applicate
Line 1,267:
=={{header|Python}}==
Tested on Python 3+, the file download will work only if the link is still active. It is possible that you may be able to fetch the file in your browser but download via code may still fail. Check whether you are connected to a VPN, it works on open networks.
<syntaxhighlight lang="python">
#Aamrun, 5th November 2021
Line 1,288:
if newWord in filteredWords:
print(newWord)
</syntaxhighlight>
{{Output}}
Yes, there are duplicates, the task doesn't say that only unique elements should be present, hence the complete raw list will appear as below :
Line 1,326:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
my %words_eq_9 = @words_ge_9 .grep( *.chars == 9 ).Set;
Line 1,335:
}
.say for unique @new_words;</
{{out}}
<pre>
Line 1,369:
It also allows the minimum length to be specified on the command line (CL) as well as the dictionary file identifier.
<
parse arg minL iFID . /*obtain optional arguments from the CL*/
if minL=='' | minL=="," then minL= 9 /*Not specified? Then use the default.*/
Line 1,396:
end /*j*/
/*stick a fork in it, we're all done. */
say copies('─', 30) finds ' neighbor words found with a minimum length of ' minL</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,430:
=={{header|Ring}}==
<
cStr = read("unixdict.txt")
wordList = str2list(cStr)
Line 1,474:
see "done..." + nl
</syntaxhighlight>
Output:
<pre>
Line 1,508:
=={{header|VBScript}}==
Run it in CScript.
<syntaxhighlight lang="vb">
with createobject("ADODB.Stream")
.charset ="UTF-8"
Line 1,541:
next
</syntaxhighlight>
{{out}}
<pre>
Line 1,572:
=={{header|Vlang}}==
{{trans|AutoHotkey}}
<
fn main() {
Line 1,601:
}
return res_arr
}</
{{out}}
Line 1,614:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<
import "/sort" for Find
import "/fmt" for Fmt
Line 1,630:
alreadyFound.add(word)
}
}</
{{out}}
Line 1,661:
=={{header|XPL0}}==
<
int Dict(26000); \pointers to words (enough for unixdict.txt)
int DictSize; \actual number of pointers in Dict
Line 1,725:
until DI >= DictSize-9;
CrLf(0);
]</
{{out}}
Line 1,736:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<
open "unixdict.txt" for reading as #1
p = 0
Line 1,785:
next n
end
</syntaxhighlight>
{{out}}
<pre>
|