Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#211] support more puzzle test cases #212

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/pdd/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,18 @@ def minutes(num, units)
#
# Fetch puzzle tail (all lines after the first one)
def tail(lines, prefix, start)
prefix = prefix.rstrip
prefix = " #{' ' * start}" if prefix.empty? # fallback to space indentation
line = lines[0][prefix.length + 1, lines[0].length] if lines[0]
line = lines[0][prefix.length, lines[0].length] if lines[0]
is_indented = line&.start_with?(' ')
lines
.take_while { |t| match_markers(t).none? && t.start_with?(prefix) }
.take_while do |t|
!is_indented || t[prefix.length + 1, t.length].start_with?(' ')
start = t.length > prefix.length ? prefix : prefix.rstrip
match_markers(t).none? && t.start_with?(start)
end
.take_while do |t|
# account for carriage return in line endings
t_len = t.length - 1
t_len <= prefix.length || t_len > prefix.length + 2
!is_indented || t[prefix.length, t.length].start_with?(' ')
end
.map { |t| t[prefix.length, t.length] }
.map { |t| t.start_with?(' ') ? t[1, t.length] : t }
.map { |t| t[prefix.length, t.length]&.lstrip }
end
# rubocop:enable Metrics/CyclomaticComplexity

Expand Down
File renamed without changes.
File renamed without changes.