Word search: Difference between revisions
Content deleted Content added
m →{{header|Phix}}: use unix_dict() |
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
||
Line 54:
{{trans|Python}}
<
dirs = [[1, 0], [ 0, 1], [ 1, 1],
[1, -1], [-1, 0],
Line 192:
print(grid.solutions[size - 1])
print_result(create_word_search(&read_words(‘unixdict.txt’)))</
{{out}}
Line 229:
=={{header|C sharp}}==
{{trans|Java}}
<
using System.Collections.Generic;
using System.Linq;
Line 437:
}
}
}</
<pre>
Line 473:
=={{header|C++}}==
<
#include <iomanip>
#include <ctime>
Line 643:
return 0;
}
</syntaxhighlight>
{{out}}
<pre>
Line 684:
=={{header|D}}==
{{trans|Java}}
<
import std.stdio;
Line 877:
writeln(grid.solutions[size - 1]);
}
}</
{{out}}
Line 922:
FILLED was not set to FALSE every time Initialize was called.
Set all integer to (U)long.
<
#Macro TrmSS (n)
Line 1,280:
Sleep
End</
{{out}}
<pre style="height:52ex;overflow:scroll"> 0 1 2 3 4 5 6 7 8 9
Line 1,370:
<br>
The link to "unixdict" appears to be broken so I've used instead the dictionary at "/usr/share/dict/words" which came pre-installed with my Ubuntu 16.04 distribution. I've no idea whether these dictionaries are the same or not.
<
import (
Line 1,558:
unixDictPath := "/usr/share/dict/words"
printResult(createWordSearch(readWords(unixDictPath)))
}</
{{out}}
Line 1,599:
Implementation:
<
unixdict=:verb define
Line 1,651:
puz=. (_23{.":i.10),' ',1j1#"1(":i.10 1),.' ',.10 10$fill (I.grid=' ')} grid
puz,' ',1 1}._1 _1}.":((</.~ <.) i.@# * 3%#)key
)</
Notes:
Line 1,695:
Example run:
<
0 1 2 3 4 5 6 7 8 9
Line 1,718:
cop 10 8 nw │ paz 8 10 west │ wan 9 6 west
fizzle 1 6 sw │ penna 1 9 south│
</syntaxhighlight>
=={{header|Java}}==
{{works with|Java|7}}
<
import static java.lang.String.format;
import java.util.*;
Line 1,894:
System.out.println(grid.solutions.get(size - 1));
}
}</
<pre>Attempts: 2
Line 1,929:
=={{header|Julia}}==
Modified from the Go version. The task listed word list is offline, so the Debian distribution file "words.txt" was used instead.
<
const stepdirections = [[1, 0], [0, 1], [1, 1], [1, -1], [-1, 0], [0, -1], [-1, -1], [-1, 1]]
Line 2,045:
printresult(wordmatrix("words.txt", false))
</
Attempts: 1
Number of words: 25
Line 2,078:
=={{header|Kotlin}}==
{{trans|Java}}
<
import java.util.Random
Line 2,228:
fun main(args: Array<String>) {
printResult(createWordSearch(readWords("unixdict.txt")))
}</
Sample output:
Line 2,266:
=={{header|Nim}}==
{{trans|D}}
<
const
Line 2,395:
randomize()
let grid = initGrid("unixdict.txt".readWords())
grid.printResult()</
{{out}}
Line 2,431:
=={{header|Perl}}==
<
use strict; # http://www.rosettacode.org/wiki/Word_search
Line 2,530:
return undef;
}</
{{out}}
<pre>
Line 2,560:
=={{header|Phix}}==
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\wordsearch.exw
Line 2,670:
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</
{{out}}
<pre>
Line 2,706:
{{trans|Java}}
{{works with|Python|3.x}}
<
import re
from random import shuffle, randint
Line 2,870:
if __name__ == "__main__":
print_result(create_word_search(read_words("unixdict.txt")))
</syntaxhighlight>
{{out}}
Line 2,910:
The following zip file is needed for the Unix dictionary and a QB64 words mod for fun! ...and some samples.<br>
[https://www.qb64.org/forum/index.php?action=dlattach;topic=2334.0;attach=5434 Rosetta Code Word Search Challenge.zip]
<
_TITLE "Puzzle Builder for Rosetta" 'by B+ started 2018-10-31
' 2018-11-02 Now that puzzle is working with basic and plus starters remove them and make sure puzzle works as well.
Line 3,235:
NEXT
CLOSE #1
END SUB</
----
Line 3,319:
(or at least it started out that way... so more "inspired by")
<
;; ---------------------------------------------------------------------------------------------------
(module+ main
Line 3,431:
[(hash-has-key? cells (cons r c)) (loop r (add1 c) cells msg)]
[else (loop r (add1 c) (hash-set cells (cons r c) (car msg)) (cdr msg))])))))
</syntaxhighlight>
{{out}}
Line 3,531:
{{works with|Rakudo|2020.01}}
<syntaxhighlight lang="raku"
my $cols = 10;
Line 3,659:
}
True
}</
{{out|Sample output}}
<pre> A B C D E F G H I J
Line 3,694:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<
ReadOnly Dirs As Integer(,) = {
Line 3,917:
End Sub
End Module</
{{out}}
<pre>Attempts: 148
Line 3,955:
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<
import "/ioutil" for FileUtil
import "/pattern" for Pattern
Line 4,112:
}
printResult.call(createWordSearch.call(readWords.call("unixdict.txt")))</
{{out}}
Line 4,152:
=={{header|zkl}}==
Repeat words allowed. Rather brute force as I didn't realize that the message has to fit exactly.
<
var [const] dirs=T(T(1,0), T(0,1), T(1,1), T(1,-1), T(-1,0),T(0,-1), T(-1,-1), T(-1,1));
vs,v:=List(),List();
Line 4,178:
foreach r,c in (10,10){ if(grid[r][c]=="?") grid[r][c]=MSG.next() }
MSG._n==msg.len() // use all of, not more, not less, of msg?
}</
<
validWord:=RegExp("[A-Za-z]+\n$").matches;
Line 4,208:
fcn([(r,c,w)]){ "%-19s".fmt("[%d,%d]: %s ".fmt(r,c,w)) }) }
);
fitted.apply(fcn(w){ w[2].len() }).sum(0).println();</
{{out}}
<pre>
|