September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,16 @@
# Input: an array representing the apartment house, with null at a
# particular position signifying that the identity of the occupant
# there has not yet been determined.
# Output: an elaboration of the input array but including person, and
# satisfying cond, where . in cond refers to the placement of person
def resides(person; cond):
range(0;5) as $n
| if (.[$n] == null or .[$n] == person) and ($n|cond) then .[$n] = person
else empty # no elaboration is possible
end ;
# English:
def top: 4;
def bottom: 0;
def higher(j): . > j;
def adjacent(j): (. - j) | (. == 1 or . == -1);

View file

@ -0,0 +1,9 @@
[]
| resides("Baker"; . != top) # Baker does not live on the top floor
| resides("Cooper"; . != bottom) # Cooper does not live on the bottom floor
| resides("Fletcher"; . != top and . != bottom) # Fletcher does not live on either the top or the bottom floor.
| index("Cooper") as $Cooper
| resides("Miller"; higher( $Cooper) ) # Miller lives on a higher floor than does Cooper
| index("Fletcher") as $Fletcher
| resides("Smith"; adjacent($Fletcher) | not) # Smith does not live on a floor adjacent to Fletcher's.
| select( $Fletcher | adjacent( $Cooper ) | not ) # Fletcher does not live on a floor adjacent to Cooper's.

View file

@ -0,0 +1,8 @@
$ jq -n -f Dinesman.jq
[
"Smith",
"Cooper",
"Baker",
"Fletcher",
"Miller"
]