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

Adding TIO links, shrinking byte-count, adding a bit of exposition
Source Link
Robert Benson
  • 1.8k
  • 11
  • 13

AWKAWK, (削除) 113 (削除ここまで) 103(削除) 103 (削除ここまで) 98 bytes

{for(;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}
{OFS=""
for(n=split(0,ドルa,"");i<=n;s=a[++i]){$i=(L?tolower(s):toupper(s))
L=!(index("-. /&#",s))}}1

Try it online!

This works fine for single line content, but for multilinemulti-line input a couplefew more inits need to be added

{O=""
for(L=0;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

AWK , 104 bytes

{OFS=i=s=L=""
for(n=split(0,ドルa,"");i<=n;s=a[++i]){$i=(L?tolower(s):toupper(s))
L=!(index("-. /&#",s))}}1

Try it online!

It would behave been nice if we couldto take advantage of theAWK's automatic splitting of a record into fields and modifying said fields, but we would then lose ourthat throws away the field separators. :(

I know this isn'tThis update throws away the golfiestidea of answers and this istacking characters onto a rather old questionstring and then printing the string. Instead, but I feel that AWK is underrepresented ineach character becomes its own field. Without the answer-space of CG :)OFS="" bit, each character/field would be separated by a space when printed, which isn't what was requested.

(Thanks @manatwork for testing the code, it should work now :) Also changed Realizing that "" is essentially the flow but keptsame thing as 0 in AWK shortens the byte-count for the same, by replacing somemulti-line version a little bit. ; with newlines(I know it's different... I said 'essentially' :p )

AWK, (削除) 113 (削除ここまで) 103 bytes

{for(;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

This works fine for single line content, but for multiline input a couple inits need to be added

{O=""
for(L=0;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

It would be nice if we could take advantage of the automatic splitting of a record into fields and modifying said fields, but we would then lose our field separators. :(

I know this isn't the golfiest of answers and this is a rather old question, but I feel that AWK is underrepresented in the answer-space of CG :)

(Thanks @manatwork for testing the code, it should work now :) Also changed the flow but kept the byte-count the same, by replacing some ; with newlines.)

AWK, (削除) 113 (削除ここまで) (削除) 103 (削除ここまで) 98 bytes

{OFS=""
for(n=split(0,ドルa,"");i<=n;s=a[++i]){$i=(L?tolower(s):toupper(s))
L=!(index("-. /&#",s))}}1

Try it online!

This works fine for single line content, but for multi-line input a few more inits need to be added

AWK , 104 bytes

{OFS=i=s=L=""
for(n=split(0,ドルa,"");i<=n;s=a[++i]){$i=(L?tolower(s):toupper(s))
L=!(index("-. /&#",s))}}1

Try it online!

It would have been nice to take advantage of AWK's automatic splitting of a record into fields and modifying said fields, but that throws away the field separators. :(

This update throws away the idea of tacking characters onto a string and then printing the string. Instead, each character becomes its own field. Without the OFS="" bit, each character/field would be separated by a space when printed, which isn't what was requested.

Realizing that "" is essentially the same thing as 0 in AWK shortens the byte-count for the multi-line version a little bit. (I know it's different... I said 'essentially' :p )

Commonmark migration
Source Link

##AWK, (削除) 113 (削除ここまで) 103 bytes

AWK, (削除) 113 (削除ここまで) 103 bytes

{for(;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

This works fine for single line content, but for multiline input a couple inits need to be added

{O=""
for(L=0;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

It would be nice if we could take advantage of the automatic splitting of a record into fields and modifying said fields, but we would then lose our field separators. :(

I know this isn't the golfiest of answers and this is a rather old question, but I feel that AWK is underrepresented in the answer-space of CG :)

(Thanks @manatwork for testing the code, it should work now :) Also changed the flow but kept the byte-count the same, by replacing some ; with newlines.)

##AWK, (削除) 113 (削除ここまで) 103 bytes

{for(;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

This works fine for single line content, but for multiline input a couple inits need to be added

{O=""
for(L=0;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

It would be nice if we could take advantage of the automatic splitting of a record into fields and modifying said fields, but we would then lose our field separators. :(

I know this isn't the golfiest of answers and this is a rather old question, but I feel that AWK is underrepresented in the answer-space of CG :)

(Thanks @manatwork for testing the code, it should work now :) Also changed the flow but kept the byte-count the same, by replacing some ; with newlines.)

AWK, (削除) 113 (削除ここまで) 103 bytes

{for(;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

This works fine for single line content, but for multiline input a couple inits need to be added

{O=""
for(L=0;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

It would be nice if we could take advantage of the automatic splitting of a record into fields and modifying said fields, but we would then lose our field separators. :(

I know this isn't the golfiest of answers and this is a rather old question, but I feel that AWK is underrepresented in the answer-space of CG :)

(Thanks @manatwork for testing the code, it should work now :) Also changed the flow but kept the byte-count the same, by replacing some ; with newlines.)

Fixed a capitalization error in the code and tweaked the formatting.
Source Link
Robert Benson
  • 1.8k
  • 11
  • 13

##AWK, (削除) 113 (削除ここまで) 103 bytes

{for(;++i<=split(0,ドルa,"");){s=a[i];O=Os=a[i]
O=O (L?tolower(s):toupper(s));L=1;if
L=1
if(index("-. /&#",s))l=0L=0}print O}

This works fine for single line content, but for multiline input a couple inits need to be added

{O="";forO=""
for(L=0;++i<=split(0,ドルa,"");){s=a[i];O=Os=a[i]
O=O (L?tolower(s):toupper(s));L=1;if
L=1
if(index("-. /&#",s))l=0L=0}print O}

It would be nice if we could take advantage of the automatic splitting of a record into fields and modifying said fields, but we would then lose our field separators. :(

I know this isn't the golfiest of answers and this is a rather old question, but I feel that AWK is underrepresented in the answer-space of CG :)

(Thanks @manatwork for testing the code, it should work now :) Also changed the flow but kept the byte-count the same, by replacing some ; with newlines.)

##AWK, (削除) 113 (削除ここまで) 103 bytes

{for(;++i<=split(0,ドルa,"");){s=a[i];O=O (L?tolower(s):toupper(s));L=1;if(index("-. /&#",s))l=0}print O}

This works fine for single line content, but for multiline input a couple inits need to be added

{O="";for(L=0;++i<=split(0,ドルa,"");){s=a[i];O=O (L?tolower(s):toupper(s));L=1;if(index("-. /&#",s))l=0}print O}

It would be nice if we could take advantage of the automatic splitting of a record into fields and modifying said fields, but we would then lose our field separators. :(

I know this isn't the golfiest of answers and this is a rather old question, but I feel that AWK is underrepresented in the answer-space of CG :)

##AWK, (削除) 113 (削除ここまで) 103 bytes

{for(;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

This works fine for single line content, but for multiline input a couple inits need to be added

{O=""
for(L=0;++i<=split(0,ドルa,"");){s=a[i]
O=O (L?tolower(s):toupper(s))
L=1
if(index("-. /&#",s))L=0}print O}

It would be nice if we could take advantage of the automatic splitting of a record into fields and modifying said fields, but we would then lose our field separators. :(

I know this isn't the golfiest of answers and this is a rather old question, but I feel that AWK is underrepresented in the answer-space of CG :)

(Thanks @manatwork for testing the code, it should work now :) Also changed the flow but kept the byte-count the same, by replacing some ; with newlines.)

Removed a few bytes and split the multi-line case from the single-line case
Source Link
Robert Benson
  • 1.8k
  • 11
  • 13
Loading
Source Link
Robert Benson
  • 1.8k
  • 11
  • 13
Loading

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