Hey /g/, I'm a total newbie trying to make a simple code on C++ that counts the number of time the largest digit of a number repeated itself as an assignment in school, but I can't seem to get it right. Can anybody help me?
Here's the code if anyone's interested
http://pastebin.com/h15HBW47
>>51243893
/g/ is not for assignment solving, but I have one advice for you: your program is basically the translation of the procedure that you mentally use to solve the problem by hand. If you have no idea how to solve the problem by hand, you won't go far in your program.
>>51243893
What the guy above me said except I was super bored.
http://pastebin.com/k44ryMnu
>>51243893
The problem is easy, but C++ isn't the right language for it. It's more suited for a functional language. By recursion you can construct a list (or ordered binary tree, for more efficiency in finding the latest digit) of digits given a number, and you can then analyze that list.
Here's a quick implementation in Scheme, assuming you have remainder and integer quotient procedures defined:(define (digit-list n)
(cond ((< n 10) (list n))
(else (cons (remainder n 10) (digit-list (quotient n 10))))))
(define (max-element list)
(if (null? (cdr list))
(car list)
(max (car list) (max-element (cdr list)))))
(define (count-in element list)
(cond ((null? list) 0)
((= element (car list)) (1+ (count-in element (cdr list)))
(else (count-in element (cdr list)))))
(define (problem number)
(let ((digits (digit-list number)))
(count-in (max-element digits) digits)))
t. sicp pro
>>51243893
>int _tmain
stopped reading there
>>51244062
This is infinitely more readable than OP's.
Hello everyone. I have been wanting to learn how to use java script/coding and so on. so far i know how to lock files using java is there any schools i can go to. I would like to know more about it
>>51244261
Codecademy
"Head first" books
"Learn X the hard way"
TheNewBoston (YT channel and website)
These and more are good starters
Thank you very much.
and is The onion router a good thing to use?
>>51244238
I was going to give tips on how to make his code work instead of writing an implementation of my own... until I saw it.
>>51244214
>FP
>or how to kill flies with nuclear bombs
OPs required function in java, ultrareadable
>inb4 java sucks
I already know java sucksprivate static long function(long number) {
List<Integer> digits = new ArrayList<Integer>();
while(number != 0) {
digits.add((int) (number % 10));
number /= 10;
}
Integer largest = digits.stream().max(Comparator.<Integer>naturalOrder()).get();
long count = digits.stream().filter(integer -> integer.equals(largest)).count();
return count;
}
Does anyone here use Tor?
>>51244479
You seem to be lost, the thread you're looking for is /sqt/.
Yes i am very lost right now i would look to know where i have stumbled on to