#Clojure , (削除) 122 (削除ここまで) 117 bytes
Clojure , (削除) 122 (削除ここまで) 117 bytes
-5 bytes by shortcutting the indices of the characters to swap
(fn[p](map #(let[l(count %)v(vec %)y(dec l)z(- l 2)](apply str(assoc v y(v z)z(v y))))(clojure.string/split p #" ")))
It's a shame that most of Clojure's String function are tucked away inside of Clojure.string, and that there are no good ways of manipulating the characters of Strings directly. clojure.string/split is atrociously long, and the conversion to-and-from vectors added quite a lot. I might be able to shave off a couple bytes by shortcutting the trailing indices, but this is the only decent algorithm I could think of.
(defn flip-last [phrase]
(let [words (clojure.string/split phrase #" ")]
; For each word...
(map #(let [len (count %)
; Need to turn the string into a vector so we can manipulate it using indices
vec-word (vec %)]
; ... then turn the vector of characters back into a String.
(apply str
; Associate the element at the second last index with the element at the last index,
; and vice-versa...
(assoc vec-word (dec len) (vec-word (- len 2))
(- len 2) (vec-word (dec len)))))
words)))
#Clojure , (削除) 122 (削除ここまで) 117 bytes
-5 bytes by shortcutting the indices of the characters to swap
(fn[p](map #(let[l(count %)v(vec %)y(dec l)z(- l 2)](apply str(assoc v y(v z)z(v y))))(clojure.string/split p #" ")))
It's a shame that most of Clojure's String function are tucked away inside of Clojure.string, and that there are no good ways of manipulating the characters of Strings directly. clojure.string/split is atrociously long, and the conversion to-and-from vectors added quite a lot. I might be able to shave off a couple bytes by shortcutting the trailing indices, but this is the only decent algorithm I could think of.
(defn flip-last [phrase]
(let [words (clojure.string/split phrase #" ")]
; For each word...
(map #(let [len (count %)
; Need to turn the string into a vector so we can manipulate it using indices
vec-word (vec %)]
; ... then turn the vector of characters back into a String.
(apply str
; Associate the element at the second last index with the element at the last index,
; and vice-versa...
(assoc vec-word (dec len) (vec-word (- len 2))
(- len 2) (vec-word (dec len)))))
words)))
Clojure , (削除) 122 (削除ここまで) 117 bytes
-5 bytes by shortcutting the indices of the characters to swap
(fn[p](map #(let[l(count %)v(vec %)y(dec l)z(- l 2)](apply str(assoc v y(v z)z(v y))))(clojure.string/split p #" ")))
It's a shame that most of Clojure's String function are tucked away inside of Clojure.string, and that there are no good ways of manipulating the characters of Strings directly. clojure.string/split is atrociously long, and the conversion to-and-from vectors added quite a lot. I might be able to shave off a couple bytes by shortcutting the trailing indices, but this is the only decent algorithm I could think of.
(defn flip-last [phrase]
(let [words (clojure.string/split phrase #" ")]
; For each word...
(map #(let [len (count %)
; Need to turn the string into a vector so we can manipulate it using indices
vec-word (vec %)]
; ... then turn the vector of characters back into a String.
(apply str
; Associate the element at the second last index with the element at the last index,
; and vice-versa...
(assoc vec-word (dec len) (vec-word (- len 2))
(- len 2) (vec-word (dec len)))))
words)))
#Clojure, (削除) 122 (削除ここまで) 117 bytes
-5 bytes by shortcutting the indices of the characters to swap
(fn[p](map #(let[l(count %)v(vec %)y(dec l)z(- l 2)](apply str(assoc v y(v z)z(v y))))(clojure.string/split p #" ")))
It's a shame that most of Clojure's String function are tucked away inside of Clojure.string, and that there are no good ways of manipulating the characters of Strings directly. clojure.string/split is atrociously long, and the conversion to-and-from vectors added quite a lot. I might be able to shave off a couple bytes by shortcutting the trailing indices, but this is the only decent algorithm I could think of.
(defn flip-last [phrase]
(let [words (clojure.string/split phrase #" ")]
; For each word...
(map #(let [len (count %)
; Need to turn the string into a vector so we can manipulate it using indices
vec-word (vec %)]
; ... then turn the vector of characters back into a String.
(apply str
; Associate the element at the second last index with the element at the last index,
; and vice-versa...
(assoc vec-word (dec len) (vec-word (- len 2))
(- len 2) (vec-word (dec len)))))
words)))
#Clojure, (削除) 122 (削除ここまで) 117 bytes
-5 bytes by shortcutting the indices of the characters to swap
(fn[p](map #(let[l(count %)v(vec %)y(dec l)z(- l 2)](apply str(assoc v y(v z)z(v y))))(clojure.string/split p #" ")))
It's a shame that most of Clojure's String function are tucked away inside of Clojure.string. clojure.string/split is atrociously long. I might be able to shave off a couple bytes by shortcutting the trailing indices, but this is the only decent algorithm I could think of.
(defn flip-last [phrase]
(let [words (clojure.string/split phrase #" ")]
; For each word...
(map #(let [len (count %)
; Need to turn the string into a vector so we can manipulate it using indices
vec-word (vec %)]
; ... then turn the vector of characters back into a String.
(apply str
; Associate the element at the second last index with the element at the last index,
; and vice-versa...
(assoc vec-word (dec len) (vec-word (- len 2))
(- len 2) (vec-word (dec len)))))
words)))
#Clojure, (削除) 122 (削除ここまで) 117 bytes
-5 bytes by shortcutting the indices of the characters to swap
(fn[p](map #(let[l(count %)v(vec %)y(dec l)z(- l 2)](apply str(assoc v y(v z)z(v y))))(clojure.string/split p #" ")))
It's a shame that most of Clojure's String function are tucked away inside of Clojure.string, and that there are no good ways of manipulating the characters of Strings directly. clojure.string/split is atrociously long, and the conversion to-and-from vectors added quite a lot. I might be able to shave off a couple bytes by shortcutting the trailing indices, but this is the only decent algorithm I could think of.
(defn flip-last [phrase]
(let [words (clojure.string/split phrase #" ")]
; For each word...
(map #(let [len (count %)
; Need to turn the string into a vector so we can manipulate it using indices
vec-word (vec %)]
; ... then turn the vector of characters back into a String.
(apply str
; Associate the element at the second last index with the element at the last index,
; and vice-versa...
(assoc vec-word (dec len) (vec-word (- len 2))
(- len 2) (vec-word (dec len)))))
words)))
#Clojure, (削除) 122 (削除ここまで) 117 bytes
-5 bytes by shortcutting the indices of the characters to swap
(fn[p](map #(let[l(count %)v(vec %)y(dec l)z(- l 2)](apply str(assoc v y(v z)z(v y))))(clojure.string/split p #" ")))
It's a shame that most of Clojure's String function are tucked away inside of Clojure.string. clojure.string/split is atrociously long. I might be able to shave off a couple bytes by shortcutting the trailing indices, but this is the only decent algorithm I could think of.
(defn flip-last [phrase]
(let [words (clojure.string/split phrase #" ")]
; For each word...
(map #(let [len (count %)
; Need to turn the string into a vector so we can manipulate it using indices
vec-word (vec %)]
; ... then turn the vector of characters back into a String.
(apply str
; Associate the element at the second last index with the element at the last index,
; and vice-versa...
(assoc vec-word (dec len) (vec-word (- len 2))
(- len 2) (vec-word (dec len)))))
words)))