text:
Depalindromize this string!
Given a palindrome generated according to this challenge, depalindromize it.
Test cases
abcdedcba -> abcde
johncenanecnhoj -> johncena
ppapapp -> ppap
codegolflogedoc -> codegolf

As this is about depalindromizing, your code cannot be a palindrome.
Remember, this is code-golf, so the code with the fewest bytes wins.

-1 for the pointless restriction on your code not being a palindrome. It adds nothing to the challenge IMO, in very few languages would it matter.

+1 for the restriction. It´s so mirroring the paliondrome challenge ... and it´s adding challenge to esolangs. I like it. Am I correct in the assumption that input will always have an uneven length?

The non-palindrome restriction is probably a joke based on the previous challenge. Did anyone really downvote based on that?

@Titus for that challenge, it almost always required extra work to make the code a palindrome. Here, it almost always requires no extra work to make the code not a palindrome.

@EasterlyIrk Don't you see the symmetry? It's quite beautiful, if I do say so myself. But to be serious, I really don't see anything wrong with the so-called "pointless restriction" that would warrant a downvote. It might be trivial, but it's not the main focus of the challenge. The main focus of the challenge is to depalindromize the string, not to create a non-palindromic code.

@MamaFunRoll I feel that it adds nothing to the challenge, and might as well not be there, and thus probably shouldn't be there.

@EasterlyIrk You could also argue that because it adds nothing to the challenge, it might as well be there as nothing will happen either way. Really, in this case the final say goes to the OP. After all, it's sort of nice to have complementary challenges like this.

It does prevent single-byte solutions. @diynevala +1 for the unnecessary +1.

@Adám So it is essentially "do X without Y" challenge as well. My +1 is not unnecessary, as it supports the choice to restrict palindromous code

@LuisMendo No, it's not a joke, the [tag:restricted-source] tag exists. I have -1'd.

@EriktheGolfer But the restriction is virtually ineffective. It's very unlikely that the unrestricted code turns out to be palindromic

@LuisMendo Hypothesis: What if I made a language which happened to have an depalindromize operator (let's say q)? I couldn't use it if I didn't do <space>q instead :(

Palindrome tag is not appropriate here, is there a "non-palindrome" tag? :)

What if the string is not a palindrome to begin with?

What is expected output when the string is one char long? What is the expected output for empty string (is empty string a palindrome to begin with?)?

@LuisMendo BTW, I didn't -1 but I also didn't +1.

@EasterlyIrk You must not play Magic the Gathering.

@Xavon_Wrentaile I agree with the notion of that. I almost only see special forms of list accessing, instead of interesting logic, simply because recognizing palindromes does not seem to be a requirement.

Julia, 21 15 bytes
x->x[1:end/2+1]

Try it online! (extra code is for printing output)

end/2 is cool feature

@Downgoat yes, dennis showed it to me.

05AB1E, 3 bytes
2ä¬

Uses the CP-1252 encoding. Try it online!

Python 2, 23 bytes
I am not able to test on my phone, but this should work:
lambda s:s[:-~len(s)/2]

If you are running on android, you can use QPython from the google play store. It's the best I've found :)

termux apt-get install python2

@Matt That's overkill if all you want is Python.

@Matt as well as that if you can find apt-get on your phone, it's probably not a normal phone.

@MathManiac termux is installed from Google Play onto any non rooted Android phone. Can't get much more normal than that.

Fuzzy Octo Guacamole, 4 bytes
2.^/

I spent a while searching for a language in which this challenge is short, and realized I was dumb and my own language did that.

05AB1E, 5 bytes
Dg;î£

Try it online!
Explanation:
D      Duplicate
 g;î   Divide length by two and round up
    £  First b letters of a

Cheddar, 22 18 bytes
@.head($0.len/2+1)

So simple I don't think needs explanation but I'll add one if wanted.
Try it online

Pyth - 4 bytes
hc2Q

Test Suite.

JavaScript (ES6), 32 26 25 bytes
1 byte saved thanks to Neil:
s=>s.slice(0,-s.length/2)

f=
  s=>s.slice(0,-s.length/2)
;
console.log(f('abcdedcba'))
console.log(f('johncenanecnhoj'))
console.log(f('ppapapp'))
console.log(f('codegolflogedoc'))

Previous solutions
26 bytes thanks to Downgoat:
s=>s.slice(0,s.length/2+1)

32 bytes:
s=>s.slice(0,(l=s.length/2)+l%2)

You can shorten to just s=>s.slice(0,s.length/2+1) Since length will always be odd

@Downgoat thanks to you I found that for one more byte s=>s.slice(0,s.length/2+.5) would work for even length too.

-s.length/2 works for both odd and even lengths.

WinDbg, 87 71 bytes
db$t0 L1;.for(r$t1=@$t0;@$p;r$t1=@$t1+1){db$t1 L1};da$t0 L(@$t1-@$t0)/2

-16 bytes by not inserting NULL, instead passing length to da
Input is passed in via an address in psuedo-register $t0. For example:
eza 2000000 "abcdedcba"       * Write string "abcdedcba" into memory at 0x02000000
r $t0 = 33554432              * Set $t0 = 0x02000000
* Edit: Something got messed up in my WinDB session, of course r $t0 = 2000000 should work
* not that crazy 33554432.

It works by replacing the right of middle char (or right-middle if the string has even length) with a null and then prints the string from the original starting memory address.
db $t0 L1;                                   * Set $p = memory-at($t0)
.for (r $t1 = @$t0; @$p; r $t1 = @$t1 + 1)   * Set $t1 = $t0 and increment until $p == 0
{
    db $t1 L1                                * Set $p = memory-at($t1)
};
da $t0 L(@$t1-@$t0)/2                        * Print half the string

Output:
0:000> eza 2000000 "abcdeedcba"
0:000> r $t0 = 33554432
0:000> db$t0 L1;.for(r$t1=@$t0;@$p;r$t1=@$t1+1){db$t1 L1};da$t0 L(@$t1-@$t0)/2
02000000  61                                               a
02000000  61                                               a
02000001  62                                               b
02000002  63                                               c
02000003  64                                               d
02000004  65                                               e
02000005  65                                               e
02000006  64                                               d
02000007  63                                               c
02000008  62                                               b
02000009  61                                               a
0200000a  00                                               .
02000000  "abcde"

Haskell, 27 bytes
take=<<succ.(`div`2).length

Pointfree version of
\x->take(div(length x)2+1)x

which is also 27 bytes.

MATL, 7 6 bytes
9LQ2/)

Try it online!
Explanation
9L       % Push array [1, 1j]
  Q      % Add 1: transforms into [2, 1+1j]
   2/    % Divide by 2: transforms into [1, 0.5+0.5j]
     )   % Apply as index into implicit input. The array [1, 0.5+0.5j] used as an index
         % is interpreted as [1:0.5+end*0.5]

Wow, that is a very neat way to handle complex values as arguments for slicing

@miles Thanks! Yes, it's handy. The imaginary unit works as end, and colons between the array elements are implicit

Jelly, 4 bytes
œs2Ḣ

Try it online!
Explanation
œs2      Split input into 2 chunks of similar lengths. For odd-length input,
         the first chunk is the longest
   Ḣ     Keep the first chunk

V, 12 bytes
Two completely different solutions, both 12 bytes.
ò"Bx$xh|ò"bP

Try it online!
Ó./&ò
MjdGÍî

Try it online!

Brachylog, 4 bytes
@2tr

Try it online!
Explanation
@2        Split in half
  t       Take the second half
   r      Reverse it

If the input has odd length, the second half generated by @2 is the one that is the longest, that is the one we should return (after reversing it).

Java 7, 57 bytes
String c(String s){return s.substring(0,s.length()/2+1);}

You're missing a closing } (so it's 57 bytes).

@KevinCruijssen fixed.

Dyalog APL, 9 bytes
⊢↑⍨2÷⍨1+≢

⊢ the argument
↑⍨ truncated at
2÷⍨ half of
1+ one plus
≢  the length
TryAPL online!

Perl, 15 bytes
Includes +2 for -lp
Give input string on STDIN:
depal.pl <<< "HelleH"

depal.pl:
#!/usr/bin/perl -lp
s/../chop/reg

The -l is not really needed if you input the palindrome without final newline, but I included it to be fair to the other perl solutions that use it.

PHP, 40 bytes
<?=substr($a=$argv[1],0,1+strlen($a)/2);

strlen($a)/2 gets cast to int, with the input always having odd length, +1 suffices to round up.
42 bytes for any length:
<?=substr($a=$argv[1],0,(1+strlen($a))/2);

for unknown length, (1+strlen)/2 gets cast to int, rounding up strlen/2.

As the input is defined as coming from this (http://codegolf.stackexchange.com/questions/98325/palindromize-this-string) challenge it's length will always be odd, so you can just go with your shorter one.

TI-Basic, 14 bytes
Standard function. Returns string from index 1 to index (length/2 + 1/2).
sub(Ans,1,.5+.5length(Ans

GameMaker Language, 59 bytes
a=argument0 return string_copy(a,1,ceil(string_length(a)/2)

Dip, 8 bytes
H{C'0ÏEI

Explanation:
           # Implicit input
 H         # Push length of input
  {        # Add 1
   C       # Divide by 2
    '      # Convert to int
     0Ï    # Get string back
       E   # Push prefixes of string
        I  # Push prefixes[a]
           # Implicit print

This could probably be much improved.

Pyth, 8 7 bytes
<zh/lz2

Saved 1 with thanks to @Steven H
Not the shortest Pyth answer (by half) but I'm making an effort to learn the language and this is my first post using it. Posted as much for comments and feedback as anything. It's also the first Pyth program that I have actually got to work :)
Now I just need to work out how the 4 byte answer from @Maltysen works :-)

If you still want to know how Maltysen's answer works, it chops the input Q into 2 pieces and takes the first piece using h (which, thanks to the implementation of chop, will grab the center letter as well).  As for your code, you could replace +1 with h, the built-in for incrementing numbers.

Thanks for the explanation and for the h hint @Steven H. There are so many built-ins I guess it just takes some time to find them all :)

No problem! If you ever need any help, try pinging me in the Nineteenth byte.

Perl, 14 + 3 (-lF flag) = 19 17 bytes
For 5.20.0+:
perl -lF -E 'say@F[0..@F/2]'

For 5.10.0+ (19 bytes):
perl -nlaF -E 'say@F[0..@F/2]'

Ungolfed:
while (<>) {             # -n flag (implicitly sets by -F in 5.20.0+)
    chomp($_)            # -l flag
    @F = split('', $_);  # -aF flag (implicitly sets by -F in 5.20.0+)
    say(@F[0 .. (scalar(@F) / 2)]);
}

Thanx to @simbabque.

You can save two bytes, you don't need to set -n and -a because -F does so implicitly.

@simbabque Yes. But for 5.20.0+ only.

Befunge, 24 22 bytes
~:0`!#v_\1+
0:-2,\_@#`

Try it online!

Befunge has no string or array type so the everything is done on the stack one character at a time. The first loop (on the top line) counts the number of characters read (swapping with less than 2 elements in the stack produces an initial 0). The second (on the middle line) prints characters while counting down twice as fast. As a result only the last half of the input is printed, but LIFO so it's in the correct order.
Thanks to Brian Gradin for a better version of the first loop.

You beat me by half an hour and 7 bytes :)
http://befunge.tryitonline.net/#code=K346MGAhI3ZfXDEKLzIrJTI6JDx2Cl9AIzotMSxcPA&input=Y29kZWdvbGZsb2dlZG9j

@BrianGradin, nice. now I've beat beat you by 9 bytes ;)

Ah, ok. I see what you did. Didn't occur to me to count down by two rather than calculate the actual number of characters to print. Nicely done.

C, 31 30 bytes
Saving 1 byte thanks to Cyoce.
f(char*c){c[-~strlen(c)/2]=0;}

Usage:
main(){
 char a[]="hellolleh";
 f(a);
 printf("%s\n",a);
}

@KevinCruijssen fixed

Hi, sorry I deleted my comment. I was correct in saying it won't work for even palindromes. But, since this is the reverse of that other challenge, there won't be any test cases for even palindromes.. Sorry about that, you can undo your change. +1 from me. :)

Well, it has the same length now, works for even+odd and looks golfier. I am okay with this.

This is arguably a memory leak :-)

@ShreevatsaR In case it was a malloc'ed string, the memory manager does not know if it is a string or anything else, so the free would free everything

Good point! (We're keeping around memory during the program's execution that we don't need, but you're right that when the string is freed, all of its memory is freed.)

I think you can remove the space in char* c

@Cyoce Yes i can, thank you!

Does setting the middle character to zero delete the rest of the string? (Not too familiar with C)

@Cyoce A string in C is delimited by a \0, so printing it afterwards yields only the first half. Technically, the tail is still present, but all string related functions only count up to the \0.

Actually, 5 bytes
l½KßH

Try it online!
-1 byte thanks to Sherlock9
Explanation:
l½K@H
l½K    ceil(len(input)/2)
   ßH  first (len(input)//2 + 1) characters of input

6 bytes: ;l½K@H :D

Perl, 23 + 2 (-pl flag) = 28 25 bytes
perl -ple '$_=substr$_,0,1+y///c/2'

Ungolfed:
while (<>) {             # -p flag
    chomp($_)            # -l flag
    $_ = substr($_, 0, 1 + length($_) / 2);
    print($_, "\n")      # -pl flag
}

Thanx to @ardnew.

you can save 3 chars by replacing length() with y|||c

Brainfuck, 20 bytes
,
[
  [>,]
  <[<]
  >.,>[>]
  <<
]

Try it online.
This saves a byte over the more straightforward approach of consuming the input before starting the main loop:
,[>,]
<
[
  [<]
  >.,>[>]
  <,<
]

Python 2, 23 bytes
lambda x:x[:len(x)/2+1]

I think this requires Python 2; you should indicate that in your answer

@LuisMendo oh, thanks!

MATLAB / Octave, 20 19 18 16 bytes
1 byte off borrowing an idea from Easterly Irk's answer (add 1 instead of .5)
2 bytes off thanks to @StewieGriffin (unnecessary parentheses)
@(x)x(1:end/2+1)

Try it at Ideone.

@StewieGriffin Thanks! I don't know what I was thinking...

Neither do I :P It's not like it's a "trick" you didn't know about... I've had a few of those too :)

GO, 43 bytes
func(s string)string{return s[:len(s)/2+1]}
Try it online!

Python 2, 22 bytes
lambda _:_[len(_)/2:]

Depalindromizes a given string. Still fails on all the test cases. Weird... ;-)

Welcome to PPCG! However, I get edcba instead of abcde when I give the string abcdedcba. Please fix this.

You can actually fix it by changing len(_)/2: to :-~len(_)/2.

@Oliver It is depalindromized ;p I'll fix it ASAP.

Racket 48 bytes
(substring s 0(+ 1(floor(/(string-length s)2))))

Ungolfed:
(define (f s)
  (substring s 0 (+ 1
                    (floor
                     (/ (string-length s)
                        2)))))

Testing:
(f "abcdedcba")
(f "johncenanecnhoj")
(f "ppapapp")
(f "codegolflogedoc")

Output:
"abcde"
"johncena"
"ppap"
"codegolf"

CJam, 7 bytes
r_,-2/<

Try it online!

C# 51 50 bytes
s=>string.Join("",s.Where((_,i)=>i<=s.Count()/2));

It's a lambda, woo!
You can catch it with:
Func<string,string> f=<your lambda here>

it requires the string to be a palindrome.

Pyke, 4 bytes
le>_

Try it here!
l    -    len(input)
 e   -   ^//2
  >  -  input[^:]
   _ - reversed(^)

IBM/Lotus Notes Formula, 21 bytes
@Left(a;@Length(a)/2)

Computed field that takes input from an editable field a. Works because Notes rounds up when an odd number is divided by 2.
Test Cases

Retina, 24 bytes
I basically took this from another answer of mine.
^((.)*?.??)(?<-2>.)*$
$1

Try it online

Python 3.5, 87 Bytes
x=list(input())
for q in range(0,int(round((len(x)/2)-0.1,0))):x.pop()
print(''.join(x))

i'm new to this codegolfing, but it's to be fun. I probably won't win but oh well.

Welcome to PPCG!

Hexagony, 56 bytes
This is awful, but I just wanted to do it in Hexagony :)
Golfed:
,<_..){/"./..\&..$@....>;{.....'..>"+"+"&"='&'&=}\}=.:(<

In a hexagon:
     , < _ . .
    ) { / " . /
   . . \ & . . $
  @ . . . . > ; {
 . . . . . ' . . >
  " + " + " & " =
   ' & ' & = } \
    } = . : ( <
     . . . . .

Way to many no-ops...

><>, 7 15 bytes
l1+2,[v
 ;!?lo<

Try it here!
This is a full program. To use it simply place the palindrome on the stack, and the result will be outputted to stdout!
Explanation
l       get the stack length
 1+     add one
   2,   divide by two
     [  pop the value, create a new stack of that length

That's the meat of it, ol?!; just outputs until the stack is empty.
*><>, 11 bytes (non-competing)
l5+2,]r{[$.

Try it here! (first line is a program that calls the function, outputs the stack, then exits)
This is a function. To use it simply call it (instruction C) with the palindrome on the stack, and the result will be on the stack! This part is non-competing because *><> is younger than the challenge.
Explanation
l             get the stack length
 5+           add five
   2,         divide by two
     ]        close the stack
      r       reverse the stack
       {      shift the stack left
        [     pop the value on the end, create a new stack of that length
         $    swap the two values on the end of the stack
          .   jump back, with the result on the stack

For ><> coders who might be confused by this, a new stack is created when a function is called, so you can actually call ] right from the start if you're inside a function. The data inside this stack is the x, y coordinate of the ><> when C was called.

Keg, 7 bytes
^(!2/|_

That is easy but really hard to golf.
Explanation
^       # Input in the right order
 (!2/   # Repeat half of length times:
     |_ # Pop the stack

TIO

R, 35 bytes
substr(x<-scan(,''),1,nchar(x)/2+1)

Try it online!

Vyxal, 2 bytes
½h

Try it Online!
Makes a list of each half of the string and takes the first item. Vyxal rounds up when splitting odd numbers in half. Don't think this can be golfed to 1 byte because the code can't be a palindrome :p

Ruby, 21 19 bytes
->s{s[0..s.size/2]}

you can use size

Haskell, 27 bytes
f[x]=[x]
f(a:b)=a:f(init b)

No indexing. Recursively takes from the start and end, keeping letters from the end.

Perl 6, 21 bytes
*.substr(0,1+* div 2)

Expanded:
*\            # Whatever lambda
.substr(
  0,
  1 + * div 2 # Whatever lambda
)

Dyalog APL, 9 bytes
⊢↑⍨2÷⍨1+⍴

Thanks to  Adám for saving 4 bytes.

I just saw your answer now. You should know that constants are allowed as the left tine of a fork, so 2÷⍨ works. Since constants are only allowed as left tine, you can swap the arguments of commutative functions to make them permitted, so 1+⍴ works. For non-commutative functions, use ⍨.

Scala, 21 bytes
a=>a.take(a.size/2+1)

requires an assignment with a type annotation: val f:(Seq[_]=>Seq[_])...

Clojure, 30 bytes
Clojure port of basically every answer here:
#(subs % 0(inc(/(count %)2)))

Should be self explanatory.

Java 8, 33 bytes
Same logic as @Numberknot, but with 24 less bytes due to the use of lambdas. I tried to add this as an update to @Numberknot but with no response therefore I posted this as a separate answer since it's a big difference in bytes between his and my answer.
s->s.substring(0,s.length()/2+1);

Ungolfed version:
interface Func { String foo(String s); }

public class Main
{
    public static void main(String[] args)
    {
        Func s = s->s.substring(0,s.length()/2+1);
    }
}

why -1? The other Java answers are pretty much the same only written in Java 7. Java 8 with the use of lambdas makes the answer shorter.

Probably because it looks like you just copied @Numberknot's answer, without giving him any credit...

QBIC, 18 bytes
;?left$$|(A,_lA|/2)

; gets a command line parameter, then we print the left half of it using _l. Works fine for even and odd-length strings.

Lua, 28 bytes
x=...print(x:sub(1,#x//2+1))

Common Lisp, 43
(lambda(s)(subseq s 0(ceiling(length s)2)))

Truly hard to golf without accidentally writing a palindrome, will all those ( matching opposite ).
I know, this is not what "palindrome" means.

Element, 11 bytes
_2:$'[(`)#]

Try it online!
_2:$'[(`)#]
_             take input
 2:           make a second copy
   $          length of string
    '[    ]   FOR loop
     [(`  ]   chop off then print the first character
     [  )#]   chop off then discard the last character

The FOR loop is actually executed about twice as many times as it needs to be, but those extra iterations do not affect the output since it runs out of data to print.

Brain-Flak, 45 bytes
([][()]<>){({}[()()])<>{}<>}<>{({}<>)<>}<>

Try it online!
42 bytes of code, and +3 for the -c flag which enables ASCII input and output.

Python 3,  28 26 24 bytes
Python 3 strings don't like non-int indexes...
lambda S:S[:len(S)//2+1]

Alternatively, with the same byte count,
lambda S:S[:-~len(S)//2]

I think you can use one / for the second one

@Farhan.K no - in py3, / creates a float which is not a valid index, so floordiv (//) has to be used. The single slash, however, works in python 2

Oh right, didn't see that it was python 3 :)

Java 7, 57 bytes
String c(String s){return s.substring(0,-~s.length()/2);}

At first I misinterpreted the question and also made code that supported even palindromes (which isn't necessary due to this being the reverse of that other challenge, and therefore there aren't any even palindrome test-cases). So I deleted my answer.
After seeing @KarlNapf's great answer however, I undeleted and edited this. It's the same byte count as the other Java 7 answer, but works for both odd and even length palindromes (although only odd were asked for this challenge).
Ungolfed & test code:
Try it here.
class M{
  static String c(String s){
    return s.substring(0, -~s.length()/2);
  }

  public static void main(String[] a){
    System.out.println(c("abcdedcba"));
    System.out.println(c("abcddcba"));
  }
}

Output:
abcde
abcd

i post it before you and this time i beat you

@Numberknot It fails on palindromes of even length though. :) "abcddcba" outputs abcdd instead of abcd.

@Numberknot Nevermind, I'm an idiot. Although I'm correct in saying it doesn't work for even palindromes, since this is the reverse of that other challenge, there won't be any test cases for even palindromes. I'll delete my answer..

Python 3, 26 bytes
lambda c:c[:(len(c)+1)//2]

This squeezes 2 chars out of the other Python3 answer by replacing the int() with division with //.

You could replace len(c)+1 with -~len(c) and remove the parentheses

or len(c)//2+1 as I did in my solution

R, 59 bytes
Not pretty but it gets the job done.
cat(strsplit(scan(,""),"")[[1]][0:(nchar(x)%/%2)+1],sep="")

GolfSharp, 20 bytes
v=>v.R(0,v.L()/2+1);

PowerShell, 46 36 bytes
Unfortunately there's no PowerShell on Try it Online. Alas, here's my attempt.
$args[0][0..(($args[0].Length-1)/2)]

This seems to print the characters on different lines. https://tio.run/nexus/powershell#@6@SWJReHG0QG22gp6ehAePp@aTmpZdk6Bpq6htpxv7//z85PyU1PT8nLSc/PTUlPxkA Or am I doing something wrong?

Yeah, it does. As far as the rules go this should be fine though.

R, 35 bytes
Always late to the party.
substr(x<-scan(,""),1,nchar(x)/2+1)

Ruby, 20 bytes
->n{n[0,-~n.size/2]}

anonymous lambda that returns the first half (rounded up) of a string. The -~n is a 1+n with a higher priority than the division by two, so I don't need any parentheses. Unlike the other Ruby solution, this works on strings with even lengths.
Usage:
->n{n[0,-~n.size/2]}["abba"]
->n{n[0,-~n.size/2]}["abcba"]
->n{n[0,-~n.size/2]}["a"]

Returns:
"ab"
"abc"
"a"

C#, 26 bytes
s=>s.Remove(s.Length/2+1);

This removes the end of the string.

OIL, 61 bytes
5
0
12
0
26
1
26
24
14
div
0
24
1
0
19
8
19
13
27

0
4
0
3

2

This uses the div from the standard library.

Japt, 5 bytes
¯ÒUÊz

Try it here

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Count without 3
Background
When I was in elementary school, we used to play a game in math class that goes as follows.
All kids sit in a big circle and take turns counting, starting from 1.
However, the following numbers must be skipped while counting:

Numbers that are multiples of 3.
Numbers that have a 3 in its decimal representation.

The first 15 numbers the kids should say are
1 2 4 5 7 8 10 11 14 16 17 19 20 22 25

Whenever somebody gets a number wrong – says a number that isn't in the sequence or skips a number that is – he's removed from the circle. This goes on until there's only one kid left.
Task
You're bad at this game, so you decide to cheat. Write a program or a function that, given a number of the sequence, calculates the next number of the sequence.
You don't have to handle numbers that cannot be represented using your language's native numeric type, provided that your program works correctly up to input 251 and that your algorithm works for arbitrarily large inputs.
Input and output can use any convenient base.
Since you have to conceal your code, it must be as short as possible. In fact, this is code-golf, so the shortest code in bytes wins.
Test cases
  1 ->   2
  2 ->   4
 11 ->  14
 22 ->  25
 29 ->  40
251 -> 254

I feel like we had a challenge like this...

Goddangit the fricking rationale.

It was always 7 that was skipped when I played it, but you'd say something else, instead, rather than going to the next number in line.

@mbomb007 Different countries, different games. :)

Related

@mbomb007: When I played it, you would not be removed from the circle. Instead, you would drink. But that wasn't in the elementary school. Anyway, getting over 80 was near impossible, especially after the first hour.

@tomasz Seems like proof that drinking is bad for your intelligence.

@mbomb007 Depends on the blood alcohol concentration.

@mbomb007: That would depend on the proof of whatever you are drinking.

Related. I am not aware of the existence of this question when I posted that.

can I begin in 1->1?

@sergiol The input is the previous number, not an index.

Counting without 3… I feel like it's favorite Valve's game.

Brachylog, 10 bytes
<.='e3:I'*

Try it online!
Explanation
(?)<.                Output > Input
    .=               Assign a value to the Output
    . 'e3            3 cannot be an element of the Output (i.e. one of its digits)
        3:I'*(.)     There is no I such that 3*I = Output

Answers like this are so beautiful in Brachylog :)

@Emigna It almost doesn't feel golfy enough sometimes because it basically describes the challenge directly. That's the case for a lot of answers in that language :)

JavaScript (ES6), 30 bytes
f=n=>++n%3*!/3/.test(n)?n:f(n)

Both index 2 and index 3 return the number 4 with this function

@nl-x Yes, because 4 is the next number in the sequence after both 2 and 3. It's not indexed; it's simply the next number in the sequence.

I think I'm starting to understand it... My bad

J, 24 bytes
3(]0&({$:)~e.&":+.0=|)>:

Straight-forward approach that just iterates forward from input n until it finds the next number that is valid by the rules.
Forms five smileys, $:, :), 0=, =|, and >:.
Usage
   f =: 3(]0&({$:)~e.&":+.0=|)>:
   (,.f"0) 1 2 11 22 29 251
  1   2
  2   4
 11  14
 22  25
 29  40
251 254

Explanation
3(]0&({$:)~e.&":+.0=|)>:  Input: integer n
                      >:  Increment n
3                         The constant 3
 (                   )    Operate dyadically with 3 (LHS) and n+1 (RHS)
                    |       Take (n+1) mod 3
                  0=        Test if equal to 0
             &":            Format both 3 and n+1 as a string
           e.               Test if it contains '3' in str(n+1)
                +.          Logical OR the results from those two tests
  ]                         Right identity, gets n+1
   0&(   )~                 If the result from logical OR is true
       $:                     Call recursively on n+1
      {                       Return that as the result
                            Else act as identity function and return n+1

Well, J is probably the most smiley-prone programming language.

Python 2, 73 66 43 bytes
Thanks to xnor for telling me I was being silly by using 2 variables, and thanks to Mitch Schwartz too.
x=~input()
while'3'[:x%3]in`x`:x-=1
print-x

The two-variable updating looks much too complicated. I think you just need x=input()+1
while'3'[:x%3]in`x`:x+=1
print x.

@xnor, oh yeah silly me I don't know why I did that

One byte improvement by starting with x=~input(), subtracting instead of adding, and printing -x.

@MitchSchwartz, oh thanks!

Best edit ever.

@Dopapp Since you're counting backwards, did you mean x-=1? Right now, 2 outputs 2 when it's meant to output 4

@Artyer That's only 1 of the 3 mistakes introduced in that edit.

@MitchSchwartz, are the mistakes that x+=1 should be x-=1 and print-x should be print -x. And your name. That was autocorrect.

@Dopapp print-x works for me

@Artyer, so what's the third mistake?

@Dopapp The current revision (Without the space) is 43 bytes? https://mothereff.in/byte-counter#x%3D~input%28%29%0Awhile%273%27%5B%3Ax%253%5Din%60x%60%3Ax-%3D1%0Aprint-x

Perl, 19 bytes
18 bytes code + 1 for -p.
++$_%3&&!/3/||redo

Usage
perl -pe '++$_%3&&!/3/||redo' <<< 8
10

perl -pe '++$_%3&&!/3/||redo' <<< 11
14

@dan1111 It's Perl, what did you expect? Clarity?

@EriktheGolfer what?  This is the very definition of "self-documenting code".

@dan1111 It seems you know Perl. I have no idea of how Perl works, because of its famous weirdness.

@dan1111 Thanks! Quite happy with how short it turned out!

@EriktheGolfer I don't know what you mean! I've heard people describe Perl as write only code, but surely not this... :D

@DomHastings Well, in PPCG, we take Perl as the top level of weirdness, and Jelly/Actually/O5AB1E as the top level of mess. It seems that you haven't ever seen this challenge then :)

You can save 1 byte if you use * instead of &&: Try it online!

05AB1E, 11 bytes
[>Ð3ås3Ö~_#

Try it online!
Explanation
               # implicit input
[              # start loop
 >             # increase current number
  Ð            # triplicate
          #    # break loop IF
         _     # logical negation of
   3å          # number has one or more 3's in it
        ~      # OR
     s3Ö       # number % 3 == 0

Java 8, 57 56 55 50 bytes
Thanks to @Numberknot for 1 byte
Thanks to @Kevin Cruijssen for 5 bytes
i->{for(;++i%3<1|(i+"").contains("3"););return i;}

This is a Function<Integer, Integer>
Explanation
Naive implementation that simply increments until it reaches an acceptable number.
Test Class
public class CodeGolf {

    public static void main(String[] args) {
        Function<Integer, Integer> countingGame = i->{for(;++i%3<1|(i+"").contains("3"););return i;};
        int val = 1;
        for (int i = 0; i < 10; i++) {
            System.out.print(val + " ");
            val = countingGame.apply(val);
        }
    }

}

Output of Test Class:
1 2 4 5 7 8 10 11 14 16

You can use | instead of ||

@Numberknot I had no idea bitwise operators functioned as logical ones in some contexts! Thanks!

Why the do-while? Just a regular for-loop is shorter: i->{for(;++i%3<1|(i+"").contains("3"););return i;} (50 bytes)

@KevinCruijssen Well... I thought of comparing while and do-while, and they both gave me the same score, but I liked the way do-while looked... I didn't think of using a for loop... Thanks!

Python 2, 49 44 42 bytes
f=lambda x:'3'[:~x%3]in`~x`and f(x+1)or-~x

The other Python entry beats this (edit: not any more :-D), but I posted it because I rather like its recursive approach.
Thanks to Mitch Schwarz and Erik the Golfer for helping me make this shorter.

You can do this in Python 2: f=lambda x:f(x+1)if x%3>1or'3'in`x+1`else-~x. If you want to keep Python 3, you can golf the last x+1 to -~x and remove the space.

@EriktheGolfer Thanks! I'll change it to Python 2, as it's way shorter.

42s: f=lambda x:'3'[:~x%3]in\~x`and f(x+1)or-~xandf=lambda x:f(x+1)if'3'[:~x%3]in`~x`else-~x`

Japt, 18 bytes
°U%3*!Us f'3 ?U:ßU

Test it online
I finally have a chance to use ß :-)
How it works
                    // Implicit: U = input integer
°U%3                // Increment U, and take its modulo by 3.
     !Us f'3        // Take all matches of /3/ in the number, then take logical NOT.
                    // This returns true if the number does not contain a 3.
    *               // Multiply. Returns 0 if U%3 === 0  or the number contains a 3.
             ?U     // If this is truthy (non-zero), return U.
               :ßU  // Otherwise, return the result of running the program again on U.
                    // Implicit: output last expression

PowerShell v2+, 46 bytes
for($a=$args[0]+1;$a-match3-or!($a%3)){$a++}$a

Takes input $args[0], adds 1, saves into $a, starts a for loop. The conditional keeps the loop going while either $a-match3 (regex match) -or $a%3 is zero (the ! of which is 1). The loop simply increments $a++. At the end of the loop, we simply place $a on the pipeline, and output via implicit Write-Output happens at program completion.
Examples
PS C:\Tools\Scripts\golfing> 1,2,11,22,29,33,102,251,254|%{"$_ --> "+(.\count-without-three.ps1 $_)}
1 --> 2
2 --> 4
11 --> 14
22 --> 25
29 --> 40
33 --> 40
102 --> 104
251 --> 254
254 --> 256

R, 46 bytes
n=scan()+1;while(!n%%3|grepl(3,n))n=n+1;cat(n)

I think that returning a value (rather than printing to stdout) is allowed, so you can save 5 bytes by having just n instead of cat(n).

Haskell, 50 48 bytes
f n=[x|x<-[n..],mod x 3>0,notElem '3'$show x]!!1

Try it on Ideone. Saved 2 bytes thanks to @Charlie Harding.
Alternative: (50 bytes)
g=f.(+1)
f n|mod n 3<1||(elem '3'.show)n=g n|1<3=n

Also 50 bytes: until(\x->mod x 3>0&&notElem '3'(show x))succ.succ.

Labyrinth, 117 102 bytes
?       """""""""""_
):_3    (         0/{!@
;  %;:}_';:_3-_10 1
"  1            %;_
""""_""""""""{;;'

Try it online!
Labyrinth is a two-dimensional, stack-based programming language and at junctions, direction is determined by the top of the stack (positive goes right, negative goes left, zero goes straight). There are two main loops in this programs. The first mods the integer input by 3 and increments if 0. The second repeatedly checks if the last digit is 3 (by subtracting 3 and modding by 10) and then dividing by 10 to get a new last digit.

Lua, 58 Bytes
i=...+1while(i%3==0or(i..""):find"3")do i=i+1 end print(i)

Pyke, 13 bytes
Whii3%!3`i`{|

Try it here!
              - i = input
W             - do:
 hi           -  i += 1
   i3%!       -    not (i % 3)
            | -   ^ or V
       3`i`{  -    "3" in str(i)
              - while ^

At first I though this said while at the beginning.

If you glance at it I can see that

C#, 56, 51 bytes.
This is surprisingly short for a C# answer!
x=>{while(++x%3<1|(x+"").Contains("3"));return x;};

You can get it down to 43 if you make it recursive t=x=>(++x)%3<1|(x+"").Contains("3")?t(x):x;  In Visual Studio, you just need to define the variable and set it to null Func<int, int> t = null; and then define the recursive function on the following line.

The problem is that if I make it recursive, I then have to count the function and type definitions.

Is there somewhere I can go to see these guidelines?  I find C# golfing confusing on here.

@Grax Basically, you need to include any code required for the code to run except the assignment to a name in the case of a non-recursive function. I don't know where you would find a concrete set of guidelines, unfortunately.

@MorganThrapp please check out my c# answer with recursion at 49 bytes :)

Pyth, 11 bytes
f&-I`T3%T3h

Try it online: Demonstration or Test Suite
Explanation:
f&-I`T3%T3hQ   implicit Q at the end
f         hQ   find the smallest integer T >= input + 1 which fulfills:
  -I`T3           T is invariant under removing the digit 3
 &                and
       %T3        T mod 3 leaves a positive remainder

Excel, 79 66 bytes
It Taylor Rained 13 bytes
=MIN(LET(r,ROW(A:A),FILTER(r,ISERR(FIND(3,r))*MOD(r,3)*(r>A1)>0)))

Input is in the cell A1. Output is wherever the formula is.
The LET() function allows you to define variables for later reference so ti works in pairs of variable,value. The last argument is unpaired as it is the output.

r,ROW(A:A) creates an array of 1 to whatever the last row is. In the latest version of Excel, that's 1,048,576.
g,FILTER(r,~*~*~>0) takes that array and filters just for the values that aren't multiples of 3 and don't have a 3 in them. This done is by multiplying:

ISERR(FIND(3,r)) which returns TRUE if if a 3 is not in the number and FALSE if it is
MOD(r,3) which returns 0 if it's a multiple of 3 and some positive integer if it isn't
(r>A1) creates an array of TRUE / FALSE where the first TRUE value will be the first term that's larger than the input.
When you do math on booleans, Excel uses TRUE=1 and FALSE=0 so the formula ~*~*~>0 only returns TRUE when the three pieces are TRUE (no 3 in number), some positive integer (not a multiple of 3), and TRUE (larger than the input).

MIN(LET(~)) finds the smallest value in the filtered array which only includes the "without 3" numbers larger than the input so the first value in the array is the next value in the sequence.

Would =MIN(LET(r,ROW(A:A),FILTER(r,ISERR(FIND(3,r))*MOD(r,3)*(r>A1)>0))) work for all tests?

Nice, not sure if appreciated but for 64 bytes you can use: =LET(r,ROW(A:A),MATCH(1,ISERR(FIND(3,r))*(MOD(r,3)>0)*(r>K1),0))

Python 3, 49 48 bytes
-3 bytes thx to The Thonnu, I missed some spaces and swapping else x+1 and else-~x allowed another space to be taken out, not
+2 bytes bc I didn't know I need to count f= on a recursive function, thx xnor :)
seems clunky but i cant see more golfs, please lmk if you see something!
f=lambda x:f(x+1)if x%3>1or'3'in str(x+1)else-~x

Try it online!

I think you can remove the spaces between 1 or and str(x+1) else

46 bytes

You need to count the f= because your function is recursive.

MATL, 14 bytes
`Qtt3\wV51-hA~

Try it online!
Explanation
`       % Do...while
  Q     %   Add 1. Takes input implicitly in the first iteration
  tt    %   Duplicate twice
  3\    %   Modulo 3
  wV    %   Swap, string representation
  51-   %   Subtract 51, which is ASCII for '3'
  h     %   Concatenate
  A~    %   True if any result was 0. That indicates that the number
        %   was a multiple of 3 or had some '3' digit; and thus a
        %   new iteration is needed

GolfSharp, 43 bytes
m=>r(m,m).w(n=>n%3>0&!n.t().I("3")).a()[1];

PHP, 60 55 54 46 bytes
Thanks to @user59178 for shaving off a few bytes, @AlexHowansky for a byte, @Titus for another few bytes
for(;strstr($i=++$argv[1],51)|$i%3<1;);echo$i;

Called from command line with -r. Naive method that loops while the number is a multiple of 3, or has 3 in its digits.

You can save 7 bytes by just using a program taking input from the command line rather than a function: for($i=$argv[1];!(++$i%3)|strpos(" $i",'3'););echo$i; it may be possible to do better by assigning $i while using it too.

@user59178 I assumed the function had to return $i

most of the time questions are pretty flexible in how  input and output is done, as long as the right thing is given and received. Besides, looking at answers in other languages, most choose to print to stdout.

Save a byte with strpos(_.$i,'3')

Save one byte with %3<1, one with 51 instead of '3', two more with strstr($i) instead of strpos(_.$i) and another two by swapping the | operands in the second version: <?for(;strstr($i=++$argv[1],51)|$i%3<1;);echo$i; -> 48 bytes

Ruby, 47 bytes
i=gets.to_i;i while(i+=1)%3==0||"#{i}"=~/3/;p i

I really feel like this can be golfed further.

you can use i instead of "#{i}"

Jelly, 11 bytes
D;Æf3ḟµ‘#2ị

Try it online!
How it works
D;Æf3ḟµ‘#2ị  Main link. Argument: n

      µ      Combine the links to the left into a chain.
       ‘#    Execute the chain for k = n, n + 1, n + 2, ... until n + 1 matches
             were found. Yield the array of all n + 1 matches.
D            Decimal; yield the array of k's decimal digits.
  Æf         Yield the array of k's prime factors.
 ;           Concatenate both.
    3ḟ       Filter false; remove digits and factors from [3].
             This yields [3] (truthy) if neither digits nor factors contain 3,
             [] (falsy) if they do.
         2ị  Extract the second match. (The first match is n.)

PHP, 47 41 bytes
inspired by Xanderhall, but the latest idea finally justifies an own answer.
while(strstr($n+=$n=&$argn%3,51));echo$n;

or
while(strpbrk($n+=$n=&$argn%3,3));echo$n;

This takes advantage from the fact that the input is also from the sequence: For $n%3==1, the new modulo is 2. For $n%3==2, the new modulo is 4-3=1. $n%3==0 never happens.
Run as pipe with -R or try them online.

Turing Machine Code, 390 bytes
0 * * r 0
0 _ _ l 1
1 1 2 l 2
1 2 3 r 0
1 3 4 l 2
1 4 5 l 2
1 5 6 l 2
1 6 7 l 2
1 7 8 l 2
1 8 9 l 2
1 9 0 l 1
1 * 1 l 2
2 * * l 2
2 _ _ r 3
3 1 1 r 4
3 4 4 r 4
3 7 7 r 4
3 2 2 r 5
3 5 5 r 5
3 8 8 r 5
3 _ _ l 1
4 1 1 r 5
4 4 4 r 5
4 7 7 r 5
4 2 2 r 3
4 5 5 r 3
4 8 8 r 3
5 1 1 r 3
5 4 4 r 3
5 7 7 r 3
5 2 2 r 4
5 5 5 r 4
5 8 8 r 4
* 0 0 r *
* 6 6 r *
* 9 9 r *
* 3 3 r 0
* _ _ * halt

Try it online.

Can you explain this answer?

@sintax Added some explanatory comments at the provided link.

Perl 6, 27 25 24 bytes
{max $_+1...{!/3/&$_%3}}

Try it online!
Finds the first number larger than the input that doesn't have a three and has a remainder when moduloed by 3. I was hoping to do something fancy with the condition, like !/3/&*%3 but it doesn't work with the !. :(
Explanation:
{                      }   # Anonymous code block
     $_+1                  # From the input+1
         ...               # Get the series
            {         }    # That ends when
             !/3/            # The number does not contain a 3
                 &           # and
                  $_%3       # The number is not divisible by 3
 max                       # And get the last element of the series

APL (Dyalog Unicode), 33 28 27 19 bytesSBCS
1∘+⍣{('3'∊⍕⍺)<×3|⍺}

Try it online!
-6 thanks to Adám. -8 thanks to ngn.
Old Explanation:
1-⍨g⍣((×3|⊢)>'3'∊⍕)∘(g←+∘1)
                       +∘1  ⍝ curry + with 1, gives the increment function
                            ⍝ increments the left argument so we do not return the number itself
                    (g←   ) ⍝ assign to "g"
                   ∘        ⍝ compose g with the repeat
                 ⍕          ⍝ does parsing the argument to a string...
             '3'∊           ⍝ ...contain '3'?
        3|⊢                 ⍝ residue of a division by 3
      (×   )                ⍝ direction (0 if 0, 1 if greater, ¯1 is lower)
     (      >     )         ⍝ and not (we want the left side to be 1, the right side 0)
   g⍣                       ⍝ repeat "g" (increment) until this function is true ^
1-⍨                         ⍝ afterwards, decrement: inversed -

APL (Dyalog Extended), 23 17 bytesSBCS
1∘+⍣(3(×⍤|>∊⍥⍕)⊣)

Try it online!
Thanks to Adám. -6 thanks to ngn.
Old Explanation:
0+⍣(3(×⍤|>∊⍥⍕)⊢)⍢(1+⊢)⊢
0                       ⍝ the left argument (⍺)
 +⍣(3(×⍤|>∊⍥⍕)⊢)        ⍝ the left function (⍺⍺)
                 (1+⊢)  ⍝ the right function (⍵⍵)
                        ⍝     (increments its argument)
                      ⊢ ⍝ the right argument (⍵)
                        ⍝     (just returns the input)
                ⍢       ⍝ under:
                        ⍝     calls (⍵⍵ ⍵) first, which increments the input
                        ⍝     also (⍵⍵ ⍺) which gives 1
                        ⍝     then calls (⍺incremented ⍺⍺ ⍵incremented)
                        ⍝     afterwards, does the opposite of ⍵⍵, and decrements the result
  ⍣                     ⍝ ⍣ fixpoint: repeats the left operation until the right side is truthy
 +                      ⍝ calls + with ⍺incremented and the input (so, 1+input)
   (3(×⍤|>∊⍥⍕)⊢)        ⍝ right operation
    3                   ⍝ on its left, "3"
              ⊢         ⍝ on its right, the current iteration
      ×⍤|               ⍝ divisibility check: × atop |
        |               ⍝     starts with 3|⊢ (residue of ⊢/3)
      ×                 ⍝     then returns the direction (0 if 0, 1 if greater, ¯1 is lower)
          ∊⍥⍕           ⍝ contains 3:
            ⍕           ⍝    stringifies both its arguments (3 and ⊢)
          ∊⍥            ⍝    checks for membership
         >              ⍝ divisibility "and not" contains 3

APOL, 51 bytes
v(0 +(⧣ 1));w(|(!(%(⁰ 3)) c(t(⁰) '3')) ∆(0));-(⁰ 1)

Swift, 84 bytes
func f(_ n:Int)->Int{var n=n+1;while String(n).contains("3")||n%3==0{n+=1};return n}

Welcome to Code Golf, and nice first submission!

Clojure, 73 bytes
(fn c[n](let[m(inc n)](if(or(=(rem m 3)0)(some #(=\3 %)(str m)))(c m)m)))

Recursively loops while n is divisible by 3, or contains a 3 in its string representation. Although I'm using unoptimized recursion, it was able to handle 2999999 as an input, so it should be ok.
Ungolfed
(defn count-without-3 [n]
  (let [m (inc n)]
    (if (or (= (rem m 3) 0)
            (some #(= \3 %) (str m)))
      (count-without-3 m)
      m)))

C, 81 bytes
f(int n){int m;l:if(++n%3){for(m=n;m>0;m/=10)if(m%10==3)goto l;return n;}goto l;}

reticular, 30 bytes
in v
?v$>1+d3,qds:3@cQm*
;\$o

Try it online!
Explanation
1: initialization
in v

This converts the input to a number, then goes down (v)
2: loop
?v$>1+d3,qds:3@cQm*
   >                 go right!              [n]
    1+               add 1                  [n+1]
      d3,            duplicate and mod 3    [n+1, (n+1)%3]
         qd          reverse and duplicate  [(n+1)%3, n+1, n+1]
           s         cast to string         [(n+1)%3, n+1, `n+1`]
            :3@c     count numbers of "3"   [(n+1)%3, n+1, `n+1`.count(3)]
                Qm*  negate and rotate      [n+1, continue?]
?v                   terminate if continue
  $                  drop continue

3: final
;\$o
 \$o  drop and output
;     terminate

JavaScript, 35 bytes
f=n=>++n%3&&!(n+"").match(3)?n:f(n)

Try it online!

I am not an expert in JavaScript but this doesn't look very golfed.  It looks like you have a lot of whitespace that could be removed.  You might want to check out the tips page for JavaScipt.

Ah, sorry, First time on this stackexchange. I thought this was just a problem to solve. Didn't realize there were rules. I wasn't sure what "golfed" meant.

No need to apologize.  All puzzles here have a "winning criterion", quite often, such as in this challenge, it is code golf.  If you want more general puzzles look into the [tag:programming-puzzle] tag.  Welcome to PPCG I hope you have fun.

"Golfed" means you try to make the program as small as possible. Then you compete against other users to get the shortest Javascript answer. I would read through this page and [edit] your post if you can come up with a shorter solution.

Batch, 93 bytes
@set/pn=
:l
@set/an+=1,r=n%%3
@if %r%==0 goto l
@if not "%n:3=%"=="%n%" goto l
@echo %n%

Takes input on STDIN.

CJam, 19 bytes
ri{)__3%!\`'3e=e|}g

ONLINE
Explanation:
ri{)__3%!\`'3e=e|}g
r                   Get token
 i                  Convert to integer
  {              }  Block
   )                 Increment
    _                Duplicate
     _               Duplicate
      3              Push 3
       %             Modulo
        !            NOT gate
         \           Swap
          `          String representation
           '3        Push '3'
             e=      Count occurrences
               e|    OR gate
                  g While popped ToS is true

If a less verbose explanation was asked, I would have done this:
ri{)__3%!\`'3e=e|}g
ri                  Get integer
  {              }  Block
   )                 Increment
    __               Triplicate
      3%!            Test non-divisibility with 3
         \           Swap
          `'3e=      Count occurrences of '3' in string repr
               e|    OR gate
                  g While popped ToS is true

Pyth, 19 bytes
JhQW|!%J3/`J\3=hJ;J

Test suite
I am sure I can golf this... it's the same as my CJam answer.
Explanation:
JhQW|!%J3/`J\3=hJ;J
  Q                 Evaluated input
 h                  Increment
J                   Assign J to value
       J            Variable J
        3           Value 3
      %             Modulo
     !              Logical NOT
           J        Variable J
          `         String representation
            \3      Value "3"
         /          Count occurrences
    |               Logical OR
               h    Increment
                J   Variable J
              =     Apply function then assign
                 ;  End statement block
                  J Variable J

I posted a way shorter solution. Nevertheless here is a tip for your approach: Don't use the variable J. You can increment Q. And if your doing it clever, you can inline the operation into the while condition: W|!%=hQ3/Q\3;Q`.

Sorry: W|!%=hQ3/`Q\3;Q

@Jakube The variable is not just incrementing but thanks.

Mathematica, 51 bytes
#+1//.t_/;t~Mod~3<1||!IntegerDigits@t~FreeQ~3:>t+1&

Try it online!

Stax, 9 bytes
ú╜H▌»NWì╤

Run and debug it
Unpacked, ungolfed, and commented it looks like this.
w       repeat rest of the program while the produced value is true
  ^c    increment and copy value
  E3#   (a) count number of digits that are 3
  n     copy incremented value
  3%!   (b) is multiple of 3?
  +     sum of (a) + (b) values

Run and debug this one

Japt, 12 bytes
_%3«Zsø3}a°U

Run it online

Ruby, 29 bytes
->n{0until"#{n+=n%3}"!~/3/;n}

Try it online!

Forth (gforth), 81 bytes
: f begin 1+ >r i i 3 mod 1 r> begin 10 /mod >r 3 <> * r> ?dup 0= until * until ;

Try it online!
Explanation

Add 1
check if multiple of 3
check if contains a 3
if the result of step 3 or step 4 is true, repeat from step 1

Code Explanation
: f               \ start a new word definition
  begin           \ start an indefinite loop
    1+            \ add 1 to current number
    >r i i        \ put current number on return stack, then place on normal stack twice
    3 mod         \ check if number is multiple of 3
    1 r>          \ place a 1 on the stack, then move the current number to the normal stack
    begin         \ start another indefinite loop
      10 /mod     \ get quotient and remainder of dividing by 10
      >r          \ put quotient on return stack
      3 <>        \ check if remainder does not equal 3
      *           \ multiply by accumulator (cheaper version of "and")
      r>          \ remove quotient from return stack
      ?dup 0=     \ if quotient does not equal 0, duplicate, else put -1 on stack
     until        \ end loop if top of stack does not equal 0
     *            \ multiply result of both checks (cheaper "and")
   until          \ end outer loop
 ;                \ end word definition

TI-BASIC, 36 35 bytes
Repeat fPart(Ans/3)max(3≠int(10fPart(Ans₁₀^(seq(-X-1,X,0,log(Ans:Ans+1:End:Ans

Input is in Ans.
Output is in Ans and is implicitly printed when the program completes.
Examples:
17
              17
prgmCDGFF
              19
299
             299
prgmCDGFF
             400

Explantion:
(Newlines added for readability.  They do not appear in the source code.)
Repeat                                              ;loop until...
  fPart(Ans/3)                                      ; the current number is not
                                                    ;  a multiple of 3
  max(3≠int(10fPart(Ans₁₀^(seq(-X-1,X,0,log(Ans     ; and until it does not
                                                    ;  contain any 3s
Ans+1                                               ;add 1 to the current number
End
Ans                                                 ;leave the current number
                                                    ; in "Ans" and implicitly
                                                    ; print it

Note:  TI-BASIC is a tokenized language.  Character count does not equal byte count.

-1 byte by removing the and (A and B ~ A*B = AB) [I think]

@MarcMush and is a 1-byte token, so AB would be the only byte save of the two suggestions (A*B vs AB).  Unless I misread your comment, in which AB would indeed be a byte saved.

yes, that's what I meant

Vyxal, 10 bytes
λ›D₃$3c∨[x

Try it Online!
It would be 9 bytes with ₌ (parallel apply), but that seems to clear the stack, so that didn't work.
How?
λ›D₃$3c∨[x
λ           # Open a lambda (for recursion)
 ›          # Increment
  D         # Triplicate, push three copies of a to the stack
   ₃        # Is it divisible by three?
    $       # Swap
     3c     # Does the number contain a three?
       ∨    # Is either of the top two things on the stack true?
        [x  # Then recurse

Julia 1.0, 34 bytes
!n='3'∈"$(n+=1)"||n%3<1 ? !n : n

Try it online!

Ruby, 39 bytes
f=->n{n+=1;(n%3<1||n.to_s=~/3/)?f[n]:n}

Try it online!

Thunno 2 +, 11 bytes
(D3Ḋsd3Ƈ|;⁺

Attempt This Online!
Explanation
(D3Ḋsd3Ƈ|;⁺  # Implicit input
             # Increment
(            # While loop
 D           # (condition)  Duplicate
  3Ḋ         #              Divisible by 3?
    s        #              Swap
     d       #              Digits
      3Ƈ     #              Contains 3?
        |    #              Logical OR
         ;⁺  # (body)  Increment
             # Implicit input

Go, 100 bytes
import(."strings";."fmt")
func f(n int)int{i:=n+1
for;i%3<1&&Contains(Sprint(i),"3");i++{}
return i}

Try it online!

Vyxal 3, 9 bytes
э∥3c3Ḋ∵¬Ẇ

Try it Online!

GNU sed -E, 148 bytes
Could be easier with a language with a modulo operator. Or division. Or counting. Or some idea about what numbers are. sed has neither, but it can solve the challenge much like a elementary school kid would:
s/^/0123456789-0/
:1
s/((.)(.).*)\2$/\1\3/
:2
s/((.)(.).*)\2-/\1\30/
t2
/-.*3/b1
h
:3
s/((.)(.).*-.*)\3/\1x\2/
s/x0*x0*x//
t3
/x/!{g;b1}
g
s/.*-0*//

Try it online!

Google Sheets, 63 bytes
=+let(n,sequence(254),filter(n,n>A1,mod(n,3),iserr(find(3,n))))

Put the input in cell A1 and the formula in B1.
The filter() gets all matching values above the value in A1 and the unary plus + gets the first value from that list.

C#, 49 bytes
int A(int n)=>(++n+"").IndexOf('3')*n%3<0?n:A(n);

Slightly different and shorter than the above c#, using recursion and another trick I came up with to condense the two conditions into one

Perl 6, 39 bytes
{my$a=$_+1;$a++while $a%%3||$a~~/3/;$a}

BotEngine, 770 107x7 = 749 (740 bytes)
This can almost certainly be made rather more compact than it currently is, but I finally managed to get it working at least.
v  0 1 2 3 4 5 6 7 8 9 $ $   0 1 2 3 4 5 6 7 8 9 $  0 1 2 3 4 5 6 7 8 9 $> 0 1 2 3 4 5 6 7 8 9 $v$ $3
I>>S S S S S S S S S S S>S$v>S S S S S S S S S S S >S S S S S S S S S S S >S S S S S S S S S S S>e>SS~v
R  e1e2e3e4e5e6e7e8e9e0e1>e ^e0e1e2e3e4e5e6e7e8e9e$ e0e1e2e3e4e5e6e7e8e9>^ e0e1e2e3e4e5e6e7e8e9>^  Re3  $
$e^                  < e$   ^<     <     <     <        <     <     <        <     <     <         P>  >S~v
>^ >>>>>>>>>>>>>>>>>>>>>^ ~<   >     >     >       ^<     <     <     <        <     <     <      ^   <^  <
                                 >     >     >        >     >     >       ^<     <     <     <          e$
  ^                                              <                                                      <

Input and output is in standard big-endian decimal, although most of the program uses little-endian internally to make the increment cycle more straightforwards.

MathGolf, 10 9 bytes
ö)_3‼╧÷+▲

Try it online!
Explanation
The program loops until it finds a number that is neither divisible by 3 or contains the number 3. ‼ is a new addition to MathGolf, and is newer than this challenge (and this answer). It has been an idea I had in mind for a while, but I finally got everything together to implement it.
ö           start block of length 7
 )          increment
  _         duplicate TOS
   3        push 3
    ‼       apply next two operators separately to the stack
     ╧      pop a, b, a.contains(b)
      ÷     is divisible
       +    pop a, b : push(a+b) (works as a logical OR)
        ▲   do while true with pop

APL(NARS), 54 chars, 108 bytes
r←h w;c
r←c←0
→3×⍳(0=3∣r)∨'3'∊⍕r⋄c+←1⋄→0×⍳r>w
r+←1⋄→2

I prefer this, the loop, to all recursive functions; test:
  h¨1 2 11 22 29 251
2 4 14 25 40 254
  h¨3 6 10
4 7 11

Binary-Encoded Golfical, 80 bytes
This binary-encoded format can be converted to the standard graphical version using the encoder utility included in the github repo, or run directly using the interpreter by adding the -x flag.
Hexdump of binary encoding:
01 70 03 15 14 14 1b 1a 14 04 01 14 14 2c 14 14
00 03 14 14 0a 01 14 14 2f 14 14 53 2d 14 23 1d
14 32 14 14 1b 14 1a 00 0a 14 14 0a 01 14 14 2f
14 14 53 31 14 06 03 14 14 23 1d 14 00 0a 14 14
0a 01 1c 14 2d 17 14 3d 2d 14 23 1d 14 1c 2c 1d

Original image (23x3):

Magnified 20x:

C, 59 bytes
n,m;f(){if(++n%3)for(m=n;m;m/=10)(m%10==3)?f():0;else f();}

Welcome to PPCG! Which compiler did you use to test this? I can't seem to get it working with gcc, tcc, or clang. Also, functions are required to take input using one of these method.

K (oK), 24 23 bytes
Solution:
(1+)/[{(~3!x)|51in$x};]

Try it online!
Explanation:
Iterate from input+1 until valid number is found. Bit of a cheat dropping whitespace between 51 and in.
(1+)/[{(~3!x)|51in$x};] / the solution
    /[{             };] / iterate (/) while {} is true
                  $x    / string x, e.g. 12 => "12"
              51in      / is "3" (51 in ASCII) in the string?
             |          / or
       (    )           / do this together
         3!x            / x modulo 3
        ~               / not
 1+                     / add 1 to x (e.g. x++)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Print a letter Fibonacci
Given N (2 <= N), print N lines of the letter Fibonacci series like this (i.e. N = 5)
First, start with a and b:
a
b

Next, add the two lines.
a
b
ab

Keep adding the last two lines.
a
b
ab
bab

Keep going...
a
b
ab
bab
abbab

And we're done.
Remember, this is code-golf, so the code with the fewest bytes wins.

Related

Can it be a function which returns a list of terms up to N?

Do we have to print the result or can we return a list of strings from a function?

Wait, so it doesn't have to work for n=1?

Also, can we use 0-based indexing?

@SocraticPhoenix The input isn't really an index, but the number of strings we should print.

@Dennis ahh... I misunderstood, there goes my solution :(

printing the entire sequence seems like a trivial addition to the challenge that doesn't add any substance to the questions. print element(n) would be much more desirable IMO

Python 2, 41 bytes
Saved 3 bytes thanks to @xnor
a,b="ab";exec"print a;a,b=b,a+b;"*input()

Test on Ideone
Simply follows the recursive definition.

This is shorter as a program: a,b="ab";exec"print a;a,b=b,a+b;"*input().

Might want to specify python 2 :)

Haskell, 29 35 32 bytes
a%b=a:b%(a++b)
(`take`("a"%"b"))

Simple recursion.
For reference: the old version (an adaption of this answer),
concatenated the strings in the wrong order, so I had to add a flip(...) which made it too long (35 bytes).
f="a":scanl(flip(++))"b"f
(`take`f)

The output is different from the example (different order in concatenation): ["b","a","ab","aba","abaab"]

@Angs: Oops what a mistake! Fixed.

05AB1E, 12 11 bytes
Thanks to Emigna for saving a byte!
'a='b¹GD=Š«

Uses the CP-1252 encoding. Try it online!

Íƒ could just as well be G as you're not using N :)

@Emigna Oh yeah, you're right! Thanks :)!

JavaScript (ES6), 43 42 bytes
Saved a byte thanks to @Arnauld
f=(n,a="a",b="b")=>n&&f(n-!alert(a),b,a+b)

Jelly,  11 10 bytes
”a”bṄ;¥@¡f

Try it online!
How it works
”a”bṄ;¥@¡f  Main link. Argument: n

”a          Set the return value to 'a'.
  ”b    ¡   Call the link to the left n times, with left argument 'b' and right
            argument 'a'. After each call, the right argument is replaced with the
            left one, and the left argument with the return value. The final
            return value is yielded by the quicklink.
      ¥       Combine the two atoms to the left into a dyadic chain.
    Ṅ           Print the left argument of the chain, followed by a linefeed.
     ;          Concatenate the left and right argument of the chain.
       @      Call the chain with reversed argument order.
         f  Filter the result by presence in n. This yields an empty string
            and thus suppresses the implicit output.

I had the ”a”b;@Ṅ part down, but I couldn't figure out where to go from there... now I know :-)

Java 7, 69 bytes
String c(int n,String a,String b){return n--<1?"":a+"\n"+c(n,b,a+b);}

ungolfed
 class fibb {

public static void main(String[] args) {
    System.out.println( c( 7, "a" , "b" ) );

}
static String c(int n,String a,String b) {

    return n-- < 1  ? "" : a + "\n" + c(n,b,a + b);

}
}

You really need to format your ungolfed code a bit more in your answers.. xD +1 though, and it even works for any other starting strings different than just a and b. I'm not sure if the "a" and "b" parameters should be counted towards the byte-count though, since the question specifically states it should use a and b. Not that Java will ever win anyway. ;)

@KevinCruijssen the string parameters are required because their values change each time the method is invoked.

@Snowman I know they are required.. I'm just saying that the byte-count should maybe be 75 bytes (+6 for "a" and "b") instead of 69 because the challenge specifically asked for a and b, and the code-snipped/method currently uses a variable input. Not sure what the rules are regarding something like this, but I personally think it should be counted. Otherwise you could in some languages have a function that executes a parameter function, and then simply give the entire challenge-function in the parameter without counting its bytes. Sounds like a standard-loophole type of rule.

I love Java answers. They stand out so nice - 12 bytes here, 5 there, 17 here... 70 bytes there... wait, what? Oh, it's Java again... +1

Emacs, 26, 25-ish keystrokes
Program
#n to be read as key with digit(s) n:
ARETBRETF3UPUPC-SPACEC-EM-WDOWNDOWNC-Y
UPC-AC-SPACEC-EM-WDOWNC-EC-YRETF4C-#(n-2)F4
Explanation
command(s)               explanation                      buffer reads (| = cursor aka point)
-----------------------------------------------------------------------------------------------
A<RET> B<RET>            input starting points            "a\nb\n|"
<F3>                     start new macro                  "a\nb\n|"
<UP><UP>                 move point two lines up          "|a\nb\n"
C-<SPACE> C-E M-W        copy line at point               "a|\nb\n"
<DOWN><DOWN>             move point two lines down        "a\nb\n|"
C-Y                      yank (paste)                     "a\nb\na|"
<UP>                     move point one line up           "a\nb|\na"
C-A C-<SPACE> C-E M-W    copy line at point               "a\nb|\na"
<DOWN>                   move point one line down         "a\nb|\na|"
C-E C-Y <RET>            yank (paste) and add new line    "a\nb|\nab\n|"
<F4>                     stop macro recording             "a\nb|\nab\n|"
C-#(n-3) <F4>            apply macro n-3 times            "a\nb|\nab\nbab\nabbab\n|"

With n=10
a
b
ab
bab
abbab
bababbab
abbabbababbab
bababbababbabbababbab
abbabbababbabbababbababbabbababbab
bababbababbabbababbababbabbababbabbababbababbabbababbab

I'm torn. On one hand, I always upvote editor-golf, but on the other hand I use vim. Oh well, +1 anyway. :)

@DrMcMoylex just convert it to vim with C-u M-x convert-to-vim

CJam, 19 17 bytes
'a'b{_@_n\+}ri*;;

explanation
"a": Push character literal "a" onto the stack.
"b": Push character literal "b" onto the stack.
{_@_p\+}
    {: Block begin.
    _: duplicate top element on the stack
    @: rotate top 3 elements on the stack
    _: duplicate top element on the stack
    n: print string representation
    \: swap top 2 elements on the stack
    +: add, concat
    }: Block end.
r: read token (whitespace-separated)
i: convert to integer
*: multiply, join, repeat, fold (reduce)
;: pop and discard
;: pop and discard

By the way, the number of strings is currently off by one; the last p should be a ;. You can get rid of the quotes around the output if you use n instead of p. Finally, 'a'b saves two bytes over "a""b".

V, 18 bytes
ia
bkÀñyjGpgJkñdj

Try it online!
Or, the more readable version:
ia
b<esc>kÀñyjGpgJkñdj

Explanation:
ia
b<esc>          " Insert the starting text and escape back to normal mode
k               " Move up a line
 Àñ       ñ     " Arg1 times:
   yj           "   Yank the current line and the line below
     G          "   Move to the end of the buffer
      p         "   Paste what we just yanked
       gJ       "   Join these two lines
         k      "   Move up one line
           dj   " Delete the last two lines

Python 2, 55 bytes
def f(n):m='a','b';exec'print m[-2];m+=m[-2]+m[-1],;'*n

MATL, 14 bytes
97c98ci2-:"yyh

Try it online!
97c     % Push 'a'
98c     % Push 'b'
i2-     % Input number. Subtract 2
:"      % Repeat that many times
  yy    %   Duplicate the top two elements
  h     %   Concatenate them

Retina, 33 bytes
.+
$*
^11
a¶b
+`¶(.+?)1
¶$1¶$%`$1

Try it online!
Saved 10 (!) bytes thanks to @MartinEnder!
Explanation
Converts the input to unary, subtracts 2 and adds the a and the b, then recursively replaces the remaining 1s with the concatenation of the two previous strings.

Saved a few bytes by avoiding unnecessary captures: http://retina.tryitonline.net/#code=LisKJCoKXjExCmHCtmIKK2DCtiguKz8pMQrCtiQxwrYkJWAkMQ&input=NQ

@MartinEnder Nice! Didn't quite see the power of $%` ! and that other capture was just bad planning... Amazing, thank you!

Stack my Golf, 63 bytes
Get my language here: https://github.com/cheertarts/Stack-My-Golf.
($1=(_(a))($2=(_(b))($2-f:1-f,)?)?)f\($1=(f)($1-p(\n),:f,)?)p\p

There is probably a shorter way but this is the most obvious.

Batch, 102 93 bytes
@set a=a
@set b=b
@for /l %%i in (2,1,%1)do @call:l
:l
@echo %a%
@set a=%b%&set b=%a%%b%

Fortunately variables are expanded for every line before assignments take effect, so I can set both a and b using their old values without needing a temporary. Edit: Saved 9 bytes thanks to @nephi12.

I was about to do this ;) By the way, you can save 8 bytes by removing the "exit/b" and starting your loop from 2: for /l %%i in (2,1,%1) etc..

One more (the newline) by putting the set commands on the same line @set a=a&set b=b like you did with the last one. though techncally they could all be on the same line... but that would be ugly... hmm...

Perl, 45 +1 = 46 bytes
+1 byte for -n flag
$a=a,$b=b;say($a),($a,$b)=($b,$a.$b)for 1..$_

Slight improvement over the existing 49-byte solution, but developed separately.  The parentheses for say($a) are necessary because otherwise, it interprets $a,($a,$b)=($b,$a.$b) as the argument of say which outputs more junk than we need.
Perl, 42 bytes
$b=<>;$_=a;say,y/ab/bc/,s/c/ab/g while$b--

A separate approach from the above solution:
$b=<>;                                       #Read the input into $b
      $_=a;                                  #Create the initial string 'a' stored in $_
           say                               #Print $_ on a new line
               y/ab/bc/                      #Perform a transliteration on $_ as follows:
                                   #Replace 'a' with 'b' and 'b' with 'c' everywhere in $_
                        s/c/ab/g             #Perform a replacement on $_ as follows:
                                   #Replace 'c' with 'ab' everywhere in $_
              ,        ,         while$b--   #Perform the operations separated by commas
                                   #iteratively as long as $b-- remains truthy

I'm not yet convinced I can't combine the transliteration and replacement into a single, shorter operation.  If I find one, I'll post it.

SOML, 8 bytes
 a b.{;t⁴+

explanation:
 a b.{;t⁴+                                        stack on 1st cycle
 a              push "a"                               ["a"]
   b            push "b"                               ["a","b"]
    .{          repeat input times                     ["a","b"]
      ;         swap the two top things on the stack   ["b","a"]
       t        output the top thing on the stack      ["b","a"]
        ⁴       copy the 2nd from top thing from stack ["b","a","b"]
         +      join them together                     ["b","ab"]

This language is still in development and I did add a couple new functions while writing this.
Also, 1st post on PPCG!

Welcome to PPCG! Great first post!

Perl, 36 35 bytes
Includes +3 for -n
Give count on STDIN
perl -M5.010 fibo.pl <<< 5

fibo.pl
#!/usr/bin/perl -n
$_=$'.s/1//.$_,say$`for(a1.b)x$_

Swift 3, 76 Bytes
func f(_ n:Int,_ x:String="a",_ y:String="b"){if n>1{print(x);f(n-1,y,x+y)}}

Perl, 48 bytes
47 bytes code + 1 for -n.
Simple approach. Try using an array slice originally $a[@a]="@a[-2,-1]" but that necessitates $"="" or similar :(. Save 1 byte thanks to @Dada!
@;=(a,b);$;[@;]=$;[-2].$;[-1]for 3..$_;say for@

Usage
perl -nE '@;=(a,b);$;[@;]=$;[-2].$;[-1]for 3..$_;say for@' <<< 5
a
b
ab
bab
abbab

You can save one byte by using @; instead of @a so you can omit the final semicolon (see what I mean?). (I know, one byte is pretty cheap but I didn't have any better idea..)

@Dada Yeah, I tried that, but it wound't compile on my machine, so I thought perhaps there's something odd going on with mine: perl -pe '@;=(a,b);$;[@;]=$;[-2].$;[-1]for 3..$_;say for@' <<< 5    syntax error at -e line 1, at EOF    Execution of -e aborted due to compilation errors. but didn't think it'd be fair to add as an answer if I couldn't get it working!

Sure this isn't related to the -pe instead of -nE ? Any way, it works on mine, so it's probably related to your perl version or system... But trust me, I tested it and it works! ;)

@Dada I get the same with -nE as well (don't know where -pe came from! Must be Friday...) I'll update that when I get a mo! Thanks for sharing!

PHP, 63 62 bytes
Recursive version:
function f($n,$a=a,$b=b){return$n--?"$a
".f($n,$b,$a.$b):'';}

unnecessary whitespace after return

C, 156 bytes (without indent)
void f(int n)
{
    char u[999]="a",v[999]="b",*a=u,*b=a+1,*c=v,*d=c+1,*e,i;
    for(i=0;i<n;++i)
    {
        printf("%s\n",a);
        for(e=c;*b++=*e++;);
        e=a;a=c;c=e;e=b+1;b=d;d=e;
    }
}

Two buffers (u & v) store the last two lines. The newest line (tracked with two pointers: start=c, end=d) is appended to the oldest one (start=a, end=b). Swap (a,b) and (c,d), and loop. Pay attention to buffer size before requesting too much lines.
Not so short (as expected of a low-level language), but was fun to code.

You hardcoded the 5 but it should be user input

Hmm... I do not see "user input" as a requirement in the puzzle... Following the same path as Perl, Python, C++, ... answers, replace "int main()" with "void f(int n)".

Given N (2 <= N), print N lines of the letter Fibonacci series like this (i.e. N = 5)

Well, user input was a bad choice in term of words. I meant more like dynamic N and not fixed. Or the user might be somebody who uses your function/program.

I've corrected a stupid mistake about not copying the nul terminator. I've also put the function in a more readable state (one liners are funny, but not handy). To actually test this function, use this : int main(int n, char**p){f(n<2?5:atoi(p[1]));return 0;}

I don't have an interpreter on me, but I think these things should work: Remove the void keyword before f, remove the int keyword before n; remove the char keyword, move the declarations after the char keyword to somewhere before the definition of f and prefix the string literals with L. Should reduce byte count by 12.

05AB1E, 15 bytes
'a'bVUFX,XYUYJV

Python 2, 56 bytes
a,b="ab"
for i in range(input()):
	print(a+b)
	a,b=b,a+b

Try it online!
Python 2, 44 bytes
a,b="ab"
exec"print(a+b);a,b=b,a+b;"*input()

Try it online!

Ruby (1.9+) 46 bytes
a,b=?a,?b;ARGV[0].to_i.times{puts a;a,b=b,a+b}

Pyth - 14 bytes
(yeah, another pyth answer)
A<G2VQG=H+~GHH

Try it online
Explanation
A<G2              - take "ab" from the var G, dump "a" into G and "b" into H.
    VQ            - for N in range(Q)
      G           - print G
          ~GH     - like =GH but returns the previous G
         +   H    - concatenate the old G with the current H
       =H         - put that value back into H

Actually, 16 bytes
There might be a shorter way to duplicate the top two elements of the stack in Actually, but I'm not sure what that way is. Golfing suggestions welcome. Try it online!
'a'b,¬`2╟2αio`na

Ungolfing
'a'b     Push "a" then "b" to the stack.
,        Explicitly take input n.
¬        Push n-2.
`...`n   Run the following function n-2 times.
  2╟2α     Push a list that repeats the top two elements of the stack twice.
  i        Flatten that list to the stack. Stack: b, a, b, a, prev_iterations
  o        Append b to the end of a. Stack: ab, b, a, prev_iterations
a        Reverse the stack so that the strings will print in the correct order.
         Implicit print all of the elements in the stack.

A different approach
This is also 16 bytes.
Try it online!
'a'b,¬`│ok╔Ri`na

Ungolfing
The main difference is the function in the middle, so I'll only ungolf that here.
`...`n   Run the following function n-2 times.
  │        Duplicate the stack.
  o        Append the last item to the end of the second-to-last item.
  k╔       Uniquify the stack by wrapping the stack in a list and then calling uniquify().
  Ri       Reverse that list before returning everything to the stack
            so that the last items are at TOS again.

Java 8 40 bytes
Same answer as @Numberknot only written as a lambda in Java 8 which makes it smaller.
c=(n,a,b)->n--<1?"":a+"\n"+c.f(n,b,a+b);

Ungolfed version:
interface Function
{
    String f(int n, String a, String b);
}

public class Main
{
    static Function c; //c needs to be a member or static variable in order
                       //to reference it recursively inside the lambda

    public static void main(String[] args)
    {
        c=(n,a,b)->n--<1?"":a+"\n"+c.f(n,b,a+b);
    }
}

Pyth, 17 bytes
J,\a\bjP.U=+Js>2J

A program that takes input of an integer and prints the result.
Try it online!
How it works
J,\a\bjP.U=+Js>2J  Program. Input: Q
 ,\a\b             Yield the two element list ['a', 'b']
J                  Assign to J
        .U         Reduce over [0, 1, 2, 3, ..., Q] (implicit input):
          =J+        J = J +
              >2J     the last two elements of J
             s        concatenated
       P           All of that except the last element
      j            Join on newlines
                   Implicitly print

Pyth - 16 15 bytes
A"ab" m=H+
~GHH

Try it online here.

APL, 30 bytes.
⎕IO must be 1.
{⎕←⍵}¨{⍵∊⍳2:⍵⌷'ab'⋄∊∇¨⍵-⌽⍳2}¨⍳

Mathematica, 49 bytes
f@1="a";f@2="b";f@n_:=f[n-2]<>f[n-1];g=f~Array~#&

Defines a function g taking the single numerical input; returns a list of strings. Straightforward recursive implementation, using the string-joining operator <>.
Mathematica, 56 bytes
NestList[#~StringReplace~{"a"->"b","b"->"ab"}&,"a",#-1]&

Unnamed function, same input/output format as above. This solution uses an alternate way to generate the strings: each string in the list is the result of simultaneously replacing, in the previous string, all occurrences of "a" with "b" and all occurrences of "b" with "ab".

PHP, 61 57 bytes
<?=$c=a;for($b=b;--$argv[1];$b=$c.$b,$c=$a)echo"
",$a=$b;

come php 7.1 you can save 3 bytes by changing to: an "old" version that I wish was short:
<?=$a=a;for($b=b;--$argv[1];[$a,$b]=[$b,$a.$b])echo"
$b";

If a trailing new line is acceptable then:
for($b=b;$argv[1]--;$a=$b,$b=$c.$b)echo$c=$a?:a,"
";

is only 52 bytes.
edit: 4 bytes saved (on both usable versions) thanks to Titus.

You do not have to use open tags unless there's a full program requirement :)

@chocochaos I know, but i'm using it to print the first a and <?= is shorter than echo. I can do better if a trailing new line is fine and will edit the answer to that effect.

save 4 bytes on your 1st version <?=$c=a;for($b=b;--$argv[1];$b=$c.$b,$c=$a)echo"\n",$a=$b; and 4 bytes on your 3rd version for($b=b;$argv[1]--;$a=$b,$b=$c.$b)echo$c=$a?:a,"\n";

@Titus thanks, that's really clever, I'll pay attention to that in the future!

Groovy, 79 Bytes
{println("a\nb");x=['a','b'];(it-2).times{println(y=x.sum());x[0]=x[1];x[1]=y}}

C++11, 89 98 bytes
+7 bytes for all lines, not only the last one. +2 bytes more for N being the number of lines printed, not some 0-based stuff.
#include<string>
using S=std::string;S f(int n,S a="a",S b="b"){return n-1?a+"\n"+f(n-1,b,a+b):a;}

Usage:
f(5)

PHP, 53 bytes
for($a=b,$b=a;$argv[1]--;$a=($_=$b).$b=$a)echo$b.'
';

save one byte by using double quotes and putting $b in the string.

R, 82 bytes
This can surely be golfed.
x=c("b","a");for(i in 2:scan()-2)x=c(paste0(x[2],x[1]),x);cat(rev(x[-1]),sep="\n")

C#, 142 Bytes
Edit: only had it printing the last line out... V2:
Golfed:
string L(int n){var r=new List<string>(){"a","b"};int i=3;while(i<=n){r.Add(string.Concat(r[i-3],r[i-2]));i++;}return string.Join("\r\n", r);}

Ungolfed:
public string L(int n)
{
  var r = new List<string>() { "a", "b" };

  int i = 3;

  while (i <= n)
  {
    r.Add(string.Concat(r[i-3], r[i-2]));
    i++;
  }

  return string.Join("\r\n", r);
}

Test:
var printALetterFibonacci = new PrintALetterFibonacci();
Console.WriteLine(printALetterFibonacci.L(5));

a
b
ab
bab
abbab

var printALetterFibonacci = new PrintALetterFibonacci();
Console.WriteLine(printALetterFibonacci.L(7));

a
b
ab
bab
abbab
bababbab
abbabbababbab

This just returns the final line, you should print/output the (N-1) lines leading up to it as well.

@HaraldKorneliussen I missed that in the post, corrected now, thanks :)

GNU sed, 43 Bytes
Includes +2 for -rn.
s/1/a\nb\n/
:
P
s/(.*)\n(.*\n)./\2\1\2/
t

Takes input in unary (see this consensus).
Try it Online!
Explanation:
s/1/a\nb\n/              # prepend an 'a' and a 'b' on their own lines and remove a '1'
:                        # nameless label
P                        # print everything before the first newline
s/(.*)\n(.*\n)./\2\1\2/  # replace the first two lines and the next character
                         # (one of the '1's) with the second line then the first line
                         # concatenated with the second
                         # E.g.
                         #     a           b
                         #     b      ->   ab
                         #     11111       1111
t                        # loop to the label if there was a '1' left (i.e. there was
                         # a substitution)

Powershell 1.0+, 41 51 :( Bytes
$x,$y='a','b';0..(read-host)|%{$x;$x,$y=$y,($x+$y)}

4 *nix goto https://github.com/PowerShell/PowerShell
Corrected for user input :)

Welcome to PPCG! This answer doesn't look like it takes input -- instead it just always prints out the first 10 results.

Hi TimmyD, thats right, but you can alter the amount of lines here :) 0..N

I did not really figure out if it is needed to ask the user for Input in the question, but I can extend it for user Input ;)

Yes, you'll need to take input via a standard input method. For this, something like 0..$args[0] and having the input be a command-line parameter would probably be shortest.

Unfortunately i found only (read-host) then it would be like:

that 1..(read-host) which is too long.
except giving alias before is alowed ;)

Thunno d, \$17\log_{256}(96)\approx\$ 13.99 bytes
'aX'bYR{xDZKyAx+Y

Attempt This Online!

Japt -R, 12 bytes
@Zä+ Ì}ha¬pb

Try it

Thunno 2 --, 11 bytes
'aß'bß${Ɓ+ß

Try it online!
Given n, prints the first n terms (as the challenge asks).
Thunno 2, 7 bytes
`abdµµ+

Attempt This Online!
Prints the infinite sequence (probably not allowed).
Explanation
'aß'bß${Ɓ+ß  # Implicit input
'aß         '# Print "a" without popping
   'bß      '# Print "b" without popping
      ${     # Repeat (input - 2) times:
        Ɓ    #  Without popping,
         +   #  concatenate the last two items
          ß  #  Print without popping

`abdµµ+  # Full program
`abd     # Starting from ["a", "b"],
    µµ   # construct an infinite sequence
      +  # by concatenating the last two terms
         # Implicit output

Javascript (ES6), 35 bytes
f=v=>v&&v-1?f(v-2)+f(v-1):v?'b':'a'

Can you make use of 'ab'[v]?

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
1, 2, 3, 4, 5, Shaggy
This is my first code golf exercise for you:
Your input is two integers n and k. You can assume n >= 1 and k >= 1
You have to output all numbers from 1 to n (inclusively) and replace every element that is a multiple of k or that contains k with "Shaggy".
you can take the input in any convenient form and output it in a human readable form (seperators can be whitespaces, commas or whatever)
Standard loop holes are forbidden. Functions or programs are acceptable. Shortest code in byte wins!
This is different from the "Bzzt"-game, as this takes a variable "Bzzt" parameter, which, for values>=10, may increase the difficulty in some languages.
Examples:
Input: 20 6
Output: 1 2 3 4 5 Shaggy 7 8 9 10 11 Shaggy 13 14 15 Shaggy 17 Shaggy 19 20

Input: 21 4
Output: 1 2 3 Shaggy 5 6 7 Shaggy 9 10 11 Shaggy 13 Shaggy 15 Shaggy 17 18 19 Shaggy 21

Input: 212 11
Output: 1 2 3 4 5 6 7 8 9 10 Shaggy 12 13 14 15 16 17 18 19 20 21 Shaggy 23 24 25 26 27 28 29 30 31 32 Shaggy 34 35 36 37 38 39 40 41 42 43 Shaggy 45 46 47 48 49 50 51 52 53 54 Shaggy 56 57 58 59 60 61 62 63 64 65 Shaggy 67 68 69 70 71 72 73 74 75 76 Shaggy 78 79 80 81 82 83 84 85 86 87 Shaggy 89 90 91 92 93 94 95 96 97 98 Shaggy 100 101 102 103 104 105 106 107 108 109 Shaggy Shaggy Shaggy Shaggy Shaggy Shaggy Shaggy Shaggy Shaggy Shaggy 120 Shaggy 122 123 124 125 126 127 128 129 130 131 Shaggy 133 134 135 136 137 138 139 140 141 142 Shaggy 144 145 146 147 148 149 150 151 152 153 Shaggy 155 156 157 158 159 160 161 162 163 164 Shaggy 166 167 168 169 170 171 172 173 174 175 Shaggy 177 178 179 180 181 182 183 184 185 186 Shaggy 188 189 190 191 192 193 194 195 196 197 Shaggy 199 200 201 202 203 204 205 206 207 208 Shaggy 210 Shaggy 212

must it be a full program or may it be a function? and does "1 to n" include both endpoints?

full program or function. 1 to n is inclusively.

Clear spec, but a bit simple (which is where the downvotes are coming from).  Regardless, welcome to the site!

Thanks. Too me, it was not so simple to determine if a number like 1621 contains the forbidden number "6". At least not very golfy.

I'd definitely have a test case where k >= 10.

Hi @infinitezero and welcome. You may want to try posting in the sandbox first next time to get some feedback on your challenge.

added the bigger test case.
Thanks for pointing me to the sandbox :)

This extends it to a variable k, not only 3 and allows for k > 10, which might be a little more difficult.

@infinitezero It's still very similar. That's why it says "Possible dupelicate" (emphasis mine).

Not really convinced that this is a duplicate. The question linked to specified 3 as the replaceable number and also specifies 500 as a max. This one requires inputs for the replaceable and the max. Similar? Sure. Duplicate? Not convinced. IMHO

@ElPedro, It's a duplicate in the since that answer from one question can be copied with little to no modification and still be competative. Replace coded numbers with variables and your done in most cases.

Pyth, 25 23 bytes
m?|!%dQ}`Q`d"Shaggy"dSE

A program that takes input of two newline-separated integers k, n and prints a list.
Try it online!
How it works
m?|!%dQ}`Q`d"Shaggy"dSE  Program. Inputs: Q, E
m                    SE  Map over [1, 2, 3, 4, ..., E] with varaible d:
 ?                         If
    %dQ                    d % Q
   !                       negated is truthy (divisible by H)
  |                        or
        `Q                 str(Q)
       }                   is in
          `d               str(d):
            "Shaggy"         Yield "Shaggy"
                           Else:
                    d        Yield d
                           Implicitly print

Python 2, 64 63 bytes
Anonymous function with arguments n and k, returns the list to output.
lambda n,k:[[i,'Shaggy'][i%k<1or`k`in`i`]for i in range(1,n+1)]

Alternatively, a function which prints to STDOUT for the same bytecount:
def f(n,k,i=1):exec"print[i,'Shaggy'][i%k<1or`k`in`i`];i+=1;"*n

Just spent 15 minutes fighting with this one in Python but I think I was missing the obvious. Nice answer.

sometimes, the shortest solutions are the simplest :) but I liked your recursive solution too @ElPedro

Thanks. Shame the input was specified as two integers otherwise I could have used def f(a,b,c) and called it using f(a,b,1) and only been 8 bytes behind you ;-)

SQL (PostgreSQL flavour), 130 136 bytes
Done as a prepared statement:
prepare p(int,int)as select CASE WHEN i%$2=0or i::char like'%'||$2||'%'THEN'Shaggy'else i::char end from generate_series(1,$1)a(i)

This is executed in the following manner
execute p(20,6)

and the result is output as rows.

Lua, 71 70 Bytes
Saved a byte thanks to Flp.Tkc
Getting in before Jelly or Pyth or similar can swoop in and destroy my byte count.
a,b=...for i=1,a do print(((i..""):find(b)or i%b<1)and"Shaggy"or i)end

Ungolfed with comments
local a,b = ...                         -- Command Line Input
for i=1, a do                           -- For all numbers between 1 and a
    print(                              -- Print with newlines...
            ((i..""):find(b) or i%b<1)  -- if the String version of i contains b, or if the remainder when i is divided by b == 0
            and "Shaggy"                -- then Shaggy
            or i                        -- Else i
        )
end

could you use i%b<1 to save a byte?

I could use i%b<1, which I will do. Thanks. (<0 will always return false)

haha sorry i meant to put a 1 there

Python 2, 74 72 bytes
Having already been soundly beaten by @Flp.Tkc I'll just post my 74 72 byte recursive solution because it's different and it works and not because it will win (and also because I like recursive functions).
def f(a,b,c=1):
 print(c,"Shaggy")[c%b<1or`b`in`c`]
 if c<a:f(a,b,c+1)

Edit
-2 by removing the unneeded `` around the c in the print statement
From comments:
Call using
 f(a,b)

c will default to 1 due to the
 c=1

in the function definition and can then be incremented for the recursive function calls.

Am I confused, or do you never need to assign to c?

The function call is f(a,b). c defaults to 1 because of the c=1 in the function definition. That means I can use c in the first run without having to add it to the function call (Python functions accept optional keyword args). I can then increment it on the recursive function calls and its value on the recall overrides the default. Hope that makes it clear. Took me a while to get to grips with it :)

Basically it means that c starts with a default value of 1 and I just add 1 to it every time I call the function while c<a

My pleasure. Always happy to (try to) explain :)

Explanation added to my answer for info.

C, 122 bytes
f(n,k){int m,i;for(i=1;i<=n;++i){if(i%k){for(m=i;m>0;m/=10)if(m%10==k)goto l;printf("%d ",i);continue;}l:puts("Shaggy");}}

Newlines and spaces both act as separators.

C#, 97 bytes
n=>k=>{var r="";for(int i=1;i<=n;i++)r+=i%k>0&&(i+"").IndexOf(k+"")<0?i+" ":"Shaggy ";return r;};

Full program with ungolfed method and test cases:
using System;

namespace Shaggy
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<int,Func<int,string>>f= n=>k=>
            {
                var r = "";
                for(int i = 1; i <=n ; i++)
                    r += i % k > 0 && (i + "").IndexOf(k + "") < 0 ? i + " " : "Shaggy ";
                return r;
            };

            Console.WriteLine(f(20)(6));
            Console.WriteLine(f(21)(4));
            Console.WriteLine(f(212)(11));
        }
    }
}

Hi, you could golf it to this: n=>k=>{var r="";for(int i=0;++i<=n;)r+=i%k<1|(i+"").Contains(k+"")?"Shaggy ":i+" ";return r;}; (94 bytes)

C, 98 96 bytes
n,h[],t[];s(i,j){for(;n<=i;n&&puts(!strstr(t,h)&&n%j?t:"Shaggy"),n++)sprintf(n?t:h,"%d",n?n:j);}

Wandbox