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 23 characters in body
Source Link
betseg
  • 8.8k
  • 3
  • 30
  • 61

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

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

IFS=
b=ppcg
while [ "$${b/hello}" ];do
read -rN1 a
b="$b=${b: -4}$a"$a
echo -n "$a"$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=${b: -4}$a"$a # set b to its last 4 chars + the inputted char
 echo -n "$a"$a # output the inputted char
done

Try it online! Try it online!

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!

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

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

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!

deleted 38 characters in body
Source Link
betseg
  • 8.8k
  • 3
  • 30
  • 61

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

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

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

Explanation:

IFS= # making sure we can read whitespace properly
b=ppcg # set the variable b to some arbitrary 4 letter string
while read[ -rN1"${b/hello}" a;]; do # while the variable #b whiledoesn't inputcontain comes"hello", do the following
 b = "${b:read -4}$a" rN1 a # set b to its last 4 letters +# inputtedget characterinput
 echob="${b: -n4}$a" "$a" # set b to its last 4 #chars output+ the inputted characterchar
 [ "$b" =echo hello-n ]"$a" && exit # if the last 5 inputted characters are "hello", then# exitoutput the programinputted char
done

Try it online! Try it online!

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

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

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

Explanation:

IFS= # making sure we can read whitespace properly
b=ppcg # set the variable b to some arbitrary 4 letter string
while read -rN1 a; do # while input comes, do the following
 b = "${b: -4}$a"  # set b to its last 4 letters + inputted character
 echo -n "$a" # output the inputted character
 [ "$b" = hello ] && exit # if the last 5 inputted characters are "hello", then exit the program 
done

Try it online!

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!

deleted 169 characters in body
Source Link
betseg
  • 8.8k
  • 3
  • 30
  • 61

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

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

IFS=;whileIFS=;b=ppcg;while read -rN1 a;do b+=$a;c=$b="${b: -5};((${#c4}>4))&&b=$c;echo$a";echo -n "$a";[ $c"$b" = hello ]&&exit;done

Explanation:

IFS= # making sure we can read whitespace properly
while read -rN1 a; do b=ppcg # while input comes; do
 set the variable b += $a to some arbitrary 4 letter string
while read -rN1 a; do # addwhile inputtedinput charactercomes, todo variablethe bfollowing
 cb = $"${b: -54}$a" # set variable cb to theits last 5 letters of th variable b
  (( ${#c} > 4 )) && b = $c # if c has more than 5 letters, eg if b has more
 # than 5 letters, set b to var c (its last+ 5inputted characters)character
 echo -n "$a" # output the inputted character
 [ $c"$b" = hello ] && exit # if the last 5 inputted characters formare "hello", finishthen exit the program
done # end of loop

Try it online! Try it online!

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

-4 bytes thanks to @DigitalTrauma!

IFS=;while read -rN1 a;do b+=$a;c=${b: -5};((${#c}>4))&&b=$c;echo -n "$a";[ $c = hello ]&&exit;done

Explanation:

IFS= # making sure we can read whitespace properly
while read -rN1 a; do  # while input comes; do
  b += $a  # add inputted character to variable b
 c = ${b: -5} # set variable c to the last 5 letters of th variable b
  (( ${#c} > 4 )) && b = $c # if c has more than 5 letters, eg if b has more
 # than 5 letters, set b to var c (its last 5 characters)
 echo -n "$a" # output the inputted character
 [ $c = hello ] && exit # if last 5 inputted characters form "hello", finish the program
done # end of loop

Try it online!

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

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

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

Explanation:

IFS= # making sure we can read whitespace properly
b=ppcg # set the variable b to some arbitrary 4 letter string
while read -rN1 a; do # while input comes, do the following
 b = "${b: -4}$a" # set b to its last 4 letters + inputted character
 echo -n "$a" # output the inputted character
 [ "$b" = hello ] && exit # if the last 5 inputted characters are "hello", then exit the program
done

Try it online!

added 763 characters in body
Source Link
betseg
  • 8.8k
  • 3
  • 30
  • 61
Loading
added 75 characters in body
Source Link
betseg
  • 8.8k
  • 3
  • 30
  • 61
Loading
added 3 characters in body
Source Link
betseg
  • 8.8k
  • 3
  • 30
  • 61
Loading
Post Undeleted by betseg
Post Deleted by betseg
Source Link
betseg
  • 8.8k
  • 3
  • 30
  • 61
Loading

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