Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Card Guess
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Card Guess
Commits
cef1979b
Commit
cef1979b
authored
Dec 02, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use common methods
parent
13ef911c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
5 deletions
+15
-5
guess.ts
guess.ts
+15
-5
No files found.
guess.ts
View file @
cef1979b
...
...
@@ -38,9 +38,20 @@ async function loadConstants() {
}
}
function
joinWithAnd
(
clauses
:
string
[])
{
return
`and (1
${
clauses
.
join
(
"
"
)}
)`
;
}
function
joinWithOr
(
clauses
:
string
[])
{
const
wrappedClauses
=
clauses
.
map
(
c
=>
`(1
${
c
}
)`
)
return
`and (
${
wrappedClauses
.
join
(
"
or
"
)}
)`
;
}
function
wrapWithNot
(
clause
:
string
)
{
return
`and not (1
${
clause
}
)`
;
}
function
replaceClause
(
clause
:
string
|
any
,
statement
:
boolean
)
{
if
(
typeof
(
clause
)
!==
"
string
"
)
{
return
(
statement
===
(
clause
===
0
))
?
"
0
"
:
"
1
"
;
return
(
statement
===
(
clause
===
0
))
?
"
and 0
"
:
"
and
1
"
;
}
let
newClause
=
clause
;
for
(
let
constantKey
of
Array
.
from
(
constantDict
.
keys
()))
{
...
...
@@ -59,7 +70,7 @@ function parseWhereClause(whereClause: (string | any)[]) {
return
""
;
}
const
newClauses
=
whereClause
.
map
(
w
=>
replaceClause
(
w
,
true
));
return
newClauses
.
join
(
'
'
);
return
joinWithAnd
(
newClauses
);
}
function
getCombination
(
arr
:
number
[],
count
:
number
):
number
[][]
{
...
...
@@ -105,11 +116,10 @@ function parseMayIncorrectStatement(mayIncorrectStatement: MayIncorrectStatement
const
correctSequences
=
generateBoolSequence
(
mayIncorrectStatement
.
where
.
length
,
i
);
for
(
let
correctSequence
of
correctSequences
)
{
const
clauses
=
mayIncorrectStatement
.
where
.
map
((
clause
,
index
)
=>
replaceClause
(
clause
,
correctSequence
[
index
]));
const
combinedClause
=
`(1
${
clauses
.
join
(
'
'
)}
)`
;
outerClauses
.
push
(
combinedClause
);
outerClauses
.
push
(
joinWithAnd
(
clauses
));
}
}
return
`and (
${
outerClauses
.
join
(
'
or
'
)}
)`
;
return
joinWithOr
(
outerClauses
)
;
}
function
parseMayIncorrectStatements
(
mayIncorrectStatements
:
MayIncorrectStatement
[])
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment