Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 150 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 18
  • 44

Jelly, 29 bytes

ḟŒPŒ!€Ẏ;ṙ-ɗ€Ḋ=Ṗ}ɗƝẠ$ƇLÞṪ;Ṫ}\/

Try it online!

Golfy, but inefficient answer that generates all combinations of all power sets of the country code set minus the start and end, and then checks which ones fit the rules. A dyadic link that takes as its left argument the set of codes and its right argument the end and start in that order. Returns 0 if no path exists. Otherwise returns the longest path, and if there is more than one, the last as determined by the order of the input set.

Jelly, (削除) 42 (削除ここまで) 43 bytes

ṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßẎ;W)
ÇẎ0ị$Ḋ=4Ṗ¤ƲƇLÞṪṭ@;Ṫ}\/

Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination. Works recursively, and handles longer cases relatively efficiently.

Jelly, 29 bytes

ḟŒPŒ!€Ẏ;ṙ-ɗ€Ḋ=Ṗ}ɗƝẠ$ƇLÞṪ;Ṫ}\/

Try it online!

Golfy, but inefficient answer that generates all combinations of all power sets of the country code set minus the start and end, and then checks which ones fit the rules. A dyadic link that takes as its left argument the set of codes and its right argument the end and start in that order.

Jelly, (削除) 42 (削除ここまで) 43 bytes

ṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßẎ;W)
ÇẎ0ị$Ḋ=4Ṗ¤ƲƇLÞṪṭ@;Ṫ}\/

Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination. Works recursively, and handles longer cases relatively efficiently.

Jelly, 29 bytes

ḟŒPŒ!€Ẏ;ṙ-ɗ€Ḋ=Ṗ}ɗƝẠ$ƇLÞṪ;Ṫ}\/

Try it online!

Golfy, but inefficient answer that generates all combinations of all power sets of the country code set minus the start and end, and then checks which ones fit the rules. A dyadic link that takes as its left argument the set of codes and its right argument the end and start in that order. Returns 0 if no path exists. Otherwise returns the longest path, and if there is more than one, the last as determined by the order of the input set.

Jelly, (削除) 42 (削除ここまで) 43 bytes

ṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßẎ;W)
ÇẎ0ị$Ḋ=4Ṗ¤ƲƇLÞṪṭ@;Ṫ}\/

Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination. Works recursively, and handles longer cases relatively efficiently.

added 726 characters in body; deleted 5 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 18
  • 44

Jelly, 29 bytes

ḟŒPŒ!€Ẏ;ṙ-ɗ€Ḋ=Ṗ}ɗƝẠ$ƇLÞṪ;Ṫ}\/

Try it online!

Golfy, but inefficient answer that generates all combinations of all power sets of the country code set minus the start and end, and then checks which ones fit the rules. A dyadic link that takes as its left argument the set of codes and its right argument the end and start in that order.

Jelly , (削除) 42 (削除ここまで) 43 bytes

ṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßẎ;W)
ÇẎ0ị$Ḋ=4Ṗ¤ƲƇLÞṪṭ@;Ṫ}\/

Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination. Works recursively, and handles longer cases relatively efficiently.

Jelly, (削除) 42 (削除ここまで) 43 bytes

ṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßẎ;W)
ÇẎ0ị$Ḋ=4Ṗ¤ƲƇLÞṪṭ@;Ṫ}\/

Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination.

Jelly, 29 bytes

ḟŒPŒ!€Ẏ;ṙ-ɗ€Ḋ=Ṗ}ɗƝẠ$ƇLÞṪ;Ṫ}\/

Try it online!

Golfy, but inefficient answer that generates all combinations of all power sets of the country code set minus the start and end, and then checks which ones fit the rules. A dyadic link that takes as its left argument the set of codes and its right argument the end and start in that order.

Jelly , (削除) 42 (削除ここまで) 43 bytes

ṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßẎ;W)
ÇẎ0ị$Ḋ=4Ṗ¤ƲƇLÞṪṭ@;Ṫ}\/

Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination. Works recursively, and handles longer cases relatively efficiently.

added 19 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 18
  • 44

Jelly, 42(削除) 42 (削除ここまで) 43 bytes

Wṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßƊ0ị$Ḋ=4Ṗ¤Ʋ?€Ẏṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßẎ;W)
ÇLÞṪṭ@;ṪÇẎ0ị$Ḋ=4Ṗ¤ƲƇLÞṪṭ@;Ṫ}\/

Try it online! Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination.

Jelly, 42 bytes

Wṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßƊ0ị$Ḋ=4Ṗ¤Ʋ?€Ẏ
ÇLÞṪṭ@;Ṫ}\/

Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination.

Jelly, (削除) 42 (削除ここまで) 43 bytes

ṭ@Ɱ5ḟṖ=\Ƈ0ị$Ḋ$ƲßẎ;W)
ÇẎ0ị$Ḋ=4Ṗ¤ƲƇLÞṪṭ@;Ṫ}\/

Try it online!

A full program that takes three arguments: the starting country in a nested list, the final country and the list of country codes. Returns a Jelly string of the longest path if one exists with the sort order determined by the reverse of the listing of the country codes. If no valid path exists, returns 0 followed by the last letter of the destination.

Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 18
  • 44
Loading

AltStyle によって変換されたページ (->オリジナル) /