Skip to content

Instantly share code, notes, and snippets.

@Steffan153
Last active December 20, 2022 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Steffan153/5f29615dcf9f93ed5e6a4739a8b41c09 to your computer and use it in GitHub Desktop.
Save Steffan153/5f29615dcf9f93ed5e6a4739a8b41c09 to your computer and use it in GitHub Desktop.
Get the shortest solution for every hole given a language
require 'json'
require 'net/http'
require 'uri'
lang = 'ruby'
a = JSON.parse Net::HTTP.get_response(URI.parse "https://code.golf/scores/all-holes/#{lang}/all").body
o = JSON.parse Net::HTTP.get_response(URI.parse 'https://code.golf/api/holes').body
o.each do |x|
print x['name'] + ': '
z = a.select { |y| y['hole'] == x['id'] }
if z.empty?
puts "No solution"
else
m = z.min_by { |y| y['bytes'] }
puts "#{m['bytes']} by #{m['login']}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment