<commit_before>w,h = STDIN.gets.chomp.split(',')
p "#{w}, #{h}"<commit_msg>implement code which is able to solve 3,3 but slow #16<commit_after>@w,@h = STDIN.gets.chomp.split(',')
@w,@h = @w.to_i,@h.to_i
pass = []
# p "#{@w}, #{@h}"

def solve pass, from, to

  r_f,c_f = from.split(',')
  r_t,c_t = to.split(',')
  next_root = r_f < r_t || c_f < c_t ? from + "@" + to : to + "@" + from

  pass << next_root

  if next_root == "0,0@0,1"
    # p pass
    return pass.count
  end

  n_a = to + "@" + (r_t.to_i+1).to_s + "," + c_t # down
  n_b = to + "@" + r_t + "," + (c_t.to_i+1).to_s # right
  n_c = r_t + "," + (c_t.to_i-1).to_s + "@" + to # left
  n_d = (r_t.to_i-1).to_s + "," + c_t + "@" + to # up

  # p "#{r_t}, #{c_t}, #{n_a}"
  # p "#{r_t}, #{c_t}, #{n_b}"
  # p "#{r_t}, #{c_t}, #{n_c}" if n_c == "0,0@0,1"
  # p "#{r_t}, #{c_t}, #{n_d}" if n_d == "0,1@1,1"

  # p r.to_i < @h && !pass.include?(n_a)
  # p c.to_i < @w && !pass.include?(n_b)
  # p c.to_i > 0 && !pass.include?(n_c)
  # p r.to_i > 0 && !pass.include?(n_d)

  a = (r_t.to_i < @h && !pass.include?(n_a)) ? solve(Marshal.load(Marshal.dump(pass)), to, (r_t.to_i+1).to_s + "," + c_t) : 0
  b = (c_t.to_i < @w && !pass.include?(n_b)) ? solve(Marshal.load(Marshal.dump(pass)), to, r_t + "," + (c_t.to_i+1).to_s) : 0
  c = (c_t.to_i > 0 && !pass.include?(n_c)) ? solve(Marshal.load(Marshal.dump(pass)), to, r_t + "," + (c_t.to_i-1).to_s) : 0
  d = (r_t.to_i > 0 && !pass.include?(n_d)) ? solve(Marshal.load(Marshal.dump(pass)), to, (r_t.to_i-1).to_s + "," + c_t) : 0

  # p a
  # p b
  # p c
  # p d

  answer = [a,b,c,d]
  # p answer
  return answer.max
end

answer = solve [], "0,0", "1,0"
p answer
{'fraction_non_alphanumeric': 0.2702702702702703, 'fraction_numerical': 0.021621621621621623, 'mean_word_length': 3.05352798053528, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2085032', 'n_tokens_mistral': 883, 'n_tokens_neox': 873, 'n_words': 165}