This file contains 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
We will play a game called “Where in the world is GPT Santiago” | |
Game synopsis: | |
A detective is chasing the notorious thief “GPT Santiago” worldwide. | |
The detective visits different cities that the thief visited, and by asking for hints from the locals, they get a sense of what city they should visit next. | |
If the detective makes too many mistakes and arrives at the wrong destinations, the thief slips away. | |
If the deactivate reaches the last city with a small number of mistakes or no mistakes, they manage the apprehend the thief and win the game. | |
Gameplay: | |
I will be the detective. You (ChatGPT) will create a sequence of 10 random cities that will be the route of the thief. |
This file contains 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
public class MergeTwoLists { | |
public class ListNode { | |
int val; | |
ListNode next; | |
ListNode(int val) { | |
this.val = val; | |
this.next = null; | |
} | |
} |
This file contains 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
public class ListNode { | |
int val; | |
ListNode next; | |
ListNode(int val) { | |
this.val = val; | |
this.next = null; | |
} | |
} | |
public ListNode mergeTwoLists(ListNode l1, ListNode l2) { |
This file contains 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
data class Direction(val positionChange: PositionChange, directionType: DirectionType) | |
val directions = listOf( | |
Direction(PositionChange(-1,0), DirectionType.LEFT), | |
..... //TODO: add the other 3 entries | |
) | |
This file contains 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
package leetcode | |
import leetcode.Action.* | |
import leetcode.PersonState.* | |
import leetcode.StateOfPerson.Asleep | |
import leetcode.StateOfPerson.Awake | |
enum class PersonState { | |
AWAKE, | |
ASLEEP, |
This file contains 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
operator fun<A> ((A)->A).times(rhs: (A)->A): (A)->(A) = fun(arg: A): A = this(rhs(arg)) | |
fun <A,B,C> curryLeft(func: (A,B) -> C) = fun(lhs: A) = fun(rhs: B) = func(lhs, rhs) | |
fun <A,B,C> curryRight(func: (A,B) -> C) = fun(rhs: B) = fun(lhs: A) = func(lhs, rhs) | |
fun div(content: String) = "<div>$content</div>" | |
fun anchor(link: String, text: String) = "<a href =\"$link\"> $text </a>" |
This file contains 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
class TreeNode(var `val`: Int) { | |
var left: TreeNode? = null | |
var right: TreeNode? = null | |
} | |
fun main(args: Array<String>) { | |
val root = TreeNode(1).apply { | |
left = TreeNode(2).apply { // left child of 1 | |
left = TreeNode(4) // left child of 2 |
This file contains 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
fun maxSubArray(nums: IntArray): Int = nums.map { it to Integer.MIN_VALUE } | |
.fold(Pair(0, Integer.MIN_VALUE)) { | |
currSum,num -> with (num.first + currSum.first) { | |
Pair(this.takeIf { it >= 0 } ?: 0 , this.coerceAtLeast(currSum.second) ) | |
} | |
} | |
.second |
This file contains 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
fun reverseList(head: Node?): Node? = reverseList(null, head) | |
fun reverseList(current: Node?, next: Node?): Node { | |
if (next == null) { | |
return current!! | |
} | |
val nextnext = next.next | |
next.next = current | |
return reverseList(next, nextnext) |
This file contains 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
data class Node(val data: Int, var next: Node? = null) | |
fun reverseList(head: Node?): Node? = ... //implement this | |
fun reverseList(current: Node?, next: Node?): Node? = ... //implement this |
NewerOlder