Jump to content

Word search: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: use unix_dict())
m (syntax highlighting fixup automation)
Line 54:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">-V
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’)))</langsyntaxhighlight>
 
{{out}}
Line 229:
=={{header|C sharp}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 437:
}
}
}</langsyntaxhighlight>
 
<pre>
Line 473:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <iomanip>
#include <ctime>
Line 643:
return 0;
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 684:
=={{header|D}}==
{{trans|Java}}
<langsyntaxhighlight Dlang="d">import std.random : Random, uniform, randomShuffle;
import std.stdio;
 
Line 877:
writeln(grid.solutions[size - 1]);
}
}</langsyntaxhighlight>
 
{{out}}
Line 922:
FILLED was not set to FALSE every time Initialize was called.
Set all integer to (U)long.
<langsyntaxhighlight lang="freebasic">Randomize Timer ' OK getting a good puzzle every time
 
#Macro TrmSS (n)
Line 1,280:
 
Sleep
End</langsyntaxhighlight>
{{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.
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,558:
unixDictPath := "/usr/share/dict/words"
printResult(createWordSearch(readWords(unixDictPath)))
}</langsyntaxhighlight>
 
{{out}}
Line 1,599:
Implementation:
 
<langsyntaxhighlight Jlang="j">require'web/gethttp'
 
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
)</langsyntaxhighlight>
 
Notes:
Line 1,695:
Example run:
 
<langsyntaxhighlight Jlang="j"> genpuz''
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>
</lang>
 
=={{header|Java}}==
{{works with|Java|7}}
<langsyntaxhighlight lang="java">import java.io.*;
import static java.lang.String.format;
import java.util.*;
Line 1,894:
System.out.println(grid.solutions.get(size - 1));
}
}</langsyntaxhighlight>
 
<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.
<langsyntaxhighlight lang="julia">using Random
 
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))
</langsyntaxhighlight>{{output}}<pre>
Attempts: 1
Number of words: 25
Line 2,078:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.2.0
 
import java.util.Random
Line 2,228:
fun main(args: Array<String>) {
printResult(createWordSearch(readWords("unixdict.txt")))
}</langsyntaxhighlight>
 
Sample output:
Line 2,266:
=={{header|Nim}}==
{{trans|D}}
<langsyntaxhighlight Nimlang="nim">import random, sequtils, strformat, strutils
 
const
Line 2,395:
randomize()
let grid = initGrid("unixdict.txt".readWords())
grid.printResult()</langsyntaxhighlight>
 
{{out}}
Line 2,431:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # http://www.rosettacode.org/wiki/Word_search
Line 2,530:
 
return undef;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,560:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,706:
{{trans|Java}}
{{works with|Python|3.x}}
<langsyntaxhighlight lang="python">
import re
from random import shuffle, randint
Line 2,870:
if __name__ == "__main__":
print_result(create_word_search(read_words("unixdict.txt")))
</syntaxhighlight>
</lang>
 
{{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]
<langsyntaxhighlight lang="qbasic"> OPTION _EXPLICIT
_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</langsyntaxhighlight>
 
----
Line 3,319:
(or at least it started out that way... so more "inspired by")
 
<langsyntaxhighlight lang="racket">#lang racket
;; ---------------------------------------------------------------------------------------------------
(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>
</lang>
 
{{out}}
Line 3,531:
{{works with|Rakudo|2020.01}}
 
<syntaxhighlight lang="raku" perl6line>my $rows = 10;
my $cols = 10;
 
Line 3,659:
}
True
}</langsyntaxhighlight>
{{out|Sample output}}
<pre> A B C D E F G H I J
Line 3,694:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
ReadOnly Dirs As Integer(,) = {
Line 3,917:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>Attempts: 148
Line 3,955:
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "random" for Random
import "/ioutil" for FileUtil
import "/pattern" for Pattern
Line 4,112:
}
 
printResult.call(createWordSearch.call(readWords.call("unixdict.txt")))</langsyntaxhighlight>
 
{{out}}
Line 4,152:
=={{header|zkl}}==
Repeat words allowed. Rather brute force as I didn't realize that the message has to fit exactly.
<langsyntaxhighlight lang="zkl">fcn buildVectors(R,C){ //-->up to 8 vectors of wild card strings
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?
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">msg:="RosettaCode";
 
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();</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.