Problem Make a program that, given an integer of reasonable size, outputs the greatest prime factor of that integer, in binary, but with all 0s replaced with underscores (_) and all 1s replaced with minus signs (-).
class C{public static void main(String[]a){long x=Long.decode(a[0]),i=x;while(i-->2)x=(x%i)==0?i:x;System.out.print(Long.toString(x,2).replace('0','_').replace('1','-'));}}
2
3298
185
8/3/2014 6:16:11 PM
Spoiler For Spoiler:
class G{public static void main(String[]c){int n=Integer.parseInt(c[0]),i=2;while(i<n)if(n%i==0)n/=i;else++i;System.out.print(Integer.toString(n,2).replace('0','_').replace('1','-'));}}
TI-83+ z80
Rank
User
Size
Date
Code
1
Runer112
58
8/3/2014 2:17:19 PM
Spoiler For Spoiler:
;#SECTION "MAIN", CODE
org userMem - 2 db 0BBh, 6Dh Start: B_CALL _RclAns B_CALL _ConvOP1 ld h, d ld l, e TrialDivideLoop: push de push hl B_CALL _DivHLByDE ld a, h or l pop hl pop de jq nz, NotFactor ld h, d ld l, e NotFactor: dec de ld a, e dec a or d jq nz, TrialDivideLoop ld b, h ld c, l ld hl, OP1 + 15 ld (hl), d BitLoop: dec hl srl b rr c ld (hl), '_' jq nc, BitUnset ld (hl), '-' ld d, h ld e, l BitUnset: jq nz, BitLoop ex de, hl B_CALL _PutS B_CALL _NewLine ret
XTend
Rank
User
Size
Date
Code
1
3298
179
8/3/2014 6:16:11 PM
Spoiler For Spoiler:
class G{def static void main(String[]c){var n=Integer.parseInt(c.get(0))var i=2while(i<n)if(n%i==0)n=n/i else i=i+1print(Integer.toString(n,2).replace('0','_').replace('1','-'))}}
Language Ranking
Rank
Lang
User
Size
Date
1
CJam
Runer112
16
8/3/2014 2:17:19 PM
2
Golfscript
Runer112
33
8/3/2014 2:17:19 PM
3
TI-83+ z80
Runer112
58
8/3/2014 2:17:19 PM
4
SysRPL
3298
59.5 (don't ask me why; I'm going off of what he said)
Welcome to the forums! You somehow remind me of the guy who registered and made a new topic just so he could get a solution to a level in Portal Prelude.
Anyways, so yeah, unless you post 4 more times AND PM me your solutions by the end of the day, I'll PM you with my email.
You know what? Let's just assume no trailing, leading, or repeating spaces, and all alphanumeric characters. That would bring my solution down from 465 bytes to about 280 bytes.
Can we get some official clarification on input format, JWinslow23/willrandship? The main questions that come to mind are:
Are words/clusters composed of alphanumeric characters, any printable characters, or something in between?
Are leading, trailing, or duplicated (successive) spaces valid?
A good way to solidify all of these rules at once could be to specify a regular expression for valid input.
Well, if you use regular expressions, now you got TWO problems.
Words are made up of any printable characters except for the space. Trailing, leading, and repeating spaces are valid, but shall be deleted so there is only one space between words upon output.
s,n="",0 for w in clipboard.getText():gmatch"%S+"do if tonumber(w)then n=n+w else s=w.." "..s end end print(s..n)
2
LDStudios
162
7/23/2014 3:30:25 PM
Spoiler For Spoiler:
i="" p={} function on.charIn(h) s="" i=i..h p=i:split(s) n=0 for i,v in ipairs(p) do if v:find("%a") then s=v.." "..s elseif v:find("%d") then n=n+v end end print(i) print(s..n) end
Python3
Rank
User
Size
Date
Code
1
willrandship
83
7/22/2014 3:08:29 PM
Spoiler For Spoiler:
s=0;o='' for w in input().split(): try:s+=int(w) except:o=o+w+" " print(o+str(s))
Java
Rank
User
Size
Date
Code
1
Runer112
174
7/27/2014 12:27:24 PM
Spoiler For Spoiler:
class B{public static void main(String[]a){int x=0,i=a.length;while(i>0)try{x+=Integer.parseInt(a[--i]);}catch(Exception e){System.out.print(a+' ');}System.out.print(x);}}
public class Main{public static void main(String[] args){String s="";int i=0;for(String t:args[0].split(" ")){try{i+=Integer.parseInt(t);}catch(Exception e){s=t+" "+s;}}s+=i;System.out.println(s);}}
CJam
Rank
User
Size
Date
Code
1
Runer112
27
7/27/2014 12:27:24 PM
Spoiler For Spoiler:
qS%W%0\{_:i:|'A<{~+}{S@}?}/
XTend
Rank
User
Size
Date
Code
1
3298
159
7/27/2014 1:58:00 PM
Spoiler For Spoiler:
class G{static var n=0;def static void main(String[]c){println(c.get(0).split(" ").fold("")[s,i|try{n=n+Integer.parseInt(i);s}catch(Exception _){i+" "+s}]+n)}}
Haskell
Rank
User
Size
Date
Code
1
3298
138
7/27/2014 1:58:00 PM
Spoiler For Spoiler:
import Text.Read g c=(fst f)++show(snd f)where f=foldr(\i(s,n)->case readMaybe i of Nothing->(s++i++" ",n);Just m->(s,n+m))("",0)(words c)