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 Revisions

6 of 7
deleted 38 characters in body
betseg
  • 8.8k
  • 3
  • 30
  • 61

Bash, (削除) 74 (削除ここまで) (削除) 75 (削除ここまで) (削除) 103 (削除ここまで) (削除) 99 (削除ここまで) (削除) 88 (削除ここまで) 82 bytes

-10 bytes thanks to @DigitalTrauma!
-11 bytes thanks to @manatwork!

IFS=
b=ppcg
while [ "${b/hello}" ];do
read -rN1 a
b="${b: -4}$a"
echo -n "$a"
done

Explanation:

IFS= # making sure we can read whitespace properly
b=ppcg # set the variable b to some arbitrary 4 letter string
while [ "${b/hello}" ]; do # while the variable b doesn't contain "hello", do the following
 read -rN1 a # get input
 b="${b: -4}$a" # set b to its last 4 chars + the inputted char
 echo -n "$a" # output the inputted char
done

Try it online!

betseg
  • 8.8k
  • 3
  • 30
  • 61

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