Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ippon-extreme-startup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
François SARRADIN
ippon-extreme-startup
Commits
91942358
Commit
91942358
authored
7 years ago
by
François Sarradin
Browse files
Options
Downloads
Patches
Plain Diff
add SHA-1 question
parent
7aa7d1dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/extreme_startup/question_factory.rb
+38
-0
38 additions, 0 deletions
lib/extreme_startup/question_factory.rb
with
38 additions
and
0 deletions
lib/extreme_startup/question_factory.rb
+
38
−
0
View file @
91942358
...
...
@@ -2,6 +2,7 @@
require
'set'
require
'prime'
require
'digest/sha1'
module
ExtremeStartup
class
Question
...
...
@@ -627,6 +628,43 @@ module ExtremeStartup
end
end
class
Sha1Question
<
GetQuestion
def
initialize
(
player
,
word
=
nil
)
if
word
@word
=
word
else
size
=
rand
(
5
)
+
5
@word
=
generate_string
(
size
)
end
end
def
as_text
"what is the SHA-1 hash of
#{
@word
}
"
end
private
def
correct_answer
Digest
::
SHA1
.
hexdigest
@word
end
def
generate_string
(
size
)
random_chars
[
0
..
size
].
reduce
(:
+
)
end
def
random_chars
randoms
=
Set
.
new
loop
do
is_upper
=
rand
(
2
)
if
is_upper
==
1
c
=
'A'
.
ord
else
c
=
'a'
.
ord
end
randoms
<<
(
c
+
rand
(
26
)).
chr
return
randoms
.
to_a
if
randoms
.
size
>=
10
end
end
end
class
QuestionFactory
attr_reader
:round
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment