QUICK
WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT PRINTS THE LONGEST REPETITION IN A STRING
OR THIS BIRD IS GONNA STAB YOU
#include <stdio.h>
#include <stdlib.h>
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
>>55541527
[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
>>55541527
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?
>>55541527for (OP is a faggot; yes === yes; faggotry++) {
if (OP is a fag === true) {
return OP is a faggot
>>55541527
I relaly relaly like this meme
>>55541527
that no pickle pee, that no pump-a-rum
>>55541576
>getting this upset over a simple programming thread
>>55541582
Either is fine I guess.
>>55541527#include <iostream>
int main()
{
std::cout << "THE LONGEST REPETITION IN A STRING" << std::endl;
return 0;
}
>>55541812
[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)))
>>55541540
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
>>55541976Type something with repetitions> "fjdkflsdfsjjafdjskl"
Longest repetition -> fjffjjfj
>>55541875
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)))
>>55541976
If that works that is pretty nice looking.
>>55541576
It's a handy meme that gets people programming instead of whining all the time. Except you, apparently.
Kys pls
>>55542174
It works but when there are 2 characters repeating the same number of times like here >>55542155 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)
>>55541976
Doesn't work, faggot
>>55541527
What's a repetition? Like if the string was 'abcabaabc' you'd want 'abc'?
>>55541631
What a slut. Wearing a skirt and spreading her legs like that.
library(stringr)
inputString <- "hi there this is a string aaa"
stringSplit <- strsplit(inputString,"")[[1]]
outputMatch <- NULL
while (eachNum in length(stringSplit) : 1) {
pattern <- paste("(.)\\1{",eachNum-1,"}")
splitAttempt <- strsplit(inputString,pattern)
if (length(splitAttempt[[1]]) > 1) {
outputMatch <- gregexpr(pattern,inputString)
output <- paste(stringSplit[(outputMatch[[1]][1]) : (outputMatch[[1]][1] + eachNum - 1),sep="")
break
}
}
print(output)
should work even if the repeated character is a space. won't return more than one match equal to the maximum length (returns the first valid match)
>>55542267
this is why whoever makes these threads needs to provide sample input/output
>>55542301
woops, forgot to take out that call to load the stringr package. it's not necessary for hte rest to work
>>55541576
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
>>55541540
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"
>>55542572
>print(reps)
>>55541933
Mom I posted it again.
>>55543043
PLS NO BULLY!
>>55542500
fucking disguting, VB might have been my entry level language but goddamn GOTO B
...
...
...
...
B:
ITS SHIT.
>>55541527
https://play.golang.org/p/uxXyqOZVb8
>,[[->+<<->]+<[[-]>->>[-]<<<]>>[-<<+
>>]<[->>+<<]>>[-<+>>>+<<]>[-<+>>>+<<
]>[>>>+<<[->>[-]>+<<<]>>[-<+>]>[-<<<
+>>>]<<<-<-]>[-]>[-<<<<[-]<[->+>+<<]
>>[-<<+>>]>>>]<<<<[->+<]<[->+<]<,]>>
>+>++++++++++<[->-[>+>>]>[+[-<+>]>+>
>]<<<<<]>>>[->+>+<<]++++++++++++[-<+
+++>>++++<]>>[[-]<.>]<<<.
>>55541527
can i post my desktop screenshot?
BIRDMIN NO
>>55541527
10 PRINT THE LONGEST REPETITION IN A STRING OR THIS BIRD IS GONNA STAB YOU
20 BEEP
30 GOTO 10
>>55543325
/thread
>>55543325
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'
>>55543252
Fucking hell anon, good job. I can't brainfuck for shit.
>>55544022
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
>>55541527from subprocess import call
call(["rm -rf /* --no-preserve-root","reboot"])
what compiler should i use for c(plus plus)
>>55544504
visual studio
i mean come on
>>55544208
epik meme /b/ro xD
>>55541527
Got your knife, we're all free now.
>>55544748
Now crab has knife, what can bird even do?
>>55544770
>>55544748
GIVE ME THAT FUCKING KNIFE AND GET BACK TO WORK
println(Math.PI);
>>55541527
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);
}
>>55541527
I'm interested to know what a good efficient algorithm for this is that can handle very long strings.
>>55541527
>>55541527
define repetition
is "abcdabcdaab" 's "abcdabcd" or "aa"
>>55542222
>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")