A new method that merged artificial intelligence with electrical brain stimulation improved brain functions related to self-control and mental flexibility.