Last active
December 20, 2022 23:43
-
-
Save Steffan153/5f29615dcf9f93ed5e6a4739a8b41c09 to your computer and use it in GitHub Desktop.
Get the shortest solution for every hole given a language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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