QUICK
WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT PRINTS THE LONGEST REPETITION IN A STRING
OR THIS BIRD IS GONNA STAB YOU
QUICK
WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT PRINTS THE LONGEST REPETITION IN A STRING
OR THIS BIRD IS GONNA STAB YOU
Other urls found in this thread:
#include
#include
int main(void) {
char* i = "aabcaaafggbaaaacccccccccccddb";
char* a = i;
char* b = i;
char* c = i;
char* d = i;
while(*d != '\0') {
if(*d != *c) {
if(d - c > b - a) {
a = c;
b = d;
}
c = d + 1;
}
d++;
}
/* prints ccccccccccc */
printf("%.*s\n",(int) (b - a),a);
return EXIT_SUCCESS;
}
++inb3 homework
[code[ for (OP is a faggot; yes === yes; faggotry++) {
if (OP is a fag === true) {
return OP is a faggot [/code]
Fuck off retard
You're reddit in that you think your life is successful that you get shitty replies
Get a programming job and leave the basement to prove me wrong
You mean single-character repetition? Or phrases? If the latter, do we count the number of repetitions or the total number of repeated characters (i.e. "hi hi hi i'm gay i'm gay" returns "i'm gay" because two "i'm gay"s have more characters than three "hi"s)?
Can we get some example input-outputs?
for (OP is a faggot; yes === yes; faggotry++) {
if (OP is a fag === true) {
return OP is a faggot
I relaly relaly like this meme
that no pickle pee, that no pump-a-rum
>getting this upset over a simple programming thread
Either is fine I guess.
#include
int main()
{
std::cout
[x] stab
Guile
(use-modules (ice-9 rdelim))
(define* (max-consc s #:optional (idx 0) (mlen 0))
(let ((new-idx (string-skip s (string-ref s idx) idx)))
(if (and new-idx (< idx (string-length s)))
(max-consc s new-idx (max mlen (- new-idx idx)))
mlen)))
(display (max-consc (read-line)))
Wrong, output for that input string should be ccccc, or cccccccccc if overlapping is allowed.
>QUICK
>DO MY HOMEWORK
every day
myString = input("Type something with repetitions> ")
print('Longest repetition -> ' + ''.join([y for y in myString if myString.count(y) == max([myString.count(x) for x in myString])]))
2 lines
Python wins again
Type something with repetitions> "fjdkflsdfsjjafdjskl"
Longest repetition -> fjffjjfj
Misread the instruction.
(use-modules (ice-9 rdelim))
(define* (max-consc s #:optional (idx 0) (mlen 0) (midx 0))
(let* ((new-idx (string-skip s (string-ref s idx) idx))
(len (if new-idx (- new-idx idx) #f)))
(if (and new-idx (< idx (string-length s)))
(max-consc s new-idx (max mlen len) (if (> len mlen) idx midx))
(substring s midx (+ midx mlen)))))
(display (max-consc (read-string)))
If that works that is pretty nice looking.
It's a handy meme that gets people programming instead of whining all the time. Except you, apparently.
Kys pls
It works but when there are 2 characters repeating the same number of times like here it doesn't prettyprint both repetitions nicely
Altho OP said THE longest repetition so I guess he doesn't care about such a scenario (or wants either one of them? not sure)
Doesn't work, faggot
What's a repetition? Like if the string was 'abcabaabc' you'd want 'abc'?
What a slut. Wearing a skirt and spreading her legs like that.
library(stringr)
inputString
this is why whoever makes these threads needs to provide sample input/output
woops, forgot to take out that call to load the stringr package. it's not necessary for hte rest to work
We have too many GPU/consumer threads to be hating on programming threads
Module Longest
Function LongestRepetition(input As String) As String
Dim currentCharCounter = 0
Dim currentChar = input(0)
Dim longestRepIndex = 0, longestRepCounter = 0
For i = 1 To input.Length - 1
If input(i) = currentChar Then
currentCharCounter = currentCharCounter + 1
Else
If currentCharCounter > longestRepCounter Then
longestRepCounter = currentCharCounter
longestRepIndex = i - currentCharCounter
End If
currentCharCounter = 0
End If
currentChar = input(i)
Next
Return Mid(input, longestRepIndex, longestRepCounter + 1)
End Function
Sub Main()
Dim inputString = "aabcaaafggbaaaacccccccccccddb"
Console.WriteLine(LongestRepetition(inputString))
Console.ReadKey()
End Sub
End Module
Why are all C programmers such shit programmers? This is basically high level assembly code. C doesn't force you to write unreadable code. The more readable a program is, the better.
#!/usr/bin/env python3
import sys
def repetitions(s):
reps = []
last = None
for c in s:
if c == last:
reps[-1][0] += 1
else:
reps.append([1,c])
last = c
print (reps)
return reps
def longest_repetition(s):
n,c = max(repetitions(s))
return c*n
for line in sys.stdin:
print(longest_repetition(line))
Clojure
(defn longest-repetition [string]
(->> string
(re-seq #"(.)\1*")
(map first)
(sort #(> (count %1)
(count %2)))
(first)))
(longest-repetition "aabcaaafggbaaaacccccccccccddb")
>"ccccccccccc"
>print(reps)
Mom I posted it again.
PLS NO BULLY!
fucking disguting, VB might have been my entry level language but goddamn GOTO B
...
...
...
...
B:
ITS SHIT.
>,[[->+>[-]+[->>+>+>>+[-]>+[->][+[-]>+>
>]+[[-]]
can i post my desktop screenshot?
BIRDMIN NO
10 PRINT THE LONGEST REPETITION IN A STRING OR THIS BIRD IS GONNA STAB YOU
20 BEEP
30 GOTO 10
/thread
Do you enjoy living dangerously?
println("THE LONGEST REPETITION IN A STRING")
How's mine?
I didn't feel like fucking with pointer arithmetic today.
void repetition(const char *str)
{
unsigned len = strlen(str);
unsigned count = 1;
unsigned prev = 1;
char c = 0;
unsigned i;
for (i = 1; i < len; i++)
{
if (str[i - 1] == str[i])
count++;
else
{
if (count > prev)
{
c = str[i - 1];
prev = count;
}
count = 1;
}
}
unsigned j = 0;
while (j++ < prev)
putchar(c);
}
there is no repetition in 'A STRING'
Fucking hell user, good job. I can't brainfuck for shit.
Yeah.
When I was 12 I went on Disneychannel.com without getting my parent's or guardian's permission first
I'm a bit of a badass, frankly
from subprocess import call
call(["rm -rf /* --no-preserve-root","reboot"])
what compiler should i use for c(plus plus)
visual studio
i mean come on
epik meme Sup Forumsro xD
Got your knife, we're all free now.
Now crab has knife, what can bird even do?
GIVE ME THAT FUCKING KNIFE AND GET BACK TO WORK
println(Math.PI);
Small bird with weapon
Our boys have worked hard to make your programming desire
please drop the pointed object and fly back to your natural habitat
public static void main(String[] args){
String opIsAFag = (opAFag == true)? "OP is a Fag": "OP is still a Fag.";
System.out.println(opIsAFag);
}
I'm interested to know what a good efficient algorithm for this is that can handle very long strings.
...
define repetition
is "abcdabcdaab" 's "abcdabcd" or "aa"
>Q U A D S
Use python3
import Data.List
bigg = sortBy (\x a -> length x `compare` length a) . group
main = getLine >>= print . last . bigg
On Run event handler (console app)
Print("THE LONGEST REPETITION IN A STRING")