There is a 7-digit number with all distinct digits. The product of the first 3 digits = product of the middle 3 digits = product of the last 3 digits. Find the number.
-
-
Save theycallmeswift/3145373 to your computer and use it in GitHub Desktop.
Solutions to the circle hackathon challenge
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
fits = (str) -> | |
p1 = str.charAt(0) * str.charAt(1) * str.charAt(2) | |
p2 = str.charAt(2) * str.charAt(3) * str.charAt(4) | |
p3 = str.charAt(4) * str.charAt(5) * str.charAt(6) | |
return p1 == p2 && p2 == p3 | |
for x in [1000000..9999999] | |
if /^(?:(.)(?!.*?\1))*$/.test(x) && fits("#{x}") | |
console.log("#{x}".charAt(3)) | |
return |
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
% Swift's solution to the A16Z Hackathon challenge. | |
all_distinct([]). | |
all_distinct([_]). | |
all_distinct([Head|Tail]) :- not(member(Head, Tail)), all_distinct(Tail). | |
set_bounds(X) :- between(0,9,X). | |
has_property([A,B,C,D,E,F,G]) :- | |
P1A is A * B, P1 is P1A * C, | |
P2A is C * D, P2 is P2A * E, | |
P3A is E * F, P3 is P3A * G, | |
P1 = P2, P2 = P3. | |
a16z(List) :- | |
length(List, 7), | |
all_distinct(List), | |
has_property(List), | |
!. | |
solve(Puzzle) :- | |
maplist(set_bounds, Puzzle), | |
a16z(Puzzle). |
Yo can you explain the regex on that?
nvm got it!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Relevant: http://discovercircle.com/hackathon