Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
8
Task/Ordered-words/Python/ordered-words-1.py
Normal file
8
Task/Ordered-words/Python/ordered-words-1.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import urllib.request
|
||||
|
||||
url = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
|
||||
words = urllib.request.urlopen(url).read().decode("utf-8").split()
|
||||
ordered = [word for word in words if word==''.join(sorted(word))]
|
||||
maxlen = len(max(ordered, key=len))
|
||||
maxorderedwords = [word for word in ordered if len(word) == maxlen]
|
||||
print(' '.join(maxorderedwords))
|
||||
11
Task/Ordered-words/Python/ordered-words-2.py
Normal file
11
Task/Ordered-words/Python/ordered-words-2.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import urllib.request
|
||||
|
||||
mx, url = 0, 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
|
||||
|
||||
for word in urllib.request.urlopen(url).read().decode("utf-8").split():
|
||||
lenword = len(word)
|
||||
if lenword >= mx and word==''.join(sorted(word)):
|
||||
if lenword > mx:
|
||||
words, mx = [], lenword
|
||||
words.append(word)
|
||||
print(' '.join(words))
|
||||
43
Task/Ordered-words/Python/ordered-words-3.py
Normal file
43
Task/Ordered-words/Python/ordered-words-3.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
'''The longest ordered words in a list'''
|
||||
|
||||
from functools import reduce
|
||||
from operator import le
|
||||
import urllib.request
|
||||
|
||||
|
||||
# longestOrds :: [String] -> [String]
|
||||
def longestOrds(ws):
|
||||
'''The longest ordered words in a given list.
|
||||
'''
|
||||
return reduce(triage, ws, (0, []))[1]
|
||||
|
||||
|
||||
# triage :: (Int, [String]) -> String -> (Int, [String])
|
||||
def triage(nxs, w):
|
||||
'''The maximum length seen for an ordered word,
|
||||
and the ordered words of this length seen so far.
|
||||
'''
|
||||
n, xs = nxs
|
||||
lng = len(w)
|
||||
return (
|
||||
(lng, ([w] if n != lng else xs + [w])) if (
|
||||
ordered(w)
|
||||
) else nxs
|
||||
) if lng >= n else nxs
|
||||
|
||||
|
||||
# ordered :: String -> Bool
|
||||
def ordered(w):
|
||||
'''True if the word w is ordered.'''
|
||||
return all(map(le, w, w[1:]))
|
||||
|
||||
|
||||
# ------------------------- TEST -------------------------
|
||||
if __name__ == '__main__':
|
||||
print(
|
||||
'\n'.join(longestOrds(
|
||||
urllib.request.urlopen(
|
||||
'http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'
|
||||
).read().decode("utf-8").split()
|
||||
))
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue