21
\$\begingroup\$

For your hard thing to do, you must make a thing for a computer to do that finds out if some words are explained in a simple way. Something is explained in a simple way if it only uses the ten hundred most used words. If not, it is explained in a hard way. This can be a full computer thing or part of a computer thing. (full program or function)

There is a thing for a computer to read that has all of the ten hundred words in it with a space between each word. The name of the thing for the computer to read is called 'most used.txt'. You can take this thing from this computer place.

The person who uses the computer thing will enter some words. (This can be from STDIN, function arguments or command line arguments) The computer must say something like a true if the words are simple and something like a not true if it is hard. (truthy-falsy) The person who makes the shortest thing for the computer to do is the best. The things that every person knows are bad are bad. (standard loopholes apply)


More stuff to know about how the computer thing works:

  • It doesn't matter if the words are BIG or little.

  • The pictures that make what the word meaning easier to know (punctuation) don't matter. So if the person who uses the computer thing says "dont" it isn't a different word than the word "don't". Numbers and other pictures also don't matter. So if the person says "HE$$ll9o" the computer should read it like "hello"

  • The little lines between words (dashes) work the same way as spaces. So the word "up-goer-five" is the same as the words "up goer five".


More stuff to know about making words like this:

https://xkcd.com/1133/

http://splasho.com/upgoer5/#

\$\endgroup\$
11
  • 7
    \$\begingroup\$ So check the computer thing user's words to the big word thing to see if all the words in the little word thing are in the big word thing? \$\endgroup\$
    – Geobits
    Jul 17, 2015 at 20:19
  • 24
    \$\begingroup\$ Maybe it's just me, but I found this exceptionally difficult to read. \$\endgroup\$
    – Alex A.
    Jul 17, 2015 at 20:24
  • 8
    \$\begingroup\$ It might be better to give a synopsis in simple-talk, followed by an actual spec in "real" English. \$\endgroup\$
    – Geobits
    Jul 17, 2015 at 20:32
  • 2
    \$\begingroup\$ Does the dictionary have to be read from a file? That might downright exclude a couple of languages. \$\endgroup\$
    – Dennis
    Jul 17, 2015 at 20:44
  • 1
    \$\begingroup\$ You should have had a penalty for every word used which is hard in the program \$\endgroup\$
    – Beta Decay
    Jul 18, 2015 at 19:45

8 Answers 8

8
\$\begingroup\$

R, 106 bytes

Is not sure if is understand challenge because is has hard time reading.

function(s){u=toupper;all(strsplit(gsub("[^A-Z -']","",u(s)),"[ -]")[[1]]%in%u(scan("most used.txt","")))}

This creates an unnamed part of a computer thing that accepts a string and returns something like a true or like a not true.

Ungolfed + explanation:

partOfAComputerThing <- function(s) {
    # Remove everything but letters, spaces, dashes, and single quotes
    s <- gsub("[^A-Z -']", "", toupper(s))

    # Split s into a vector on spaces/dashes
    v <- strsplit(s, "[ -]")[[1]]

    # Read the file of words (assumed to reside in the current directory)
    m <- scan("most used.txt", "")

    # Determine if all words in the input are in the file
    all(v %in% toupper(m))
}

Thanks to Dennis for inspiration thing.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Something like part-of-a-computer-thing(s){...} should be worth bonus points. \$\endgroup\$
    – Dennis
    Jul 17, 2015 at 21:00
  • \$\begingroup\$ @Dennis: How's this? :) \$\endgroup\$
    – Alex A.
    Jul 17, 2015 at 21:26
  • \$\begingroup\$ Much better!​​​ \$\endgroup\$
    – Dennis
    Jul 17, 2015 at 21:38
6
\$\begingroup\$

CJam, 41 bytes

q"file:///most used.txt"g]{el_euS--S%}/-!

This makes the rather unclean assumption that most used.txt is in the root directory, since CJam cannot handle relative paths.

Alternatively, we have the following web-based solutions (78 and 29 bytes):

q"https://docs.google.com/uc?id=0B2sM8IORrbL3RVpJWTZNUy1rOFU"g]{el_euS--S%}/-!
q"j.mp/-o_O"g]{el_euS--S%}/-!

The "proper" way of doing this in CJam would be reading both inputs from STDIN (input on the first line, dictionary on the second), which is possible in 18 bytes:

qN%{el_euS--S%}/-!

You can try the last version in the CJam interpreter. (permalink tested in Chrome)

Examples

$ cjam <(echo 'q"file:///most used.txt"g]{el_euS--S%}/-!') <<< 'ten hundred'; echo
1
$ cjam <(echo 'q"file:///most used.txt"g]{el_euS--S%}/-!') <<< 'thousand'; echo
0
\$\endgroup\$
2
  • 2
    \$\begingroup\$ You could use tinyurl on the Drive url to make it shorter \$\endgroup\$
    – DeadChex
    Jul 17, 2015 at 21:28
  • 1
    \$\begingroup\$ @M.I.Wright Figured it out. That and uploading the file to Pastebin saved 12 bytes. Thanks! \$\endgroup\$
    – Dennis
    Jul 17, 2015 at 22:02
3
\$\begingroup\$

Python 3, 148 bytes

import re
print(all(i in open("most used.txt").read().lower().split(' ')for i in re.sub("[^a-z ']+","",input().replace("-"," ").lower()).split(" ")))

Outputs True and False

Examples

Input:  Don't
Output: True

Input:  The poison air he's breathing has a dirty smell of dying
Output: False

Input:  Who let the dogs out?
Output: False
\$\endgroup\$
7
  • \$\begingroup\$ Will this handle an input of don't correctly? \$\endgroup\$
    – Alex A.
    Jul 19, 2015 at 15:07
  • \$\begingroup\$ @AlexA. It returns True. Is that correct? \$\endgroup\$
    – Beta Decay
    Jul 19, 2015 at 15:18
  • \$\begingroup\$ Any reason you split most used.txt by new lines? I'm not 100% sure on how this works, but I imagine you're trying to split it into each individual word in the file? \$\endgroup\$
    – DeadChex
    Jul 19, 2015 at 15:19
  • \$\begingroup\$ @DeadChex What is the supplied text file separated by? I can't access it because it keeps throwing an SSL error. \$\endgroup\$
    – Beta Decay
    Jul 19, 2015 at 15:22
  • 1
    \$\begingroup\$ The question states "There is a thing for a computer to read that has all of the ten hundred words in it with a space between each word" \$\endgroup\$
    – DeadChex
    Jul 19, 2015 at 15:23
2
\$\begingroup\$

Pyth, 35 bytes

!-Fm@LGcrXd\-bZ),zs'"most used.txt

Tests, where the above is the file common.pyth

$ pyth common.pyth <<< 'I can write this way too-hell99#0O.'
True
$ pyth common.pyth <<< 'But I get confused easily.'
False

Explanation:

!-Fm@LGcrXd\-bZ),zs'"most used.txt
   m            ,zs'"most used.txt    Map over input and input file:
         Xd\-b                        Replace hyphens with newlines.
        r     Z                       Cast to lower case.
       c       )                      Split on whitespace.
    @LG                               Remove non-alphabetic characters.
 -F                                   Setwise difference - remove anything in
                                      the text file from the input.
!                                     Logical negation.
\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog), 69 bytes

Assumes that the file is in the current directory.

s←819⌶' '(1↓¨,⊂⍨⊣=,)'[- ]' '\W'⎕R' ' ''
∧/(s⍞)∊s⊃⎕NGET'most used.txt'

Try it online!

The first line defines a normalising and splitting-into-list-of-strings helper function, s:

s←s is
819⌶ the lowercased
' '( result of the following function, with a space as left argument…
1↓¨ drop one from each of
, the concatenation of the arguments
⊂⍨ cut before each element where
 the left argument
= is equal to
, the concatenation of the arguments
) applied to
'[- ]' '\W'⎕R' ' '' the PCRE replacements dash/space→space, non-word-char→nothing

∧/() is it all-true that
s the normalised and split
 text input
 are members of
s the normalised and split
 first element of
⎕NGET'most used.txt' the (content, encoding, newline-style) of the file

\$\endgroup\$
0
\$\begingroup\$

PHP, 101 bytes

foreach(preg_split("#[^\w']+#",$argn)as$w)preg_match("#\b$w\b#i",end(file("most used.txt")))?:die(1);

takes input from STDIN, assumes single line dictionary
exits with 1 (error) for falsy, 0 (ok) for truthy. Run with -R.

Split input by non-word characters, loop through resulting array (words):
If word is in the dictionary, continue; else exit(1).
implicit exit(0).

or, simply put:

one word after another: If word is in the most used words, continue; else return 1. return 0.

and: I could save two points if the most used words had a space each in front and at the end.

\$\endgroup\$
0
\$\begingroup\$

JavaScript (ES7), 161 bytes

s=>fetch("most used.txt").then(t=>t.text()).then(d=>alert(s.split(/[ -]/g).every(l=>d.split` `.map(w=>w.replace(/[\.']/,"")).includes(l.replace(/[^a-z]/g,"")))))

Anyone got a copy of the file online that I can use to create a working Snippet?

\$\endgroup\$
4
  • \$\begingroup\$ I guess that you can save 22 bytes by removing then and 7 bytes by removing alert. \$\endgroup\$
    – Titus
    Apr 25, 2017 at 16:37
  • \$\begingroup\$ Can you elaborate, @Titus? Each step of this returns a promise so the thens are required to execute subsequent code when they resolve. \$\endgroup\$
    – Shaggy
    Apr 25, 2017 at 17:04
  • \$\begingroup\$ I´m not that familiar with ES7; was thinking in the wrong direction. But maybe you can come up with something shorter if You reduce the input to all words not in the list? I doubt that PHP can really beat JS by almost 40%. \$\endgroup\$
    – Titus
    Apr 25, 2017 at 17:28
  • \$\begingroup\$ Oh, yeah, there's definitely room for improvement there; this was my last challenge of the day and I had brainache so I posted what I had so far to revisit tomorrow. Unfortunately, the chain of promises required just to get at the contents of a file puts JS at a disadvantage in these challenges against the likes of PHP but it's still better than the alternative of using XHR. \$\endgroup\$
    – Shaggy
    Apr 25, 2017 at 17:39
-1
\$\begingroup\$

Java, 248 bytes

With the Phrase passed as an argument.

void g(String s) throws Exception{String c=new java.util.Scanner(new java.io.File("most used.txt")).useDelimiter("\\Z").next(),x="false";for(String l:s.split(" "))if(c.contains(l.toLowerCase().replaceAll("![a-z]","")))x="true";System.out.print(x);}

input/output:

g("was he")         --> "true"
g("was h!e")         --> "true"
g("delicious cake") --> "false"

Spaced and tabbed out:

void g(String s) throws Exception{
    String c=new java.util.Scanner(new java.io.File("most used.txt")).useDelimiter("\\Z").next()
      ,x="false";
    for(String l:s.split(" "))
      if(c.contains(l.toLowerCase().replaceAll("![a-z]","")))
          x="true";
    System.out.print(x);
}
\$\endgroup\$
4
  • \$\begingroup\$ What do you mean it's up to you to import what's needed? \$\endgroup\$
    – Beta Decay
    Jul 19, 2015 at 12:48
  • \$\begingroup\$ @Beta I use some of Java's utility classes that, if you were to put this function in a program you'd have to import (namely java.io.* and java.util.*), much like pythons import statement \$\endgroup\$
    – DeadChex
    Jul 19, 2015 at 14:45
  • 3
    \$\begingroup\$ Well you have to include these imports in your byte count. You aren't allowed to exclude import statements in Python, so you can't exclude them in Java \$\endgroup\$
    – Beta Decay
    Jul 19, 2015 at 14:47
  • \$\begingroup\$ @BetaDecay Tweaked the program, no more imports needed \$\endgroup\$
    – DeadChex
    Jul 19, 2015 at 15:09

Your Answer

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

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