TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Taxicab Numbers « Programming Praxis -- Google Interview Question

3 pointsby srsamarthyamover 12 years ago

1 comment

ankurdhamaover 12 years ago
A bit of logic programming in core.logic:<p>(defn cubo [a r] (fresh [a1] (<i>fd a a a1) (</i>fd a a1 r)))<p>(defn taxi-cab [n] (run* [q] (fresh [a ac b bc] (infd a b (interval 1 (int (java.lang.Math/cbrt n)) )) (infd ac bc (interval 0 n)) (cubo a ac) (cubo b bc) (+fd ac bc n) (== q [a b]))))<p>NOTE: FYI, could be made more efficient.